From bd1dfc9e6c9b9f8076ca2783ce598e0936b4c664 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 22 十二月 2021 14:36:03 +0800
Subject: [PATCH] 2021-12-22

---
 src/tabviews/commontable/index.jsx |  725 +++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 465 insertions(+), 260 deletions(-)

diff --git a/src/tabviews/commontable/index.jsx b/src/tabviews/commontable/index.jsx
index 9a7f5fd..9469b12 100644
--- a/src/tabviews/commontable/index.jsx
+++ b/src/tabviews/commontable/index.jsx
@@ -2,16 +2,18 @@
 import PropTypes from 'prop-types'
 import {connect} from 'react-redux'
 import { is, fromJS } from 'immutable'
-import { notification, Spin, Tabs, Icon, Switch, Row, Col } from 'antd'
+import { notification, Spin, Tabs, Switch, Row, Col } from 'antd'
 
 import Api from '@/api'
 import zhCN from '@/locales/zh-CN/main.js'
 import enUS from '@/locales/en-US/main.js'
 import Utils from '@/utils/utils.js'
+import options from '@/store/options.js'
 import UtilsDM from '@/utils/utils-datamanage.js'
-import UtilsUpdate from '@/utils/utils-update.js'
+import { updateCommonTable } from '@/utils/utils-update.js'
 import asyncComponent from '@/utils/asyncComponent'
 import asyncSpinComponent from '@/utils/asyncSpinComponent'
+import MkIcon from '@/components/mk-icon'
 import MKEmitter from '@/utils/events.js'
 import NotFount from '@/components/404'
 import './index.scss'
@@ -25,6 +27,7 @@
 const CardComponent = asyncSpinComponent(() => import('@/tabviews/zshare/cardcomponent'))
 const ChartComponent = asyncSpinComponent(() => import('@/tabviews/zshare/chartcomponent'))
 const PagemsgComponent = asyncComponent(() => import('@/tabviews/zshare/pageMessage'))
+const AutoMatic = asyncComponent(() => import('@/tabviews/zshare/automatic'))
 
 const { TabPane } = Tabs
 
@@ -44,7 +47,7 @@
     viewlost: false,      // 椤甸潰涓㈠け锛�1銆佹湭鑾峰彇鍒伴厤缃�-椤甸潰涓㈠け锛�2銆侀〉闈㈡湭鍚敤
     lostmsg: '',          // 椤甸潰涓㈠け鏃剁殑鎻愮ず淇℃伅
     config: {},           // 椤甸潰閰嶇疆淇℃伅锛屽寘鎷寜閽�佹悳绱€�佹樉绀哄垪銆佹爣绛剧瓑
-    userConfig: null,     // 鐢ㄦ埛鑷畾涔夎缃�
+    shortcuts: null,      // 蹇嵎閿�
     searchlist: null,     // 鎼滅储鏉′欢
     actions: null,        // 鎸夐挳闆�
     columns: null,        // 鏄剧ず鍒�
@@ -60,32 +63,37 @@
     search: '',           // 鎼滅储鏉′欢鏁扮粍锛屼娇鐢ㄦ椂闇�鍒嗗満鏅鐞�
     BIDs: {},             // 涓婄骇琛╥d
     pickup: false,        // 涓昏〃鏁版嵁闅愯棌鏄剧ず鍒囨崲
-    tabActive: null,      // 鏍囩椤靛睍寮�鎺у埗
     chartId: '',          // 灞曞紑鍥捐〃ID
     statFields: [],       // 鍚堣瀛楁
     statFValue: [],       // 鍚堣鍊�
     absFields: [],        // 缁濆鍊煎瓧娈�
