From da7068bd48791cdee966c786ce0dfd46f6e03df9 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期五, 08 一月 2021 19:02:24 +0800
Subject: [PATCH] 2021-01-08

---
 src/tabviews/custom/components/card/data-card/index.jsx |  114 ++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 97 insertions(+), 17 deletions(-)

diff --git a/src/tabviews/custom/components/card/data-card/index.jsx b/src/tabviews/custom/components/card/data-card/index.jsx
index 92dc59b..30ba645 100644
--- a/src/tabviews/custom/components/card/data-card/index.jsx
+++ b/src/tabviews/custom/components/card/data-card/index.jsx
@@ -100,9 +100,10 @@
   }
 
   componentDidMount () {
-    MKEmitter.addListener('syncRefreshComponentId', this.reload)
+    MKEmitter.addListener('reloadData', this.reloadData)
     MKEmitter.addListener('resetSelectLine', this.resetParentParam)
     MKEmitter.addListener('getexceloutparam', this.getexceloutparam)
+    MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult)
   }
 
   shouldComponentUpdate (nextProps, nextState) {
@@ -139,21 +140,48 @@
     this.setState = () => {
       return
     }
-    MKEmitter.removeListener('syncRefreshComponentId', this.reload)
+    MKEmitter.removeListener('reloadData', this.reloadData)
     MKEmitter.removeListener('resetSelectLine', this.resetParentParam)
     MKEmitter.removeListener('getexceloutparam', this.getexceloutparam)
+    MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult)
   }
 
-  reload = (syncId) => {
+  /**
+   * @description 鎸夐挳鎵ц瀹屾垚鍚庨〉闈㈠埛鏂�
+   * @param {*} menuId     // 鑿滃崟Id
+   * @param {*} position   // 鍒锋柊浣嶇疆
+   * @param {*} btn        // 鎵ц鐨勬寜閽�
+   */
+  refreshByButtonResult = (menuId, position, btn) => {
+    const { config, BID } = this.state
+
+    if (config.uuid !== menuId) return
+
+    this.loadData(btn)                                                         // 鏁版嵁鍒锋柊
+
+    if (btn.syncComponentId && btn.syncComponentId !== config.uuid && btn.syncComponentId !== config.setting.supModule) {
+      MKEmitter.emit('reloadData', btn.syncComponentId)                        // 鍚岀骇鏍囩鍒锋柊
+    }
+
+    if (position === 'mainline' && config.setting.supModule) {                 // 涓昏〃琛屽埛鏂�
+      MKEmitter.emit('reloadData', config.setting.supModule, (BID || 'empty'))
+    } else if (position === 'popclose') {                                      // 鏍囩鍏抽棴鍒锋柊
+      config.setting.supModule && MKEmitter.emit('reloadData', config.setting.supModule, (BID || 'empty'))
+      btn.$tabId && MKEmitter.emit('refreshPopButton', btn.$tabId)
+    }
+  }
+
+  reloadData = (menuId, id) => {
     const { config } = this.state
 
-    if (syncId && syncId !== config.uuid) return
+    if (config.uuid !== menuId) return
+    if (id === 'empty') return
 
-    this.setState({
-      pageIndex: 1
-    }, () => {
+    if (!id) {
       this.loadData()
-    })
+    } else {
+      this.loadLinedata(id)
+    }
   }
 
   resetParentParam = (MenuID, id, data) => {
@@ -255,17 +283,69 @@
     }
   }
 
-  updateStatus = (type, position, btn) => {
-    const { config } = this.state
+  /**
+   * @description 鑾峰彇鍗曡鏁版嵁
+   */ 
+  async loadLinedata (id) {
+    const { mainSearch, menuType } = this.props
+    const { config, arr_field, pageIndex, search, BID } = this.state
 
-    if (type === 'refresh' && position === 'grid') {
-      this.loadData()
-      if (btn && btn.syncComponent && btn.syncComponent[0]) {
-        let syncId = btn.syncComponent.slice(-1)[0]
-        if (config.uuid !== syncId) {
-          MKEmitter.emit('syncRefreshComponentId', syncId)
+    let searches = fromJS(search).toJS()
+    if (mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢
+      let keys = searches.map(item => item.key.toLowerCase())
+      mainSearch.forEach(item => {
+        if (!keys.includes(item.key.toLowerCase())) {
+          searches.push(item)
+        }
+      })
+    }
+
+    this.setState({
+      loading: true
+    })
+
+    let _orderBy = config.setting.order || ''
+    let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, pageIndex, config.setting.pageSize, BID, menuType, id)
+
+    if (param.func === 'sPC_Get_TableData') {
+      param.menuname = config.name || ''
+    }
+
+    let result = await Api.genericInterface(param)
+    if (result.status) {
+      let data = fromJS(this.state.data).toJS()
+      if (result.data && result.data[0]) {
+        let _data = result.data[0]
+
+        try {
+          data = data.map(item => {
+            if (item[config.setting.primaryKey] === _data[config.setting.primaryKey]) {
+              _data.key = item.key
+              _data.$$uuid = _data[config.setting.primaryKey] || ''
+              _data.$$BID = BID || ''
+              return _data
+            } else {
+              return item
+            }
+          })
+        } catch {
+          console.warn('鏁版嵁鏌ヨ閿欒')
         }
       }
+
+      this.setState({
+        data: data,
+        loading: false
+      })
+    } else {
+      this.setState({
+        loading: false
+      })
+      notification.error({
+        top: 92,
+        message: result.message,
+        duration: 10
+      })
     }
   }
 
@@ -396,7 +476,7 @@
           {data && data.length > 0 ? <div className="card-row-list">
             {data.map((item, index) => (
               <Col className={activeKey === index ? 'active' : (selectKeys.indexOf(index) > -1 ? 'selected' : '')} key={index} span={card.setting.width} offset={!index ? offset : 0} onClick={() => {this.changeCard(index, item)}}>
-                <CardItem card={card} cards={config} data={item} updateStatus={this.updateStatus}/>
+                <CardItem card={card} cards={config} data={item}/>
               </Col>
             ))}
           </div> : null}

--
Gitblit v1.8.0