From 9e716f3bd30820a08757845b592db73363faa48c Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期一, 25 四月 2022 14:53:37 +0800
Subject: [PATCH] 2022-04-25

---
 src/tabviews/subtabtable/index.jsx |  795 ++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 507 insertions(+), 288 deletions(-)

diff --git a/src/tabviews/subtabtable/index.jsx b/src/tabviews/subtabtable/index.jsx
index 7602306..9343c02 100644
--- a/src/tabviews/subtabtable/index.jsx
+++ b/src/tabviews/subtabtable/index.jsx
@@ -2,40 +2,33 @@
 import PropTypes from 'prop-types'
 import {connect} from 'react-redux'
 import { is, fromJS } from 'immutable'
-import { notification, Spin, Col, Row, Icon, Tabs} from 'antd'
+import { notification, Spin} 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 { updateSubTabTable } from '@/utils/utils-update.js'
 import asyncComponent from '@/utils/asyncComponent'
 import asyncSpinComponent from '@/utils/asyncSpinComponent'
-import SubSearch from '@/tabviews/zshare/topSearch'
 import NotFount from '@/components/404'
 import MKEmitter from '@/utils/events.js'
 
 import './index.scss'
 
-const { TabPane } = Tabs
+const SubSearch = asyncComponent(() => import('@/tabviews/zshare/topSearch'))
 const SubAction = asyncComponent(() => import('@/tabviews/zshare/actionList'))
 const SubTable = asyncSpinComponent(() => import('@/tabviews/zshare/normalTable'))
