From 137fb8ea6af2789b3238b22bac31d80bced41dfe Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 28 七月 2021 11:39:39 +0800
Subject: [PATCH] 2021-07-28

---
 src/tabviews/subtable/index.jsx |   97 ++++++++++++++++++++++++++++--------------------
 1 files changed, 56 insertions(+), 41 deletions(-)

diff --git a/src/tabviews/subtable/index.jsx b/src/tabviews/subtable/index.jsx
index b31d3b2..f917266 100644
--- a/src/tabviews/subtable/index.jsx
+++ b/src/tabviews/subtable/index.jsx
@@ -141,16 +141,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 +261,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 缁熶竴鏍煎紡
@@ -306,6 +297,26 @@
           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)
+        })
       }
 
       this.setState({
@@ -319,10 +330,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 || BID || Tab.isTreeNode)) { // 鍒濆鍖栧彲鍔犺浇
           this.loadData()
         }
       })
@@ -350,23 +361,17 @@
       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) {
-      let prex = this.props.Tab && this.props.Tab.label ? this.props.Tab.label + '-' : ''
-      let labels = requireFields.map(item => item.label)
-      labels = Array.from(new Set(labels))
-
-      notification.warning({
-        top: 92,
-        message: prex + this.state.dict['form.required.input'] + labels.join('銆�') + ' !',
-        duration: 3
-      })
-      return
-    } else if (this.props.Tab.supMenu && !BID) { // 涓昏〃ID涓嶅瓨鍦ㄦ椂锛屼笉鏌ヨ瀛愯〃
+    if (this.props.Tab.supMenu && !BID) { // 涓昏〃ID涓嶅瓨鍦ㄦ椂锛屼笉鏌ヨ瀛愯〃
       this.setState({
         data: [],
         selectedData: [],
@@ -466,7 +471,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') {
@@ -481,6 +486,9 @@
 
         this.customCallbackRequest(_result)
       } else {
+        if (Array.isArray(res)) {
+          res = { data: res }
+        }
         res.mk_api_key = mkey
         this.customCallbackRequest(res)
       }
@@ -596,6 +604,11 @@
     this.getStatFieldsValue(searches)
 
     if (result.status) {
+      let start = 1
+      if (setting.laypage) {
+        start = pageSize * (pageIndex - 1) + 1
+      }
+
       this.setState({
         data: result.data.map((item, index) => {
           if (absFields.length) {
@@ -609,6 +622,7 @@
           item.key = index
           item.$$uuid = item[setting.primaryKey] || ''
           item.$$BID = BID || ''
+          item.$Index = start + index + ''
 
           return item
         }),
@@ -676,6 +690,7 @@
           data = data.map(item => {
             if (item.$$uuid === _data.$$uuid) {
               _data.key = item.key
+              _data.$Index = item.$Index
               return _data
             } else {
               return item
@@ -813,7 +828,7 @@
   /**
    * @description 瀵煎嚭Excel鏃讹紝鑾峰彇椤甸潰鎼滅储鎺掑簭绛夊弬鏁�
    */
-  getexceloutparam = (menuId, btnId) => {
+  queryModuleParam = (menuId, btnId) => {
     const { Tab, mainSearch, MenuID } = this.props
     const { arr_field, orderBy, search, setting} = this.state
 
@@ -824,7 +839,7 @@
       searches = [...mainSearch, ...search]
     }
 
-    MKEmitter.emit('execExcelout', MenuID, btnId, {
+    MKEmitter.emit('returnModuleParam', MenuID, btnId, {
       arr_field: arr_field,
       orderBy: orderBy || setting.order,
       search: searches,
@@ -920,7 +935,7 @@
 
   componentDidMount () {
     MKEmitter.addListener('reloadData', this.reloadData)
-    MKEmitter.addListener('getexceloutparam', this.getexceloutparam)
+    MKEmitter.addListener('queryModuleParam', this.queryModuleParam)
     MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult)
   }
 
@@ -932,7 +947,7 @@
       return
     }
     MKEmitter.removeListener('reloadData', this.reloadData)
-    MKEmitter.removeListener('getexceloutparam', this.getexceloutparam)
+    MKEmitter.removeListener('queryModuleParam', this.queryModuleParam)
     MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult)
   }
 
@@ -943,7 +958,7 @@
       <div className="subtable" id={'subtable' + this.props.MenuID}>
         {loadingview && <Spin />}
         {searchlist && searchlist.length ?
-          <SubSearch BID={this.props.BID} searchlist={searchlist} menuType={this.props.menuType} refreshdata={this.refreshbysearch}/> : null
+          <SubSearch BID={this.props.BID} setting={setting} searchlist={searchlist} menuType={this.props.menuType} refreshdata={this.refreshbysearch}/> : null
         }
         {config ? <Row className="chart-view" gutter={16}>
           {/* 瑙嗗浘缁� */}
@@ -973,7 +988,7 @@
                   </div>
                   <div className="subtable-box">
                     {(setting.tableType === 'radio' || setting.tableType === 'checkbox') && this.state.data && this.state.data.length > 0 ?
-                      <Switch title="鏀惰捣" className="subtable-pickup" checkedChildren="寮�" unCheckedChildren="鍏�" defaultChecked={pickup} onChange={this.pickupChange} /> : null
+                      <Switch title="鏀惰捣" className="subtable-pickup" checkedChildren="寮�" unCheckedChildren="鍏�" checked={pickup} onChange={this.pickupChange} /> : null
                     }
                     <SubTable
                       tableId={this.props.Tab.uuid}

--
Gitblit v1.8.0