From 7051e15582aee4163b3c8dd13dc85f4f1e2ce6eb Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期五, 07 二月 2020 02:11:43 +0800
Subject: [PATCH] 2020-02-07

---
 src/tabviews/formtab/index.jsx |  466 ++++++++++++++++------------------------------------------
 1 files changed, 130 insertions(+), 336 deletions(-)

diff --git a/src/tabviews/formtab/index.jsx b/src/tabviews/formtab/index.jsx
index 84aca6d..98b0f19 100644
--- a/src/tabviews/formtab/index.jsx
+++ b/src/tabviews/formtab/index.jsx
@@ -2,7 +2,7 @@
 import PropTypes from 'prop-types'
 import {connect} from 'react-redux'
 import { is, fromJS } from 'immutable'
-import { BackTop, notification, Spin, Tabs, Icon, Modal, Button} from 'antd'
+import { BackTop, notification, Spin, Tabs, Icon} from 'antd'
 import moment from 'moment'
 
 import Api from '@/api'
@@ -11,14 +11,12 @@
 import Utils from '@/utils/utils.js'
 
 import FormGroup from './formgroup'
-import MainAction from '@/tabviews/tableshare/actionList'
+import FormAction from './actionList'
 import SubTable from '@/tabviews/subtable'
 import NotFount from '@/components/404'
-import asyncComponent from '@/utils/asyncLoadComponent'
 import {refreshTabView} from '@/store/action'
 import './index.scss'
 
-const SubTabTable = asyncComponent(() => import('@/tabviews/subtabtable'))
 const { TabPane } = Tabs
 
 class NormalTable extends Component {
@@ -35,22 +33,16 @@
     viewlost: false,      // 椤甸潰涓㈠け锛�1銆佹湭鑾峰彇鍒伴厤缃�-椤甸潰涓㈠け锛�2銆侀〉闈㈡湭鍚敤
     lostmsg: '',          // 椤甸潰涓㈠け鏃剁殑鎻愮ず淇℃伅
     config: {},           // 椤甸潰閰嶇疆淇℃伅锛屽寘鎷寜閽�佽〃鍗曘�佹爣绛剧瓑
+    groups: null,         // 琛ㄥ崟缁�
     actions: null,        // 鎸夐挳闆�
     arr_field: '',        // 浣跨敤 sPC_Get_TableData 鏃剁殑鏌ヨ瀛楁闆�
     setting: null,        // 椤甸潰鍏ㄥ眬璁剧疆锛氭暟鎹簮銆佹寜閽強鏄剧ず鍒楀浐瀹氥�佷富閿瓑
     data: null,           // 鍒楄〃鏁版嵁闆�
-    loading: false,       // 鍒楄〃鏁版嵁鍔犺浇涓�
-    pageIndex: 1,         // 椤电爜
-    pageSize: 10,         // 姣忛〉鏁版嵁鏉℃暟
-    orderColumn: '',      // 鎺掑簭瀛楁
-    orderType: 'asc',     // 鎺掑簭鏂瑰紡
-    search: '',           // 鎼滅储鏉′欢鏁扮粍锛屼娇鐢ㄦ椂闇�鍒嗗満鏅鐞�
     configMap: {},        // 椤甸潰閰嶇疆淇℃伅锛氫笅鎷夈�佹寜閽瓑
     BIDs: {},             // 涓婄骇琛╥d
     setsingle: false,     // 涓昏〃鍗曢�夊閫夊垏鎹�
     pickup: false,        // 涓昏〃鏁版嵁闅愯棌鏄剧ず鍒囨崲
     isLinkMain: false,    // 鏄惁瀛樺湪涓庝富琛ㄥ叧鑱旂殑瀛愯〃
-    popAction: false,     // 寮规椤甸潰锛屾寜閽俊鎭�
     popData: false,       // 寮规椤甸潰锛屾墍閫夌殑琛ㄦ牸鏁版嵁
     visible: false        // 寮规鏄剧ず闅愯棌鎺у埗
   }
@@ -109,7 +101,7 @@
         })
         _arrField = _arrField.join(',')
       }
-      console.log(config)
+
       // 鏉冮檺杩囨护
       config.action = config.action.filter(item => permAction[item.uuid])
       // config.tabgroups.forEach(group => {
