From f01086dc94827dbb15811760e5d13683977fcec9 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 10 十一月 2022 00:40:12 +0800
Subject: [PATCH] 2022-11-10

---
 src/tabviews/custom/components/table/normal-table/index.jsx |  138 +++++++++++++++++++++++++++++++++-------------
 1 files changed, 99 insertions(+), 39 deletions(-)

diff --git a/src/tabviews/custom/components/table/normal-table/index.jsx b/src/tabviews/custom/components/table/normal-table/index.jsx
index 85e4fe5..d95478b 100644
--- a/src/tabviews/custom/components/table/normal-table/index.jsx
+++ b/src/tabviews/custom/components/table/normal-table/index.jsx
@@ -1,14 +1,14 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
-import {connect} from 'react-redux'
 import { is, fromJS } from 'immutable'
-import { notification, Collapse } from 'antd'
+import { notification, Collapse, Modal } from 'antd'
 
 import Api from '@/api'
 import Utils from '@/utils/utils.js'
 import UtilsDM from '@/utils/utils-datamanage.js'
 import asyncComponent from '@/utils/asyncComponent'
 import MKEmitter from '@/utils/events.js'
+import TimerTask from '@/utils/timer-task.js'
 import './index.scss'
 
 // 閫氱敤缁勪欢