-const CardComponent = asyncSpinComponent(() => import('@/tabviews/zshare/cardcomponent'))
-const ChartComponent = asyncSpinComponent(() => import('@/tabviews/zshare/chartcomponent'))
 
 class SubTabModalTable extends Component {
   static propTpyes = {
-    type: PropTypes.any,             // 绫诲瀷锛宑alendar闇�鐗规畩澶勭悊
     Tab: PropTypes.any,              // 鏃ュ巻鏍囩淇℃伅鎴栨爣绛炬寜閽俊鎭�
     BID: PropTypes.string,           // 涓婄骇鏁版嵁ID
     BData: PropTypes.any,            // 涓婄骇鏁版嵁
     MenuID: PropTypes.string,        // 鑿滃崟Id
-    mainSearch: PropTypes.any,       // 涓昏〃鎼滅储鏉′欢
     SupMenuID: PropTypes.string,     // 涓婄骇鑿滃崟Id
-    refreshSupView: PropTypes.any,   // 鍒锋柊涓婄骇鑿滃崟
-    closeModalView: PropTypes.any    // 鍏抽棴妯℃�佹
   }
 
   state = {
@@ -47,10 +40,9 @@
     searchlist: null,     // 鎼滅储鏉′欢
     actions: null,        // 鎸夐挳闆�
     columns: null,        // 鏄剧ず鍒�
-    logcolumns: null,     // 鏃ュ織涓樉绀虹殑鍒椾俊鎭� (澧炲姞鑷冲叏閮ㄥ垪锛岄櫎鍘诲悎骞跺垪)
     arr_field: '',        // 浣跨敤 sPC_Get_TableData 鏃剁殑鏌ヨ瀛楁闆�
     setting: null,        // 椤甸潰鍏ㄥ眬璁剧疆锛氭暟鎹簮銆佹寜閽強鏄剧ず鍒楀浐瀹氥�佷富閿瓑
-    data: null,           // 鍒楄〃鏁版嵁闆�
+    data: [],             // 鍒楄〃鏁版嵁闆�
     selectedData: [],     // 宸查�夎〃鏍兼暟鎹�
     total: 0,             // 鎬绘暟
     loading: false,       // 鍒楄〃鏁版嵁鍔犺浇涓�
@@ -58,16 +50,18 @@
     pageSize: 10,         // 姣忛〉鏁版嵁鏉℃暟
     orderBy: '',          // 鎺掑簭
     search: '',           // 鎼滅储鏉′欢鏁扮粍锛屼娇鐢ㄦ椂闇�鍒嗗満鏅鐞�
-    chartId: '',          // 灞曞紑鍥捐〃ID
     statFields: [],       // 鍚堣瀛楁
-    statFValue: []        // 鍚堣鍊�
+    statFValue: [],       // 鍚堣鍊�
+    absFields: [],        // 缁濆鍊煎瓧娈�
+    loadCustomApi: true,  // 鍔犺浇澶栭儴璧勬簮
+    hasReqFields: false
   }
 
   /**
    * @description 鑾峰彇椤甸潰閰嶇疆淇℃伅
    */
   async loadconfig () {
-    const { permAction, type } = this.props
+    const { permAction, Tab } = this.props
 
     let param = {
       func: 'sPC_Get_LongParam',
@@ -79,6 +73,8 @@
 
       try { // 閰嶇疆淇℃伅瑙f瀽
         config = JSON.parse(window.decodeURIComponent(window.atob(result.LongParam)))
+        config.setting.MenuName = Tab.label
+        config.setting.$name = Tab.label
       } catch (e) {
         console.warn('Parse Failure')
         config = ''
@@ -105,19 +101,30 @@
 
       let _arrField = []     // 瀛楁闆�
       let _columns = []      // 鏄剧ず鍒�
-      let _logcolumns = []   // 鏃ュ織鏄剧ず鍒�
       let _hideCol = []      // 闅愯棌鍙婂悎骞跺垪涓瓧娈电殑uuid闆�
       let colMap = new Map()
       let statFields = []    // 鍚堣瀛楁淇℃伅
+      let absFields = []     // 缁濆鍊煎瓧娈�
 
       // 鐗堟湰鍏煎
-      config = UtilsUpdate.updateSubTable(config)
+      config = updateSubTabTable(config)
 
-      // 浠呮敮鎸乪xec銆乸rompt銆乸op 涓夌绫诲瀷鎸夐挳
-      if (type === 'calendar') {
-        config.action = config.action.filter(item => ['exec', 'prompt', 'pop', 'tab', 'excelIn', 'excelOut'].includes(item.OpenType))
-      } else {
-        config.action = config.action.filter(item => ['exec', 'prompt', 'pop'].includes(item.OpenType))
+      // 涓嶆敮鎸乫uncbutton銆乸opview 绫诲瀷鎸夐挳
+      let labels = []
+      config.action = config.action.filter(item => {
+        if (['exec', 'prompt', 'pop', 'tab', 'excelIn', 'excelOut', 'innerpage'].includes(item.OpenType)) return true
+
+        labels.push(item.label)
+
+        return false
+      })
+
+      if (window.GLOB.systemType !== 'production' && labels.length > 0) {
+        notification.warning({
+          top: 92,
+          message: `涓嶆敮鎸佹寜閽紙${labels.join('銆�')}锛夌殑鎵撳紑鏂瑰紡锛乣,
+          duration: 5
+        })
       }
 
       // 鏉冮檺杩囨护
@@ -125,73 +132,42 @@
         config.action = config.action.filter(item => permAction[item.uuid])
       }
 
-      // 瀛楁鏉冮檺榛戝悕鍗�
-      config.search = config.search.filter(item => {
-        item.oriInitval = item.initval
-        if (!item.blacklist || item.blacklist.length === 0) return item
+      config.search = Utils.initSearchVal(config.search)
 
-        let _black = item.blacklist.filter(v => {
-          return this.props.permRoles.indexOf(v) !== -1
-        })
-
-        if (_black.length > 0) {
-          item.Hide = 'true'
+      let hasReqFields = false
+      config.search.forEach(field => {
+        if (field.required) {
+          hasReqFields = true
         }
-
-        return item
       })
 
-      config.columns = config.columns.filter(col => {
-        if (!col.field || !col.blacklist || col.blacklist.length === 0 || config.setting.primaryKey === col.field) return col
+      // 瀛楁鏉冮檺榛戝悕鍗�
+      let roleId = sessionStorage.getItem('role_id') || '' // 瑙掕壊ID
 
-        let _black = col.blacklist.filter(v => {
-          return this.props.permRoles.indexOf(v) !== -1
-        })
-
-        if (_black.length > 0) {
+      config.columns = config.columns.map(col => {
+        if (!col.blacklist || col.blacklist.length === 0) return col
+        if (col.blacklist.filter(v => roleId.indexOf(v) > -1).length > 0) {
           col.Hide = 'true'
         }
 
         return col
       })
 
-      // 瑙嗗浘鏉冮檺
-      config.charts = config.charts.filter(item => {
-        if (item.Hide === 'true') return false
-        if (!item.blacklist || item.blacklist.length === 0) return true
-
-        let _black = item.blacklist.filter(v => {
-          return this.props.permRoles.indexOf(v) !== -1
-        })
-
-        if (_black.length > 0 || item.Hide === 'true') {
-          return false
-        } else {
-          return true
-        }
-      })
-
-      if (config.charts.length <= 1) {
-        config.expand = true
-      }
-
-      let chartId = config.charts[0] ? config.charts[0].uuid : ''
-
       // 1銆佺瓫閫夊瓧娈甸泦锛�2銆佽繃婊ら殣钘忓垪鍙婂悎骞跺垪涓殑瀛楁uuid
       config.columns.forEach(col => {
         if (col.field) {
           _arrField.push(col.field)
-          _logcolumns.push(col)
 
           col.nameField && _arrField.push(col.nameField) // 閾炬帴鍚嶅瓧娈�
           if (col.Hide !== 'true' && col.type === 'number' && col.sum === 'true') {
             statFields.push(col)
           }
+          if (col.format === 'abs') {
+            absFields.push(col.field)
+          }
         }
         if (col.type === 'colspan' && col.sublist) { // 绛涢�夐殣钘忓垪
           _hideCol = _hideCol.concat(col.sublist)
-        } else if (col.Hide === 'true') {
-          _hideCol.push(col.uuid)
         }
         colMap.set(col.uuid, col)
       })
@@ -200,20 +176,24 @@
       config.columns.forEach(col => {
         if (_hideCol.includes(col.uuid)) return
 
-        if (col.linkThdMenu) {
-          col.linkThdMenu = ''
-        }
+        col.linkThdMenu = '' // 寮圭獥涓笉鍙娇鐢ㄥ瓧娈甸�忚
 
-        if (col.type === 'colspan' && col.sublist) {
-          let _col = JSON.parse(JSON.stringify(col))
-          let subColumn = []
-          _col.sublist.forEach(sub => {
+        if (col.type === 'colspan') {
+          if (col.unfold !== 'true') { // 涓嶅睍寮�涓烘棫鐗堝悎骞跺垪
+            col.type = 'old_colspan'
+          }
+
+          let _col = fromJS(col).toJS()
+          let subcols = []
+          _col.sublist && _col.sublist.forEach(sub => {
             if (colMap.has(sub)) {
-              subColumn.push(colMap.get(sub))
+              subcols.push(colMap.get(sub))
             }
           })
-          _col.subColumn = subColumn
-          _columns.push(_col)
+          if (subcols.length > 0) {
+            _col.subcols = subcols
+            _columns.push(_col)
+          }
         } else {
           _columns.push(col)
         }
@@ -223,9 +203,8 @@
       let _operations = []  // 鎿嶄綔鍒楁寜閽紙瀛樺湪鏃讹級
 
       config.action.forEach(item => {
-        if (item.execMode) {
-          item.OpenType = 'funcbutton'
-        }
+        item.logLabel = Tab.label + '-' + item.label // 鐢ㄤ簬sPC_TableData_InUpDe璁板綍鎿嶄綔鎸夐挳
+        item.$menuId = this.props.MenuID
 
         if (item.position === 'toolbar') {
           _actions.push(item)
@@ -239,20 +218,13 @@
         _columns.push(config.gridBtn)
       }
 
-      let valid = true // 鎼滅储鏉′欢蹇呭~楠岃瘉
-      config.search.forEach(field => {
-        if (field.required === 'true' && !field.initval) {
-          valid = false
-        }
-      })
-
       config.setting.tabType = 'subtab'
       // 鏁版嵁婧愪俊鎭澶勭悊
       config.setting.laypage = config.setting.laypage !== 'false'     // 鏄惁鍒嗛〉锛岃浆涓篵oolean 缁熶竴鏍煎紡
       config.setting.execute = config.setting.default !== 'false'     // 榛樿sql鏄惁鎵ц锛岃浆涓篵oolean 缁熶竴鏍煎紡
       config.setting.customScript = ''                                // 鑷畾涔夎剼鏈�
 
-      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 => {
@@ -273,7 +245,7 @@
           config.setting.dataresource = '(' + config.setting.dataresource + ') tb'
         }
   
-        if (this.props.dataManager) { // 鏁版嵁鏉冮檺
+        if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺
           config.setting.dataresource = config.setting.dataresource.replace(/\$@/ig, '/*')
           config.setting.dataresource = config.setting.dataresource.replace(/@\$/ig, '*/')
           config.setting.customScript = config.setting.customScript.replace(/\$@/ig, '/*')
@@ -282,24 +254,60 @@
           config.setting.dataresource = config.setting.dataresource.replace(/@\$|\$@/ig, '')
           config.setting.customScript = config.setting.customScript.replace(/@\$|\$@/ig, '')
         }
+
+        let userName = sessionStorage.getItem('User_Name') || ''
+        let fullName = sessionStorage.getItem('Full_Name') || ''
+        let city = sessionStorage.getItem('city') || ''
+
+        if (sessionStorage.getItem('isEditState') === 'true') {
+          userName = sessionStorage.getItem('CloudUserName') || ''
+          fullName = sessionStorage.getItem('CloudFullName') || ''
+        }
+
+        let regs = [
+          { reg: /@userName@/ig, value: `'${userName}'` },
+          { reg: /@fullName@/ig, value: `'${fullName}'` },
+          { reg: /@login_city@/ig, value: `'${city}'` }
+        ]
+
+        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.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'
+      } else {
+        config.setting.orisel = true
+      }
+
+      if (config.setting.controlField) {
+        if (config.setting.controlVal) {
+          config.setting.controlVal = config.setting.controlVal.split(',')
+        } else {
+          config.setting.controlVal = ['']
+        }
       }
 
       this.setState({
+        pageSize: config.setting.pageSize || 10,
         loadingview: false,
-        chartId: chartId,
-        config: config,
-        statFields: statFields,
+        config,
+        absFields,
+        statFields,
         setting: config.setting,
         searchlist: config.search,
         actions: _actions,
         columns: _columns,
-        logcolumns: _logcolumns,
         arr_field: _arrField.join(','),
-        search: Utils.initMainSearch(config.search) // 鎼滅储鏉′欢鍒濆鍖栵紙鍚湁鏃堕棿鏍煎紡锛岄渶瑕佽浆鍖栵級
+        search: Utils.initMainSearch(config.search), // 鎼滅储鏉′欢鍒濆鍖栵紙鍚湁鏃堕棿鏍煎紡锛岄渶瑕佽浆鍖栵級
+        hasReqFields
       }, () => {
-        if (config.setting.onload !== 'false' && valid) { // 鍒濆鍖栧彲鍔犺浇
-          this.loadmaindata()
-          this.getStatFieldsValue()
+        if (config.setting.onload !== 'false') { // 鍒濆鍖栧彲鍔犺浇
+          this.loadData()
         }
       })
     } else {
@@ -315,49 +323,273 @@
     }
   }
 
-  /**
-   * @description 瀛愯〃鏁版嵁鍔犺浇
-   */
-  async loadmaindata () {
-    const { mainSearch, BID } = this.props
-    const { setting, arr_field, search, orderBy, pageIndex, pageSize } = this.state
+  loadData = (id) => {
+    const { setting, search, hasReqFields, loadCustomApi } = this.state
 
     let searches = fromJS(search).toJS()
-    if (mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢
-      searches = [...mainSearch, ...searches]
+
+    if (hasReqFields) {
+      let requireFields = searches.filter(item => item.required && item.value === '')
+      if (requireFields.length > 0) {
+        this.setState({
+          loading: false
+        })
+        return
+      }
     }
 
-    let requireFields = search.filter(item => item.required && (!item.value || item.value.length === 0))
-
-    if (requireFields.length > 0) {
-      let labels = requireFields.map(item => item.label)
-      labels = Array.from(new Set(labels))
-
+    if (window.GLOB.systemType === 'production' && setting.interType === 'custom' && !setting.proInterface) {
       notification.warning({
         top: 92,
-        message: this.state.dict['form.required.input'] + labels.join('銆�') + ' !',
+        message: '鏈缃寮忕郴缁熷湴鍧�!',
         duration: 3
       })
       return
     }
 
     this.setState({
-      selectedData: [],
+      selectedData: []
+    })
+
+    if (setting.interType === 'custom' && loadCustomApi) {
+      if (setting.execTime === 'once') {
+        this.setState({loadCustomApi: false})
+      }
+
+      this.loadOutResource(searches)
+      if (setting.execType === 'async') {
+        this.loadmaindata(id)
+      }
+    } else {
+      this.loadmaindata(id)
+    }
+  }
+
+  loadOutResource = (searches) => {
+    const { setting } = this.state
+
+    let param = UtilsDM.getPrevQueryParams(setting, searches, this.props.BID, this.props.menuType)
+
+    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
+
+    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.props.BID) {
+        param.BID = this.props.BID
+      }
+
+      if (this.props.menuType === 'HS') { // 鍑芥暟 sPC_TableData_InUpDe 浜戠楠岃瘉
+        param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp)
+      }
+    } else {
+      let name = this.props.Tab ? (this.props.Tab.label || '') : ''
+      param.func = 's_ex_result_back'
+      param.s_ex_result = lines.map((item, index) => ({
+        MenuID: this.props.MenuID,
+        MenuName: name,
+        TableName: item.table,
+        LongText: window.btoa(window.encodeURIComponent(`${item.insert}  ${item.selects.join(` union all `)}`)),
+        Sort: index + 1
+      }))
+
+      if (window.GLOB.debugger === true || (window.debugger === true && options.sysType !== 'cloud')) {
+        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 (id) {
+    const { BID } = this.props
+    const { setting, arr_field, search, orderBy, pageIndex, pageSize, absFields } = this.state
+
+    let searches = fromJS(search).toJS()
+
+    this.setState({
       loading: true
     })
 
     let _orderBy = orderBy || setting.order
-    let param = UtilsDM.getQueryDataParams(setting, arr_field, searches, _orderBy, pageIndex, pageSize, BID, this.props.menuType, this.props.dataManager)
-
-    if (param.func === 'sPC_Get_TableData') {
-      param.menuname = this.props.Tab.label || ''
-    }
+    let param = UtilsDM.getQueryDataParams(setting, arr_field, searches, _orderBy, pageIndex, pageSize, BID, this.props.menuType)
 
     let result = await Api.genericInterface(param)
+
+    this.getStatFieldsValue(searches)
+
     if (result.status) {
+      let start = 1
+      if (setting.laypage) {
+        start = pageSize * (pageIndex - 1) + 1
+      }
+
+      if (setting.selected !== 'false' || (setting.orisel && id)) {
+        setTimeout(() => {
+          MKEmitter.emit('mkTableCheckTopLine', this.props.MenuID, id)
+        }, 200)
+        if (setting.selected === 'init') {
+          this.setState({setting: {...setting, selected: 'false'}})
+        }
+      }
+
       this.setState({
         data: result.data.map((item, index) => {
+          if (absFields.length) {
+            absFields.forEach(field => {
+              if (!item[field]) return
+              if (isNaN(Math.abs(item[field]))) return
+
+              item[field] = Math.abs(item[field])
+            })
+          }
           item.key = index
+          item.$$uuid = item[setting.primaryKey] || ''
+          item.$$key = '' + item.key + item.$$uuid
+          item.$$BID = BID || ''
+          item.$Index = start + index + ''
+
+          if (setting.controlField) {
+            if (setting.controlVal.includes(item[setting.controlField])) {
+              item.$disabled = true
+            }
+          }
+
           return item
         }),
         total: result.total,
@@ -378,29 +610,15 @@
   /**
    * @description 鑾峰彇鍚堣瀛楁鍊�
    */
-  getStatFieldsValue = () => {
-    const { mainSearch, BID } = this.props
-    const { setting, search, orderBy, statFields } = this.state
+  getStatFieldsValue = (searches) => {
+    const { BID } = this.props
+    const { setting, orderBy, statFields } = this.state
 
-    let searches = fromJS(search).toJS()
-    if (mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢
-      searches = [...mainSearch, ...searches]
-    }
-
-    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, searches, _orderBy, BID, this.props.menuType, this.props.dataManager)
+    let param = UtilsDM.getStatQueryDataParams(setting, statFields, searches, _orderBy, BID, this.props.menuType)
 
-    if (param.func === 'sPC_Get_TableData') {
-      param.menuname = this.props.Tab.label || ''
-    }
-    
     Api.genericInterface(param).then(res => {
       if (res.status) {
         let _data = res.data[0]
@@ -435,17 +653,90 @@
   }
 
   /**
+   * @description 鑾峰彇鍗曡鏁版嵁
+   */ 
+  async loadmainLinedata (id) {
+    const { BID } = this.props
+    const { setting, arr_field, search, orderBy, pageIndex, pageSize, absFields } = this.state
+
+    let searches = fromJS(search).toJS()
+
+    this.setState({
+      loading: true
+    })
+
+    let _orderBy = orderBy || setting.order
+    let param = UtilsDM.getQueryDataParams(setting, arr_field, searches, _orderBy, pageIndex, pageSize, BID, this.props.menuType, id)
+
+    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] || {}
+
+        if (absFields.length) {
+          absFields.forEach(field => {
+            if (!_data[field]) return
+            if (isNaN(Math.abs(_data[field]))) return
+            
+            _data[field] = Math.abs(_data[field])
+          })
+        }
+
+        _data.$$uuid = _data[setting.primaryKey] || ''
+        _data.$$BID = BID || ''
+
+        try {
+          data = data.map(item => {
+            if (item.$$uuid === _data.$$uuid) {
+              _data.key = item.key
+              _data.$$key = '' + item.key + item.$$uuid
+              _data.$Index = item.$Index
+              return _data
+            } else {
+              return item
+            }
+          })
+          selectedData = selectedData.map(item => {
+            if (_data.$$uuid === item.$$uuid) {
+              return _data
+            }
+            return item
+          })
+        } catch (e) {
+          console.warn('鏁版嵁鏌ヨ閿欒')
+        }
+      }
+
+      this.setState({
+        data,
+        selectedData,
+        loading: false
+      })
+    } else {
+      this.setState({
+        loading: false
+      })
+      notification.error({
+        top: 92,
+        message: result.message,
+        duration: 10
+      })
+    }
+  }
+
+  /**
    * @description 鎼滅储鏉′欢鏀瑰彉鏃讹紝閲嶇疆琛ㄦ牸鏁版嵁
    * 鍚湁鍒濆涓嶅姞杞界殑椤甸潰锛屼慨鏀硅缃�
    */
   refreshbysearch = (searches) => {
-    MKEmitter.emit('resetTable', this.props.MenuID + this.props.Tab.uuid) // 鍒楄〃閲嶇疆
+    MKEmitter.emit('resetTable', this.props.Tab.uuid) // 鍒楄〃閲嶇疆
     this.setState({
       pageIndex: 1,
       search: searches
     }, () => {
-      this.loadmaindata()
-      this.getStatFieldsValue()
+      this.loadData()
     })
   }
 
@@ -466,21 +757,26 @@
       pageSize: pagination.pageSize,
       orderBy: (sorter.field && sorter.order) ? `${sorter.field} ${sorter.order}` : ''
     }, () => {
-      this.loadmaindata()
+      this.loadData()
     })
   }
 
   /**
    * @description 琛ㄦ牸鍒锋柊
    */
-  reloadtable = () => {
-    MKEmitter.emit('resetTable', this.props.MenuID + this.props.Tab.uuid) // 鍒楄〃閲嶇疆
-    this.setState({
-      pageIndex: 1
-    }, () => {
-      this.loadmaindata()
-      this.getStatFieldsValue()
-    })
+  reloadtable = (btn, id) => {
+    if (!btn || btn.resetPageIndex !== 'false') {
+      MKEmitter.emit('resetTable', this.props.Tab.uuid) // 鍒楄〃閲嶇疆
+      this.setState({
+        pageIndex: 1
+      }, () => {
+        this.loadData(id)
+      })
+    } else {
+      MKEmitter.emit('resetTable', this.props.Tab.uuid, 'false') // 鍒楄〃閲嶇疆
+      this.loadData(id)
+    }
+    
   }
 
   /**
@@ -491,56 +787,39 @@
   }
 
   /**
-   * @description 椤甸潰鍒锋柊锛岄噸鏂拌幏鍙栭厤缃�
+   * @description 瀵煎嚭Excel鏃讹紝鑾峰彇椤甸潰鎼滅储鎺掑簭绛夊弬鏁�
    */
-  reloadview = () => {
-    this.setState({ loadingview: true, viewlost: false, lostmsg: '', config: null, searchlist: null, actions: null, columns: null,
-      arr_field: '', setting: null, data: null, total: 0, loading: false, pageIndex: 1, pageSize: 10, orderBy: '', search: ''
-    }, () => {
-      this.loadconfig()
+  queryModuleParam = (menuId, btnId) => {
+    const { Tab, MenuID } = this.props
+    const { arr_field, orderBy, search, setting} = this.state
+
+    if (MenuID !== menuId) return
+
+    MKEmitter.emit('returnModuleParam', MenuID, btnId, {
+      arr_field: arr_field,
+      orderBy: orderBy || setting.order,
+      search: search,
+      menuName: Tab.label
     })
   }
 
   /**
-   * @description 鎸夐挳鎿嶄綔瀹屾垚鍚庯紙鎴愬姛鎴栧け璐ワ級锛岄〉闈㈠埛鏂帮紝閲嶇疆椤电爜鍙婇�夋嫨椤�
+   * @description 鎸夐挳鎵ц瀹屾垚鍚庨〉闈㈠埛鏂�
+   * @param {*} menuId     // 鑿滃崟Id
+   * @param {*} position   // 鍒锋柊浣嶇疆
+   * @param {*} btn        // 鎵ц鐨勬寜閽�
    */
-  refreshbyaction = (position) => {
-    if (position === 'grid' || position === 'maingrid') {
-      this.reloadtable()
-      this.props.refreshSupView()
-    } else if (position === 'view') {
-      this.reloadview()
-      this.props.refreshSupView()
-    } else if (position === 'trigger') { // 鏃ュ巻瀛愯〃瑙﹀彂鏍囩鐐瑰嚮浜嬩欢
-      this.props.closeModalView && this.props.closeModalView()
+  refreshByButtonResult = (menuId, position, btn, id = '', lines) => {
+    const { MenuID } = this.props
+
+    if (MenuID !== menuId) return
+
+    if (position === 'line' && lines && lines.length === 1) {
+      this.loadmainLinedata(lines[0].$$uuid)
+    } else {
+      this.reloadtable(btn, id)
     }
-  }
-
-  /**
-   * @description 瀵煎嚭Excel鏃讹紝鑾峰彇椤甸潰鎼滅储鎺掑簭绛夊弬鏁�
-   */
-  getexceloutparam = () => {
-    const { Tab, mainSearch } = this.props
-    const { arr_field, orderBy, search, setting} = this.state
-
-    let searches = search
-    if (mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢
-      searches = [...mainSearch, ...search]
-    }
-
-    return {
-      arr_field: arr_field,
-      orderBy: orderBy || setting.order,
-      search: searches,
-      menuName: Tab.label
-    }
-  }
-
-  /**
-   * @description 鍥捐〃瑙嗗浘鍒囨崲
-   */
-  changeChart = (uuid) => {
-    this.setState({chartId: uuid})
+    MKEmitter.emit('refreshPopButton', this.props.Tab.uuid)
   }
 
   UNSAFE_componentWillMount () {
@@ -552,6 +831,11 @@
     return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
   }
 
+  componentDidMount () {
+    MKEmitter.addListener('queryModuleParam', this.queryModuleParam)
+    MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult)
+  }
+
   /**
    * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊
    */
@@ -559,109 +843,46 @@
     this.setState = () => {
       return
     }
+    MKEmitter.removeListener('queryModuleParam', this.queryModuleParam)
+    MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult)
   }
 
   render() {
-    const { config, setting, searchlist, pageSize, actions, columns, loadingview, viewlost, chartId, selectedData } = this.state
+    const { config, setting, searchlist, pageSize, actions, columns, loadingview, viewlost, selectedData } = this.state
 
     return (
       <div className="subtabtable" id={'subtabtable' + this.props.MenuID}>
         {loadingview && <Spin />}
-        {searchlist && searchlist.length > 0 ?
-          <SubSearch
+        {searchlist && searchlist.length ?
+          <SubSearch BID={this.props.BID} setting={setting} searchlist={searchlist} menuType={this.props.menuType} refreshdata={this.refreshbysearch}/> : null
+        }
+        {config ? <div style={{minHeight: '25px'}}>
+          <SubAction
+            setting={setting}
+            actions={actions}
+            columns={columns}
             BID={this.props.BID}
             dict={this.state.dict}
-            searchlist={searchlist}
-            menuType={this.props.menuType}
-            dataManager={this.props.dataManager}
-            refreshdata={this.refreshbysearch}
-          /> : null
-        }
-        {config ? <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>
-            ))}
-          </Tabs> : null}
-          {config.charts.map(item => {
-            if (!config.expand && chartId !== item.uuid) return null
-
-            if (item.chartType === 'table') {
-              return (
-                <Col span={item.width || 24} key={item.uuid}>
-                  {config.charts.length > 1 ? <p className="chart-table chart-title">{item.title}</p> : null}
-                  <div style={{minHeight: '25px'}}>
-                    <SubAction
-                      setting={setting}
-                      actions={actions}
-                      BID={this.props.BID}
-                      dict={this.state.dict}
-                      BData={this.props.BData}
-                      selectedData={selectedData}
-                      MenuID={this.props.SupMenuID}
-                      MenuName={this.props.Tab.label}
-                      logcolumns={this.state.logcolumns}
-                      refreshdata={this.refreshbyaction}
-                      getexceloutparam={this.getexceloutparam}
-                    />
-                  </div>
-                  <SubTable
-                    tableId={this.props.Tab.uuid}
-                    config={config}
-                    setting={setting}
-                    columns={columns}
-                    pageSize={pageSize}
-                    BID={this.props.BID}
-                    data={this.state.data}
-                    dict={this.state.dict}
-                    BData={this.props.BData}
-                    total={this.state.total}
-                    MenuID={this.props.MenuID}
-                    loading={this.state.loading}
-                    MenuName={this.props.Tab.label}
-                    refreshdata={this.refreshbytable}
-                    logcolumns={this.state.logcolumns}
-                    statFValue={this.state.statFValue}
-                    refreshbyaction={this.refreshbyaction}
-                    chgSelectData={this.changeSelectedData}
-                    handleTableId={() => {}}
-                  />
-                </Col>
-              )
-            } else if (item.chartType === 'card') {
-              return (
-                <Col span={item.width} key={item.uuid}>
-                  <CardComponent
-                    tableId=""
-                    plot={item}
-                    config={config}
-                    BID={this.props.BID}
-                    data={this.state.data}
-                    BData={this.props.BData}
-                    loading={this.state.loading}
-                    MenuName={this.props.Tab.label}
-                    logcolumns={this.state.logcolumns}
-                    refreshdata={this.refreshbyaction}
-                    handleTableId={() => {}}
-                  />
-                </Col>
-              )
-            } else {
-              return (
-                <Col span={item.width} key={item.uuid}>
-                  <ChartComponent
-                    plot={item}
-                    config={config}
-                    data={this.state.data}
-                    loading={this.state.loading}
-                    MenuName={this.props.Tab.label}
-                  />
-                </Col>
-              )
-            }
-          })}
-        </Row> : null }
+            BData={this.props.BData}
+            selectedData={selectedData}
+            MenuID={this.props.SupMenuID}
+          />
+        </div> : null}
+        {config ? <SubTable
+          tableId={this.props.Tab.uuid}
+          setting={setting}
+          columns={columns}
+          pageSize={pageSize}
+          data={this.state.data}
+          dict={this.state.dict}
+          BData={this.props.BData}
+          total={this.state.total}
+          MenuID={this.props.MenuID}
+          loading={this.state.loading}
+          refreshdata={this.refreshbytable}
+          statFValue={this.state.statFValue}
+          chgSelectData={this.changeSelectedData}
+        /> : null}
         {viewlost ? <NotFount msg={this.state.lostmsg} /> : null}
       </div>
     )
@@ -672,8 +893,6 @@
   return {
     menuType: state.editLevel,
     permAction: state.permAction,
-    permRoles: state.permRoles,
-    dataManager: state.dataManager,
     memberLevel: state.memberLevel
   }
 }

--
Gitblit v1.8.0