@@ -139,19 +131,33 @@
         }
       })
 
+      let _data = null
+      let _isCustomData = false
+
+      if (this.props.param && this.props.param.data) {
+        _data = this.props.param.data
+      }
+
+      if ((config.setting.interType === 'inner' && config.setting.innerFunc) || (config.setting.interType === 'outer' && config.setting.interface)) {
+        _isCustomData = true
+        _data = null
+      }
+
+
       this.setState({
-        loadingview: false,
         config: config,
         setting: config.setting,
         actions: config.action,
         isLinkMain: _isLinkMain,
         arr_field: _arrField,
-        search: Utils.initMainSearch(config.search), // 鎼滅储鏉′欢鍒濆鍖栵紙鍚湁鏃堕棿鏍煎紡锛岄渶瑕佽浆鍖栵級
-        loading: true
+        data: _data,
+        BIDs: {
+          mainTable: (!_isCustomData && _data && _data[0] && _data[0][config.setting.primaryKey]) || ''
+        }
       }, () => {
-        this.improveSearch()
+        this.improveSelectOption(config.groups)
 
-        if (config.setting.onload !== 'false') {
+        if (_isCustomData) {
           this.loadmaindata()
         }
       })
@@ -169,77 +175,87 @@
   }
 
   /**
-   * @description 鎼滅储鏉′欢涓嬫媺閫夐」棰勫姞杞�
+   * @description 琛ㄥ崟涓嬫媺閫夐」鍔犺浇
    */
