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/prop-card/index.jsx |   68 +++++++++++++++++++++++++---------
 1 files changed, 50 insertions(+), 18 deletions(-)

diff --git a/src/tabviews/custom/components/card/prop-card/index.jsx b/src/tabviews/custom/components/card/prop-card/index.jsx
index 92e6324..9f47cca 100644
--- a/src/tabviews/custom/components/card/prop-card/index.jsx
+++ b/src/tabviews/custom/components/card/prop-card/index.jsx
@@ -21,6 +21,7 @@
   }
 
   state = {
+    BID: '',                   // 涓婄骇ID
     config: null,              // 鍥捐〃閰嶇疆淇℃伅
     loading: false,            // 鏁版嵁鍔犺浇鐘舵��
     activeKey: '',             // 閫変腑鏁版嵁
@@ -29,7 +30,7 @@
   }
 
   UNSAFE_componentWillMount () {
-    const { data, initdata } = this.props
+    const { data, initdata, BID } = this.props
     let _config = fromJS(this.props.config).toJS()
     let _cols = new Map()
 
@@ -55,6 +56,10 @@
       _data = {}
     }
 
+    if (_data) {
+      _data.$$BID = BID || ''
+    }
+
     _config.columns.forEach(item => {
       _cols.set(item.field, item)
     })
@@ -77,6 +82,7 @@
     this.setState({
       sync: _sync,
       data: _data,
+      BID: BID || '',
       config: _config,
       arr_field: _config.columns.map(col => col.field).join(','),
     }, () => {
@@ -88,6 +94,7 @@
 
   componentDidMount () {
     MKEmitter.addListener('syncRefreshComponentId', this.reload)
+    MKEmitter.addListener('resetSelectLine', this.resetParentParam)
   }
 
   shouldComponentUpdate (nextProps, nextState) {
@@ -99,13 +106,14 @@
       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 = {}
@@ -113,7 +121,12 @@
         _data = nextProps.data[config.dataName]
         if (_data && Array.isArray(_data)) {
           _data = _data[0]
+        } else {
+          _data = {}
         }
+      }
+      if (_data) {
+        _data.$$BID = BID || ''
       }
 
       this.setState({sync: false, data: _data})
@@ -126,6 +139,17 @@
     }
   }
 
+  resetParentParam = (MenuID, id) => {
+    const { config } = this.state
+
+    if (config.wrap.datatype === 'static' || !config.setting.supModule || config.setting.supModule !== MenuID) return
+    if (id !== this.state.BID) {
+      this.setState({ BID: id }, () => {
+        this.loadData()
+      })
+    }
+  }
+
   reload = (syncId) => {
     const { config } = this.state
 
@@ -135,8 +159,22 @@
   }
 
   async loadData () {
-    const { mainSearch, BID, menuType } = this.props
-    const { config, arr_field } = this.state
+    const { mainSearch, menuType } = this.props
+    const { config, arr_field, BID } = this.state
+
+    if (config.wrap.datatype === 'static') {
+      this.setState({
+        data: {$$BID: BID || ''},
+        loading: false
+      })
+      return
+    } else if (config.setting.supModule && !BID) { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇�
+      this.setState({
+        data: {$$BID: BID || ''},
+        loading: false
+      })
+      return
+    }
 
     let searches = []
     if (mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢
@@ -148,26 +186,21 @@
       })
     }
 
-    if (config.wrap.datatype === 'static') {
-      this.setState({
-        loading: false,
-        data: {}
-      })
-      return
-    } else {
-      this.setState({
-        loading: true
-      })
-    }
+    this.setState({
+      loading: true
+    })
 
     let _orderBy = config.setting.order || ''
     let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, 1, 1, BID, menuType)
 
     let result = await Api.genericInterface(param)
     if (result.status) {
+      let _data = result.data && result.data[0] ? result.data[0] : {}
+      _data.$$BID = BID || ''
+
       this.setState({
         activeKey: '',
-        data: result.data && result.data[0] ? result.data[0] : {},
+        data: _data,
         loading: false
       })
     } else {
@@ -207,7 +240,6 @@
   }
 
   render() {
-    const { BID } = this.props
     const { config, loading, data, activeKey } = this.state
 
     return (
@@ -221,7 +253,7 @@
         <div className="card-row-list">
           {config.subcards.map((item, index) => (
             <Col className={activeKey === index ? 'active' : ''} key={index} span={item.setting.width || 6} onClick={() => {this.changeCard(index, item)}}>
-              <CardItem BID={BID} card={item} cards={config} data={data} updateStatus={this.updateStatus}/>
+              <CardItem card={item} cards={config} data={data} updateStatus={this.updateStatus}/>
             </Col>
           ))}
         </div>

--
Gitblit v1.8.0