From fa381753ef2a2b25b1c0722549ac17e333da79be Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 06 九月 2022 22:50:54 +0800
Subject: [PATCH] 2022-09-06

---
 src/tabviews/custom/components/card/table-card/index.jsx |   93 ++++++++++++++++++++++++++++++++--------------
 1 files changed, 64 insertions(+), 29 deletions(-)

diff --git a/src/tabviews/custom/components/card/table-card/index.jsx b/src/tabviews/custom/components/card/table-card/index.jsx
index bdc334c..c0e6424 100644
--- a/src/tabviews/custom/components/card/table-card/index.jsx
+++ b/src/tabviews/custom/components/card/table-card/index.jsx
@@ -3,6 +3,7 @@
 import { connect } from 'react-redux'
 import { is, fromJS } from 'immutable'
 import { Spin, notification, Row, Col, Empty, Pagination } from 'antd'
+import { DownOutlined } from '@ant-design/icons'
 
 import Api from '@/api'
 import Utils from '@/utils/utils.js'
@@ -16,11 +17,9 @@
 
 class TableCard extends Component {
   static propTpyes = {
-    BID: PropTypes.any,              // 鐖剁骇Id
     data: PropTypes.array,           // 缁熶竴鏌ヨ鏁版嵁
     config: PropTypes.object,        // 缁勪欢閰嶇疆淇℃伅
     mainSearch: PropTypes.any,       // 澶栧眰鎼滅储鏉′欢
-    menuType: PropTypes.any,         // 鑿滃崟绫诲瀷
   }
 
   state = {
@@ -40,12 +39,24 @@
    * 1銆� initdata 涓烘墦鍗版椂浣跨敤鐨勬暟鎹泦
    */
   UNSAFE_componentWillMount () {
-    const { data, initdata, BID, BData } = this.props
+    const { data, initdata } = this.props
     let _config = fromJS(this.props.config).toJS()
     let _cols = new Map()
 
     let _data = null
     let _sync = _config.setting.sync === 'true'
+
+    let BID = ''
+    let BData = ''
+
+    if (_config.setting.supModule) {
+      BData = window.GLOB.CacheData.get(_config.setting.supModule)
+    } else {
+      BData = window.GLOB.CacheData.get(_config.$pageId)
+    }
+    if (BData) {
+      BID = BData.$BID || ''
+    }
 
     if (_config.setting.sync === 'true' && data) {
       _data = data[_config.dataName] || []
@@ -90,6 +101,8 @@
         return item
       })
     })
