From 89e7167a83e0d8409ca87698e4c08651a37cc26e Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期五, 12 六月 2020 18:19:35 +0800
Subject: [PATCH] 2020-06-12

---
 src/tabviews/zshare/normalTable/index.jsx |  113 +++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 99 insertions(+), 14 deletions(-)

diff --git a/src/tabviews/zshare/normalTable/index.jsx b/src/tabviews/zshare/normalTable/index.jsx
index 14ab88f..272a670 100644
--- a/src/tabviews/zshare/normalTable/index.jsx
+++ b/src/tabviews/zshare/normalTable/index.jsx
@@ -1,22 +1,24 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
 import md5 from 'md5'
+import { is, fromJS } from 'immutable'
+import {connect} from 'react-redux'
 import { Table, message, Affix, Button, Typography, Modal, Icon } from 'antd'
+
+import { modifyTabview } from '@/store/action'
 import './index.scss'
 import '@/assets/css/table.scss'
 
 const { Paragraph } = Typography
 
-export default class MainTable extends Component {
+class NormalTable extends Component {
   static defaultProps = {
-    pagination: true,
-    total: 0,
-    menuType: 'normal'
+    total: 0
   }
 
   static propTpyes = {
-    menuType: PropTypes.any,       // 涓夌骇鑿滃崟绫诲瀷锛孒S闇�鐗规畩澶勭悊
     tableId: PropTypes.string,     // 鍒楄〃Id
+    resetTable: PropTypes.bool,    // 琛ㄦ牸閲嶇疆
     pageSize: PropTypes.any,       // 姣忛〉鏁版嵁
     dict: PropTypes.object,        // 瀛楀吀椤�
     config: PropTypes.object,      // 椤甸潰閰嶇疆
@@ -29,10 +31,8 @@
     loading: PropTypes.bool,       // 琛ㄦ牸鍔犺浇涓�
     refreshdata: PropTypes.func,   // 琛ㄦ牸涓帓搴忓垪銆侀〉鐮佺殑鍙樺寲鏃跺埛鏂�
     buttonTrigger: PropTypes.func, // 琛ㄦ牸涓寜閽Е鍙戞搷浣�
-    linkTrigger: PropTypes.func,   // 瀛楁閫忚
     handleTableId: PropTypes.func, // 鏁版嵁鍒囨崲
-    memberLevel: PropTypes.any,    // 浼氬憳绛夌骇
-    pagination: PropTypes.any      // 鏁版嵁鍒嗛〉
+    chgSelectData: PropTypes.func, // 鏁版嵁鍒囨崲
   }
 
   state = {
@@ -139,7 +139,31 @@
     })
   }
 
+  shouldComponentUpdate (nextProps, nextState) {
+    return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
+  }
+
+  /**
+   * @description 涓婄骇鑿滃崟id鍙樺寲鏃讹紝鍒锋柊鏁版嵁
+   */
+  UNSAFE_componentWillReceiveProps(nextProps) {
+    if (this.props.resetTable !== nextProps.resetTable) {
+      this.resetTable()
+    }
+  }
+
+  /**
+   * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊
+   */
+  componentWillUnmount () {
+    this.setState = () => {
+      return
+    }
+  }
+
+  // 瀛楁閫忚
   triggerLink = (item, record) => {
+    const { tabviews, MenuID } = this.props
     let tabmenu = item.linkThdMenu
     let iframes = ['Main/Index', 'bda/rdt', 'Home/rdt']
 
@@ -165,7 +189,29 @@
       searchval: record[item.field] || ''
     }
 
-    this.props.linkTrigger(tabmenu)
+    tabmenu.selected = true
+
+    let index = 0
+    let isexit = false
+    let tabs = tabviews.map((tab, i) => {
+      tab.selected = false
+
+      if (tab.MenuID === MenuID) {
+        index = i
+      } else if (tab.MenuID === tabmenu.MenuID) {
+        tab.param = tabmenu.param
+        tab.selected = true
+        isexit = true
+      }
+
+      return tab
+    })
+
+    if (!isexit) {
+      tabs.splice(index + 1, 0, tabmenu)
+    }
+
+    this.props.modifyTabview(tabs)
   }
 
   getMark = (record, marks) => {
@@ -602,6 +648,9 @@
     }
   }
 
+  /**
+   * @description 鍥剧墖缂╂斁
+   */
   imgScaleClose = () => {
     this.setState({
      imgShow: false
@@ -634,6 +683,9 @@
     message.success(this.props.dict['main.copy.success'])
   }
 
+  /**
+   * 
+   */
   onSelectChange = selectedRowKeys => {
     let index = ''
     if (selectedRowKeys.length > 0) {
@@ -643,19 +695,29 @@
     this.changedata(index)
 
     this.setState({ selectedRowKeys })
+
+    let selects = []
+    selectedRowKeys.forEach(item => {
+      selects.push(this.props.data[item])
+    })
+
+    this.props.chgSelectData(selects)
   }
 
+  /**
+   * @description 鐐瑰嚮鏁磋锛岃Е鍙戝垏鎹紝 鍒ゆ柇鏄惁鍙�夛紝鍗曢�夋垨澶氶�夛紝杩涜瀵瑰簲鎿嶄綔
+   */
   changeRow = (record, index) => {
-    // 鐐瑰嚮鏁磋锛岃Е鍙戝垏鎹紝鍒ゆ柇鏄惁鍙�夛紝鍗曢�夋垨澶氶�夛紝杩涜瀵瑰簲鎿嶄綔
     if (!this.props.setting.tableType || this.props.pickup) return
     
     let newkeys = JSON.parse(JSON.stringify(this.state.selectedRowKeys))
-    let _re = newkeys.includes(index)
 
     if (this.props.setting.tableType === 'radio') {
+      newkeys = [index]
       this.changedata(index)
-      this.setState({ selectedRowKeys: [index] })
+      this.setState({ selectedRowKeys: newkeys })
     } else {
+      let _re = newkeys.includes(index)
       if (_re) {
         newkeys = newkeys.filter(item => item !== index)
         this.changedata('')
@@ -666,6 +728,13 @@
 
       this.setState({ selectedRowKeys: newkeys })
     }
+
+    let selects = []
+    newkeys.forEach(item => {
+      selects.push(this.props.data[item])
+    })
+    
+    this.props.chgSelectData(selects)
   }
 
   changeTable = (pagination, filters, sorter) => {
@@ -701,7 +770,7 @@
   }
 
   render() {
-    const { setting, pickup, pagination } = this.props
+    const { setting, pickup } = this.props
     const { selectedRowKeys, lineMarks, colMap } = this.state
 
     // 璁剧疆琛ㄦ牸閫夋嫨灞炴�э細鍗曢�夈�佸閫夈�佷笉鍙��
@@ -737,7 +806,7 @@
     }
 
     let _pagination = false
-    if (pagination) {
+    if (setting.laypage !== 'false') {
       _pagination = {
         current: this.state.pageIndex,
         pageSize: this.state.pageSize,
@@ -846,3 +915,19 @@
     )
   }
 }
+
+const mapStateToProps = (state) => {
+  return {
+    menuType: state.editLevel,
+    tabviews: state.tabviews,
+    memberLevel: state.memberLevel
+  }
+}
+
+const mapDispatchToProps = (dispatch) => {
+  return {
+    modifyTabview: (tabviews) => dispatch(modifyTabview(tabviews))
+  }
+}
+
+export default connect(mapStateToProps, mapDispatchToProps)(NormalTable)
\ No newline at end of file

--
Gitblit v1.8.0