+    loadCustomApi: true,  // 鍔犺浇澶栭儴璧勬簮
+    hasReqFields: false,
+    autoMatic: null
   }
 
   /**
    * @description 鑾峰彇椤甸潰閰嶇疆淇℃伅
    */
   async loadconfig () {
-    const { permAction, permMenus, param, MenuName } = this.props
+    const { permAction, permMenus, param, MenuName, MenuID } = this.props
 
     let _param = {
       func: 'sPC_Get_LongParam',
-      MenuID: this.props.MenuID
+      MenuID: MenuID
     }
     let result = await Api.getCacheConfig(_param)
 
     if (result.status) {
       let config = ''
-      let userConfig = null
-      let _curUserConfig = ''
+      let shortcuts = []
 
       try { // 閰嶇疆淇℃伅瑙f瀽
         config = JSON.parse(window.decodeURIComponent(window.atob(result.LongParam)))
+        config.MenuID = MenuID
+        config.MenuName = MenuName
+        config.setting.MenuName = MenuName
+        config.setting.$name = MenuName
       } catch (e) {
         console.warn('Parse Failure')
         config = ''
@@ -94,11 +102,36 @@
       // HS涓嶄娇鐢ㄨ嚜瀹氫箟璁剧疆
       if (result.LongParamUser && this.props.menuType !== 'HS') {
         try { // 閰嶇疆淇℃伅瑙f瀽
-          userConfig = JSON.parse(window.decodeURIComponent(window.atob(result.LongParamUser)))
-          _curUserConfig = userConfig[this.props.MenuID]
+          let userConfig = JSON.parse(window.decodeURIComponent(window.atob(result.LongParamUser)))
+          if (userConfig && !userConfig.version) {
+            Object.keys(userConfig).forEach(key => {
+              let component = userConfig[key]
+
+              if (!component.action) return
+
+              Object.keys(component.action).forEach(uuid => {
+                let item = {uuid: uuid, parentId: key, shortcut: component.action[uuid].shortcut}
+                let printer = component.action[uuid].printer
+
+                if (item.shortcut) {
+                  item.$shortcut = item.shortcut.join('+')
+                  shortcuts.push(item)
+                }
+                if (printer) {
+                  item.printer = printer.defaultPrinter || ''
+                  item.printerList = printer.printerList || ''
+                  window.GLOB.UserCacheMap.set(key + uuid, item)
+                }
+              })
+            })
+          } else if (userConfig) {
+            shortcuts = userConfig.action
+            userConfig.printers.forEach(item => {
+              window.GLOB.UserCacheMap.set(item.parentId + item.uuid, item)
+            })
+          }
         } catch (e) {
           console.warn('Parse Failure')
-          userConfig = null
         }
       }
 
@@ -122,13 +155,27 @@
       }
 
       // 鐗堟湰鍏煎
-      config = UtilsUpdate.updateCommonTable(config)
+      config = updateCommonTable(config)
 
       // 鏉冮檺杩囨护
       if (this.props.menuType !== 'HS') {
         config.action = config.action.filter(item => permAction[item.uuid])
         config.tabgroups.forEach(group => {
-          group.sublist = group.sublist.filter(tab => permAction[tab.linkTab])
+          group.sublist = group.sublist.filter(tab => {
+            if (tab.supMenu === 'mainTable') {
+              tab.supMenu = MenuID
+            }
+            return permAction[tab.linkTab]
+          })
+        })
+      } else {
+        config.tabgroups.forEach(group => {
+          group.sublist = group.sublist.map(tab => {
+            if (tab.supMenu === 'mainTable') {
+              tab.supMenu = MenuID
+            }
+            return tab
+          })
         })
       }
       // 鍘婚櫎绌鸿鏍囩
@@ -147,22 +194,17 @@
       }
       let chartId = config.charts[0] ? config.charts[0].uuid : ''
 
-      // 瀛楁鏉冮檺榛戝悕鍗�
+      config.search = Utils.initSearchVal(config.search)
+
+      // 瀛楁閫忚鍙婂繀濉爣蹇�
+      let hasReqFields = false
       config.search = config.search.map(item => {
-        item.oriInitval = item.initval
-        if (['text', 'select', 'link'].includes(item.type) && param) {
-          if (param.searchkey === item.field) {
-            item.initval = param.searchval
-          } else if (param.BID && item.field.toLowerCase() === 'bid') {
-            item.initval = param.BID
-          } else if (param.data && param.data[item.field]) {
-            item.initval = param.data[item.field]
-          }
+        if (['text', 'select', 'link'].includes(item.type) && param && param.$searchkey === item.field) {
+          item.initval = param.$searchval
         }
 
-        if (!item.blacklist || item.blacklist.length === 0) return item
-        if (item.blacklist.filter(v => roleId.indexOf(v) > -1).length > 0) {
-          item.Hide = 'true'
+        if (item.required) {
+          hasReqFields = true
         }
 
         return item
@@ -184,8 +226,9 @@
       config.setting.laypage = config.setting.laypage !== 'false'     // 鏄惁鍒嗛〉锛岃浆涓篵oolean 缁熶竴鏍煎紡
       config.setting.execute = config.setting.default !== 'false'     // 榛樿sql鏄惁鎵ц锛岃浆涓篵oolean 缁熶竴鏍煎紡
       config.setting.customScript = ''                                // 鑷畾涔夎剼鏈�
+      config.setting.dataresource = config.setting.dataresource || ''
 
-      if (config.setting.interType === 'system') {
+      if (config.setting.interType === 'system' || (config.setting.interType === 'custom' && config.setting.requestMode === 'system')) {
         if (config.setting.scripts && config.setting.scripts.length > 0) {
           let _customScript = ''
           config.setting.scripts.forEach(item => {
@@ -199,10 +242,7 @@
   
         if (!config.setting.execute) { // 榛樿sql 涓嶆墽琛屾椂 缃┖
           config.setting.dataresource = ''
-        } else {
-          config.setting.dataresource = config.setting.dataresource || ''
-        }
-        if (/\s/.test(config.setting.dataresource)) {
+        } else if (/\s/.test(config.setting.dataresource)) {
           config.setting.dataresource = '(' + config.setting.dataresource + ') tb'
         }
   
@@ -215,37 +255,37 @@
           config.setting.dataresource = config.setting.dataresource.replace(/@\$|\$@/ig, '')
           config.setting.customScript = config.setting.customScript.replace(/@\$|\$@/ig, '')
         }
-      }
 
-      if (_curUserConfig) {
-        config.easyCode = _curUserConfig.easyCode || config.easyCode || ''
+        let userName = sessionStorage.getItem('User_Name') || ''
+        let fullName = sessionStorage.getItem('Full_Name') || ''
+        let city = sessionStorage.getItem('city') || ''
 
-        config.action = config.action.map(item => {
-          if (_curUserConfig.action[item.uuid]) {
-            delete _curUserConfig.action[item.uuid].label
-            item = {...item, ..._curUserConfig.action[item.uuid]}
-          }
-          
-          if (item.OpenType === 'funcbutton' && item.funcType === 'print' && item.verify && item.printer) {
-            item.verify.defaultPrinter = item.printer.defaultPrinter || ''
-            if (item.verify.printerTypeList && item.printer.printerList) {
-              item.verify.printerTypeList = item.verify.printerTypeList.map(cell => {
-                cell.printer = item.printer.printerList[cell.Value] || ''
+        if (sessionStorage.getItem('isEditState') === 'true') {
+          userName = sessionStorage.getItem('CloudUserName') || ''
+          fullName = sessionStorage.getItem('CloudFullName') || ''
+        }
 
-                return cell
-              })
-            }
-          }
+        let regs = [
+          { reg: /@userName@/ig, value: `'${userName}'` },
+          { reg: /@fullName@/ig, value: `'${fullName}'` },
+          { reg: /@login_city@/ig, value: `'${city}'` }
+        ]
 
-          return item
+        regs.forEach(cell => {
+          config.setting.dataresource = config.setting.dataresource.replace(cell.reg, cell.value)
+          config.setting.customScript = config.setting.customScript.replace(cell.reg, cell.value)
         })
+
+        if (config.urlFields) {
+          let _param = param || {}
+          config.urlFields.forEach(field => {
+            let reg = new RegExp('@' + field + '@', 'ig')
+            let val = `'${_param[field] || ''}'`
+            config.setting.dataresource = config.setting.dataresource.replace(reg, val)
+            config.setting.customScript = config.setting.customScript.replace(reg, val)
+          })
+        }
       }
-
-      let _tabActive = {} // 绛涢�夊睍寮�鐨則ab椤�
-
-      config.tabgroups.forEach(group => {
-        _tabActive[group.uuid] = group.sublist[0].uuid
-      })
 
       let _arrField = []     // 瀛楁闆�
       let _columns = []      // 鏄剧ず鍒�
@@ -260,6 +300,22 @@
       config.action.forEach(item => {
         item.logLabel = MenuName + '-' + item.label // 鐢ㄤ簬sPC_TableData_InUpDe璁板綍鎿嶄綔鎸夐挳
         item.$menuId = this.props.MenuID
+
+        if (item.OpenType === 'funcbutton' && item.funcType === 'print' && item.verify) { // 鎵撳嵃鏈鸿缃�
+          let _item = window.GLOB.UserCacheMap.get(this.props.MenuID + item.uuid)
+
+          if (_item) {
+            item.printer = _item.printer || ''
+            item.verify.defaultPrinter = _item.printer || ''
+            if (item.verify.printerTypeList && _item.printerList) {
+              item.verify.printerTypeList = item.verify.printerTypeList.map(cell => {
+                cell.printer = _item.printerList[cell.Value] || ''
+  
+                return cell
+              })
+            }
+          }
+        }
         
         if (item.position === 'toolbar') {
           _actions.push(item)
@@ -272,6 +328,13 @@
       config.columns.forEach(col => {
         if (col.field) {
           _arrField.push(col.field)
+
+          if (col.linkmenu && col.linkmenu.length > 0) {
+            let menu_id = col.linkmenu.slice(-1)[0]
+            col.linkThdMenu = permMenus.filter(m => m.MenuID === menu_id)[0] || ''
+          } else {
+            col.linkThdMenu = ''
+          }
 
           col.nameField && _arrField.push(col.nameField) // 閾炬帴鍚嶅瓧娈�
           if (col.Hide !== 'true' && col.type === 'number' && col.sum === 'true') {
@@ -290,13 +353,6 @@
       // 鐢熸垚鏄剧ず鍒楋紝澶勭悊鍚堝苟鍒椾腑鐨勫瓧娈�
       config.columns.forEach((col, index) => {
         if (_hideCol.includes(col.uuid)) return
-        
-        if (col.linkmenu && col.linkmenu.length > 0) {
-          let menu_id = col.linkmenu.slice(-1)[0]
-          col.linkThdMenu = permMenus.filter(m => m.MenuID === menu_id)[0] || ''
-        } else {
-          col.linkThdMenu = ''
-        }
 
         col.sort = index
 
@@ -326,50 +382,44 @@
         _columns.push(config.gridBtn)
       }
 
-      let valid = true // 鎼滅储鏉′欢蹇呭~楠岃瘉, 鍒濆鎼滅储鏉′欢, 濡傞�氳繃涓婄骇閫忚锛屽啓鍏ユ悳绱㈡潯浠�
-      let initSearch = config.search.map(item => {
-        let _item = fromJS(item).toJS()
+      if (config.setting.selected !== 'init' && config.setting.selected !== 'always') {
+        config.setting.selected = 'false'
+      } else if (config.setting.selected === 'init' && config.setting.onload === 'false') {
+        config.setting.selected = 'false'
+      }
 
-        if (_item.required === 'true' && !_item.initval) {
-          valid = false
-        }
-        return _item
-      })
-
-      if (_curUserConfig) {
-        _columns = _columns.map(item => {
-          if (_curUserConfig.columns[item.uuid]) {
-            delete _curUserConfig.columns[item.uuid].label
-            item = {...item, ..._curUserConfig.columns[item.uuid]}
+      let autoMatic = null
+      if (config.autoMatic && config.autoMatic.enable === 'true') {
+        _actions.forEach(item => {
+          if (item.uuid === config.autoMatic.action && (['pop', 'prompt', 'exec'].includes(item.OpenType) || (item.OpenType === 'funcbutton' && item.funcType === 'print'))) {
+            autoMatic = config.autoMatic
+            autoMatic.OpenType = item.execMode || item.OpenType
+            config.setting.selected = 'false'
+            item.autoMatic = true
           }
-
-          return item
-        })
-
-        _columns.sort((pre, next) => {
-          return pre.sort - next.sort
         })
       }
 
       this.setState({
+        pageSize: config.setting.pageSize || 10,
         loadingview: false,
         absFields,
+        autoMatic,
         chartId,
         config,
         statFields,
-        userConfig,
-        tabActive: _tabActive,
+        shortcuts,
         setting: config.setting,
         searchlist: config.search,
         actions: _actions,
         columns: _columns,
         arr_field: _arrField.join(','),
-        BID: param && param.BID ? param.BID : '',
-        search: Utils.initMainSearch(initSearch) // 鎼滅储鏉′欢鍒濆鍖栵紙鍚湁鏃堕棿鏍煎紡锛岄渶瑕佽浆鍖栵級
+        BID: param && param.$BID ? param.$BID : '',
+        search: Utils.initMainSearch(config.search),
+        hasReqFields
       }, () => {
-        if (config.setting.onload !== 'false' && valid) { // 鍒濆鍖栧彲鍔犺浇
-          this.loadmaindata()
-          this.getStatFieldsValue()
+        if (config.setting.onload !== 'false') { // 鍒濆鍖栧彲鍔犺浇
+          this.loadData()
         }
         this.setShortcut()
       })
@@ -387,8 +437,12 @@
   }
 
   setShortcut = () => {
-    const { actions, userConfig, config } = this.state
-    if (!userConfig) return
+    const { shortcuts } = this.state
+
+    if (!shortcuts || shortcuts.length === 0) {
+      document.onkeydown = () => {}
+      return
+    }
 
     document.onkeydown = (event) => {
       let e = event || window.event
@@ -403,88 +457,241 @@
         preKey = 'alt'
       }
 
-      if (!preKey) return
+      if (!preKey || !keyCode) return
 
-      let triggerId = ''
+      let _shortcut = `${preKey}+${keyCode}`
 
-      actions.some(item => {
-        if (Array.isArray(item.shortcut) && preKey === item.shortcut[0] && keyCode === item.shortcut[1]) {
-          e.preventDefault()
-          triggerId = item.uuid
+      shortcuts.some(item => {
+        if (item.$shortcut === _shortcut) {
+          MKEmitter.emit('triggerBtnId', item.uuid)
+
+          let element = item.parentId && item.parentId !== this.props.MenuID ? document.getElementById(item.parentId) : '' // 鏍囩鍒囨崲
+          if (element && element.click) {
+            element.click()
+          }
+
           return true
         }
         return false
       })
+    }
+  }
 
-      if (triggerId) {
-        MKEmitter.emit('triggerBtnId', triggerId)
+  loadData = () => {
+    const { MenuID } = this.props
+    const { setting, search, loadCustomApi, hasReqFields, ContainerId } = this.state
+
+    this.setState({
+      selectedData: []
+    })
+    MKEmitter.emit('changeTableLine', ContainerId, MenuID, '', '')
+
+    if (hasReqFields) {
+      let requireFields = search.filter(item => item.required && item.value === '')
+
+      if (requireFields.length > 0) {
+        this.setState({
+          loading: false
+        })
         return
       }
+    }
 
-      Object.keys(userConfig).some(key => {
-        if (key === this.props.MenuID || !userConfig[key].action) return false
+    if (window.GLOB.systemType === 'production' && setting.interType === 'custom' && !setting.proInterface) {
+      notification.warning({
+        top: 92,
+        message: '鏈缃寮忕郴缁熷湴鍧�!',
+        duration: 3
+      })
+      return
+    }
 
-        let _actions = userConfig[key].action
+    if (setting.interType === 'custom' && loadCustomApi) {
+      if (setting.execTime === 'once') {
+        this.setState({loadCustomApi: false})
+      }
 
-        Object.keys(_actions).some(btnkey => {
-          let item = _actions[btnkey]
+      this.loadOutResource()
+      if (setting.execType === 'async') {
+        this.loadmaindata()
+      }
+    } else {
+      this.loadmaindata()
+    }
+  }
 
-          if (Array.isArray(item.shortcut) && preKey === item.shortcut[0] && keyCode === item.shortcut[1]) {
-            e.preventDefault()
-            triggerId = btnkey
+  loadOutResource = () => {
+    const { setting, search, BID } = this.state
 
-            let _groupId = ''
-            let _ActiveTabId = ''
-            config.tabgroups.forEach(group => {
-              let _tab = group.sublist.filter(tab => tab.uuid === key)[0]
+    let param = UtilsDM.getPrevQueryParams(setting, search, BID, this.props.menuType)
 
-              if (!_tab) return
-
-              _groupId = group.uuid
-              _ActiveTabId = _tab.uuid
-            })
-
-            if (_ActiveTabId && this.state.tabActive[_groupId] === _ActiveTabId) {
-              MKEmitter.emit('triggerBtnId', triggerId)
-              return true
-            }
-          }
-          return false
-        })
-
-        if (triggerId) return true
-        return false
+    if (setting.execType === 'sync') {
+      this.setState({
+        loading: true
       })
     }
+
+    Api.genericInterface(param).then(res => {
+      if (res.status) {
+        if (res.mk_ex_invoke === 'false' || res.mk_ex_invoke === false) {
+          this.loadmaindata()
+        } else {
+          this.customOuterRequest(res)
+        }
+      } else {
+        this.setState({
+          loading: false
+        })
+        notification.error({
+          top: 92,
+          message: res.message,
+          duration: 10
+        })
+      }
+    }, () => {
+      this.setState({
+        loading: false
+      })
+    })
+  }
+
+  customOuterRequest = (result) => {
+    const { setting } = this.state
+    let url = ''
+
+    if (window.GLOB.systemType === 'production') {
+      url = setting.proInterface
+    } else {
+      url = setting.interface
+    }
+
+    let mkey = result.mk_api_key || ''
+
+    delete result.mk_ex_invoke // 鏄惁缁х画鎵ц
+    delete result.status
+    delete result.message
+    delete result.ErrCode
+    delete result.ErrMesg
+    delete result.mk_api_key   // 褰撳墠璇锋眰鐨刱ey鍊硷紝鐢ㄤ簬鍥炶皟
+
+    let param = {}
+
+    Object.keys(result).forEach(key => {
+      key = key.replace(/^mk_/ig, '')
+      param[key] = result[key]
+    })
+
+    Api.directRequest(url, setting.method, param, setting.cross).then(res => {
+      if (typeof(res) !== 'object') {
+        let error = '鏈煡鐨勮繑鍥炵粨鏋滐紒'
+
+        if (typeof(res) === 'string') {
+          error = res.replace(/'/ig, '"')
+        }
+
+        let _result = {
+          mk_api_key: mkey,
+          $ErrCode: 'E',
+          $ErrMesg: error
+        }
+
+        this.customCallbackRequest(_result)
+      } else {
+        if (Array.isArray(res)) {
+          res = { data: res }
+        }
+        res.mk_api_key = mkey
+        this.customCallbackRequest(res)
+      }
+    }, (e) => {
+      let _result = {
+        mk_api_key: mkey,
+        $ErrCode: 'E',
+        $ErrMesg: e && e.statusText ? e.statusText : ''
+      }
+
+      this.customCallbackRequest(_result)
+    })
+  }
+
+  customCallbackRequest = (result) => {
+    const { setting } = this.state
+    let errSql = ''
+    if (result.$ErrCode === 'E') {
+      errSql = `
+        set @ErrorCode='E'
+        set @retmsg='${result.$ErrMesg}'
+      `
+      delete result.$ErrCode
+      delete result.$ErrMesg
+    }
+
+    let lines = UtilsDM.getCallBackSql(setting, result)
+    let param = {}
+
+    if (setting.callbackType === 'script') { // 浣跨敤鑷畾涔夎剼鏈�
+      let sql = lines.map(item => (`
+        ${item.insert}
+        ${item.selects.join(` union all
+        `)}
+      `))
+      sql = sql.join('')
+      
+      param = UtilsDM.getCallBackQueryParams(setting, sql, errSql)
+
+      if (this.state.BID) {
+        param.BID = this.state.BID
+      }
+
+      if (this.props.menuType === 'HS') { // 鍑芥暟 sPC_TableData_InUpDe 浜戠楠岃瘉
+        param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp)
+      }
+    } else {
+      param.func = 's_ex_result_back'
+      param.s_ex_result = lines.map((item, index) => ({
+        MenuID: this.state.config.MenuID,
+        MenuName: this.state.config.MenuName,
+        TableName: item.table,
+        LongText: window.btoa(window.encodeURIComponent(`${item.insert}  ${item.selects.join(` union all `)}`)),
+        Sort: index + 1
+      }))
+
+      if ((window.GLOB.systemType !== 'production' && options.sysType !== 'cloud') || window.debugger === true) {
+        let sql = lines.map(item => (`
+          ${item.insert}
+          ${item.selects.join(` union all
+          `)}
+        `))
+        sql = sql.join('')
+        console.info(sql.replace(/\n\s{10}/ig, '\n'))
+      }
+    }
+
+    Api.genericInterface(param).then(res => {
+      if (res.status) {
+        this.loadmaindata()
+      } else {
+        this.setState({
+          loading: false
+        })
+        notification.error({
+          top: 92,
+          message: res.message,
+          duration: 10
+        })
+      }
+    }, () => {
+      this.setState({
+        loading: false
+      })
+    })
   }
 
   /**
    * @description 涓昏〃鏁版嵁鍔犺浇
    */ 
   async loadmaindata () {
-    const { setting, arr_field, BIDs, search, orderBy, BID, pageIndex, pageSize, absFields } = this.state
-    let requireFields = search.filter(item => item.required && (!item.value || item.value.length === 0))
-
-    this.setState({
-      selectedData: [],
-      BIDs: {
-        ...BIDs,
-        mainTable: '',
-        mainTabledata: ''
-      }
-    })
-
-    if (requireFields.length > 0) {
-      let labels = requireFields.map(item => item.label)
-      labels = Array.from(new Set(labels))
-
-      notification.warning({
-        top: 92,
-        message: this.state.dict['form.required.input'] + labels.join('銆�') + ' !',
-        duration: 3
-      })
-      return
-    }
+    const { setting, arr_field, search, orderBy, BID, pageIndex, pageSize, absFields, autoMatic } = this.state
 
     this.setState({
       loading: true
@@ -493,12 +700,25 @@
     let _orderBy = orderBy || setting.order
     let param = UtilsDM.getQueryDataParams(setting, arr_field, search, _orderBy, pageIndex, pageSize, BID, this.props.menuType)
 
-    if (param.func === 'sPC_Get_TableData') {
-      param.menuname = this.props.MenuName || ''
-    }
-
     let result = await Api.genericInterface(param)
+
+    this.getStatFieldsValue()
+
     if (result.status) {
+      let start = 1
+      if (setting.laypage) {
+        start = pageSize * (pageIndex - 1) + 1
+      }
+
+      if (setting.selected !== 'false') {
+        setTimeout(() => {
+          MKEmitter.emit('mkTableCheckTopLine', this.props.MenuID)
+        }, 200)
+        if (setting.selected === 'init') {
+          this.setState({setting: {...setting, selected: 'false'}})
+        }
+      }
+
       this.setState({
         data: result.data.map((item, index) => {
           if (absFields.length) {
@@ -513,6 +733,7 @@
           item.key = index
           item.$$uuid = item[setting.primaryKey] || ''
           item.$$BID = BID || ''
+          item.$Index = start + index + ''
 
           return item
         }),
@@ -520,10 +741,21 @@
         loading: false,
         pickup: false
       })
+
+      if (autoMatic) {
+        if (result.data && result.data.length > 0) {
+          MKEmitter.emit('autoGetData', this.props.MenuID)
+        } else {
+          MKEmitter.emit('autoMaticOver', this.props.MenuID)
+        }
+      }
     } else {
       this.setState({
         loading: false
       })
+      if (autoMatic) {
+        MKEmitter.emit('autoMaticError', this.props.MenuID)
+      }
       notification.error({
         top: 92,
         message: result.message,
@@ -545,15 +777,12 @@
     let _orderBy = orderBy || setting.order
     let param = UtilsDM.getQueryDataParams(setting, arr_field, search, _orderBy, pageIndex, pageSize, BID, this.props.menuType, id)
 
-    if (param.func === 'sPC_Get_TableData') {
-      param.menuname = this.props.MenuName || ''
-    }
-
     let result = await Api.genericInterface(param)
     if (result.status) {
       let data = fromJS(this.state.data).toJS()
+      let selectedData = fromJS(this.state.selectedData).toJS()
       if (result.data && result.data[0]) {
-        let _data = result.data[0]
+        let _data = result.data[0] || {}
 
         if (absFields.length) {
           absFields.forEach(field => {
@@ -563,26 +792,33 @@
             _data[field] = Math.abs(_data[field])
           })
         }
+        _data.$$uuid = _data[setting.primaryKey] || ''
+        _data.$$BID = BID || ''
 
         try {
           data = data.map(item => {
-            if (item[setting.primaryKey] === _data[setting.primaryKey]) {
+            if (item.$$uuid === _data.$$uuid) {
               _data.key = item.key
-              _data.$$uuid = _data[setting.primaryKey] || ''
-              _data.$$BID = BID || ''
-
+              _data.$Index = item.$Index
               return _data
             } else {
               return item
             }
           })
-        } catch {
+          selectedData = selectedData.map(item => {
+            if (_data.$$uuid === item.$$uuid) {
+              return _data
+            }
+            return item
+          })
+        } catch (e) {
           console.warn('鏁版嵁鏌ヨ閿欒')
         }
       }
 
       this.setState({
-        data: data,
+        data,
+        selectedData,
         loading: false
       })
     } else {
@@ -603,19 +839,10 @@
   getStatFieldsValue = () => {
     const { setting, search, BID, orderBy, statFields } = this.state
 
-    if (statFields.length === 0 || setting.interType !== 'system' || !setting.dataresource) return
-
-    let requireFields = search.filter(item => item.required && (!item.value || item.value.length === 0))
-    if (requireFields.length > 0) {
-      return
-    }
+    if (statFields.length === 0 || !(setting.interType === 'system' || (setting.interType === 'custom' && setting.requestMode === 'system')) || !setting.dataresource) return
 
     let _orderBy = orderBy || setting.order
     let param = UtilsDM.getStatQueryDataParams(setting, statFields, search, _orderBy, BID, this.props.menuType)
-
-    if (param.func === 'sPC_Get_TableData') {
-      param.menuname = this.props.MenuName || ''
-    }
 
     Api.genericInterface(param).then(res => {
       if (res.status) {
@@ -663,17 +890,15 @@
         search: searches,
         setting: {...setting, onload: 'true'}
       }, () => {
-        this.loadmaindata()
-        this.getStatFieldsValue()
+        this.loadData()
       })
     } else {
-      MKEmitter.emit('resetTable', this.props.MenuID + 'mainTable') // 鍒楄〃閲嶇疆
+      MKEmitter.emit('resetTable', this.props.MenuID) // 鍒楄〃閲嶇疆
       this.setState({
         pageIndex: 1,
         search: searches
       }, () => {
-        this.loadmaindata()
-        this.getStatFieldsValue()
+        this.loadData()
       })
     }
   }
@@ -682,6 +907,15 @@
    * @description 琛ㄦ牸鏉′欢鏀瑰彉鏃堕噸缃暟鎹紙鍒嗛〉鎴栨帓搴忥級
    */
   refreshbytable = (pagination, filters, sorter) => {
+    if (!sorter) {
+      this.setState({
+        pageIndex: pagination.pageIndex
+      }, () => {
+        this.loadData()
+      })
+      return
+    }
+
     if (sorter.order) {
       let _chg = {
         ascend: 'asc',
@@ -695,7 +929,7 @@
       pageSize: pagination.pageSize,
       orderBy: (sorter.field && sorter.order) ? `${sorter.field} ${sorter.order}` : ''
     }, () => {
-      this.loadmaindata()
+      this.loadData()
     })
   }
 
@@ -704,17 +938,15 @@
    */
   reloadtable = (btn) => {
     if (!btn || btn.resetPageIndex !== 'false') {
-      MKEmitter.emit('resetTable', this.props.MenuID + 'mainTable') // 鍒楄〃閲嶇疆
+      MKEmitter.emit('resetTable', this.props.MenuID) // 鍒楄〃閲嶇疆
       this.setState({
         pageIndex: 1
       }, () => {
-        this.loadmaindata()
-        this.getStatFieldsValue()
+        this.loadData()
       })
     } else {
-      MKEmitter.emit('resetTable', this.props.MenuID + 'mainTable', 'false') // 鍒楄〃閲嶇疆
-      this.loadmaindata()
-      this.getStatFieldsValue()
+      MKEmitter.emit('resetTable', this.props.MenuID, 'false') // 鍒楄〃閲嶇疆
+      this.loadData()
     }
   }
 
@@ -723,7 +955,7 @@
    */
   reloadview = () => {
     this.setState({ loadingview: true, viewlost: false, config: {}, setting: null,
-      data: null, total: 0, loading: false, pageIndex: 1,
+      data: null, total: 0, loading: false, pageIndex: 1, shortcuts: null,
       pageSize: 10, orderBy: '', search: '', BIDs: {}, pickup: false
     }, () => {
       this.loadconfig()
@@ -733,13 +965,13 @@
   /**
    * @description 瀵煎嚭Excel鏃讹紝鑾峰彇椤甸潰鎼滅储鎺掑簭绛夊弬鏁�
    */
-  getexceloutparam = (menuId, btnId) => {
+  queryModuleParam = (menuId, btnId) => {
     const { MenuName, MenuID } = this.props
     const { arr_field, orderBy, search, setting} = this.state
 
     if (MenuID !== menuId) return
 
-    MKEmitter.emit('execExcelout', MenuID, btnId, {
+    MKEmitter.emit('returnModuleParam', MenuID, btnId, {
       arr_field: arr_field,
       orderBy: orderBy || setting.order,
       search: search,
@@ -752,21 +984,6 @@
    */
   changeSelectedData = (selectedData) => {
     this.setState({selectedData})
-  }
-
-  /**
-   * @description 琛ㄦ牸Id鍙樺寲
-   */
-  handleTableId = (type, id, data) => {
-    const { BIDs } = this.state
-
-    this.setState({
-      BIDs: {
-        ...BIDs,
-        [type]: id,
-        [type + 'data']: data
-      }
-    })
   }
   
   /**
@@ -804,12 +1021,16 @@
     }
   }
 
-  reloadMenuView = (menuId) => {
+  reloadMenuView = (menuId, position) => {
     const { MenuID } = this.props
 
     if (MenuID !== menuId) return
 
-    this.reloadview()
+    if (position === 'table') {
+      this.reloadtable()
+    } else {
+      this.reloadview()
+    }
   }
 
   resetActiveMenu = (menuId) => {
@@ -820,40 +1041,35 @@
     this.setShortcut()
   }
 
+  changeTableLine = (ContainerId, tableId, id, data) => {
+    if (this.state.ContainerId !== ContainerId) return
+
+    this.setState({
+      BIDs: {...this.state.BIDs, [tableId]: id, [tableId + 'data']: data}
+    })
+  }
+
   /**
    * @description 鎸夐挳鎵ц瀹屾垚鍚庨〉闈㈠埛鏂�
    * @param {*} menuId     // 鑿滃崟Id
    * @param {*} position   // 鍒锋柊浣嶇疆
    * @param {*} btn        // 鎵ц鐨勬寜閽�
    */
-  refreshByButtonResult = (menuId, position, btn) => {
+  refreshByButtonResult = (menuId, position, btn, id, lines) => {
     const { MenuID } = this.props
 
     if (MenuID !== menuId) return
 
-    this.reloadtable(btn)
+    if (position === 'line' && lines && lines.length === 1) {
+      this.loadmainLinedata(lines[0].$$uuid)
+    } else {
+      this.reloadtable(btn)
+    }
   }
 
   UNSAFE_componentWillMount () {
     // 缁勪欢鍔犺浇鏃讹紝鑾峰彇鑿滃崟鏁版嵁
     this.loadconfig()
-  }
-
-  UNSAFE_componentWillReceiveProps(nextProps) {
-     if (!is(fromJS(this.props.tabviews), fromJS(nextProps.tabviews))) {
-      let selectTab = nextProps.tabviews.filter(tab => tab.selected)[0]
-      if (selectTab && selectTab.MenuID === this.props.MenuID) {
-        this.setShortcut()
-      }
-    } else if (nextProps.param && !is(fromJS(this.props.param), fromJS(nextProps.param))) {
-      let search = this.state.search.map(item => {
-        if (item.type === 'text' && item.key === nextProps.param.searchkey) {
-          item.value = nextProps.param.searchval
-        }
-        return item
-      })
-      this.refreshbysearch(search)
-    }
   }
 
   shouldComponentUpdate (nextProps, nextState) {
@@ -863,8 +1079,9 @@
   componentDidMount () {
     MKEmitter.addListener('reloadData', this.reloadData)
     MKEmitter.addListener('reloadMenuView', this.reloadMenuView)
+    MKEmitter.addListener('changeTableLine', this.changeTableLine)
     MKEmitter.addListener('resetActiveMenu', this.resetActiveMenu)
-    MKEmitter.addListener('getexceloutparam', this.getexceloutparam)
+    MKEmitter.addListener('queryModuleParam', this.queryModuleParam)
     MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult)
   }
 
@@ -878,26 +1095,27 @@
     document.onkeydown = () => {}
     MKEmitter.removeListener('reloadData', this.reloadData)
     MKEmitter.removeListener('reloadMenuView', this.reloadMenuView)
+    MKEmitter.removeListener('changeTableLine', this.changeTableLine)
     MKEmitter.removeListener('resetActiveMenu', this.resetActiveMenu)
-    MKEmitter.removeListener('getexceloutparam', this.getexceloutparam)
+    MKEmitter.removeListener('queryModuleParam', this.queryModuleParam)
     MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult)
   }
 
   render() {
-    const { menuType, MenuName } = this.props
-    const { BID, setting, searchlist, pageSize, actions, columns, loadingview, viewlost, pickup, config, userConfig, tabActive, chartId, search, selectedData } = this.state
+    const { menuType, MenuID } = this.props
+    const { BID, setting, searchlist, pageSize, actions, columns, loadingview, viewlost, pickup, config, chartId, search, selectedData, shortcuts, autoMatic } = this.state
 
     return (
       <div className="commontable" id={this.state.ContainerId}>
-        {loadingview && <Spin size="large" />}
+        {loadingview ? <Spin size="large" /> : null}
         {searchlist && searchlist.length ?
-          <MainSearch BID={BID} searchlist={searchlist} menuType={this.props.menuType} refreshdata={this.refreshbysearch}/> : null
+          <MainSearch BID={BID} searchlist={searchlist} setting={setting} menuType={this.props.menuType} refreshdata={this.refreshbysearch}/> : null
         }
         {setting ? <Row className="chart-view" gutter={16}>
           {/* 瑙嗗浘缁� */}
           {!config.expand ? <Tabs activeKey={chartId} onChange={this.changeChart}>
             {config.charts.map(item => (
-              <TabPane tab={<Icon type={item.icon} />} key={item.uuid}></TabPane>
+              <TabPane tab={<MkIcon type={item.icon} />} key={item.uuid}></TabPane>
             ))}
           </Tabs> : null}
           {config.charts.map(item => {
@@ -914,27 +1132,18 @@
                       actions={actions}
                       columns={columns}
                       dict={this.state.dict}
-                      MenuID={this.props.MenuID}
+                      MenuID={MenuID}
                       selectedData={selectedData}
                       ContainerId={this.state.ContainerId}
                     />
                   </div>
                   <div className="main-table-box">
-                    {this.props.menuType !== 'HS' ? <SettingComponent
-                      config={config}
-                      columns={columns}
-                      MenuName={MenuName}
-                      dict={this.state.dict}
-                      MenuID={this.props.MenuID}
-                      permAction={this.props.permAction}
-                      userConfig={this.state.userConfig}
-                      reloadview={this.reloadview}
-                    /> : null}
                     {(setting.tableType === 'radio' || setting.tableType === 'checkbox') && this.state.data && this.state.data.length > 0 ?
-                      <Switch title="鏀惰捣" className="main-pickup" checkedChildren="寮�" unCheckedChildren="鍏�" defaultChecked={pickup} onChange={this.pickupChange} /> : null
+                      <Switch title="鏀惰捣" className="main-pickup" checkedChildren="寮�" unCheckedChildren="鍏�" checked={pickup} onChange={this.pickupChange} /> : null
                     }
                     <MainTable
-                      tableId="mainTable"
+                      MenuID={MenuID}
+                      tableId={MenuID}
                       pickup={pickup}
                       setting={setting}
                       columns={columns}
@@ -942,12 +1151,10 @@
                       dict={this.state.dict}
                       data={this.state.data}
                       total={this.state.total}
-                      MenuID={this.props.MenuID}
                       loading={this.state.loading}
                       statFValue={this.state.statFValue}
                       ContainerId={this.state.ContainerId}
                       refreshdata={this.refreshbytable}
-                      handleTableId={this.handleTableId}
                       chgSelectData={this.changeSelectedData}
                     />
                   </div>
@@ -959,14 +1166,13 @@
                   <CardComponent
                     BID={BID}
                     plot={item}
+                    MenuID={MenuID}
                     config={config}
+                    tableId={MenuID}
                     columns={columns}
-                    tableId="mainTable"
                     data={this.state.data}
-                    MenuID={this.props.MenuID}
                     loading={this.state.loading}
                     ContainerId={this.state.ContainerId}
-                    handleTableId={this.handleTableId}
                   />
                 </Col>
               )
@@ -986,32 +1192,32 @@
           })}
         </Row> : null }
         {setting && config.tabgroups.map(group => (
-          <Tabs key={group.uuid} onChange={(key) => this.setState({tabActive: {...tabActive, [group.uuid]: key}})}>
+          <Tabs key={group.uuid}>
             {group.sublist.map(_tab => {
               return (
                 <TabPane tab={
-                  <span>
-                    {_tab.icon ? <Icon type={_tab.icon} /> : null}
+                  <span id={_tab.uuid}>
+                    {_tab.icon ? <MkIcon type={_tab.icon} /> : null}
                     {_tab.label}
                   </span>
                 } key={_tab.uuid}>
                   <SubTable
                     Tab={_tab}
+                    SupMenuID={MenuID}
                     MenuID={_tab.linkTab}
                     mainSearch={_tab.searchPass === 'true' ? search : null}
-                    userConfig={userConfig ? userConfig[_tab.uuid] : null}
-                    SupMenuID={this.props.MenuID}
                     ContainerId={this.state.ContainerId}
                     BID={this.state.BIDs[_tab.supMenu] || ''}
                     BData={this.state.BIDs[_tab.supMenu + 'data'] || ''}
-                    handleTableId={this.handleTableId}
                   />
                 </TabPane>
               )
             })}
           </Tabs>))
         }
-        {menuType !== 'HS' ? <PagemsgComponent menu={{MenuName: this.props.MenuName, MenuNo: this.props.MenuNo}} config={config} dict={this.state.dict} /> : null}
+        {menuType !== 'HS' && autoMatic ? <AutoMatic autoMatic={autoMatic} config={config} /> : null}
+        {menuType !== 'HS' && window.GLOB.systemType !== 'production' ? <PagemsgComponent menu={{MenuName: this.props.MenuName, MenuNo: this.props.MenuNo}} config={config} dict={this.state.dict} /> : null}
+        {menuType !== 'HS' && shortcuts ? <SettingComponent config={config} dict={this.state.dict} shortcuts={shortcuts} permAction={this.props.permAction}/> : null}
         {viewlost ? <NotFount msg={this.state.lostmsg} /> : null}
       </div>
     )
@@ -1021,7 +1227,6 @@
 const mapStateToProps = (state) => {
   return {
     menuType: state.editLevel,
-    tabviews: state.tabviews,
     permAction: state.permAction,
     permMenus: state.permMenus
   }

--
Gitblit v1.8.0