From 84804b405cb88f659d055b16eb3bd00b813ccb4a Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 10 十二月 2020 10:58:38 +0800
Subject: [PATCH] 2020-12-10

---
 src/tabviews/custom/components/share/normalTable/index.jsx |   82 ++++++++++++++++++++++++----------------
 1 files changed, 49 insertions(+), 33 deletions(-)

diff --git a/src/tabviews/custom/components/share/normalTable/index.jsx b/src/tabviews/custom/components/share/normalTable/index.jsx
index f31c53a..584b7c0 100644
--- a/src/tabviews/custom/components/share/normalTable/index.jsx
+++ b/src/tabviews/custom/components/share/normalTable/index.jsx
@@ -3,14 +3,18 @@
 import md5 from 'md5'
 import { connect } from 'react-redux'
 import { is, fromJS } from 'immutable'
-import { Table, Typography, Icon, Col } from 'antd'
+import { Table, Typography, Icon, Col, Switch } from 'antd'
 
 import { modifyTabview } from '@/store/action'
+import asyncComponent from '@/utils/asyncComponent'
 import MKEmitter from '@/utils/events.js'
+import zhCN from '@/locales/zh-CN/main.js'
+import enUS from '@/locales/en-US/main.js'
 import '@/assets/css/table.scss'
 import './index.scss'
 
 const { Paragraph } = Typography
+const CardCellComponent = asyncComponent(() => import('@/tabviews/custom/components/card/cardcellList'))
 
 class BodyRow extends React.Component {
   shouldComponentUpdate (nextProps, nextState) {
@@ -166,7 +170,7 @@
   }
 
   render() {
-    let { col, record, className, style, triggerLink, ...resProps } = this.props
+    let { col, config, record, className, style, triggerLink, updateStatus, ...resProps } = this.props
 
     if (!col) return (<td {...resProps} className={className} style={style}/>)
     
@@ -340,6 +344,10 @@
           {content && _href ? <a href={_href} target="_blank" rel="noopener noreferrer">{content}</a> : null }
         </div>
       )
+    } else if (col.type === 'custom' || col.type === 'action') {
+      resProps.children = (
+        <CardCellComponent data={record} cards={config} elements={col.elements} updateStatus={this.props.updateStatus}/>
+      )
     }
 
     if (resProps.rowSpan === 0) return null
@@ -349,42 +357,35 @@
 
 class NormalTable extends Component {
   static propTpyes = {
-    tableId: PropTypes.string,       // 鍒楄〃Id
     statFValue: PropTypes.any,       // 鍚堣瀛楁鏁版嵁
-    pageSize: PropTypes.any,         // 姣忛〉鏁版嵁
-    MenuName: PropTypes.any,         // 鑿滃崟鍚嶇О
-    dict: PropTypes.object,          // 瀛楀吀椤�
     MenuID: PropTypes.string,        // 鑿滃崟Id
     setting: PropTypes.object,       // 琛ㄦ牸鍏ㄥ眬璁剧疆锛歵ableType锛堣〃鏍兼槸鍚﹀彲閫夈�佸崟閫夈�佸閫夛級銆乧olumnfixed锛堝垪鍥哄畾锛夈�乤ctionfixed锛堟寜閽浐瀹氾級
-    pickup: PropTypes.any,           // 鏁版嵁鏀惰捣
     columns: PropTypes.array,        // 琛ㄦ牸鍒�
     lineMarks: PropTypes.array,      // 琛屾爣璁�
     fields: PropTypes.array,         // 缁勪欢瀛楁闆�
-    BID: PropTypes.any,              // 涓昏〃Id
     ContainerId: PropTypes.any,      // 鏍囩椤靛灞侷d
     BData: PropTypes.any,            // 涓昏〃鏁版嵁
     data: PropTypes.any,             // 琛ㄦ牸鏁版嵁
     total: PropTypes.any,            // 鎬绘暟
     loading: PropTypes.bool,         // 琛ㄦ牸鍔犺浇涓�
     refreshdata: PropTypes.func,     // 琛ㄦ牸涓帓搴忓垪銆侀〉鐮佺殑鍙樺寲鏃跺埛鏂�
-    handleTableId: PropTypes.func,   // 鏁版嵁鍒囨崲
     chgSelectData: PropTypes.func,   // 鏁版嵁鍒囨崲
     refreshbyaction: PropTypes.func, // 鎸夐挳鎵ц瀹屾垚鍚庡埛鏂�
   }
 
   state = {
+    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
     selectedRowKeys: [],  // 琛ㄦ牸涓�変腑琛�
     pageIndex: 1,         // 鍒濆椤甸潰绱㈠紩
     pageSize: 10,         // 姣忛〉鏁版嵁鏉℃暟
     columns: null,        // 鏄剧ず鍒�
-    imgShow: false,       // 鍥剧墖鏀惧ぇ妯℃�佹
-    imgSrc: '',           // 鍥剧墖璺緞
     activeIndex: null,    // 鏍囪褰撳墠閫変腑琛�
-    rowspans: null        // 琛屽悎骞跺瓧娈典俊鎭�
+    rowspans: null,       // 琛屽悎骞跺瓧娈典俊鎭�
+    pickup: false
   }
 
   UNSAFE_componentWillMount () {
-    const { menuType, memberLevel, pageSize } = this.props
+    const { menuType, memberLevel, setting, fields } = this.props
     let columns = fromJS(this.props.columns).toJS()
     let _columns = []
     let radio = 5          // 铏氬寲姣斾緥
@@ -428,8 +429,10 @@
             width: col.Width || 120,
             onCell: record => ({
               record,
-              col: item,
-              triggerLink: this.triggerLink
+              col,
+              config: col.type === 'custom' ? {setting, columns: fields} : null,
+              triggerLink: this.triggerLink,
+              updateStatus: this.updateStatus
             })
           })
         })