@@ -21,11 +21,9 @@
 
 class NormalTable extends Component {
   static propTpyes = {
-    BID: PropTypes.any,              // 鐖剁骇Id
     data: PropTypes.array,           // 缁熶竴鏌ヨ鏁版嵁
     config: PropTypes.object,        // 缁勪欢閰嶇疆淇℃伅
     mainSearch: PropTypes.any,       // 澶栧眰鎼滅储鏉′欢
-    menuType: PropTypes.any,         // 鑿滃崟绫诲瀷
   }
 
   state = {
@@ -34,7 +32,7 @@
     config: {},           // 椤甸潰閰嶇疆淇℃伅锛屽寘鎷寜閽�佹悳绱€�佹樉绀哄垪銆佹爣绛剧瓑
     actions: null,        // 鎸夐挳闆�
     columns: null,        // 鏄剧ず鍒�
-    arr_field: '',        // 浣跨敤 sPC_Get_TableData 鏃剁殑鏌ヨ瀛楁闆�
+    arr_field: '',        // 鏌ヨ瀛楁闆�
     setting: null,        // 椤甸潰鍏ㄥ眬璁剧疆锛氭暟鎹簮銆佹寜閽強鏄剧ず鍒楀浐瀹氥�佷富閿瓑
     data: [],             // 鍒楄〃鏁版嵁闆�
     selectedData: [],     // 宸查�夎〃鏍兼暟鎹�
@@ -52,11 +50,23 @@
    * 1銆� initdata 涓烘墦鍗版椂浣跨敤鐨勬暟鎹泦
    */
   UNSAFE_componentWillMount () {
-    const { data, initdata, BID, BData } = this.props
+    const { data, initdata } = this.props
     let _config = fromJS(this.props.config).toJS()
     let _cols = new Map()
     let _data = null
     let _sync = _config.setting.sync === 'true'
+
+    let BID = ''
+    let BData = ''
+
+    if (_config.setting.supModule) {
+      BData = window.GLOB.CacheData.get(_config.setting.supModule)
+    } else {
+      BData = window.GLOB.CacheData.get(_config.$pageId)
+    }
+    if (BData) {
+      BID = BData.$BID || ''
+    }
 
     if (_config.wrap.controlField) {
       if (_config.wrap.controlVal) {
@@ -90,6 +100,14 @@
         item.$$BID = BID || ''
         item.$$BData = BData || ''
         item.$Index = index + 1 + ''
+
+        if (_config.absFields) {
+          _config.absFields.forEach(f => {
+            if (!isNaN(item[f])) {
+              item[f] = Math.abs(item[f])
+            }
+          })
+        }
 
         if (setting.controlField) {
           if (setting.controlVal.includes(item[setting.controlField])) {
@@ -171,7 +189,7 @@
    * @param { Boolean } reset  琛ㄦ牸鏄惁閲嶇疆
    * @param { String }  repage 琛ㄦ牸鏄惁閲嶇疆椤电爜
    */
-  async loadmaindata (reset, repage, id) {
+  async loadmaindata (reset, repage, id, type) {
     const { mainSearch } = this.props
     const { setting, config, arr_field, search, orderBy, BID, pageIndex, pageSize, BData } = this.state
 
@@ -205,12 +223,14 @@
       return
     }
 
-    this.setState({
-      loading: true
-    })
+    if (type !== 'timer') {
+      this.setState({
+        loading: true
+      })
+    }
 
     let _orderBy = orderBy || setting.order
-    let param = UtilsDM.getQueryDataParams(setting, arr_field, searches, _orderBy, pageIndex, pageSize, BID, this.props.menuType)
+    let param = UtilsDM.getQueryDataParams(setting, arr_field, searches, _orderBy, pageIndex, pageSize, BID)
 
     let result = await Api.genericInterface(param)
     if (result.status) {
@@ -244,6 +264,14 @@
           item.$$BData = BData || ''
           item.$Index = start + index + ''
 
+          if (config.absFields) {
+            config.absFields.forEach(f => {
+              if (!isNaN(item[f])) {
+                item[f] = Math.abs(item[f])
+              }
+            })
+          }
+
           if (setting.controlField) {
             if (setting.controlVal.includes(item[setting.controlField])) {
               item.$disabled = true
@@ -260,11 +288,19 @@
       this.setState({
         loading: false
       })
-      notification.error({
-        top: 92,
-        message: result.message,
-        duration: 10
-      })
+      this.timer && this.timer.stop()
+      
+      if (result.ErrCode === 'N') {
+        Modal.error({
+          title: result.message,
+        })
+      } else {
+        notification.error({
+          top: 92,
+          message: result.message,
+          duration: 10
+        })
+      }
     }
   }
 
@@ -290,7 +326,7 @@
     })
 
     let _orderBy = orderBy || setting.order
-    let param = UtilsDM.getQueryDataParams(setting, arr_field, searches, _orderBy, pageIndex, pageSize, BID, this.props.menuType, id)
+    let param = UtilsDM.getQueryDataParams(setting, arr_field, searches, _orderBy, pageIndex, pageSize, BID, id)
 
     let result = await Api.genericInterface(param)
     if (result.status) {
@@ -301,6 +337,15 @@
         _data.$$uuid = _data[setting.primaryKey] || ''
         _data.$$BID = BID || ''
         _data.$$BData = BData || ''
+
+        if (config.absFields) {
+          config.absFields.forEach(f => {
+            if (!isNaN(_data[f])) {
+              _data[f] = Math.abs(_data[f])
+            }
+          })
+        }
+
         try {
           data = data.map(item => {
             if (item.$$uuid === _data.$$uuid) {
@@ -373,7 +418,7 @@
     }
 
     let _orderBy = orderBy || setting.order
-    let param = UtilsDM.getStatQueryDataParams(setting, config.statFields, searches, _orderBy, BID, this.props.menuType)
+    let param = UtilsDM.getStatQueryDataParams(setting, config.statFields, searches, _orderBy, BID)
 
     Api.genericInterface(param).then(res => {
       if (res.status) {
@@ -476,7 +521,7 @@
   /**
    * @description 瀵煎嚭Excel鏃讹紝鑾峰彇椤甸潰鎼滅储鎺掑簭绛夊弬鏁�
    */
-  queryModuleParam = (menuId, btnId) => {
+  queryModuleParam = (menuId, callback) => {
     const { mainSearch } = this.props
     const { arr_field, config, orderBy, search, setting} = this.state
 
@@ -492,7 +537,7 @@
       })
     }
 
-    MKEmitter.emit('returnModuleParam', config.uuid, btnId, {
+    callback({
       arr_field: arr_field,
       orderBy: orderBy || setting.order,
       search: searches,
@@ -516,6 +561,7 @@
     const { setting } = this.state
 
     if (!setting.supModule || setting.supModule !== MenuID) return
+
     if (id !== this.state.BID || id !== '') {
       this.setState({
         pageIndex: 1,
@@ -571,6 +617,14 @@
           item.$$BData = BData || ''
           item.$Index = index + 1 + ''
 
+          if (config.absFields) {
+            config.absFields.forEach(f => {
+              if (!isNaN(item[f])) {
+                item[f] = Math.abs(item[f])
+              }
+            })
+          }
+
           if (setting.controlField) {
             if (setting.controlVal.includes(item[setting.controlField])) {
               item.$disabled = true
@@ -591,7 +645,7 @@
       }
 
       this.setState({sync: false, data: _data})
-    } else if (config.setting.syncRefresh && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
+    } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
       this.setState({pageIndex: 1}, () => {
         this.reloadtable()
       })
@@ -603,10 +657,24 @@
   }
 
   componentDidMount () {
+    const { config } = this.state
+
     MKEmitter.addListener('reloadData', this.reloadData)
     MKEmitter.addListener('resetSelectLine', this.resetParentParam)
     MKEmitter.addListener('queryModuleParam', this.queryModuleParam)
     MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult)
+
+    if (config.timer) {
+      this.timer = new TimerTask()
+      this.timer.init(config.uuid, config.timer, config.timerRepeats, () => {
+        this.setState({
+          pageIndex: 1
+        }, () => {
+          this.loadmaindata(true, 'true', '', 'timer')
+          this.getStatFieldsValue()
+        })
+      })
+    }
   }
 
   /**
@@ -620,6 +688,8 @@
     MKEmitter.removeListener('resetSelectLine', this.resetParentParam)
     MKEmitter.removeListener('queryModuleParam', this.queryModuleParam)
     MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult)
+
+    this.timer && this.timer.stop()
   }
 
   render() {
@@ -635,17 +705,17 @@
         {config.wrap.collapse === 'true' ? <Collapse bordered={false} defaultActiveKey="1" expandIconPosition="right">
           <Panel forceRender={true} header={<NormalHeader config={config}/>} key="1">
             {config.search && config.search.length ?
-              <MainSearch BID={BID} config={config} menuType={this.props.menuType} refreshdata={this.refreshbysearch}/> : null
+              <MainSearch BID={BID} config={config} refreshdata={this.refreshbysearch}/> : null
             }
-            <MainAction
+            {actions.length > 0 ? <MainAction
               BID={BID}
               setting={setting}
               actions={actions}
               BData={BData}
               columns={config.columns}
               selectedData={selectedData}
-            />
-            <div className={'main-table-box ' + (!actions || actions.length === 0 ? 'no-action' : '')}>
+            /> : <div style={{height: '25px'}}></div>}
+            <div className="main-table-box">
               <MainTable
                 setting={setting}
                 columns={columns}
@@ -664,16 +734,16 @@
         </Collapse> : <>
           <NormalHeader config={config}/>
           {config.search && config.search.length ?
-            <MainSearch BID={BID} config={config} menuType={this.props.menuType} refreshdata={this.refreshbysearch}/> : null
+            <MainSearch BID={BID} config={config} refreshdata={this.refreshbysearch}/> : null
           }
-          <MainAction
+          {actions.length > 0 ? <MainAction
             BID={BID}
             setting={setting}
             actions={actions}
             BData={BData}
             columns={config.columns}
             selectedData={selectedData}
-          />
+          /> : <div style={{height: '15px'}}></div>}
           <div className={'main-table-box ' + (!actions || actions.length === 0 ? 'no-action' : '')}>
             <MainTable
               setting={setting}
@@ -695,14 +765,4 @@
   }
 }
 
-const mapStateToProps = (state) => {
-  return {
-    menuType: state.editLevel
-  }
-}
-
-const mapDispatchToProps = () => {
-  return {}
-}
-
-export default connect(mapStateToProps, mapDispatchToProps)(NormalTable)
\ No newline at end of file
+export default NormalTable
\ No newline at end of file

--
Gitblit v1.8.0