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/subtable/index.jsx |  167 +++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 130 insertions(+), 37 deletions(-)

diff --git a/src/tabviews/subtable/index.jsx b/src/tabviews/subtable/index.jsx
index 3a12c3a..3f28a70 100644
--- a/src/tabviews/subtable/index.jsx
+++ b/src/tabviews/subtable/index.jsx
@@ -1,27 +1,29 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
 import { is, fromJS } from 'immutable'
-import { notification, Spin} from 'antd'
+import { notification, Spin, Modal, Button} from 'antd'
 import moment from 'moment'
 import Api from '@/api'
 import SubTable from './subTable'
 import SubAction from '@/tabviews/tableshare/actionList'
 import SubSearch from '@/tabviews/tableshare/topSearch'
-// import asyncComponent from '@/utils/asyncLoadComponent'
+import asyncComponent from '@/utils/asyncLoadComponent'
 import NotFount from '@/components/404'
 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'))
 
 export default class NormalTable extends Component {
   static propTpyes = {
-    Tab: PropTypes.object,       // 鏍囩淇℃伅
-    BID: PropTypes.string,       // 涓婄骇鏁版嵁ID
-    MenuID: PropTypes.string,    // 鑿滃崟Id
-    SupMenuID: PropTypes.string  // 涓婄骇鑿滃崟Id
+    Tab: PropTypes.object,           // 鏍囩淇℃伅
+    BID: PropTypes.string,           // 涓婄骇鏁版嵁ID
+    MenuID: PropTypes.string,        // 鑿滃崟Id
+    SupMenuID: PropTypes.string,     // 涓婄骇鑿滃崟Id
+    handleTableId: PropTypes.func,   // 鎺у埗琛ㄦ牸鏁版嵁鍒囨崲鏃讹紝鏇存柊鍦ㄤ富琛ㄤ腑鐨刬d
+    handleMainTable: PropTypes.func  // 鎺у埗琛ㄦ牸鏁版嵁鍒囨崲鏃讹紝鏇存柊鍦ㄤ富琛ㄤ腑鐨刬d
   }
 
   state = {
@@ -29,23 +31,29 @@
     loadingview: true,    // 椤甸潰鍔犺浇涓�
     viewlost: false,      // 椤甸潰涓㈠け锛�1銆佹湭鑾峰彇鍒伴厤缃�-椤甸潰涓㈠け锛�2銆侀〉闈㈡湭鍚敤
     lostmsg: '',          // 椤甸潰涓㈠け鏃剁殑鎻愮ず淇℃伅
-    config: {},
-    searchlist: null,
-    actions: null,
-    columns: null,
-    arr_field: '',
-    setting: null,
-    data: [],
-    total: 0,
-    loading: false,
-    pageIndex: 1,
-    pageSize: 10,
-    orderColumn: '',
-    orderType: 'asc',
-    search: '',
-    configMap: {}
+    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: {},        // 椤甸潰閰嶇疆淇℃伅锛氫笅鎷夈�佹寜閽瓑
+    popAction: false,     // 寮规椤甸潰锛屾寜閽俊鎭�
+    popData: false,       // 寮规椤甸潰锛屾墍閫夌殑琛ㄦ牸鏁版嵁
+    visible: false        // 寮规鏄剧ず闅愯棌鎺у埗
   }
 
+  /**
+   * @description 涓婄骇鑿滃崟id鍙樺寲鏃讹紝鍒锋柊鏁版嵁
+   */
   UNSAFE_componentWillReceiveProps(nextProps) {
     if (this.props.Tab.supMenu && !is(fromJS(this.props.BID), fromJS(nextProps.BID))) {
       this.loadmaindata()
@@ -165,6 +173,9 @@
     }
   }
 
+  /**
+   * @description 鎼滅储鏉′欢涓嬫媺閫夐」棰勫姞杞�
+   */
   improveSearch = () => {
     let searchlist = JSON.parse(JSON.stringify(this.state.searchlist))
     let deffers = []
@@ -209,9 +220,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 => {
@@ -219,11 +231,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
@@ -240,7 +258,9 @@
     })
   }
 
-
+  /**
+   * @description 瀛愯〃鏁版嵁鍔犺浇
+   */
   async loadmaindata () {
     const { setting } = this.state
     let param = ''
@@ -250,6 +270,8 @@
     } else {
       param = this.getDefaultParam()
     }
+
+    this.handleTableId('')
 
     let result = await Api.genericInterface(param)
     if (result.status) {
@@ -273,6 +295,9 @@
     }
   }
 
+  /**
+   * @description 鑾峰彇鐢ㄦ埛鑷畾涔夊瓨鍌ㄨ繃绋嬩紶鍙�
+   */
   getCustomParam = () => {
     const { pageIndex, pageSize, orderColumn, orderType, search, setting } = this.state
 
@@ -298,6 +323,9 @@
     return param
   }
 
+  /**
+   * @description 鑾峰彇绯荤粺瀛樺偍杩囩▼ sPC_Get_TableData 鐨勫弬鏁�
+   */
   getDefaultParam = () => {
     const { arr_field, pageIndex, pageSize, orderColumn, orderType, search, setting } = this.state
 
@@ -329,8 +357,11 @@
     return param
   }
 
