From 145c4b6ec2ea4f1dd7986b3179ca505a79bc0598 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 18 八月 2020 17:47:44 +0800
Subject: [PATCH] 2020-08-18

---
 src/tabviews/zshare/mutilform/index.jsx |  296 ++++++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 221 insertions(+), 75 deletions(-)

diff --git a/src/tabviews/zshare/mutilform/index.jsx b/src/tabviews/zshare/mutilform/index.jsx
index e55e72c..08a4407 100644
--- a/src/tabviews/zshare/mutilform/index.jsx
+++ b/src/tabviews/zshare/mutilform/index.jsx
@@ -5,6 +5,7 @@
 import moment from 'moment'
 
 import Api from '@/api'
+import options from '@/store/options.js'
 import { formRule, calendarColors } from '@/utils/option.js'
 import Utils from '@/utils/utils.js'
 import FileUpload from '../fileupload'
@@ -176,7 +177,7 @@
           newval = newval.format('YYYY-MM-DD HH:mm:ss') === 'Invalid date' ? '' : newval
         }
         if (!newval && item.initval) {
-          newval = moment().subtract(item.initval, 'days')
+          newval = moment(moment().subtract(item.initval, 'days').format('YYYY-MM-DD') + ' 00:00:00', 'YYYY-MM-DD HH:mm:ss')
         } else if (!newval) {
           newval = null
         }