+
+    _config.wrap.pagestyle = _config.wrap.pagestyle || 'page'
 
     this.setState({
       sync: _sync,
@@ -169,20 +182,10 @@
 
     if (config.uuid !== menuId) return
 
-    let supModule = config.setting.supModule
-
-    btn.syncComponentId && MKEmitter.emit('reloadData', btn.syncComponentId)
-
-    if (!btn.syncComponentId || btn.syncComponentId !== supModule) {
-      if (position === 'mainline' || position === 'popclose') { // 鍒锋柊婧愮粍浠舵椂锛岄檮甯﹀埛鏂颁笂绾ц涓庡綋鍓嶇粍浠�
-        if (supModule && BID) {
-          MKEmitter.emit('reloadData', supModule, BID)
-        } else {
-          this.loadData()
-        }
-      } else {
-        this.loadData()
-      }
+    if ((position === 'mainline' || position === 'popclose') && config.setting.supModule && BID) { // 鍒锋柊婧愮粍浠舵椂锛岄檮甯﹀埛鏂颁笂绾ц涓庡綋鍓嶇粍浠�
+      MKEmitter.emit('reloadData', config.setting.supModule, BID)
+    } else {
+      this.loadData()
     }
 
     if (position === 'popclose') { // 鎵ц鍚姩寮圭獥鐨勬寜閽墍閫夋嫨鐨勫埛鏂伴」
@@ -212,7 +215,7 @@
    /**
    * @description 瀵煎嚭Excel鏃讹紝鑾峰彇椤甸潰鎼滅储鎺掑簭绛夊弬鏁�
    */
-  queryModuleParam = (menuId, btnId) => {
+  queryModuleParam = (menuId, callback) => {
     const { mainSearch } = this.props
     const { arr_field, config, search } = this.state
 
@@ -228,7 +231,7 @@
       })
     }
 
-    MKEmitter.emit('returnModuleParam', config.uuid, btnId, {
+    callback({
       arr_field: arr_field,
       orderBy: config.setting.order || '',
       search: searches,
@@ -236,8 +239,8 @@
     })
   }
 
-  async loadData () {
-    const { mainSearch, menuType } = this.props
+  async loadData (type) {
+    const { mainSearch } = this.props
     const { config, arr_field, pageIndex, search, BID, BData } = this.state
 
     if (config.setting.supModule && !BID) { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇�
@@ -268,7 +271,7 @@
     })
 
     let _orderBy = config.setting.order || ''
-    let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, pageIndex, config.setting.pageSize, BID, menuType)
+    let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, pageIndex, config.setting.pageSize, BID)
 
     let result = await Api.genericInterface(param)
     if (result.status) {
@@ -277,15 +280,31 @@
         start = config.setting.pageSize * (pageIndex - 1) + 1
       }
 
-      this.setState({
-        data: result.data.map((item, index) => {
+      let data = []
+
+      if (type === 'plus') {
+        let _data = (this.state.data || []).concat(result.data || [])
+        data = _data.map((item, index) => {
+          item.key = index
+          item.$$uuid = item[config.setting.primaryKey] || ''
+          item.$$BID = BID || ''
+          item.$$BData = BData || ''
+          item.$Index = index + 1 + ''
+          return item
+        })
+      } else {
+        data = result.data.map((item, index) => {
           item.key = index
           item.$$uuid = item[config.setting.primaryKey] || ''
           item.$$BID = BID || ''
           item.$$BData = BData || ''
           item.$Index = index + start + ''
           return item
-        }),
+        })
+      }
+
+      this.setState({
+        data: data,
         total: result.total,
         loading: false
       })
@@ -314,11 +333,12 @@
       let menu = null
 
       if (card.setting.MenuID) {
+        let _menu = this.props.permMenus.filter(m => m.MenuID === card.setting.MenuID)[0] || ''
         menu = {
           MenuID: card.setting.MenuID,
-          MenuName: card.setting.MenuName,
+          MenuName: _menu ? _menu.MenuName : card.setting.MenuName,
           MenuNo: card.setting.MenuNo,
-          type: card.setting.tabType
+          type: _menu ? _menu.type : card.setting.tabType
         }
       } else if (card.setting.menu && card.setting.menu.length > 0) {
         let menu_id = card.setting.menu.slice(-1)[0]
@@ -416,6 +436,20 @@
     })
   }
 
+  loadMore = () => {
+    const { total, pageIndex, loading, config } = this.state
+
+    if (loading || config.setting.pageSize * pageIndex >= total) {
+      return
+    }
+
+    this.setState({
+      pageIndex: pageIndex + 1
+    }, () => {
+      this.loadData('plus')
+    })
+  }
+
   render() {
     const { config, loading, data, BID, pageIndex, total } = this.state
 
@@ -429,14 +463,15 @@
             <Spin />
           </div> : null
         }
-        <NormalHeader config={config} BID={BID} menuType={this.props.menuType} refresh={this.refreshSearch} />
+        <NormalHeader config={config} BID={BID} refresh={this.refreshSearch} />
         {data && data.length > 0 ? <Row className="card-row-list" style={{height: config.wrap.contentHeight}}>
           {data.map(item => this.getLines(item))}
         </Row> : null}
         {data && data.length === 0 ? <div className="card-row-list" style={{height: config.wrap.contentHeight}}>
           <Empty description={false}/>
         </div> : null}
-        {config.setting.laypage ? <Pagination size="small" current={pageIndex} total={total} onChange={this.changePageIndex} /> : null}
+        {config.setting.laypage && config.wrap.pagestyle === 'page' ? <Pagination size="small" current={pageIndex} total={total} onChange={this.changePageIndex} /> : null}
+        {config.setting.laypage && config.wrap.pagestyle === 'more' && data && data.length > 0 ? <div className={'mk-more' + (config.setting.pageSize * pageIndex >= total ? ' disabled' : '')} onClick={this.loadMore}>鏌ョ湅鏇村<DownOutlined/></div> : null}
       </div>
     )
   }

--
Gitblit v1.8.0