From c98e45bfac25e9110ad0383faac54a54d98ea9d5 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 18 十一月 2021 20:47:04 +0800
Subject: [PATCH] 2021-11-18

---
 src/tabviews/custom/components/card/table-card/index.jsx |  122 +++++++++++++++++++++++++++++++++-------
 1 files changed, 99 insertions(+), 23 deletions(-)

diff --git a/src/tabviews/custom/components/card/table-card/index.jsx b/src/tabviews/custom/components/card/table-card/index.jsx
index 4babfe6..14107bf 100644
--- a/src/tabviews/custom/components/card/table-card/index.jsx
+++ b/src/tabviews/custom/components/card/table-card/index.jsx
@@ -1,5 +1,6 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
+import { connect } from 'react-redux'
 import { is, fromJS } from 'immutable'
 import { Spin, notification, Row, Col, Empty, Pagination } from 'antd'
 
@@ -31,6 +32,7 @@
     total: 0,                  // 鎬绘暟
     sync: false,               // 鏄惁缁熶竴璇锋眰鏁版嵁
     data: null,                // 鏁版嵁
+    BData: ''
   }
 
   /**
@@ -38,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()
 
@@ -58,7 +60,7 @@
         item.key = index
         item.$$uuid = item[_config.setting.primaryKey] || ''
         item.$$BID = BID || ''
-        item.$Index = index + 1
+        item.$Index = index + 1 + ''
         return item
       })
     }
@@ -90,6 +92,7 @@
     this.setState({
       sync: _sync,
       BID: BID || '',
+      BData: BData || '',
       data: _data,
       config: _config,
       search: Utils.initMainSearch(_config.search),
@@ -104,7 +107,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 +121,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 +129,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,17 +141,16 @@
         item.key = index
         item.$$uuid = item[config.setting.primaryKey] || ''
         item.$$BID = BID || ''
-        item.$Index = index + 1
+        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()
+      })
     }
   }
 
@@ -177,12 +179,12 @@
     }
   }
 
-  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()
       })
     }
@@ -199,14 +201,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())) {
@@ -215,7 +217,7 @@
       })
     }
 
-    MKEmitter.emit('execExcelout', config.uuid, btnId, {
+    MKEmitter.emit('returnModuleParam', config.uuid, btnId, {
       arr_field: arr_field,
       orderBy: config.setting.order || '',
       search: searches,
@@ -225,7 +227,7 @@
 
   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({
@@ -236,13 +238,18 @@
     }
 
     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({
@@ -264,7 +271,8 @@
           item.key = index
           item.$$uuid = item[config.setting.primaryKey] || ''
           item.$$BID = BID || ''
-          item.$Index = index + start
+          item.$$BData = BData || ''
+          item.$Index = index + start + ''
           return item
         }),
         total: result.total,
@@ -288,6 +296,64 @@
     }, () => {
       this.loadData()
     })
+  }
+
+  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) => {
@@ -320,7 +386,7 @@
 
       line.push(
         <Col key={index} span={24}>
-          <div className="card-item-box" style={item.style}>
+          <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>
@@ -363,4 +429,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