From bde2916433c7830e2879e6524e32b9f6c8bd0bab Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期日, 02 一月 2022 16:31:32 +0800
Subject: [PATCH] 2022-01-02

---
 src/tabviews/subtable/index.jsx |  225 +++++++++++++++++++++++++++++++-------------------------
 1 files changed, 124 insertions(+), 101 deletions(-)

diff --git a/src/tabviews/subtable/index.jsx b/src/tabviews/subtable/index.jsx
index dcd0099..31c67cd 100644
--- a/src/tabviews/subtable/index.jsx
+++ b/src/tabviews/subtable/index.jsx
@@ -2,7 +2,7 @@
 import PropTypes from 'prop-types'
 import {connect} from 'react-redux'
 import { is, fromJS } from 'immutable'
-import { notification, Spin, Switch, Row, Col, Icon, Tabs} from 'antd'
+import { notification, Spin, Switch, Row, Col, Tabs} from 'antd'
 
 import Api from '@/api'
 import zhCN from '@/locales/zh-CN/main.js'
@@ -13,6 +13,7 @@
 import { updateSubTable } from '@/utils/utils-update.js'
 import asyncComponent from '@/utils/asyncComponent'
 import asyncSpinComponent from '@/utils/asyncSpinComponent'
+import MkIcon from '@/components/mk-icon'
 import NotFount from '@/components/404'
 import MKEmitter from '@/utils/events.js'
 
@@ -34,7 +35,6 @@
     SupMenuID: PropTypes.string,     // 涓婄骇鑿滃崟Id
     mainSearch: PropTypes.any,       // 涓昏〃鎼滅储鏉′欢
     ContainerId: PropTypes.any,      // 涓夌骇鑿滃崟Container(html) ID
