From c0930736f5b5955efecdac4c0ca85957d4f7b574 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期一, 16 十二月 2019 22:55:17 +0800
Subject: [PATCH] 2019-12-16

---
 src/tabviews/commontable/index.jsx |  204 +++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 174 insertions(+), 30 deletions(-)

diff --git a/src/tabviews/commontable/index.jsx b/src/tabviews/commontable/index.jsx
index 893367c..00cccd9 100644
--- a/src/tabviews/commontable/index.jsx
+++ b/src/tabviews/commontable/index.jsx
@@ -162,7 +162,6 @@
     let deffers = []
     searchlist.forEach(item => {
       if (item.type !== 'select' && item.type !== 'link') return
-
       if (item.setAll === 'true') {
         item.options.unshift({
           key: Utils.getuuid(),
@@ -172,11 +171,15 @@
       }
 
       if (item.resourceType === '1' && item.dataSource) {
+        let arrfield = item.valueField + ',' + item.valueText
+        if (item.type === 'link') {
+          arrfield = arrfield + ',' + item.linkField
+        }
         let param = {
           func: 'sPC_Get_SelectedList',
           LText: item.dataSourceSql,
           obj_name: 'data',
-          arr_field: item.valueField + ',' + item.valueText
+          arr_field: arrfield
         }
 
         param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
@@ -231,35 +234,138 @@
 
   improveAction = () => {
     const { config } = this.state
-    config.action.forEach(item => {
-      if (item.OpenType !== 'pop' && item.OpenType !== 'tab' && item.OpenType !== 'blank') return
 
-      Api.getSystemCacheConfig({
-        func: 'sPC_Get_LongParam',
-        MenuID: item.uuid
-      }).then(res => {
-        if (res.status) {
-          let _LongParam = ''
-          if (res.LongParam) {
-            _LongParam = window.decodeURIComponent(window.atob(res.LongParam))
-            try {
-              _LongParam = JSON.parse(_LongParam)
-            } catch (e) {
-              _LongParam = ''
-            }
-          }
-
-          this.setState({
-            configMap: {...this.state.configMap, [item.uuid]: _LongParam}
+    let conAction = config.action.filter(item => (item.OpenType === 'pop' || item.OpenType === 'tab' || item.OpenType === 'blank'))
+    
+    if (conAction.length > 0) {
+      let deffers = conAction.map(item => {
+        return new Promise(resolve => {
+          Api.getSystemCacheConfig({
+            func: 'sPC_Get_LongParam',
+            MenuID: item.uuid
+          }).then(res => {
+            res.uuid = item.uuid
+            resolve(res)
           })
-        } else {
+        })
+      })
+
+      let _action = {}
+      let error = ''
+      Promise.all(deffers).then(result => {
+        result.forEach(res => {
+          if (res.status) {
+            let _LongParam = ''
+            if (res.LongParam) {
+              _LongParam = window.decodeURIComponent(window.atob(res.LongParam))
+              try {
+                _LongParam = JSON.parse(_LongParam)
+              } catch (e) {
+                _LongParam = ''
+              }
+            }
+
+            if (_LongParam) {
+              _action[res.uuid] = _LongParam
+            }
+          } else {
+            error = res
+            
+          }
+        })
+
+        this.setState({
+          configMap: {...this.state.configMap, ..._action}
+        })
+
+        if (error) {
           notification.warning({
             top: 92,
-            message: res.message,
+            message: error.message,
             duration: 10
           })
+        } else {
+          this.improveActionForm(Object.values(_action))
         }
       })
+    }
+  }
+
+  improveActionForm = (actions) => {
+    let subfields = []
+    actions.forEach(item => {
+      if (item.groups.length > 0) {
+        item.groups.forEach(group => {
+          group.sublist.forEach(field => {
+            if ((field.type === 'select' || field.type === 'link') && field.resourceType === '1') {
+              subfields.push(field)
+            }
+          })
+        })
+      } else {
+        item.fields.forEach(field => {
+          if ((field.type === 'select' || field.type === 'link') && field.resourceType === '1') {
+            subfields.push(field)
+          }
+        })
+      }
+    })
+
+    let deffers = subfields.map(item => {
+      let arrfield = item.valueField + ',' + item.valueText
+
+      if (item.type === 'link') {
+        arrfield = arrfield + ',' + item.linkField
+      }
+
+      let param = {
+        func: 'sPC_Get_SelectedList',
+        LText: item.dataSourceSql,
+        obj_name: 'data',
+        arr_field: arrfield
+      }
+
+      param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
+      param.secretkey = Utils.encrypt(param.LText, param.timestamp)
+      console.log(item)
+      return new Promise(resolve => {
+        Api.getSystemCacheConfig(param).then(res => {
+          res.search = item
+          resolve(res)
+        })
+      })
+    })
+
+    let _field = {}
+    let error = ''
+    Promise.all(deffers).then(result => {
+      result.forEach(res => {
+        if (res.status) {
+          let options = res.data.map(cell => {
+            return {
+              key: Utils.getuuid(),
+              Value: cell[res.search.valueField],
+              Text: cell[res.search.valueText]
+            }
+          })
+
+          _field[res.search.uuid] = options
+        } else {
+          error = res
+        }
+      })
+
+      this.setState({
+        configMap: {...this.state.configMap, ..._field}
+      })
+
+      if (error) {
+        notification.warning({
+          top: 92,
+          message: error.message,
+          duration: 10
+        })
+      }
     })
   }
 
@@ -326,6 +432,7 @@
 
     this.setState({
       loading: true,
+      pageIndex: 1,
       search: searches
     }, () => {
       this.loadmaindata()
@@ -353,15 +460,52 @@
     })
   }
 
+  reloadtable = () => {
+    this.refs.mainTable.resetTable()
+    this.setState({
+      loading: true,
+      pageIndex: 1
+    }, () => {
+      this.loadmaindata()
+    })
+  }
+
+  reloadview = () => {
+    this.setState({
+      loadingview: true,    // 椤甸潰鍔犺浇涓�
+      viewlost: false,      // 椤甸潰涓㈠け锛�1銆佹湭鑾峰彇鍒伴厤缃�-椤甸潰涓㈠け锛�2銆侀〉闈㈡湭鍚敤
+      lostmsg: '',          // 椤甸潰涓㈠け鏃剁殑鎻愮ず淇℃伅
+      config: {},
+      searchlist: null,
+      actions: null,
+      columns: null,
+      arr_field: '',
+      setting: null,
+      data: null,
+      total: 0,
+      loading: false,
+      pageIndex: 1,
+      pageSize: 10,
+      orderColumn: '',
+      orderType: 'asc',
+      search: '',
+      configMap: {}
+    }, () => {
+      this.loadconfig()
+    })
+  }
+
   refreshbyaction = (btn, type) => {
     // 鎸夐挳鎿嶄綔鍚庡埛鏂拌〃鏍�,閲嶇疆椤电爜鍙婇�夋嫨椤�
-    console.log(btn)
-    console.log(type)
-    this.refs.mainTable.resetTable()
-    // this.loadmaindata(1, this.state.param.pageSize, this.state.param.orderColumn, this.state.param.orderType, this.state.param.search)
-    // this.setState({
-    //   loading: true
-    // })
+    if (btn.execSuccess === 'grid' && type === 'success') {
+      this.reloadtable()
+    } else if (btn.execError === 'grid' && type === 'error') {
+      this.reloadview()
+    } else if (btn.execSuccess === 'view' && type === 'success') {
+      this.reloadtable()
+    } else if (btn.execError === 'view' && type === 'error') {
+      this.reloadview()
+    }
   }
 
   gettableselected = () => {

--
Gitblit v1.8.0