+  /**
+   * @description 鎼滅储鏉′欢鏀瑰彉鏃讹紝閲嶇疆琛ㄦ牸鏁版嵁
+   * 鍚湁鍒濆涓嶅姞杞界殑椤甸潰锛屼慨鏀硅缃�
+   */
   refreshbysearch = (searches) => {
-    // 鎼滅储鏉′欢鍙樺寲
     this.refs.subTable.resetTable()
 
     this.setState({
@@ -342,8 +373,10 @@
     })
   }
 
+  /**
+   * @description 琛ㄦ牸鏉′欢鏀瑰彉鏃堕噸缃暟鎹紙鍒嗛〉鎴栨帓搴忥級
+   */
   refreshbytable = (pagination, filters, sorter) => {
-    // 琛ㄦ牸鏌ヨ鏉′欢淇敼
     if (sorter.order) {
       let _chg = {
         ascend: 'asc',
@@ -363,6 +396,9 @@
     })
   }
 
+  /**
+   * @description 琛ㄦ牸鍒锋柊
+   */
   reloadtable = () => {
     this.refs.subTable.resetTable()
     this.setState({
@@ -373,11 +409,14 @@
     })
   }
 
+  /**
+   * @description 椤甸潰鍒锋柊锛岄噸鏂拌幏鍙栭厤缃�
+   */
   reloadview = () => {
     this.setState({
-      loadingview: true,    // 椤甸潰鍔犺浇涓�
-      viewlost: false,      // 椤甸潰涓㈠け锛�1銆佹湭鑾峰彇鍒伴厤缃�-椤甸潰涓㈠け锛�2銆侀〉闈㈡湭鍚敤
-      lostmsg: '',          // 椤甸潰涓㈠け鏃剁殑鎻愮ず淇℃伅
+      loadingview: true,
+      viewlost: false,
+      lostmsg: '',
       config: {},
       searchlist: null,
       actions: null,
@@ -398,8 +437,10 @@
     })
   }
 
+  /**
+   * @description 鎸夐挳鎿嶄綔瀹屾垚鍚庯紙鎴愬姛鎴栧け璐ワ級锛岄〉闈㈠埛鏂帮紝閲嶇疆椤电爜鍙婇�夋嫨椤�
+   */
   refreshbyaction = (btn, type) => {
-    // 鎸夐挳鎿嶄綔鍚庡埛鏂拌〃鏍�,閲嶇疆椤电爜鍙婇�夋嫨椤�
     if (btn.execSuccess === 'grid' && type === 'success') {
       this.reloadtable()
     } else if (btn.execError === 'grid' && type === 'error') {
@@ -408,11 +449,18 @@
       this.reloadtable()
     } else if (btn.execError === 'view' && type === 'error') {
       this.reloadview()
+    } else if (btn.popClose === 'maingrid' && type === 'pop') {
+      this.props.handleMainTable()
+    } else if (btn.popClose === 'subgrid' && type === 'pop') {
+      this.reloadtable()
     } else if (type === 'excelOut') {
       this.handleDefaultExcelout(btn)
     }
   }
 
+  /**
+   * @description 浣跨敤榛樿瀛樺偍杩囩▼ sPC_Get_TableData 瀵煎嚭excel琛ㄦ牸
+   */
   handleDefaultExcelout = (btn) => {
     const { MenuName } = this.props
     const { arr_field, orderColumn, orderType, search, setting, config } = this.state
@@ -464,8 +512,10 @@
     })
   }
 
+  /**
+   * @description 鑾峰彇琛ㄦ牸閫夋嫨椤�
+   */
   gettableselected = () => {
-    // 鑾峰彇琛ㄦ牸閫夋嫨椤�
     let data = []
     this.refs.subTable.state.selectedRowKeys.forEach(item => {
       data.push(this.refs.subTable.props.data[item])
@@ -473,8 +523,36 @@
     return data
   }
 
+  /**
+   * @description 琛ㄦ牸涓紝鎸夐挳瑙﹀彂浜嬩欢浼犻��
+   */
   buttonTrigger = (btn, record) => {
     this.refs.subButton.actionTrigger(btn, record)
+  }
+
+  /**
+   * @description 琛ㄦ牸Id鍙樺寲
+   */
+  handleTableId = (id = '') => {
+    this.props.handleTableId(this.props.Tab.uuid, id)
+  }
+
+  /**
+   * @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 () {
@@ -490,7 +568,7 @@
    * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊
    */
   componentWillUnmount () {
-    this.setState = (state, callback) => {
+    this.setState = () => {
       return
     }
   }
@@ -518,6 +596,7 @@
             dict={this.state.dict}
             MenuID={this.props.SupMenuID}
             refreshdata={this.refreshbyaction}
+            triggerPopview={this.triggerPopview}
             gettableselected={this.gettableselected}
           />
         }
@@ -533,9 +612,23 @@
             loading={this.state.loading}
             refreshdata={this.refreshbytable}
             buttonTrigger={this.buttonTrigger}
+            handleTableId={this.handleTableId}
           />
         }
-        {/* {<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>
         {viewlost ? <NotFount msg={this.state.lostmsg} /> : null}
       </div>
     )

--
Gitblit v1.8.0