From c6f8e27d35cd31bb6393a1e7f747b6b2593dbd7a Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 08 六月 2022 13:56:57 +0800
Subject: [PATCH] 2022-06-08

---
 src/tabviews/custom/components/card/table-card/index.jsx |  173 ++++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 126 insertions(+), 47 deletions(-)

diff --git a/src/tabviews/custom/components/card/table-card/index.jsx b/src/tabviews/custom/components/card/table-card/index.jsx
index a557611..9eb9281 100644
--- a/src/tabviews/custom/components/card/table-card/index.jsx
+++ b/src/tabviews/custom/components/card/table-card/index.jsx
@@ -1,7 +1,8 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
+import { connect } from 'react-redux'
 import { is, fromJS } from 'immutable'
-import { Spin, notification, Col, Empty, Pagination } from 'antd'
+import { Spin, notification, Row, Col, Empty, Pagination } from 'antd'
 
 import Api from '@/api'
 import Utils from '@/utils/utils.js'
@@ -27,11 +28,11 @@
     config: null,              // 鍥捐〃閰嶇疆淇℃伅
     loading: false,            // 鏁版嵁鍔犺浇鐘舵��
     search: null,              // 鎼滅储鏉′欢
-    preIndex: 0,               // 寮�濮嬬储寮�
     pageIndex: 1,              // 椤电爜
     total: 0,                  // 鎬绘暟
     sync: false,               // 鏄惁缁熶竴璇锋眰鏁版嵁
     data: null,                // 鏁版嵁
+    BData: ''
   }
 
   /**
@@ -39,7 +40,7 @@
    * 1銆� initdata 涓烘墦鍗版椂浣跨敤鐨勬暟鎹泦
    */
   UNSAFE_componentWillMount () {
-    const { data, initdata, BID } = this.props
+    const { data, initdata, BID, BData } = this.props
     let _config = fromJS(this.props.config).toJS()
     let _cols = new Map()
 
@@ -59,6 +60,8 @@
         item.key = index
         item.$$uuid = item[_config.setting.primaryKey] || ''
         item.$$BID = BID || ''
+        item.$$BData = BData || ''
+        item.$Index = index + 1 + ''
         return item
       })
     }
@@ -69,19 +72,20 @@
     }
 
     if (_config.setting.laypage) {
-      _config.wrap.contentHeight = _config.wrap.height - (showHeader ? 85 : 40)
+      _config.wrap.contentHeight = showHeader ? 'calc(100% - 85px)' : 'calc(100% - 40px)'
     } else {
-      _config.wrap.contentHeight = _config.wrap.height - (showHeader ? 45 : 0)
+      _config.wrap.contentHeight = showHeader ? 'calc(100% - 45px)' : '100%'
     }
 
     _config.columns.forEach(item => {
+      if (item.type !== 'number') return
       _cols.set(item.field, item)
     })
 
     _config.subcards.forEach(card => {
       card.elements = card.elements.map(item => {
-        if (item.field && _cols.has(item.field)) {
-          item.col = _cols.get(item.field)
+        if (item.eleType === 'number' && item.field && _cols.has(item.field) && typeof(item.decimal) !== 'number') {
+          item.decimal = _cols.get(item.field).decimal || 0
         }
         return item
       })
@@ -90,13 +94,16 @@
     this.setState({
       sync: _sync,
       BID: BID || '',
+      BData: BData || '',
       data: _data,
       config: _config,
       search: Utils.initMainSearch(_config.search),
       arr_field: _config.columns.map(col => col.field).join(','),
     }, () => {
       if (_config.setting.sync !== 'true' && _config.setting.onload === 'true') {
-        this.loadData()
+        setTimeout(() => {
+          this.loadData()
+        }, _config.setting.delay || 0)
       }
     })
   }
@@ -104,7 +111,7 @@
   componentDidMount () {
     MKEmitter.addListener('reloadData', this.reloadData)
     MKEmitter.addListener('resetSelectLine', this.resetParentParam)
-    MKEmitter.addListener('getexceloutparam', this.getexceloutparam)
+    MKEmitter.addListener('queryModuleParam', this.queryModuleParam)
     MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult)
   }
 
@@ -118,7 +125,7 @@
     }
     MKEmitter.removeListener('reloadData', this.reloadData)
     MKEmitter.removeListener('resetSelectLine', this.resetParentParam)
-    MKEmitter.removeListener('getexceloutparam', this.getexceloutparam)
+    MKEmitter.removeListener('queryModuleParam', this.queryModuleParam)
     MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult)
   }
 
