From f9697383bc9097be8a444558e09ae21b27f1e831 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 31 十二月 2019 09:27:21 +0800
Subject: [PATCH] 2019-12-31

---
 src/tabviews/commontable/index.jsx |  218 +++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 172 insertions(+), 46 deletions(-)

diff --git a/src/tabviews/commontable/index.jsx b/src/tabviews/commontable/index.jsx
index c52b108..e1ae84a 100644
--- a/src/tabviews/commontable/index.jsx
+++ b/src/tabviews/commontable/index.jsx
@@ -1,7 +1,7 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
 import { is, fromJS } from 'immutable'
-import { BackTop, notification, Spin, Tabs, Icon, Switch} from 'antd'
+import { BackTop, notification, Spin, Tabs, Icon, Switch, Modal, Button} from 'antd'
 import moment from 'moment'
 import Api from '@/api'
 import MainTable from './mainTable'
@@ -9,13 +9,13 @@
 import MainSearch from '@/tabviews/tableshare/topSearch'
 import SubTable from '@/tabviews/subtable'
 import NotFount from '@/components/404'
-// import asyncComponent from '@/utils/asyncLoadComponent'
+import asyncComponent from '@/utils/asyncLoadComponent'
 import zhCN from '@/locales/zh-CN/main.js'
 import enUS from '@/locales/en-US/main.js'
 import Utils from '@/utils/utils.js'
 import './index.scss'
 
-// const SubTabTable = asyncComponent(() => import('@/tabviews/subtabtable'))
+const SubTabTable = asyncComponent(() => import('@/tabviews/subtabtable'))
 const { TabPane } = Tabs
 
 export default class NormalTable extends Component {
@@ -30,25 +30,28 @@
     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: {},
-    BIDs: {},
-    setsingle: false,
-    pickup: false,
-    isLinkMain: false
+    config: {},           // 椤甸潰閰嶇疆淇℃伅锛屽寘鎷寜閽�佹悳绱€�佹樉绀哄垪銆佹爣绛剧瓑
+    searchlist: null,     // 鎼滅储鏉′欢
+    actions: null,        // 鎸夐挳闆�
+    columns: null,        // 鏄剧ず鍒�
+    arr_field: '',        // 浣跨敤 sPC_Get_TableData 鏃剁殑鏌ヨ瀛楁闆�
+    setting: null,        // 椤甸潰鍏ㄥ眬璁剧疆锛氭暟鎹簮銆佹寜閽強鏄剧ず鍒楀浐瀹氥�佷富閿瓑
+    data: null,           // 鍒楄〃鏁版嵁闆�
+    total: 0,             // 鎬绘暟
+    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        // 寮规鏄剧ず闅愯棌鎺у埗
   }
 
   /**
@@ -134,9 +137,28 @@
         })
       }
 
-      // 杩囨护宸ュ叿鏍忔寜閽紙鏈粡杩囨潈闄愯繃婊わ級
-      let _actions = config.action.filter(item => item.position === 'toolbar')
-      let _tab = config.tabs.filter(tab => tab.supMenu === 'mainTable')
+      let _actions = config.action.filter(item => item.position === 'toolbar') // 杩囨护宸ュ叿鏍忔寜閽紙鏈粡杩囨潈闄愯繃婊わ級
+      let _tab = config.tabs.filter(tab => tab.supMenu === 'mainTable')        // 妫�鏌ユ槸鍚︽湁涓庝富琛ㄥ叧鑱旂殑瀛愯〃
+
+      let supmenus = {}
+      config.tabgroups.forEach(group => {
+        if (config[group] && config[group].length > 0) {
+          config[group] = config[group].map(tab => {
+            if (tab.subtabs.length > 0) {
+              tab.subtabs.forEach(id => {
+                supmenus[id] = tab.uuid
+              })
+            }
+            if (config.setting.subtabs.includes(tab.uuid)) {
+              tab.supMenu = 'mainTable'
+            } else if (supmenus[tab.uuid]) {
+              tab.supMenu = supmenus[tab.uuid]
+            }
+
+            return tab
+          })
+        }
+      })
 
       this.setState({
         loadingview: false,
@@ -169,6 +191,9 @@
     }
   }
 
+  /**
+   * @description 鎼滅储鏉′欢涓嬫媺閫夐」棰勫姞杞�
+   */
   improveSearch = () => {
     let searchlist = JSON.parse(JSON.stringify(this.state.searchlist))
     let deffers = []
@@ -213,9 +238,10 @@
       }
     })
 
