From 0227c25e4ed573d3095ada3f9c9a4ba5f18b0de5 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 20 一月 2021 10:53:01 +0800
Subject: [PATCH] 2021-01-20

---
 src/tabviews/custom/components/table/normal-table/index.jsx |  154 ++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 102 insertions(+), 52 deletions(-)

diff --git a/src/tabviews/custom/components/table/normal-table/index.jsx b/src/tabviews/custom/components/table/normal-table/index.jsx
index 01e5a09..516709b 100644
--- a/src/tabviews/custom/components/table/normal-table/index.jsx
+++ b/src/tabviews/custom/components/table/normal-table/index.jsx
@@ -9,15 +9,15 @@
 import zhCN from '@/locales/zh-CN/main.js'
 import enUS from '@/locales/en-US/main.js'
 import UtilsDM from '@/utils/utils-datamanage.js'
-import asyncSpinComponent from '@/utils/asyncSpinComponent'
+import asyncComponent from '@/utils/asyncComponent'
 import MKEmitter from '@/utils/events.js'
-
-import MainSearch from '@/tabviews/zshare/topSearch'
 import './index.scss'
 
 // 閫氱敤缁勪欢
-const MainAction = asyncSpinComponent(() => import('@/tabviews/zshare/actionList'))
-const MainTable = asyncSpinComponent(() => import('@/tabviews/custom/components/share/normalTable'))
+const MainSearch = asyncComponent(() => import('@/tabviews/zshare/topSearch'))
+const MainAction = asyncComponent(() => import('@/tabviews/zshare/actionList'))
+const MainTable = asyncComponent(() => import('@/tabviews/custom/components/share/normalTable'))
+const NormalHeader = asyncComponent(() => import('@/tabviews/custom/components/share/normalheader'))
 
 class NormalTable extends Component {
   static propTpyes = {
@@ -121,6 +121,7 @@
    * @param { String }  repage 琛ㄦ牸鏄惁閲嶇疆椤电爜
    */
   async loadmaindata (reset, repage) {
+    const { mainSearch } = this.props
     const { setting, config, arr_field, search, orderBy, BID, pageIndex, pageSize } = this.state
     let requireFields = search.filter(item => item.required && (!item.value || item.value.length === 0))
 
@@ -146,12 +147,22 @@
       return
     }
 
+    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 = orderBy || setting.order
-    let param = UtilsDM.getQueryDataParams(setting, arr_field, search, _orderBy, pageIndex, pageSize, BID, this.props.menuType)
+    let param = UtilsDM.getQueryDataParams(setting, arr_field, searches, _orderBy, pageIndex, pageSize, BID, this.props.menuType)
 
     if (param.func === 'sPC_Get_TableData') {
       param.menuname = config.name || ''
@@ -189,14 +200,25 @@
    * @description 鑾峰彇鍗曡鏁版嵁
    */ 
   async loadmainLinedata (id) {
+    const { mainSearch } = this.props
     const { setting, config, arr_field, search, orderBy, BID, pageIndex, pageSize } = this.state
+
+    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 = orderBy || setting.order
-    let param = UtilsDM.getQueryDataParams(setting, arr_field, search, _orderBy, pageIndex, pageSize, BID, this.props.menuType, id)
+    let param = UtilsDM.getQueryDataParams(setting, arr_field, searches, _orderBy, pageIndex, pageSize, BID, this.props.menuType, id)
 
     if (param.func === 'sPC_Get_TableData') {
       param.menuname = config.name || ''
@@ -244,6 +266,7 @@
    * @description 鑾峰彇鍚堣瀛楁鍊�
    */
   getStatFieldsValue = () => {
+    const { mainSearch } = this.props
     const { setting, config, search, BID, orderBy, statFields } = this.state
 
     if (setting.supModule && !BID) { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇�
@@ -260,8 +283,18 @@
       return
     }
 
+    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)
+        }
+      })
+    }
+
     let _orderBy = orderBy || setting.order
-    let param = UtilsDM.getStatQueryDataParams(setting, statFields, search, _orderBy, BID, this.props.menuType)
+    let param = UtilsDM.getStatQueryDataParams(setting, statFields, searches, _orderBy, BID, this.props.menuType)
 
     if (param.func === 'sPC_Get_TableData') {
       param.menuname = config.name || ''
@@ -366,39 +399,38 @@
   }
 
   /**
-   * @description 鎸夐挳鎿嶄綔瀹屾垚鍚庯紙鎴愬姛鎴栧け璐ワ級锛岄〉闈㈠埛鏂帮紝閲嶇疆椤电爜鍙婇�夋嫨椤�
-   */
-  refreshbyaction = (position, btn) => {
-    if (position === 'grid' || position === 'view') {
-      this.reloadtable(btn)
-    }
-  }
-
-  /**
    * @description 瀵煎嚭Excel鏃讹紝鑾峰彇椤甸潰鎼滅储鎺掑簭绛夊弬鏁�
    */
-  getexceloutparam = () => {
+  getexceloutparam = (menuId, btnId) => {
+    const { mainSearch } = this.props
     const { arr_field, config, orderBy, search, setting} = this.state
 
-    return {
+    if (config.uuid !== menuId) return
+
+    let searches = search ? 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)
+        }
+      })
+    }
+
+    MKEmitter.emit('execExcelout', config.uuid, btnId, {
       arr_field: arr_field,
       orderBy: orderBy || setting.order,
-      search: search,
+      search: searches,
       menuName: config.name
-    }
+    })
   }
 