@@ -126,7 +133,7 @@
    * @description 鍥捐〃鏁版嵁鏇存柊锛屽埛鏂板唴瀹�
    */
   UNSAFE_componentWillReceiveProps (nextProps) {
-    const { sync, config, BID } = this.state
+    const { sync, config, BID, BData } = this.state
 
     if (sync && !is(fromJS(this.props.data), fromJS(nextProps.data))) {
       let _data = []
@@ -138,16 +145,16 @@
         item.key = index
         item.$$uuid = item[config.setting.primaryKey] || ''
         item.$$BID = BID || ''
+        item.$$BData = BData || ''
+        item.$Index = index + 1 + ''
         return item
       })
 
       this.setState({sync: false, data: _data})
-    } else if (nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
-      if (config.setting.syncRefresh === 'true') {
-        this.setState({}, () => {
-          this.loadData()
-        })
-      }
+    } else if (config.setting.syncRefresh && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
+      this.setState({}, () => {
+        this.loadData()
+      })
     }
   }
 
@@ -162,26 +169,23 @@
 
     if (config.uuid !== menuId) return
 
-    this.loadData(btn)                                                         // 鏁版嵁鍒锋柊
-
-    if (btn.syncComponentId && btn.syncComponentId !== config.uuid && btn.syncComponentId !== config.setting.supModule) {
-      MKEmitter.emit('reloadData', btn.syncComponentId)                        // 鍚岀骇鏍囩鍒锋柊
+    if ((position === 'mainline' || position === 'popclose') && config.setting.supModule && BID) { // 鍒锋柊婧愮粍浠舵椂锛岄檮甯﹀埛鏂颁笂绾ц涓庡綋鍓嶇粍浠�
+      MKEmitter.emit('reloadData', config.setting.supModule, BID)
+    } else {
+      this.loadData()
     }
 
-    if (position === 'mainline' && config.setting.supModule) {                 // 涓昏〃琛屽埛鏂�
-      MKEmitter.emit('reloadData', config.setting.supModule, (BID || 'empty'))
-    } else if (position === 'popclose') {                                      // 鏍囩鍏抽棴鍒锋柊
-      config.setting.supModule && MKEmitter.emit('reloadData', config.setting.supModule, (BID || 'empty'))
+    if (position === 'popclose') { // 鎵ц鍚姩寮圭獥鐨勬寜閽墍閫夋嫨鐨勫埛鏂伴」
       btn.$tabId && MKEmitter.emit('refreshPopButton', btn.$tabId)
     }
   }
 
-  resetParentParam = (MenuID, id) => {
+  resetParentParam = (MenuID, id, data) => {
     const { config } = this.state
 
     if (!config.setting.supModule || config.setting.supModule !== MenuID) return
-    if (id !== this.state.BID) {
-      this.setState({ BID: id }, () => {
+    if (id !== this.state.BID || id !== '') {
+      this.setState({ BID: id, BData: data, pageIndex: 1 }, () => {
         this.loadData()
       })
     }
@@ -198,14 +202,14 @@
    /**
    * @description 瀵煎嚭Excel鏃讹紝鑾峰彇椤甸潰鎼滅储鎺掑簭绛夊弬鏁�
    */
-  getexceloutparam = (menuId, btnId) => {
+  queryModuleParam = (menuId, btnId) => {
     const { mainSearch } = this.props
     const { arr_field, config, search } = this.state
 
     if (config.uuid !== menuId) return
 
     let searches = search ? fromJS(search).toJS() : []
-    if (mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢
+    if (config.setting.useMSearch && mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢
       let keys = searches.map(item => item.key.toLowerCase())
       mainSearch.forEach(item => {
         if (!keys.includes(item.key.toLowerCase())) {
@@ -214,7 +218,7 @@
       })
     }
 
-    MKEmitter.emit('execExcelout', config.uuid, btnId, {
+    MKEmitter.emit('returnModuleParam', config.uuid, btnId, {
       arr_field: arr_field,
       orderBy: config.setting.order || '',
       search: searches,
@@ -224,25 +228,29 @@
 
   async loadData () {
     const { mainSearch, menuType } = this.props
-    const { config, arr_field, pageIndex, search, BID } = this.state
+    const { config, arr_field, pageIndex, search, BID, BData } = this.state
 
     if (config.setting.supModule && !BID) { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇�
       this.setState({
         data: [],
-        total: 0,
-        preIndex: 0
+        total: 0
       })
       return
     }
 
     let searches = search ? fromJS(search).toJS() : []
-    if (mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢
+    if (config.setting.useMSearch && mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢
       let keys = searches.map(item => item.key)
       mainSearch.forEach(item => {
         if (!keys.includes(item.key)) {
           searches.push(item)
         }
       })
+    }
+
+    let requireFields = searches.filter(item => item.required && item.value === '')
+    if (requireFields.length > 0) {
+      return
     }
 
     this.setState({
@@ -254,9 +262,9 @@
 
     let result = await Api.genericInterface(param)
     if (result.status) {
-      let _preIndex = 0
+      let start = 1
       if (config.setting.laypage) {
-        _preIndex = config.setting.pageSize * (pageIndex - 1)
+        start = config.setting.pageSize * (pageIndex - 1) + 1
       }
 
       this.setState({
@@ -264,10 +272,11 @@
           item.key = index
           item.$$uuid = item[config.setting.primaryKey] || ''
           item.$$BID = BID || ''
+          item.$$BData = BData || ''
+          item.$Index = index + start + ''
           return item
         }),
         total: result.total,
-        preIndex: _preIndex,
         loading: false
       })
     } else {
@@ -290,7 +299,65 @@
     })
   }
 
-  getLines = (data, seq) => {
+  openView = (card, data) => {
+    if (card.setting.click === 'menu') {
+      let menu = null
+
+      if (card.setting.MenuID) {
+        menu = {
+          MenuID: card.setting.MenuID,
+          MenuName: card.setting.MenuName,
+          MenuNo: card.setting.MenuNo,
+          type: card.setting.tabType
+        }
+      } else if (card.setting.menu && card.setting.menu.length > 0) {
+        let menu_id = card.setting.menu.slice(-1)[0]
+        menu = this.props.permMenus.filter(m => m.MenuID === menu_id)[0] || ''
+
+        if (!menu) {
+          notification.warning({
+            top: 92,
+            message: '鑿滃崟宸插垹闄ゆ垨娌℃湁璁块棶鏉冮檺锛�',
+            duration: 5
+          })
+          return
+        }
+      }
+
+      let newtab = {
+        ...menu,
+        param: {}
+      }
+
+      if (card.setting.joint === 'true') {
+        newtab.param.$BID = data.$$uuid || ''
+      }
+
+      if (['linkage_navigation', 'linkage', 'menu_board'].includes(window.GLOB.navBar)) {
+        MKEmitter.emit('modifyTabs', newtab, 'replace')
+      } else {
+        MKEmitter.emit('modifyTabs', newtab, 'plus', true)
+      }
+    } else if (card.setting.click === 'link') {
+      let src = card.setting.linkurl
+
+      if (card.setting.joint === 'true') {
+        let con = '?'
+
+        if (/\?/ig.test(src)) {
+          con = '&'
+        }
+
+        src = src + `${con}id=${data.$$uuid || ''}&appkey=${window.GLOB.appkey}&userid=${sessionStorage.getItem('UserID')}&LoginUID=${sessionStorage.getItem('LoginUID') || ''}`
+      }
+
+      window.open(src)
+    } else if (card.setting.click === 'button' && card.setting.linkbtn) {
+      MKEmitter.emit('triggerBtnId', card.setting.linkbtn, [data], 'linkbtn')
+    }
+  }
+
+  getLines = (data) => {
     const { config } = this.state
 
     let line = []
@@ -320,8 +387,8 @@
 
       line.push(
         <Col key={index} span={24}>
-          <div className="card-item-box" style={item.style}>
-            <CardCellComponent seq={seq} data={data} cards={config} cardCell={item} elements={item.elements}/>
+          <div className="card-item-box" style={item.style} onClick={() => {this.openView(item, data)}}>
+            <CardCellComponent data={data} cards={config} cardCell={item} elements={item.elements}/>
           </div>
         </Col>
       )
@@ -340,10 +407,12 @@
   }
 
   render() {
-    const { config, loading, data, BID, pageIndex, preIndex, total } = this.state
+    const { config, loading, data, BID, pageIndex, total } = this.state
 
+    if (config.wrap.empty === 'hidden' && (!data || data.length === 0)) return null
+    
     return (
-      <div className="custom-table-card-box" style={{...config.style, height: config.wrap.height}}>
+      <div className="custom-table-card-box" id={'anchor' + config.uuid} style={{...config.style}}>
         {loading ?
           <div className="loading-mask">
             {data ? <div className="ant-spin-blur"></div> : null}
@@ -351,9 +420,9 @@
           </div> : null
         }
         <NormalHeader config={config} BID={BID} menuType={this.props.menuType} refresh={this.refreshSearch} />
-        {data && data.length > 0 ? <div className="card-row-list" style={{height: config.wrap.contentHeight}}>
-          {data.map((item, index) => this.getLines(item, preIndex + index + 1))}
-        </div> : null}
+        {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}
@@ -363,4 +432,14 @@
   }
 }
 
-export default TableCard
\ No newline at end of file
+const mapStateToProps = (state) => {
+  return {
+    permMenus: state.permMenus,
+  }
+}
+
+const mapDispatchToProps = () => {
+  return {}
+}
+
+export default connect(mapStateToProps, mapDispatchToProps)(TableCard)
\ No newline at end of file

--
Gitblit v1.8.0