-    handleTableId: PropTypes.func,   // 鎺у埗琛ㄦ牸鏁版嵁鍒囨崲鏃讹紝鏇存柊鍦ㄤ富琛ㄤ腑鐨刬d
   }
 
   state = {
@@ -62,23 +62,18 @@
     statFValue: [],       // 鍚堣鍊�
     absFields: [],        // 缁濆鍊煎瓧娈�
     loadCustomApi: true,  // 鍔犺浇澶栭儴璧勬簮
-    hasReqFields: false
+    hasReqFields: false,
+    BID: '',
+    BData: ''
   }
 
   /**
    * @description 涓婄骇鑿滃崟id鍙樺寲鏃讹紝鍒锋柊鏁版嵁
    */
   UNSAFE_componentWillReceiveProps(nextProps) {
-    const { config, setting } = this.state
+    const { setting } = this.state
 
-    if (config && setting && this.props.Tab.supMenu && !is(fromJS(this.props.BID), fromJS(nextProps.BID))) {
-      MKEmitter.emit('resetTable', this.props.MenuID + this.props.Tab.uuid) // 鍒楄〃閲嶇疆
-      this.setState({
-        pageIndex: 1
-      }, () => {
-        this.loadData()
-      })
-    } else if (setting && !this.props.Tab.supMenu && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
+    if (setting && !this.props.Tab.supMenu && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
       this.setState({}, () => {
         this.loadData()
       })
@@ -89,7 +84,7 @@
    * @description 鑾峰彇椤甸潰閰嶇疆淇℃伅
    */
   async loadconfig () {
-    const { permAction, permMenus, Tab, BID } = this.props
+    const { permAction, permMenus, Tab } = this.props
 
     let param = {
       func: 'sPC_Get_LongParam',
@@ -102,6 +97,7 @@
       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 = ''
@@ -141,16 +137,17 @@
         config.action = config.action.filter(item => permAction[item.uuid])
       }
 
-      let roleId = sessionStorage.getItem('role_id') || '' // 瑙掕壊ID
-      // 瀛楁鏉冮檺榛戝悕鍗�
-      config.search = config.search.map(item => {
-        item.oriInitval = item.initval
-        if (!item.blacklist || item.blacklist.length === 0) return item
-        if (item.blacklist.filter(v => roleId.indexOf(v) > -1).length > 0) {
-          item.Hide = 'true'
+      config.search = Utils.initSearchVal(config.search)
+
+      let hasReqFields = false
+      config.search.forEach(field => {
+        if (field.required) {
+          hasReqFields = true
         }
-        return item
       })
+
+      // 瀛楁鏉冮檺榛戝悕鍗�
+      let roleId = sessionStorage.getItem('role_id') || '' // 瑙掕壊ID
 
       config.columns = config.columns.map(col => {
         if (!col.blacklist || col.blacklist.length === 0) return col
@@ -260,16 +257,6 @@
         _columns.push(config.gridBtn)
       }
 
-      let valid = true // 鎼滅储鏉′欢蹇呭~楠岃瘉
-      let hasReqFields = false
-      config.search.forEach(field => {
-        if (field.required !== 'true') return
-        hasReqFields = true
-        if (!field.initval) {
-          valid = false
-        }
-      })
-
       config.setting.tabType = 'sub'
       // 鏁版嵁婧愪俊鎭澶勭悊
       config.setting.laypage = config.setting.laypage !== 'false'     // 鏄惁鍒嗛〉锛岃浆涓篵oolean 缁熶竴鏍煎紡
@@ -328,7 +315,24 @@
         })
       }
 
+      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 (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,
+        BID: this.props.BID || '',
+        BData: this.props.BData || '',
         loadingview: false,
         chartId,
         config,
@@ -339,10 +343,10 @@
         actions: _actions,
         columns: _columns,
         arr_field: _arrField.join(','),
-        search: Utils.initMainSearch(config.search), // 鎼滅储鏉′欢鍒濆鍖栵紙鍚湁鏃堕棿鏍煎紡锛岄渶瑕佽浆鍖栵級
+        search: Utils.initMainSearch(config.search),
         hasReqFields
       }, () => {
-        if (config.setting.onload !== 'false' && (!Tab.supMenu || BID || Tab.isTreeNode) && valid) { // 鍒濆鍖栧彲鍔犺浇
+        if (config.setting.onload !== 'false' && (!Tab.supMenu || this.props.BID || Tab.isTreeNode)) { // 鍒濆鍖栧彲鍔犺浇
           this.loadData()
         }
       })
@@ -362,32 +366,32 @@
   }
   
   loadData = () => {
-    const { mainSearch, BID } = this.props
-    const { setting, search, loadCustomApi, hasReqFields } = this.state
+    const { mainSearch } = this.props
+    const { setting, BID, search, loadCustomApi, hasReqFields } = this.state
 
     let searches = fromJS(search).toJS()
     if (mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢
       searches = [...mainSearch, ...searches]
     }
 
-    let requireFields = []
     if (hasReqFields) {
-      requireFields = searches.filter(item => item.required && (!item.value || item.value.length === 0))
+      let requireFields = searches.filter(item => item.required && item.value === '')
+      if (requireFields.length > 0) {
+        this.setState({
+          loading: false
+        })
+        return
+      }
     }
-    
-    if (requireFields.length > 0) {
-      this.setState({
-        loading: false
-      })
-      return
-    } else if (this.props.Tab.supMenu && !BID) { // 涓昏〃ID涓嶅瓨鍦ㄦ椂锛屼笉鏌ヨ瀛愯〃
+
+    if (this.props.Tab.supMenu && !BID) { // 涓昏〃ID涓嶅瓨鍦ㄦ椂锛屼笉鏌ヨ瀛愯〃
       this.setState({
         data: [],
         selectedData: [],
         statFValue: [],
         total: 0
       })
-      this.handleTableId()
+      MKEmitter.emit('changeTableLine', this.props.ContainerId, this.props.Tab.uuid, '', '')
       return
     } else if (window.GLOB.systemType === 'production' && setting.interType === 'custom' && !setting.proInterface) {
       notification.warning({
@@ -401,7 +405,7 @@
     this.setState({
       selectedData: []
     })
-    this.handleTableId()
+    MKEmitter.emit('changeTableLine', this.props.ContainerId, this.props.Tab.uuid, '', '')
 
     if (setting.interType === 'custom' && loadCustomApi) {
       if (setting.execTime === 'once') {
@@ -418,8 +422,7 @@
   }
 
   loadOutResource = (searches) => {
-    const { BID } = this.props
-    const { setting } = this.state
+    const { setting, BID } = this.state
 
     let param = UtilsDM.getPrevQueryParams(setting, searches, BID, this.props.menuType)
 
@@ -480,7 +483,7 @@
     })
 
     Api.directRequest(url, setting.method, param, setting.cross).then(res => {
-      if (typeof(res) !== 'object' || Array.isArray(res)) {
+      if (typeof(res) !== 'object') {
         let error = '鏈煡鐨勮繑鍥炵粨鏋滐紒'
 
         if (typeof(res) === 'string') {
@@ -495,6 +498,9 @@
 
         this.customCallbackRequest(_result)
       } else {
+        if (Array.isArray(res)) {
+          res = { data: res }
+        }
         res.mk_api_key = mkey
         this.customCallbackRequest(res)
       }
@@ -510,7 +516,7 @@
   }
 
   customCallbackRequest = (result) => {
-    const { setting } = this.state
+    const { setting, BID } = this.state
     let errSql = ''
     if (result.$ErrCode === 'E') {
       errSql = `
@@ -534,8 +540,8 @@
       
       param = UtilsDM.getCallBackQueryParams(setting, sql, errSql)
 
-      if (this.props.BID) {
-        param.BID = this.props.BID
+      if (BID) {
+        param.BID = BID
       }
 
       if (this.props.menuType === 'HS') { // 鍑芥暟 sPC_TableData_InUpDe 浜戠楠岃瘉
@@ -586,8 +592,8 @@
    * @description 瀛愯〃鏁版嵁鍔犺浇
    */
   async loadmaindata () {
-    const { mainSearch, BID } = this.props
-    const { setting, arr_field, search, orderBy, pageIndex, pageSize, absFields } = this.state
+    const { mainSearch } = this.props
+    const { setting, BID, arr_field, search, orderBy, pageIndex, pageSize, absFields } = this.state
 
     let searches = fromJS(search).toJS()
     if (mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢
@@ -601,10 +607,6 @@
     let _orderBy = orderBy || setting.order
     let param = UtilsDM.getQueryDataParams(setting, arr_field, searches, _orderBy, pageIndex, pageSize, BID, this.props.menuType)
 
-    if (param.func === 'sPC_Get_TableData') {
-      param.menuname = this.props.Tab.label || ''
-    }
-
     let result = await Api.genericInterface(param)
 
     this.getStatFieldsValue(searches)
@@ -613,6 +615,15 @@
       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({
@@ -628,7 +639,13 @@
           item.key = index
           item.$$uuid = item[setting.primaryKey] || ''
           item.$$BID = BID || ''
-          item.$Index = start + index
+          item.$Index = start + index + ''
+
+          if (setting.controlField) {
+            if (setting.controlVal.includes(item[setting.controlField])) {
+              item.$disabled = true
+            }
+          }
 
           return item
         }),
@@ -654,8 +671,8 @@
    * @description 鑾峰彇鍗曡鏁版嵁
    */ 
   async loadmainLinedata (id) {
-    const { mainSearch, BID } = this.props
-    const { setting, arr_field, search, orderBy, pageIndex, pageSize, absFields } = this.state
+    const { mainSearch } = this.props
+    const { setting, BID, arr_field, search, orderBy, pageIndex, pageSize, absFields } = this.state
 
     let searches = fromJS(search).toJS()
     if (mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢
@@ -668,10 +685,6 @@
 
     let _orderBy = orderBy || setting.order
     let param = UtilsDM.getQueryDataParams(setting, arr_field, searches, _orderBy, pageIndex, pageSize, BID, this.props.menuType, id)
-
-    if (param.func === 'sPC_Get_TableData') {
-      param.menuname = this.props.Tab.label || ''
-    }
 
     let result = await Api.genericInterface(param)
     if (result.status) {
@@ -708,7 +721,7 @@
             }
             return item
           })
-        } catch {
+        } catch (e) {
           console.warn('鏁版嵁鏌ヨ閿欒')
         }
       }
@@ -734,18 +747,13 @@
    * @description 鑾峰彇鍚堣瀛楁鍊�
    */
   getStatFieldsValue = (searches) => {
-    const { BID } = this.props
-    const { setting, orderBy, statFields } = this.state
+    const { setting, BID, orderBy, statFields } = this.state
 
     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)
 
-    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]
@@ -784,7 +792,7 @@
    * 鍚湁鍒濆涓嶅姞杞界殑椤甸潰锛屼慨鏀硅缃�
    */
   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,
@@ -819,14 +827,14 @@
    */
   reloadtable = (btn) => {
     if (!btn || btn.resetPageIndex !== 'false') {
-      MKEmitter.emit('resetTable', this.props.MenuID + this.props.Tab.uuid) // 鍒楄〃閲嶇疆
+      MKEmitter.emit('resetTable', this.props.Tab.uuid) // 鍒楄〃閲嶇疆
       this.setState({
         pageIndex: 1
       }, () => {
         this.loadData()
       })
     } else {
-      MKEmitter.emit('resetTable', this.props.MenuID + this.props.Tab.uuid, 'false') // 鍒楄〃閲嶇疆
+      MKEmitter.emit('resetTable', this.props.Tab.uuid, 'false') // 鍒楄〃閲嶇疆
       this.loadData()
     }
   }
@@ -858,13 +866,6 @@
    */
   changeSelectedData = (selectedData) => {
     this.setState({selectedData})
-  }
-
-  /**
-   * @description 琛ㄦ牸Id鍙樺寲
-   */
-  handleTableId = (type = this.props.Tab.uuid, id = '', data = '') => {
-    this.props.handleTableId(type, id, data)
   }
 
   /**
@@ -904,20 +905,21 @@
    * @param {*} position   // 鍒锋柊浣嶇疆
    * @param {*} btn        // 鎵ц鐨勬寜閽�
    */
-  refreshByButtonResult = (menuId, position, btn) => {
+  refreshByButtonResult = (menuId, position, btn, id, lines) => {
     const { MenuID } = this.props
 
     if (MenuID !== menuId) return
 
-    const { Tab, SupMenuID, BID } = this.props
+    const { Tab, SupMenuID } = this.props
+    const { BID } = this.state
 
-    if (position === 'grid' || position === 'view') {
+    if (position === 'line' && lines && lines.length === 1) {
+      this.loadmainLinedata(lines[0].$$uuid)
+    } else if (position === 'grid' || position === 'view') {
       this.reloadtable(btn)
     } else if (position === 'maingrid' || position === 'mainline') {
       this.reloadtable(btn)
-      if (Tab.supMenu === 'mainTable') {
-        MKEmitter.emit('reloadData', SupMenuID, (BID || 'empty'))   // 涓昏〃閲嶇疆
-      } else if (Tab.supMenu) {
+      if (Tab.supMenu) {
         MKEmitter.emit('reloadData', Tab.supMenu, (BID || 'empty')) // 涓昏〃閲嶇疆
       } else if (!Tab.supMenu && Tab.level === 0) {
         MKEmitter.emit('reloadData', SupMenuID, (BID || 'empty'))   // 鏍戝舰缁撴瀯锛�0绾ф爣绛�
@@ -930,17 +932,38 @@
     }
   }
 
+  changeTableLine = (ContainerId, tableId, id, data) => {
+    const { Tab } = this.props
+    const { setting } = this.state
+
+    if (!Tab.supMenu || tableId !== Tab.supMenu) return
+
+    this.setState({BData: data, BID: id})
+
+    if (!setting) return
+
+    if (id !== this.state.BID || id !== '') {
+      MKEmitter.emit('resetTable', this.props.Tab.uuid) // 鍒楄〃閲嶇疆
+      this.setState({
+        pageIndex: 1
+      }, () => {
+        this.loadData()
+      })
+    }
+  }
+
   UNSAFE_componentWillMount() {
     // 缁勪欢鍔犺浇鏃讹紝鑾峰彇鑿滃崟鏁版嵁
     this.loadconfig()
   }
 
-  shouldComponentUpdate (nextProps, nextState) { // handleTableId 鍑芥暟鍒ゆ柇鏃朵笉鐩哥瓑
-    return !is(fromJS({...this.props, handleTableId: ''}), fromJS({...nextProps, handleTableId: ''})) || !is(fromJS(this.state), fromJS(nextState))
+  shouldComponentUpdate (nextProps, nextState) {
+    return !is(fromJS(this.state), fromJS(nextState))
   }
 
   componentDidMount () {
     MKEmitter.addListener('reloadData', this.reloadData)
+    MKEmitter.addListener('changeTableLine', this.changeTableLine)
     MKEmitter.addListener('queryModuleParam', this.queryModuleParam)
     MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult)
   }
@@ -953,24 +976,25 @@
       return
     }
     MKEmitter.removeListener('reloadData', this.reloadData)
+    MKEmitter.removeListener('changeTableLine', this.changeTableLine)
     MKEmitter.removeListener('queryModuleParam', this.queryModuleParam)
     MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult)
   }
 
   render() {
-    const { config, setting, searchlist, pageSize, actions, columns, loadingview, viewlost, pickup, chartId, selectedData } = this.state
+    const { config, BID, BData, setting, searchlist, pageSize, actions, columns, loadingview, viewlost, pickup, chartId, selectedData } = this.state
 
     return (
       <div className="subtable" id={'subtable' + this.props.MenuID}>
         {loadingview && <Spin />}
         {searchlist && searchlist.length ?
-          <SubSearch BID={this.props.BID} setting={setting} searchlist={searchlist} menuType={this.props.menuType} refreshdata={this.refreshbysearch}/> : null
+          <SubSearch BID={BID} setting={setting} searchlist={searchlist} menuType={this.props.menuType} 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>
+              <TabPane tab={<MkIcon type={item.icon} />} key={item.uuid}></TabPane>
             ))}
           </Tabs> : null}
           {config.charts.map(item => {
@@ -981,12 +1005,12 @@
                   {config.charts.length > 1 ? <p className="chart-table chart-title">{item.title}</p> : null}
                   <div className="sub-action">
                     <SubAction
+                      BID={BID}
+                      BData={BData}
                       setting={setting}
                       actions={actions}
                       columns={columns}
                       Tab={this.props.Tab}
-                      BID={this.props.BID}
-                      BData={this.props.BData}
                       MenuID={this.props.MenuID}
                       selectedData={selectedData}
                       ContainerId={this.props.ContainerId}
@@ -997,6 +1021,7 @@
                       <Switch title="鏀惰捣" className="subtable-pickup" checkedChildren="寮�" unCheckedChildren="鍏�" checked={pickup} onChange={this.pickupChange} /> : null
                     }
                     <SubTable
+                      BData={BData}
                       tableId={this.props.Tab.uuid}
                       pickup={pickup}
                       setting={setting}
@@ -1004,14 +1029,12 @@
                       pageSize={pageSize}
                       dict={this.state.dict}
                       data={this.state.data}
-                      BData={this.props.BData}
                       total={this.state.total}
                       MenuID={this.props.MenuID}
                       loading={this.state.loading}
                       statFValue={this.state.statFValue}
                       ContainerId={this.props.ContainerId}
                       refreshdata={this.refreshbytable}
-                      handleTableId={this.handleTableId}
                       chgSelectData={this.changeSelectedData}
                     />
                   </div>
@@ -1021,17 +1044,17 @@
               return (
                 <Col className="card-view" span={item.width} key={item.uuid}>
                   <CardComponent
+                    BID={BID}
                     plot={item}
+                    BData={BData}
                     config={config}
                     columns={columns}
                     Tab={this.props.Tab}
-                    BID={this.props.BID}
-                    BData={this.props.BData}
                     data={this.state.data}
                     MenuID={this.props.MenuID}
                     loading={this.state.loading}
                     tableId={this.props.Tab.uuid}
-                    handleTableId={this.handleTableId}
+                    ContainerId={this.props.ContainerId}
                   />
                 </Col>
               )
@@ -1039,9 +1062,9 @@
               return (
                 <Col span={item.width} key={item.uuid}>
                   <ChartComponent
+                    BID={BID}
                     plot={item}
                     config={config}
-                    BID={this.props.BID}
                     Tab={this.props.Tab}
                     data={this.state.data}
                     loading={this.state.loading}

--
Gitblit v1.8.0