From 84804b405cb88f659d055b16eb3bd00b813ccb4a Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 10 十二月 2020 10:58:38 +0800
Subject: [PATCH] 2020-12-10

---
 src/tabviews/custom/components/card/table-card/index.jsx |   58 +++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 51 insertions(+), 7 deletions(-)

diff --git a/src/tabviews/custom/components/card/table-card/index.jsx b/src/tabviews/custom/components/card/table-card/index.jsx
index 2aeeb1c..75f6167 100644
--- a/src/tabviews/custom/components/card/table-card/index.jsx
+++ b/src/tabviews/custom/components/card/table-card/index.jsx
@@ -21,6 +21,7 @@
   }
 
   state = {
+    BID: '',                   // 涓婄骇ID
     config: null,              // 鍥捐〃閰嶇疆淇℃伅
     loading: false,            // 鏁版嵁鍔犺浇鐘舵��
     preIndex: 0,               // 寮�濮嬬储寮�
@@ -37,7 +38,7 @@
    * 1銆� initdata 涓烘墦鍗版椂浣跨敤鐨勬暟鎹泦
    */
   UNSAFE_componentWillMount () {
-    const { data, initdata } = this.props
+    const { data, initdata, BID } = this.props
     let _config = fromJS(this.props.config).toJS()
     let _cols = new Map()
 
@@ -50,6 +51,15 @@
     } else if (_config.setting.sync === 'true' && initdata) {
       _data = initdata || []
       _sync = false
+    }
+
+    if (_data) {
+      _data = _data.map((item, index) => {
+        item.key = index
+        item.$$uuid = item[_config.setting.primaryKey] || ''
+        item.$$BID = BID || ''
+        return item
+      })
     }
 
     let showHeader = false
@@ -80,6 +90,7 @@
       showHeader: showHeader,
       title: _config.wrap.title,
       sync: _sync,
+      BID: BID || '',
       data: _data,
       config: _config,
       arr_field: _config.columns.map(col => col.field).join(','),
@@ -92,6 +103,7 @@
 
   componentDidMount () {
     MKEmitter.addListener('syncRefreshComponentId', this.reload)
+    MKEmitter.addListener('resetSelectLine', this.resetParentParam)
   }
 
   shouldComponentUpdate (nextProps, nextState) {
@@ -103,19 +115,27 @@
       return
     }
     MKEmitter.removeListener('syncRefreshComponentId', this.reload)
+    MKEmitter.removeListener('resetSelectLine', this.resetParentParam)
   }
 
   /**
    * @description 鍥捐〃鏁版嵁鏇存柊锛屽埛鏂板唴瀹�
    */
   UNSAFE_componentWillReceiveProps (nextProps) {
-    const { sync, config } = this.state
+    const { sync, config, BID } = this.state
 
     if (sync && !is(fromJS(this.props.data), fromJS(nextProps.data))) {
       let _data = []
       if (nextProps.data && nextProps.data[config.dataName]) {
         _data = nextProps.data[config.dataName] || []
       }
+
+      _data = _data.map((item, index) => {
+        item.key = index
+        item.$$uuid = item[config.setting.primaryKey] || ''
+        item.$$BID = BID || ''
+        return item
+      })
 
       this.setState({sync: false, data: _data})
     } else if (!is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
@@ -124,6 +144,17 @@
           this.loadData()
         })
       }
+    }
+  }
+
+  resetParentParam = (MenuID, id) => {
+    const { config } = this.state
+
+    if (!config.setting.supModule || config.setting.supModule !== MenuID) return
+    if (id !== this.state.BID) {
+      this.setState({ BID: id }, () => {
+        this.loadData()
+      })
     }
   }
 
@@ -140,8 +171,17 @@
   }
 
   async loadData () {
-    const { mainSearch, BID, menuType } = this.props
-    const { config, arr_field, pageIndex } = this.state
+    const { mainSearch, menuType } = this.props
+    const { config, arr_field, pageIndex, BID } = this.state
+
+    if (config.setting.supModule && !BID) { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇�
+      this.setState({
+        data: [],
+        total: 0,
+        preIndex: 0
+      })
+      return
+    }
 
     let searches = []
     if (mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢
@@ -168,7 +208,12 @@
       }
 
       this.setState({
-        data: result.data,
+        data: result.data.map((item, index) => {
+          item.key = index
+          item.$$uuid = item[config.setting.primaryKey] || ''
+          item.$$BID = BID || ''
+          return item
+        }),
         total: result.total,
         preIndex: _preIndex,
         loading: false
@@ -208,7 +253,6 @@
   }
 
   getLines = (data, seq) => {
-    const { BID } = this.props
     const { config } = this.state
 
     let line = []
@@ -239,7 +283,7 @@
       line.push(
         <Col key={index} span={24}>
           <div className="card-item-box" style={item.style}>
-            <CardCellComponent BID={BID} seq={seq} data={data} cards={config} cardCell={item} elements={item.elements} updateStatus={this.updateStatus}/>
+            <CardCellComponent seq={seq} data={data} cards={config} cardCell={item} elements={item.elements} updateStatus={this.updateStatus}/>
           </div>
         </Col>
       )

--
Gitblit v1.8.0