-  reloadData = (menuId, id, btn) => {
+  reloadData = (menuId, id) => {
     const { config } = this.state
 
     if (config.uuid !== menuId) return
     if (id === 'empty') return
 
-    if (id === 'formtab') { // 琛ㄥ崟鏍囩椤靛埛鏂�
-      this.reloadtable(btn)
-      return
-    }
-    
     if (!id) {
       this.reloadtable()
     } else {
@@ -422,6 +454,31 @@
     }
   }
 
+  /**
+   * @description 鎸夐挳鎵ц瀹屾垚鍚庨〉闈㈠埛鏂�
+   * @param {*} menuId     // 鑿滃崟Id
+   * @param {*} position   // 鍒锋柊浣嶇疆
+   * @param {*} btn        // 鎵ц鐨勬寜閽�
+   */
+  refreshByButtonResult = (menuId, position, btn) => {
+    const { config, BID } = this.state
+
+    if (config.uuid !== menuId) return
+
+    this.reloadtable(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)
+    }
+  }
+
   UNSAFE_componentWillReceiveProps(nextProps) {
     const { sync, config, BID } = this.state
 
@@ -438,7 +495,7 @@
       })
 
       this.setState({sync: false, data: _data})
-    } else if (!is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
+    } else if (nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
       if (config.setting.syncRefresh === 'true') {
         this.setState({}, () => {
           this.reloadtable()
@@ -454,6 +511,8 @@
   componentDidMount () {
     MKEmitter.addListener('reloadData', this.reloadData)
     MKEmitter.addListener('resetSelectLine', this.resetParentParam)
+    MKEmitter.addListener('getexceloutparam', this.getexceloutparam)
+    MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult)
   }
 
   /**
@@ -465,36 +524,28 @@
     }
     MKEmitter.removeListener('reloadData', this.reloadData)
     MKEmitter.removeListener('resetSelectLine', this.resetParentParam)
+    MKEmitter.removeListener('getexceloutparam', this.getexceloutparam)
+    MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult)
   }
 
   render() {
     const { BID, setting, searchlist, actions, config, columns, selectedData } = this.state
 
     return (
-      <div className="custom-normal-table">
-        {searchlist && searchlist.length > 0 ?
-          <MainSearch
-            BID={BID}
-            dict={this.state.dict}
-            searchlist={searchlist}
-            menuType={this.props.menuType}
-            refreshdata={this.refreshbysearch}
-          /> : null
+      <div className="custom-normal-table" style={config.style}>
+        <NormalHeader config={config}/>
+        {searchlist && searchlist.length ?
+          <MainSearch BID={BID} searchlist={searchlist} menuType={this.props.menuType} refreshdata={this.refreshbysearch}/> : null
         }
-        <div className="commontable-main-action">
-          <MainAction
-            BID={BID}
-            setting={setting}
-            actions={actions}
-            dict={this.state.dict}
-            BData={this.state.BData}
-            columns={config.columns}
-            selectedData={selectedData}
-            refreshdata={this.refreshbyaction}
-            getexceloutparam={this.getexceloutparam}
-          />
-        </div>
-        <div className="main-table-box">
+        <MainAction
+          BID={BID}
+          setting={setting}
+          actions={actions}
+          BData={this.state.BData}
+          columns={config.columns}
+          selectedData={selectedData}
+        />
+        <div className={'main-table-box ' + (!actions || actions.length === 0 ? 'no-action' : '')}>
           <MainTable
             setting={setting}
             columns={columns}
@@ -506,7 +557,6 @@
             loading={this.state.loading}
             refreshdata={this.refreshbytable}
             statFValue={this.state.statFValue}
-            refreshbyaction={this.refreshbyaction}
             chgSelectData={(selects) => this.setState({selectedData: selects})}
           />
         </div>

--
Gitblit v1.8.0