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/data-card/index.jsx |   62 +++++++++++++++++++++++++++----
 1 files changed, 54 insertions(+), 8 deletions(-)

diff --git a/src/tabviews/custom/components/card/data-card/index.jsx b/src/tabviews/custom/components/card/data-card/index.jsx
index bc013cb..82c426f 100644
--- a/src/tabviews/custom/components/card/data-card/index.jsx
+++ b/src/tabviews/custom/components/card/data-card/index.jsx
@@ -23,8 +23,9 @@
   }
 
   state = {
+    BID: '',                   // 涓婄骇ID
     config: null,              // 鍥捐〃閰嶇疆淇℃伅
-    pageIndex: 1,
+    pageIndex: 1,              // 椤电爜
     activeKey: '',             // 閫変腑鍗�
     loading: false,            // 鏁版嵁鍔犺浇鐘舵��
     sync: false,               // 鏄惁缁熶竴璇锋眰鏁版嵁
@@ -34,7 +35,7 @@
   }
 
   UNSAFE_componentWillMount () {
-    const { data, initdata } = this.props
+    const { data, initdata, BID } = this.props
     let _config = fromJS(this.props.config).toJS()
     let _card = _config.subcards[0]
     let _cols = new Map()
@@ -48,6 +49,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
+      })
     }
 
     _config.columns.forEach(item => {
@@ -70,6 +80,7 @@
     this.setState({
       sync: _sync,
       data: _data,
+      BID: BID || '',
       config: _config,
       card: _card,
       arr_field: _config.columns.map(col => col.field).join(','),
@@ -82,6 +93,7 @@
 
   componentDidMount () {
     MKEmitter.addListener('syncRefreshComponentId', this.reload)
+    MKEmitter.addListener('resetSelectLine', this.resetParentParam)
   }
 
   shouldComponentUpdate (nextProps, nextState) {
@@ -89,13 +101,20 @@
   }
 
   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))) {
@@ -112,6 +131,7 @@
       return
     }
     MKEmitter.removeListener('syncRefreshComponentId', this.reload)
+    MKEmitter.removeListener('resetSelectLine', this.resetParentParam)
   }
 
   reload = (syncId) => {
@@ -126,9 +146,31 @@
     })
   }
 
+  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()
+      })
+    }
+  }
+
   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({
+        activeKey: '',
+        pageIndex: 1,
+        data: [],
+        total: 0,
+        loading: false
+      })
+      return
+    }
 
     let searches = []
     if (mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢
@@ -151,7 +193,12 @@
     if (result.status) {
       this.setState({
         activeKey: '',
-        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,
         loading: false
       })
@@ -217,7 +264,6 @@
   }
 
   render() {
-    const { BID } = this.props
     const { config, loading, data, pageIndex, total, card, activeKey } = this.state
 
     let _total = config.setting.pageSize * pageIndex
@@ -238,7 +284,7 @@
         {data && data.length > 0 ? <div className="card-row-list">
           {data.map((item, index) => (
             <Col className={activeKey === index ? 'active' : ''} key={index} span={card.setting.width || 6} onClick={() => {this.changeCard(index, item)}}>
-              <CardItem BID={BID} card={card} cards={config} data={item} updateStatus={this.updateStatus}/>
+              <CardItem card={card} cards={config} data={item} updateStatus={this.updateStatus}/>
             </Col>
           ))}
         </div> : null}

--
Gitblit v1.8.0