From af0db2414ced6089cdb829304a4409ea4231d57a Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 25 十二月 2019 17:56:36 +0800
Subject: [PATCH] 2019-12-25

---
 src/tabviews/commontable/mainTable/index.jsx |   57 ++++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 42 insertions(+), 15 deletions(-)

diff --git a/src/tabviews/commontable/mainTable/index.jsx b/src/tabviews/commontable/mainTable/index.jsx
index c89224b..f9ac39b 100644
--- a/src/tabviews/commontable/mainTable/index.jsx
+++ b/src/tabviews/commontable/mainTable/index.jsx
@@ -1,6 +1,6 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
-// import { is, fromJS } from 'immutable'
+import { is, fromJS } from 'immutable'
 import { Table, message, Affix, Button } from 'antd'
 import './index.scss'
 
@@ -9,6 +9,8 @@
     dict: PropTypes.object,        // 瀛楀吀椤�
     MenuID: PropTypes.string,      // 鑿滃崟Id
     setting: PropTypes.object,     // 琛ㄦ牸鍏ㄥ眬璁剧疆锛歵ableType锛堣〃鏍兼槸鍚﹀彲閫夈�佸崟閫夈�佸閫夛級銆乧olumnfixed锛堝垪鍥哄畾锛夈�乤ctionfixed锛堟寜閽浐瀹氾級
+    pickup: PropTypes.any,         // 鏁版嵁鏀惰捣
+    setsingle: PropTypes.any,      // 璁剧疆鍗曢�夊閫�
     columns: PropTypes.array,      // 琛ㄦ牸鍒�
     data: PropTypes.any,           // 琛ㄦ牸鏁版嵁
     total: PropTypes.number,       // 鎬绘暟
@@ -19,10 +21,12 @@
   }
 
   state = {
-    selectedRowKeys: [], // 琛ㄦ牸涓�変腑琛�
-    pageIndex: 1,        // 鍒濆椤甸潰绱㈠紩
-    pageSize: 10,        // 姣忛〉鏁版嵁鏉℃暟
-    columns: null        // 鏄剧ず鍒�
+    selectedRowKeys: [],  // 琛ㄦ牸涓�変腑琛�
+    pageIndex: 1,         // 鍒濆椤甸潰绱㈠紩
+    pageSize: 10,         // 姣忛〉鏁版嵁鏉℃暟
+    columns: null,        // 鏄剧ず鍒�
+    selectId: '',
+    isSingleSelect: false
   }
 
   UNSAFE_componentWillMount () {
@@ -42,9 +46,18 @@
       }
       _columns.push(cell)
     })
-    // {item.FieldName === 'MenuNo' ? <Icon onClick={(e) => {this.copycontent(e, record[item.FieldName])}} type="copy"/> : ''}
 
     this.setState({columns: _columns})
+  }
+
+  UNSAFE_componentWillReceiveProps(nextProps) {
+    if (!is(fromJS(this.props.setsingle), fromJS(nextProps.setsingle))) {
+      this.setState({
+        isSingleSelect: nextProps.setsingle,
+        selectedRowKeys: [],
+        selectId: ''
+      })
+    }
   }
 
   getContent = (item, record) => {
@@ -194,6 +207,8 @@
   }
 
   onSelectChange = selectedRowKeys => {
+    if (this.props.pickup) return
+
     let index = ''
     if (selectedRowKeys.length > 0) {
       index = selectedRowKeys[selectedRowKeys.length - 1]
@@ -206,12 +221,13 @@
 
   changeRow = (record, index) => {
     // 鐐瑰嚮鏁磋锛岃Е鍙戝垏鎹紝鍒ゆ柇鏄惁鍙�夛紝鍗曢�夋垨澶氶�夛紝杩涜瀵瑰簲鎿嶄綔
-    if (!this.props.setting.tableType) return
+    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') {
+    if (this.props.setting.tableType === 'radio' || this.state.isSingleSelect) {
+      this.changedata(index)
       this.setState({ selectedRowKeys: [index] })
     } else {
       if (_re) {
@@ -243,31 +259,37 @@
       _id = data[index][setting.primaryKey]
     }
 
+    this.setState({
+      selectId: _id
+    })
+
     this.props.handleTableId('mainTable', _id)
   }
 
   resetTable = () => {
     this.setState({
       pageIndex: 1,
+      selectId: '',
       selectedRowKeys: []
     })
   }
 
   render() {
-    let { selectedRowKeys } = this.state
+    const { setting, pickup } = this.props
+    let { selectedRowKeys, isSingleSelect, selectId } = this.state
 
     let rowSelection = null
-    if (this.props.setting.tableType) {
+    if (setting.tableType) {
       rowSelection = {
         selectedRowKeys,
-        type: this.props.setting.tableType === 'radio' ? 'radio' : 'checkbox',
+        type: (setting.tableType === 'radio' || isSingleSelect) ? 'radio' : 'checkbox',
         onChange: this.onSelectChange
       }
     }
     let offset = null
-    if (this.props.setting.columnfixed) {
+    if (setting.columnfixed) {
       // 琛ㄦ牸澶撮儴鍥哄畾浜庨《閮ㄦ椂锛屽垽鏂窛椤堕儴楂樺害
-      if (!this.props.setting.actionfixed) {
+      if (!setting.actionfixed) {
         offset = 48
       } else {
         let box = document.getElementById(this.props.MenuID + 'mainaction')
@@ -279,9 +301,14 @@
       }
     }
 
+    let _data = this.props.data ? this.props.data : []
+    if (selectId && pickup && isSingleSelect) {
+      _data = _data.filter(item => item[setting.primaryKey] === selectId)
+    }
+
     return (
       <div className="main-table">
-        {this.props.setting.columnfixed && <Affix offsetTop={offset} className="fix-header">
+        {setting.columnfixed && <Affix offsetTop={offset} className="fix-header">
           <Table
             size="middle"
             bordered={true}
@@ -301,7 +328,7 @@
           bordered={true}
           rowSelection={rowSelection}
           columns={this.state.columns}
-          dataSource={this.props.data ? this.props.data : []}
+          dataSource={_data}
           loading={this.props.loading}
           scroll={{ x: '100%', y: false }}
           onRow={(record, index) => {

--
Gitblit v1.8.0