-  improveSearch = () => {
-    let searchlist = JSON.parse(JSON.stringify(this.state.searchlist))
+  improveSelectOption = (groups) => {
     let deffers = []
-    searchlist.forEach(item => {
-      if (item.type !== 'multiselect' && item.type !== 'select' && item.type !== 'link') return
-      if (item.setAll === 'true') {
-        item.options.unshift({
-          key: Utils.getuuid(),
-          Value: '',
-          Text: this.state.dict['main.all']
-        })
-      }
+    groups.forEach(group => {
+      group.sublist = group.sublist.map(item => {
+        if (item.type !== 'multiselect' && item.type !== 'select' && item.type !== 'link') return item
 
-      if (item.resourceType === '1' && item.dataSource) {
-        let _option = Utils.getSelectQueryOptions(item)
-        let _sql = Utils.formatOptions(_option.sql)
-
-        let param = {
-          func: 'sPC_Get_SelectedList',
-          LText: _sql,
-          obj_name: 'data',
-          arr_field: _option.field
+        if (item.setAll === 'true') {
+          item.options.unshift({
+            key: Utils.getuuid(),
+            Value: '',
+            Text: this.state.dict['main.all']
+          })
+        }
+  
+        if (item.resourceType === '1' && item.dataSource) {
+          let _option = Utils.getSelectQueryOptions(item)
+          let _sql = Utils.formatOptions(_option.sql)
+          let isSSO = item.database === 'sso'
+  
+          let param = {
+            func: 'sPC_Get_SelectedList',
+            LText: _sql,
+            obj_name: 'data',
+            arr_field: _option.field
+          }
+  
+          param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
+          param.secretkey = Utils.encrypt(param.LText, param.timestamp)
+  
+          let defer = new Promise(resolve => {
+            Api.getSystemCacheConfig(param, isSSO).then(res => {
+              res.search = item
+              resolve(res)
+            })
+          })
+          deffers.push(defer)
+        } else if (item.resourceType === '1' && !item.dataSource) {
+          notification.warning({
+            top: 92,
+            message: item.label + ': ' + this.state.dict['main.datasource.settingerror'],
+            duration: 10
+          })
         }
 
-        param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
-        param.secretkey = Utils.encrypt(param.LText, param.timestamp)
-
-        let defer = new Promise(resolve => {
-          Api.getSystemCacheConfig(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 + ': ' + this.state.dict['main.datasource.settingerror'],
-          duration: 10
-        })
-      }
+        return item
+      })
     })
-
+    
     if (deffers.length === 0) {
-      this.setState({searchlist: JSON.parse(JSON.stringify(searchlist))})
+      this.setState({
+        loadingview: false,
+        groups: groups
+      })
       return
     }
 
     Promise.all(deffers).then(result => {
+      let _result = {}
       result.forEach(res => {
         if (res.status) {
-          searchlist = searchlist.map(item => {
-            if (item.uuid === res.search.uuid) {
-              res.data.forEach(cell => {
-                let _item = {
-                  key: Utils.getuuid(),
-                  Value: cell[res.search.valueField],
-                  Text: cell[res.search.valueText]
-                }
+          let _options = res.data.map(cell => {
+            let _item = {
+              key: Utils.getuuid(),
+              Value: cell[res.search.valueField],
+              Text: cell[res.search.valueText]
+            }
 
-                if (res.search.type === 'link') {
-                  _item.parentId = cell[res.search.linkField]
-                }
-
-                item.options.push(_item)
+            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] : ''
               })
             }
-            return item
+
+            return _item
           })
+
+          _result[res.search.uuid] = _options
         } else {
           notification.warning({
             top: 92,
@@ -249,7 +265,23 @@
         }
       })
 
-      this.setState({searchlist})
+      groups.forEach(group => {
+        group.sublist = group.sublist.map(item => {
+          if (item.type === 'select' || item.type === 'link' || item.type === 'multiselect') {
+            if (_result[item.uuid]) {
+              item.options = [...item.options, ..._result[item.uuid]]
+            }
+            item.oriOptions = JSON.parse(JSON.stringify(item.options))
+          }
+          
+          return item
+        })
+      })
+
+      this.setState({
+        loadingview: false,
+        groups: groups
+      })
     })
   }
 
@@ -257,38 +289,18 @@
    * @description 涓昏〃鏁版嵁鍔犺浇
    */ 
   async loadmaindata () {
-    const { setting, BIDs } = this.state
-    let param = ''
-
-    if (setting.interType !== 'inner' || (setting.interType === 'inner' && setting.innerFunc)) {
-      param = this.getCustomParam()
-    } else {
-      param = this.getDefaultParam()
-    }
-
-    this.setState({
-      pickup: false
-    })
-
-    this.handleTableId('mainTable', '')
+    const { setting } = this.state
+    let param = this.getCustomParam()
 
     let result = await Api.genericInterface(param)
     if (result.status) {
       this.setState({
-        data: result.data.map((item, index) => {
-          item.key = index
-          return item
-        }),
-        loading: false,
+        data: result.data,
         BIDs: {
-          ...BIDs,
-          mainTable: ''
+          mainTable: (result.data[0] && result.data[0][setting.primaryKey]) || ''
         }
       })
     } else {
-      this.setState({
-        loading: false
-      })
       notification.error({
         top: 92,
         message: result.message,
@@ -301,22 +313,21 @@
    * @description 鑾峰彇鐢ㄦ埛鑷畾涔夊瓨鍌ㄨ繃绋嬩紶鍙�
    */
   getCustomParam = () => {
-    const { pageIndex, pageSize, orderColumn, orderType, search, setting } = this.state
+    const { setting } = this.state
 
-    let _search = Utils.formatCustomMainSearch(search)
-
-    let param = {
-      PageIndex: pageIndex,
-      PageSize: pageSize,
-      OrderCol: orderColumn,
-      OrderType: orderType,
-      ..._search
-    }
+    let param = {}
 
     if (setting.interType === 'inner') {
       param.func = setting.innerFunc
     } else {
-      param.rduri = setting.interface
+      if (setting.sysInterface === 'true') {
+        param.rduri = window.GLOB.mainSystemApi || window.GLOB.subSystemApi
+      } else {
+        param.rduri = setting.interface
+      }
+
+      param.appkey = window.GLOB.appkey || '' // 璋冪敤澶栭儴鎺ュ彛澧炲姞appkey
+
       if (setting.outerFunc) {
         param.func = setting.outerFunc
       }
@@ -326,174 +337,18 @@
   }
 
   /**
-   * @description 鑾峰彇绯荤粺瀛樺偍杩囩▼ sPC_Get_TableData 鐨勫弬鏁�
-   */
-  getDefaultParam = () => {
-    const { arr_field, pageIndex, pageSize, orderColumn, orderType, search, setting } = this.state
-
-    let _search = Utils.joinMainSearchkey(search)
-
-    _search = _search ? 'where ' + _search : ''
-    
-    let param = {
-      func: 'sPC_Get_TableData',
-      obj_name: 'data',
-      arr_field: arr_field
-    }
-    
-    let orderBy = orderColumn ? (orderColumn + ' ' + orderType) : setting.order
-    let _dataresource = setting.dataresource
-
-    if (/\s/.test(_dataresource)) {
-      _dataresource = '(' + _dataresource + ') tb'
-    }
-
-    let LText = `select top ${pageSize} ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${orderBy}) as rows from ${_dataresource} ${_search}) tmptable where rows > ${pageSize * (pageIndex - 1)} order by tmptable.rows`
-
-    param.LText = Utils.formatOptions(LText)
-    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
-    param.secretkey = Utils.encrypt(param.LText, param.timestamp)
-
-    return param
-  }
-
-  /**
-   * @description 鎼滅储鏉′欢鏀瑰彉鏃讹紝閲嶇疆琛ㄦ牸鏁版嵁
-   * 鍚湁鍒濆涓嶅姞杞界殑椤甸潰锛屼慨鏀硅缃�
-   */
-  refreshbysearch = (searches) => {
-    const { setting } = this.state
-
-    if (setting.onload === 'false') {
-      this.setState({
-        loading: true,
-        pageIndex: 1,
-        search: searches,
-        setting: {...setting, onload: 'true'}
-      }, () => {
-        this.loadmaindata()
-      })
-    } else {
-      this.refs.mainTable.resetTable()
-
-      this.setState({
-        loading: true,
-        pageIndex: 1,
-        search: searches
-      }, () => {
-        this.loadmaindata()
-      })
-    }
-  }
-
-  /**
-   * @description 琛ㄦ牸鏉′欢鏀瑰彉鏃堕噸缃暟鎹紙鍒嗛〉鎴栨帓搴忥級
-   */
-  refreshbytable = (pagination, filters, sorter) => {
-    if (sorter.order) {
-      let _chg = {
-        ascend: 'asc',
-        descend: 'desc'
-      }
-      sorter.order = _chg[sorter.order]
-    }
-
-    this.setState({
-      loading: true,
-      pageIndex: pagination.current,
-      pageSize: pagination.pageSize,
-      orderColumn: sorter.field || this.state.setting.orderColumn,
-      orderType: sorter.order || 'asc'
-    }, () => {
-      this.loadmaindata()
-    })
-  }
-
-  /**
-   * @description 琛ㄦ牸鍒锋柊
-   */
-  reloadtable = () => {
-    this.refs.mainTable.resetTable()
-    this.setState({
-      loading: true,
-      pageIndex: 1
-    }, () => {
-      this.loadmaindata()
-    })
-  }
-
-  /**
-   * @description 椤甸潰鍒锋柊锛岄噸鏂拌幏鍙栭厤缃�
-   */
-  reloadview = () => {
-    this.setState({
-      loadingview: true,
-      viewlost: false,
-      lostmsg: '',
-      config: {},
-      searchlist: null,
-      actions: null,
-      arr_field: '',
-      setting: null,
-      data: null,
-      loading: false,
-      pageIndex: 1,
-      pageSize: 10,
-      orderColumn: '',
-      orderType: 'asc',
-      search: '',
-      configMap: {},
-      BIDs: {},
-      setsingle: false,
-      pickup: false,
-      isLinkMain: false
-    }, () => {
-      this.loadconfig()
-    })
-  }
-
-  /**
    * @description 鎸夐挳鎿嶄綔瀹屾垚鍚庯紙鎴愬姛鎴栧け璐ワ級锛岄〉闈㈠埛鏂帮紝閲嶇疆椤电爜鍙婇�夋嫨椤�
    */
   refreshbyaction = (btn, type) => {
     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()
-    } else if (btn.popClose === 'view' && type === 'pop') {
-      this.reloadview()
-    } else if (btn.popClose === 'grid' && type === 'pop') {
-      this.reloadtable()
+
     }
-  }
-
-  /**
-   * @description 瀛愯〃鎿嶄綔瀹屾垚鍚庡埛鏂颁富琛�
-   */
-  handleMainTable = () => {
-    this.reloadtable()
-  }
-
-  /**
-   * @description 鑾峰彇琛ㄦ牸閫夋嫨椤�
-   */
-  gettableselected = () => {
-    let data = []
-    this.refs.mainTable.state.selectedRowKeys.forEach(item => {
-      data.push(this.refs.mainTable.props.data[item])
-    })
-    return data
-  }
-
-  /**
-   * @description 琛ㄦ牸涓紝鎸夐挳瑙﹀彂浜嬩欢浼犻��
-   */
-  buttonTrigger = (btn, record) => {
-    this.refs.mainButton.actionTrigger(btn, record)
   }
 
   /**
@@ -508,50 +363,6 @@
         [type]: id
       }
     })
-  }
-
-  /**
-   * @description 琛ㄦ牸鍗曢�夊閫夊垏鎹�
-   */
-  checkChange = () => {
-    const { setsingle, BIDs } = this.state
-
-    let _BIDs = JSON.parse(JSON.stringify(BIDs))
-    _BIDs.mainTable = ''
-
-    this.setState({
-      setsingle: !setsingle,
-      pickup: false,
-      BIDs: _BIDs
-    })
-  }
-  
-  /**
-   * @description 鏁版嵁灞曞紑鍚堝苟鍒囨崲
-   */
-  pickupChange = () => {
-    const { pickup } = this.state
-    this.setState({
-      pickup: !pickup
-    })
-  }
-
-  /**
-   * @description 瑙﹀彂鎸夐挳寮圭獥锛堟爣绛鹃〉锛�
-   */
-  triggerPopview = (btn, data) => {
-    this.setState({
-      popAction: btn,
-      popData: data[0] ? data[0] : null,
-      visible: true
-    })
-  }
-
-  popclose = () => {
-    this.setState({
-      visible: false
-    })
-    this.refreshbyaction(this.state.popAction, 'pop')
   }
 
   UNSAFE_componentWillMount () {
@@ -573,31 +384,28 @@
   }
 
   render() {
-    const { setting, actions, loadingview, viewlost, isLinkMain, config } = this.state
+    const { setting, actions, loadingview, viewlost, isLinkMain, config, groups, data } = this.state
 
     return (
-      <div className={'commontable ' + (isLinkMain ? 'pick-control' : '')} id={'commontable' + this.props.MenuID}>
+      <div className={'formtab ' + (isLinkMain ? 'pick-control' : '')} id={'formtab' + this.props.MenuID}>
         {loadingview && <Spin size="large" />}
-        {config ?
+        {groups && (groups.length > 1 || groups[0].sublist.length > 0) ?
           <FormGroup
             dict={this.state.dict}
-            groups={config.groups}
+            data={data}
+            groups={groups}
+            setting={setting}
             wrappedComponentRef={(inst) => this.formGroupRef = inst}
           /> : null
         }
-        {actions && setting.onload !== 'false' ?
-          <MainAction
-            ref="mainButton"
-            BID=""
-            type="main"
+        {actions ?
+          <FormAction
             setting={setting}
             actions={actions}
             dict={this.state.dict}
             MenuID={this.props.MenuID}
             logcolumns={[]}
             refreshdata={this.refreshbyaction}
-            triggerPopview={this.triggerPopview}
-            gettableselected={this.gettableselected}
           /> : null
         }
         {setting && setting.onload !== 'false' &&
@@ -631,20 +439,6 @@
             )
           })
         }
-        <Modal
-          className="popview-modal"
-          title={this.state.popAction.label}
-          width={'80vw'}
-          maskClosable={false}
-          visible={this.state.visible}
-          onCancel={this.popclose}
-          footer={[
-            <Button key="cancel" onClick={this.popclose}>{this.state.dict['main.close']}</Button>
-          ]}
-          destroyOnClose
-        >
-          {<SubTabTable SupMenuID={this.props.MenuID} MenuID={this.state.popAction.linkTab} BID={''} ID={this.state.popData ? this.state.popData[setting.primaryKey] : ''} />}
-        </Modal>
         <BackTop>
           <div className="ant-back-top">
             <div className="ant-back-top-content">

--
Gitblit v1.8.0