-    this.setState({searchlist: JSON.parse(JSON.stringify(searchlist))})
-
-    if (deffers.length === 0) return
+    if (deffers.length === 0) {
+      this.setState({searchlist: JSON.parse(JSON.stringify(searchlist))})
+      return
+    }
 
     Promise.all(deffers).then(result => {
       result.forEach(res => {
@@ -223,11 +249,17 @@
           searchlist = searchlist.map(item => {
             if (item.uuid === res.search.uuid) {
               res.data.forEach(cell => {
-                item.options.push({
+                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)
               })
             }
             return item
@@ -244,7 +276,9 @@
     })
   }
 
-
+  /**
+   * @description 涓昏〃鏁版嵁鍔犺浇
+   */ 
   async loadmaindata () {
     const { setting, BIDs } = this.state
     let param = ''
@@ -254,6 +288,8 @@
     } else {
       param = this.getDefaultParam()
     }
+
+    this.handleTableId('mainTable', '')
 
     let result = await Api.genericInterface(param)
     if (result.status) {
@@ -281,6 +317,9 @@
     }
   }
 
+  /**
+   * @description 鑾峰彇鐢ㄦ埛鑷畾涔夊瓨鍌ㄨ繃绋嬩紶鍙�
+   */
   getCustomParam = () => {
     const { pageIndex, pageSize, orderColumn, orderType, search, setting } = this.state
 
@@ -306,6 +345,9 @@
     return param
   }
 
+  /**
+   * @description 鑾峰彇绯荤粺瀛樺偍杩囩▼ sPC_Get_TableData 鐨勫弬鏁�
+   */
   getDefaultParam = () => {
     const { arr_field, pageIndex, pageSize, orderColumn, orderType, search, setting } = this.state
 
@@ -337,9 +379,12 @@
     return param
   }
 
+  /**
+   * @description 鎼滅储鏉′欢鏀瑰彉鏃讹紝閲嶇疆琛ㄦ牸鏁版嵁
+   * 鍚湁鍒濆涓嶅姞杞界殑椤甸潰锛屼慨鏀硅缃�
+   */
   refreshbysearch = (searches) => {
     const { setting } = this.state
-    // 鎼滅储鏉′欢鍙樺寲
 
     if (setting.onload === 'false') {
       this.setState({
@@ -363,8 +408,10 @@
     }
   }
 
+  /**
+   * @description 琛ㄦ牸鏉′欢鏀瑰彉鏃堕噸缃暟鎹紙鍒嗛〉鎴栨帓搴忥級
+   */
   refreshbytable = (pagination, filters, sorter) => {
-    // 琛ㄦ牸鏌ヨ鏉′欢淇敼
     if (sorter.order) {
       let _chg = {
         ascend: 'asc',
@@ -384,6 +431,9 @@
     })
   }
 
+  /**
+   * @description 琛ㄦ牸鍒锋柊
+   */
   reloadtable = () => {
     this.refs.mainTable.resetTable()
     this.setState({
@@ -394,11 +444,14 @@
     })
   }
 
+  /**
+   * @description 椤甸潰鍒锋柊锛岄噸鏂拌幏鍙栭厤缃�
+   */
   reloadview = () => {
     this.setState({
-      loadingview: true,    // 椤甸潰鍔犺浇涓�
-      viewlost: false,      // 椤甸潰涓㈠け锛�1銆佹湭鑾峰彇鍒伴厤缃�-椤甸潰涓㈠け锛�2銆侀〉闈㈡湭鍚敤
-      lostmsg: '',          // 椤甸潰涓㈠け鏃剁殑鎻愮ず淇℃伅
+      loadingview: true,
+      viewlost: false,
+      lostmsg: '',
       config: {},
       searchlist: null,
       actions: null,
@@ -423,8 +476,10 @@
     })
   }
 
+  /**
+   * @description 鎸夐挳鎿嶄綔瀹屾垚鍚庯紙鎴愬姛鎴栧け璐ワ級锛岄〉闈㈠埛鏂帮紝閲嶇疆椤电爜鍙婇�夋嫨椤�
+   */
   refreshbyaction = (btn, type) => {
-    // 鎸夐挳鎿嶄綔鍚庡埛鏂拌〃鏍�,閲嶇疆椤电爜鍙婇�夋嫨椤�
     if (btn.execSuccess === 'grid' && type === 'success') {
       this.reloadtable()
     } else if (btn.execError === 'grid' && type === 'error') {
@@ -433,11 +488,25 @@
       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()
     } else if (type === 'excelOut') {
       this.handleDefaultExcelout(btn)
     }
   }
 
+  /**
+   * @description 瀛愯〃鎿嶄綔瀹屾垚鍚庡埛鏂颁富琛�
+   */
+  handleMainTable = () => {
+    this.reloadtable()
+  }
+
+  /**
+   * @description 浣跨敤榛樿瀛樺偍杩囩▼ sPC_Get_TableData 瀵煎嚭excel琛ㄦ牸
+   */
   handleDefaultExcelout = (btn) => {
     const { MenuName } = this.props
     const { arr_field, orderColumn, orderType, search, setting, config } = this.state
@@ -456,8 +525,9 @@
     _arr_label_field = _arr_label_field.join(',')
 
     let _search = Utils.joinMainSearchkey(search)
-    _search = _search ? 'where (' + _search + ')' : ''
-    // 鑾峰彇鍒楄〃鏁版嵁
+    _search = _search ? 'where ' + _search : ''
+
+    // 鑾峰彇excel鏁版嵁锛屼笌鑾峰彇鍒楄〃鏁版嵁涓嶅悓涓烘湭璁剧疆椤电爜绛夊弬鏁�
     let param = {
       func: 'sPC_Get_TableData',
       obj_name: 'data',
@@ -489,8 +559,10 @@
     })
   }
 
+  /**
+   * @description 鑾峰彇琛ㄦ牸閫夋嫨椤�
+   */
   gettableselected = () => {
-    // 鑾峰彇琛ㄦ牸閫夋嫨椤�
     let data = []
     this.refs.mainTable.state.selectedRowKeys.forEach(item => {
       data.push(this.refs.mainTable.props.data[item])
@@ -498,10 +570,16 @@
     return data
   }
 
+  /**
+   * @description 琛ㄦ牸涓紝鎸夐挳瑙﹀彂浜嬩欢浼犻��
+   */
   buttonTrigger = (btn, record) => {
     this.refs.mainButton.actionTrigger(btn, record)
   }
 
+  /**
+   * @description 琛ㄦ牸Id鍙樺寲
+   */
   handleTableId = (type, id) => {
     const { BIDs } = this.state
 
@@ -513,6 +591,9 @@
     })
   }
 
+  /**
+   * @description 琛ㄦ牸鍗曢�夊閫夊垏鎹�
+   */
   checkChange = () => {
     const { setsingle, BIDs } = this.state
 
@@ -526,11 +607,32 @@
     })
   }
   
+  /**
+   * @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 () {
@@ -546,7 +648,7 @@
    * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊
    */
   componentWillUnmount () {
-    this.setState = (state, callback) => {
+    this.setState = () => {
       return
     }
   }
@@ -574,6 +676,7 @@
             dict={this.state.dict}
             MenuID={this.props.MenuID}
             refreshdata={this.refreshbyaction}
+            triggerPopview={this.triggerPopview}
             gettableselected={this.gettableselected}
           /> : null
         }
@@ -603,23 +706,46 @@
             if (config[group].length === 0) return null
 
             return (
-              <Tabs defaultActiveKey="0" tabPosition="top" key={group}>
+              <Tabs defaultActiveKey="0" key={group}>
                 {config[group].map((_tab, index) => {
-                  return !_tab.supMenu || (_tab.supMenu && this.state.BIDs[_tab.supMenu]) ?
+                  // return !_tab.supMenu || (_tab.supMenu && this.state.BIDs[_tab.supMenu]) ?
+                  return (
                     <TabPane tab={
                       <span>
                         {_tab.icon ? <Icon type={_tab.icon} /> : null}
                         {_tab.label}
                       </span>
                     } key={`${index}`}>
-                      {_tab.type === 'SubTable' ? <SubTable SupMenuID={this.props.MenuID} MenuID={_tab.linkTab} Tab={_tab} BID={this.state.BIDs[_tab.supMenu] || ''} /> : null}
-                    </TabPane> : null
+                      {_tab.type === 'SubTable' ?
+                        <SubTable
+                          Tab={_tab}
+                          MenuID={_tab.linkTab}
+                          SupMenuID={this.props.MenuID}
+                          BID={this.state.BIDs[_tab.supMenu] || ''}
+                          handleTableId={this.handleTableId}
+                          handleMainTable={this.handleMainTable}
+                        /> : null}
+                    </TabPane>
+                  )
                 })}
               </Tabs>
             )
           })
         }
-        {/* {<SubTabTable SupMenuID={this.props.SupMenuID} MenuID={this.props.MenuID} Tab={this.props.Tab} BID={this.props.BID} />} */}
+        <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