From 213c70792e6af7f9ccef17d778c5f8806fbd513c Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 28 十一月 2019 15:01:24 +0800
Subject: [PATCH] 2019-11-28-01

---
 src/tabviews/commontable/index.jsx |  109 +++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 94 insertions(+), 15 deletions(-)

diff --git a/src/tabviews/commontable/index.jsx b/src/tabviews/commontable/index.jsx
index c685004..194afb2 100644
--- a/src/tabviews/commontable/index.jsx
+++ b/src/tabviews/commontable/index.jsx
@@ -10,7 +10,7 @@
 import Loading from '@/components/loading'
 import zhCN from '@/locales/zh-CN/main.js'
 import enUS from '@/locales/en-US/main.js'
-// import Utils from '@/utils/utils.js'
+import Utils from '@/utils/utils.js'
 import './index.scss'
 
 export default class NormalTable extends Component {
@@ -27,7 +27,7 @@
     searchlist: null,
     actions: null,
     columns: null,
-    select: null,
+    setting: null,
     data: null,
     total: 0,
     loading: false,
@@ -67,8 +67,15 @@
           duration: 10
         })
       }
-      this.setState({config})
-      console.log(config.columns)
+      this.setState({
+        config: config,
+        setting: config.setting,
+        searchlist: config.search,
+        actions: config.action,
+        columns: config.columns
+      }, () => {
+        this.improveSearch()
+      })
     } else {
       this.setState({
         loadingview: false,
@@ -80,6 +87,77 @@
         duration: 10
       })
     }
+  }
+
+  improveSearch = () => {
+    let searchlist = JSON.parse(JSON.stringify(this.state.searchlist))
+    let deffers = []
+    searchlist.forEach(item => {
+      if (item.type !== 'select' && item.type !== 'link') return
+
+      let unloaded = item.options.length === 0
+
+      if (item.setAll === 'true') {
+        item.options.unshift({
+          key: Utils.getuuid(),
+          Value: '',
+          Text: '鍏ㄩ儴'
+        })
+      }
+
+      if (item.resourceType === '1' && item.dataSource && unloaded) {
+        let param = {
+          func: 'sPC_Get_SelectedList',
+          // LText: item.dataSourceSql,
+          LText: 'msltk * mfrmk sOrganization',
+          obj_name: 'data',
+          arr_field: item.valueField + ',' + item.valueText
+        }
+        let defer = new Promise(resolve => {
+          Api.getSystemConfig(param).then(res => {
+            res.search = item
+            resolve(res)
+          })
+        })
+        deffers.push(defer)
+      } else if (item.resourceType === '1' && !item.dataSource) {
+        notification.warning({
+          top: 92,
+          message: item.label + '鏁版嵁婧愰厤缃敊璇�',
+          duration: 10
+        })
+      }
+    })
+
+    this.setState({searchlist: JSON.parse(JSON.stringify(searchlist))})
+
+    if (deffers.length === 0) return
+
+    Promise.all(deffers).then(result => {
+      result.forEach(res => {
+        if (res.status) {
+          searchlist = searchlist.map(item => {
+            if (item.uuid === res.search.uuid) {
+              res.data.forEach(cell => {
+                item.options.push({
+                  key: Utils.getuuid(),
+                  Value: cell[res.search.valueField],
+                  Text: cell[res.search.valueText]
+                })
+              })
+            }
+            return item
+          })
+        } else {
+          notification.warning({
+            top: 92,
+            message: res.search.label + ':' + res.message,
+            duration: 10
+          })
+        }
+      })
+      this.setState({searchlist})
+    })
   }
 
   async loadmaindata (pageIndex = 1, pageSize = 10, orderColumn = '', orderType = '', search = '') {
@@ -150,6 +228,7 @@
     // 鑾峰彇琛ㄦ牸閫夋嫨椤�
     let data = []
     this.refs.mainTable.state.selectedRowKeys.forEach(item => {
+      console.log(item)
       data.push(this.refs.mainTable.props.data[item])
     })
     return data
@@ -166,8 +245,8 @@
           key: item,
           ID: item + 'mainkey',
           ExRateName: '$',
-          SupplierName: '闃块噷宸村反' + item + '搴�',
-          SupShortName: '闃块噷宸村反',
+          SupplierName: '澶╃尗' + item + '搴�',
+          SupShortName: '澶╃尗',
           SupplierCode: '201922' + item,
           OrgName: '闃块噷宸村反',
           OrgCode: '302999',
@@ -183,35 +262,35 @@
   }
 
   render() {
-    const { config, loadingview, viewlost } = this.state
+    const { setting, searchlist, actions, columns, loadingview, viewlost } = this.state
 
     return (
       <div className="commontable">
         {loadingview && <Loading />}
-        {config.search && config.search.length > 0 ?
+        {searchlist && searchlist.length > 0 ?
           <MainSearch
             refreshdata={this.refreshbysearch}
-            searchlist={config.search}
+            searchlist={searchlist}
             dict={this.state.dict}
           /> : null
         }
-        {config.action &&
+        {actions &&
           <MainAction
             MenuID={this.props.MenuID}
-            fixed={config.setting && config.setting.actionfixed}
+            fixed={setting && setting.actionfixed}
             refreshdata={this.refreshbyaction}
             gettableselected={this.gettableselected}
-            actions={config.action}
+            actions={actions}
             dict={this.state.dict}
           />
         }
-        {config.columns &&
+        {columns &&
           <MainTable
             ref="mainTable"
             MenuID={this.props.MenuID}
-            setting={config.setting}
+            setting={setting}
             refreshdata={this.refreshbytable}
-            columns={config.columns}
+            columns={columns}
             data={this.state.data}
             total={this.state.total}
             loading={this.state.loading}

--
Gitblit v1.8.0