@@ -268,110 +269,255 @@
    * @description 鑾峰彇涓嬫媺琛ㄥ崟閫夐」淇℃伅
    */
   improveActionForm = () => {
+    const { BID, menuType } = this.props
     const { formlist } = this.state
+
+    // 闇�瑕佸姩鎬佽幏鍙栦笅鎷夎彍鍗曠殑琛ㄥ崟
+    let deForms = formlist.filter(item => ['select', 'link', 'multiselect'].includes(item.type) && item.resourceType === '1' && (item.type === 'link' || item.hidden !== 'true'))
+
+    if (deForms.length === 0) {
+      return
+    } else if (menuType !== 'HS' && options.sysType === 'local' && !window.GLOB.systemType) {
+      this.improveSimpleActionForm(deForms)
+      return
+    }
+
     let deffers = []
+    let mainItems = []  // 浜戠鎴栧崟鐐规暟鎹�
+    let localItems = [] // 鏈湴鏁版嵁
 
-    formlist.forEach(item => {
-      if (
-        !['select', 'link', 'multiselect'].includes(item.type) ||
-        item.resourceType !== '1' ||
-        (item.type !== 'link' && item.hidden === 'true')
-      ) return
-
-      let param = {
-        func: 'sPC_Get_SelectedList',
-        LText: item.data_sql,
-        obj_name: 'data',
-        arr_field: item.arr_field
+    deForms.forEach(item => {
+      if (item.database === 'sso') {
+        mainItems.push(`select '${item.field}' as obj_name,'${item.arr_field}' as arr_field,'${item.base_sql}' as LText`)
+      } else {
+        localItems.push(`select '${item.field}' as obj_name,'${item.arr_field}' as arr_field,'${item.base_sql}' as LText`)
       }
-      let isSSO = item.database === 'sso'
+    })
+    
+    if (menuType !== 'HS' && window.GLOB.systemType !== 'production') {
+      localItems = [...localItems, ...mainItems]
+      mainItems = []
+    }
 
-      if (this.props.BID) {
-        param.BID = this.props.BID
-      }
+    // 鏈湴璇锋眰
+    let param = {
+      func: 'sPC_Get_SelectedList',
+      LText: localItems.join(' union all '),
+      obj_name: '',
+      arr_field: '',
+      table_type: 'Y'
+    }
 
+    if (BID) {
+      param.BID = BID
+    }
+
+    if (param.LText) {
+      param.LText = Utils.formatOptions(param.LText)
       param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
       param.secretkey = Utils.encrypt(param.LText, param.timestamp)
 
-      if (this.props.menuType === 'HS') { // 浜戠鏁版嵁楠岃瘉
+      if (menuType === 'HS') { // 浜戠鏁版嵁楠岃瘉
         param.open_key = Utils.encrypt(param.secretkey, param.timestamp, true)
-      } else if (window.GLOB.systemType !== 'production') {
-        isSSO = false
       }
 
       deffers.push(
         new Promise(resolve => {
-          Api.getSystemCacheConfig(param, isSSO).then(res => {
-            res.$search = item
+          Api.getSystemCacheConfig(param).then(res => {
+            if (!res.status) {
+              notification.warning({
+                top: 92,
+                message: res.message,
+                duration: 5
+              })
+            }
             resolve(res)
           })
         })
-      ) 
-    })
+      )
+    }
 
-    if (deffers.length === 0) return
+    // 绯荤粺璇锋眰
+    let mainparam = {
+      func: 'sPC_Get_SelectedList',
+      LText: mainItems.join(' union all '),
+      obj_name: '',
+      arr_field: '',
+      table_type: 'Y'
+    }
 
-    let _field = {}
-    let error = ''
-    Promise.all(deffers).then(result => {
-      result.forEach(res => {
-        if (res.status) {
-          let options = res.data.map(cell => {
-            let item = {
-              key: Utils.getuuid(),
-              Value: cell[res.$search.valueField],
-              Text: cell[res.$search.valueText]
-            }
+    if (BID) {
+      mainparam.BID = BID
+    }
 
-            if (res.$search.type === 'link') {
-              item.ParentID = cell[res.$search.linkField]
-            } else if (res.$search.type === 'select' && res.$search.linkSubField && res.$search.linkSubField.length > 0) {
-              res.$search.linkSubField.forEach(_field => {
-                item[_field] = (cell[_field] || cell[_field] === 0) ? cell[_field] : ''
-              })
-            }
+    if (mainparam.LText) {
+      mainparam.LText = Utils.formatOptions(mainparam.LText)
+      mainparam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
+      mainparam.secretkey = Utils.encrypt(mainparam.LText, mainparam.timestamp)
 
-            return item
-          })
-
-          _field[res.$search.uuid] = options
-        } else {
-          error = res
+      if (menuType === 'HS') { // 浜戠鏁版嵁楠岃瘉
+        mainparam.open_key = Utils.encrypt(mainparam.secretkey, mainparam.timestamp, true)
+        if (options.cloudServiceApi) {
+          mainparam.rduri = options.cloudServiceApi
+          mainparam.userid = sessionStorage.getItem('CloudUserID') || ''
+          mainparam.LoginUID = sessionStorage.getItem('CloudLoginUID') || ''
         }
-      })
-
-      if (error) {
-        notification.warning({
-          top: 92,
-          message: error.message,
-          duration: 5
-        })
+      } else if (window.GLOB.mainSystemApi) {
+        mainparam.rduri = window.GLOB.mainSystemApi
       }
 
+      deffers.push(
+        new Promise(resolve => {
+          Api.getSystemCacheConfig(mainparam).then(res => {
+            if (!res.status) {
+              notification.warning({
+                top: 92,
+                message: res.message,
+                duration: 5
+              })
+            }
+            resolve(res)
+          })
+        })
+      )
+    }
+
+    Promise.all(deffers).then(response => {
+      let result = {...response[0], ...(response[1] || {})}
+
+      delete result.ErrCode
+      delete result.ErrMesg
+      delete result.message
+      delete result.status
+
       let _formlist = formlist.map(item => {
-        if (item.type === 'select' || item.type === 'link' || item.type === 'multiselect') {
-          if (item.resourceType === '1' && _field.hasOwnProperty(item.uuid)) {
-            item.oriOptions = [...item.oriOptions, ..._field[item.uuid]]
-          }
-        }
-        return item
-      })
-  
-      _formlist = _formlist.map(item => {
-        if (item.type === 'link') {
-          if (item.supInitVal) {
-            item.options = item.oriOptions.filter(option => option.ParentID === item.supInitVal)
-          } else {
-            item.options = item.oriOptions
-          }
-        } else if (item.type === 'select' || item.type === 'multiselect') {
-          item.options = item.oriOptions
+        if (['select', 'link', 'multiselect'].includes(item.type) && result[item.field] && result[item.field].length > 0) {
+          let options = result[item.field].map(cell => {
+            let _cell = {
+              key: Utils.getuuid(),
+              Value: cell[item.valueField],
+              Text: cell[item.valueText]
+            }
+    
+            if (item.type === 'link') {
+              _cell.ParentID = cell[item.linkField]
+            } else if (item.type === 'select' && item.linkSubField && item.linkSubField.length > 0) {
+              item.linkSubField.forEach(_field => {
+                _cell[_field] = (cell[_field] || cell[_field] === 0) ? cell[_field] : ''
+              })
+            }
+    
+            return _cell
+          })
+
+          item.oriOptions = [...item.oriOptions, ...options]
         }
         return item
       })
 
       this.setState({
-        formlist: _formlist
+        formlist: _formlist.map(item => {
+          if (item.type === 'link') {
+            if (item.supInitVal) {
+              item.options = item.oriOptions.filter(option => option.ParentID === item.supInitVal)
+            } else {
+              item.options = item.oriOptions
+            }
+          } else if (item.type === 'select' || item.type === 'multiselect') {
+            item.options = item.oriOptions
+          }
+          return item
+        })
+      })
+    })
+  }
+
+  /**
+   * @description 娴嬭瘯绯荤粺鑾峰彇涓嬫媺琛ㄥ崟閫夐」淇℃伅
+   */
+  improveSimpleActionForm = (deForms) => {
+    const { formlist } = this.state
+
+    let deffers = deForms.map(form => {
+      let param = {
+        func: 'sPC_Get_SelectedList',
+        LText: form.data_sql,
+        obj_name: form.field,
+        arr_field: form.arr_field
+      }
+  
+      if (this.props.BID) {
+        param.BID = this.props.BID
+      }
+  
+      param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
+      param.secretkey = Utils.encrypt(param.LText, param.timestamp)
+  
+      return (
+        new Promise(resolve => {
+          Api.getSystemCacheConfig(param).then(res => {
+            if (!res.status) {
+              notification.warning({
+                top: 92,
+                message: res.message,
+                duration: 5
+              })
+            }
+            resolve(res)
+          })
+        })
+      )
+    })
+
+    Promise.all(deffers).then(response => {
+      let result = {}
+      response.forEach(res => {
+        result = {...result, ...res}
+      })
+      
+      delete result.ErrCode
+      delete result.ErrMesg
+      delete result.message
+      delete result.status
+
+      let _formlist = formlist.map(item => {
+        if (['select', 'link', 'multiselect'].includes(item.type) && result[item.field] && result[item.field].length > 0) {
+          let options = result[item.field].map(cell => {
+            let _cell = {
+              key: Utils.getuuid(),
+              Value: cell[item.valueField],
+              Text: cell[item.valueText]
+            }
+    
+            if (item.type === 'link') {
+              _cell.ParentID = cell[item.linkField]
+            } else if (item.type === 'select' && item.linkSubField && item.linkSubField.length > 0) {
+              item.linkSubField.forEach(_field => {
+                _cell[_field] = (cell[_field] || cell[_field] === 0) ? cell[_field] : ''
+              })
+            }
+    
+            return _cell
+          })
+
+          item.oriOptions = [...item.oriOptions, ...options]
+        }
+        return item
+      })
+
+      this.setState({
+        formlist: _formlist.map(item => {
+          if (item.type === 'link') {
+            if (item.supInitVal) {
+              item.options = item.oriOptions.filter(option => option.ParentID === item.supInitVal)
+            } else {
+              item.options = item.oriOptions
+            }
+          } else if (item.type === 'select' || item.type === 'multiselect') {
+            item.options = item.oriOptions
+          }
+          return item
+        })
       })
     })
   }

--
Gitblit v1.8.0