From ee32a69f9a7f25c37757325dc28ac7b5127dceca Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 15 十月 2019 22:23:36 +0800
Subject: [PATCH] datamanage-update

---
 src/tabviews/datamanage/index.jsx |  100 ++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 76 insertions(+), 24 deletions(-)

diff --git a/src/tabviews/datamanage/index.jsx b/src/tabviews/datamanage/index.jsx
index c61ee55..444dbf5 100644
--- a/src/tabviews/datamanage/index.jsx
+++ b/src/tabviews/datamanage/index.jsx
@@ -1,7 +1,9 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
 import { is, fromJS } from 'immutable'
+import {connect} from 'react-redux'
 import { BackTop, notification } from 'antd'
+import {refreshTabView} from '@/store/action'
 import Api from '@/api'
 import DataSearch from './modules/search'
 import DataAction from './modules/action'
@@ -11,9 +13,10 @@
 import enUS from '@/locales/en-US/main.js'
 import './index.scss'
 
-export default class DataManage extends Component {
+class DataManage extends Component {
   static propTpyes = {
-    MenuNo: PropTypes.string // 鏍囩椤垫暟缁�
+    MenuNo: PropTypes.string, // 鑿滃崟鍙傛暟
+    MenuID: PropTypes.string // 鑿滃崟Id
   }
 
   state = {
@@ -22,18 +25,12 @@
     searchparam: null, // 鎼滅储鍙傛暟
     actions: null, // 鎸夐挳
     columns: null, // 鏄剧ず鍒�
+    mainKey: null, // 涓婚敭
     selectable: false, // 琛ㄦ牸鏄惁鍙��
     datafunc: null, // 鑾峰彇鏁版嵁鍙婃樉绀哄垪鐨勫瓨鍌ㄨ繃绋嬪悕绉�
     data: null,
     total: 0,
-    loading: true,
-    param: {
-      pageIndex: 1,
-      pageSize: 10,
-      orderColumn: '',
-      orderType: '',
-      search: ''
-    }
+    loading: true
   }
 
   async loadconfig () {
@@ -48,15 +45,23 @@
         newconfig.searchlist = result.sWheredata
       }
       if (result.sMenusdata && result.sMenusdata.length > 0) {
-        newconfig.actions = result.sMenusdata
+        newconfig.actions = result.sMenusdata.map(action => {
+          let width = +action.PopWidth
+          if (width > 100 || !width) {
+            width = 62
+          }
+          action.PopWidth = width / 100
+          return action
+        })
       }
-      newconfig.selectable = result.CheckBox === 'true'
+      newconfig.selectable = result.CheckBox !== 'true'
       newconfig.datafunc = result.sWhereAction
       this.setState(newconfig)
     } else {
       notification.warning({
         top: 92,
-        message: result.message
+        message: result.message,
+        duration: 10
       })
     }
   }
@@ -73,13 +78,13 @@
     }
     let result = await Api.commonInterface(param)
     if (result.status) {
-      result.sGriddata.length = 4
       this.setState({
         columns: result.sGriddata,
         data: result.data.map((item, index) => {
           item.key = index
           return item
         }),
+        mainKey: result.sGriddata.filter(grid => grid.IDField === '1' || grid.IDField === '2'),
         total: result.Total,
         searchparam: searches,
         loading: false
@@ -87,7 +92,8 @@
     } else {
       notification.warning({
         top: 92,
-        message: result.message
+        message: result.message,
+        duration: 10
       })
       this.setState({
         searchparam: searches,
@@ -128,13 +134,28 @@
     })
   }
 
-  refreshbyaction = () => {
+  refreshbyaction = (type) => {
     // 鎸夐挳鎿嶄綔鍚庡埛鏂拌〃鏍�,閲嶇疆椤电爜鍙婇�夋嫨椤�
-    this.refs.dataTable.resetTable()
-    this.loadDbdata(this.state.searchparam)
-    this.setState({
-      loading: true
-    })
+    if (type === 'grid') {
+      this.refs.dataTable.resetTable()
+      this.loadDbdata(this.state.searchparam)
+      this.setState({
+        loading: true
+      })
+    } else if (type === 'all') {
+      this.setState({
+        searchlist: null,
+        searchparam: null,
+        actions: null,
+        columns: null,
+        mainKey: null,
+        selectable: false,
+        datafunc: null,
+        data: null,
+        total: 0
+      })
+      this.loadconfig()
+    }
   }
 
   gettableselected = () => {
@@ -146,13 +167,27 @@
     return data
   }
 
+  switchview = (param) => {
+    console.log(param)
+  }
+
   UNSAFE_componentWillMount () {
     // 缁勪欢鍔犺浇鏃讹紝鑾峰彇鑿滃崟鏁版嵁
     this.loadconfig()
   }
 
   shouldComponentUpdate (nextProps, nextState) {
-    return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
+    if (!is(fromJS(this.props.refreshTab), fromJS(nextProps.refreshTab)) && nextProps.refreshTab && this.props.MenuNo === nextProps.refreshTab.MenuNo) {
+      // 鎺ユ敹鍒板埛鏂板懡浠わ紝涓斿埛鏂颁俊鎭腑鑿滃崟鍙傛暟涓庡綋鍓嶉〉闈㈢浉鍚�
+      this.props.refreshTabView(null)
+      this.refreshbyaction(nextProps.refreshTab.ReloadForm)
+      return false
+    } else if (!is(fromJS(this.props.refreshTab), fromJS(nextProps.refreshTab)) && !(nextProps.refreshTab && this.props.MenuNo === nextProps.refreshTab.MenuNo)) {
+      // 鏈帴鏀跺埌鍒锋柊鍛戒护锛屾垨鍒锋柊淇℃伅涓彍鍗曞弬鏁颁笌褰撳墠椤甸潰涓嶅悓
+      return false
+    } else {
+      return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
+    }
   }
 
   render() {
@@ -166,10 +201,13 @@
             dict={this.state.dict}
           />
         }
-        {this.state.actions &&
+        {this.state.actions && this.state.columns &&
           <DataAction
             MenuNo={this.props.MenuNo}
+            columns={this.state.columns}
+            mainKey={this.state.mainKey}
             refreshdata={this.refreshbyaction}
+            switchview={this.switchview}
             gettableselected={this.gettableselected}
             actions={this.state.actions}
             dict={this.state.dict}
@@ -198,4 +236,18 @@
       </div>
     )
   }
-}
\ No newline at end of file
+}
+
+const mapStateToProps = (state) => {
+  return {
+    refreshTab: state.refreshTab
+  }
+}
+
+const mapDispatchToProps = (dispatch) => {
+  return {
+    refreshTabView: (refreshTab) => dispatch(refreshTabView(refreshTab))
+  }
+}
+
+export default connect(mapStateToProps, mapDispatchToProps)(DataManage)
\ No newline at end of file

--
Gitblit v1.8.0