@@ -454,7 +457,9 @@
           onCell: record => ({
             record,
             col: item,
-            triggerLink: this.triggerLink
+            config: item.type === 'custom' || item.type === 'action' ? {setting, columns: fields} : null,
+            triggerLink: this.triggerLink,
+            updateStatus: this.updateStatus
           })
         }
       }
@@ -468,7 +473,6 @@
 
     this.setState({
       columns: _columns,
-      pageSize: pageSize ? pageSize : 10,
       rowspans
     })
   }
@@ -499,7 +503,7 @@
 
   // 瀛楁閫忚
   triggerLink = (item, record) => {
-    const { tabviews, MenuID, setting } = this.props
+    const { tabviews, MenuID } = this.props
 
     if (item.linkThdMenu) {
       let tabmenu = item.linkThdMenu
@@ -507,7 +511,7 @@
       tabmenu.param = {
         searchkey: item.field,
         searchval: record[item.field] || '',
-        BID: record[setting.primaryKey]
+        BID: record.$$uuid
       }
   
       tabmenu.selected = true
@@ -543,7 +547,7 @@
           let dataparam = {
             searchkey: item.field,
             searchval: record[item.field] || '',
-            BID: record[setting.primaryKey]
+            BID: record.$$uuid
           }
           _param.UserID = sessionStorage.getItem('UserID')
           _param.LoginUID = sessionStorage.getItem('LoginUID')
@@ -588,9 +592,9 @@
    * @description 鐐瑰嚮鏁磋锛岃Е鍙戝垏鎹紝 鍒ゆ柇鏄惁鍙�夛紝鍗曢�夋垨澶氶�夛紝杩涜瀵瑰簲鎿嶄綔
    */
   changeRow = (record, index) => {
-    const { setting, pickup } = this.props
+    const { setting } = this.props
 
-    if (!setting.tableType || pickup) return
+    if (!setting.tableType || this.state.pickup) return
     
     let newkeys = fromJS(this.state.selectedRowKeys).toJS()
 
@@ -625,13 +629,14 @@
       pageIndex: pagination.current,
       pageSize: pagination.pageSize,
       selectedRowKeys: [],
-      activeIndex: null
+      activeIndex: null,
+      pickup: false
     })
     this.props.refreshdata(pagination, filters, sorter)
   }
 
   changedata = (index) => {
-    const { data, setting } = this.props
+    const { MenuID, data, setting } = this.props
 
     let _id = ''
     let _data = ''
@@ -641,24 +646,26 @@
       _data = data[index] || ''
     }
 
-    this.props.handleTableId(this.props.tableId, _id, _data)
+    MKEmitter.emit('resetSelectLine', MenuID, _id, _data)
   }
 
   resetTable = (id, repage) => {
-    const { MenuID, tableId } = this.props
+    const { MenuID } = this.props
 
-    if (id !== (MenuID + tableId)) return
+    if (id !== MenuID) return
 
     if (repage === 'false') {
       this.setState({
         selectedRowKeys: [],
-        activeIndex: null
+        activeIndex: null,
+        pickup: false
       })
     } else {
       this.setState({
         pageIndex: 1,
         selectedRowKeys: [],
-        activeIndex: null
+        activeIndex: null,
+        pickup: false
       })
     }
   }
@@ -717,9 +724,15 @@
     return data
   }
 
+  pickupChange = () => {
+    this.setState({
+      pickup: !this.state.pickup
+    })
+  }
+
   render() {
-    const { setting, pickup, statFValue, lineMarks } = this.props
-    const { selectedRowKeys, activeIndex } = this.state
+    const { setting, statFValue, lineMarks, data } = this.props
+    const { selectedRowKeys, activeIndex, pickup } = this.state
 
     // 璁剧疆琛ㄦ牸閫夋嫨灞炴�э細鍗曢�夈�佸閫夈�佷笉鍙��
     let rowSelection = null
@@ -739,7 +752,7 @@
     }
 
     // 鏁版嵁鏀惰捣鏃讹紝杩囨护宸查�夋暟鎹�
-    let _data = this.props.data ? this.props.data : []
+    let _data = data || []
 
     if (pickup) {
       _data = _data.filter((item, index) => selectedRowKeys.includes(index))
@@ -755,7 +768,7 @@
         pageSizeOptions: ['10', '25', '50', '100', '500', '1000'],
         showSizeChanger: true,
         total: this.props.total || 0,
-        showTotal: (total, range) => `${range[0]}-${range[1]} ${this.props.dict['main.pagination.of']} ${total} ${this.props.dict['main.pagination.items']}`
+        showTotal: (total, range) => `${range[0]}-${range[1]} ${this.state.dict['main.pagination.of']} ${total} ${this.state.dict['main.pagination.items']}`
       }
     }
 
@@ -767,6 +780,9 @@
 
     return (
       <div className="normal-custom-table">
+        {(setting.tableType === 'radio' || setting.tableType === 'checkbox') && data && data.length > 0 ?
+          <Switch title="鏀惰捣" className="main-pickup" checkedChildren="寮�" unCheckedChildren="鍏�" defaultChecked={pickup} onChange={this.pickupChange} /> : null
+        }
         <Table
           size="middle"
           components={components}

--
Gitblit v1.8.0