From a9ac16fecc0cf9bc66dfaefe4e9b35fa3c722812 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 10 十一月 2020 16:58:43 +0800
Subject: [PATCH] 2020-11-10

---
 src/tabviews/custom/components/card/prop-card/index.jsx |   72 ++++++++++++++++++++++++++++++++----
 1 files changed, 64 insertions(+), 8 deletions(-)

diff --git a/src/tabviews/custom/components/card/prop-card/index.jsx b/src/tabviews/custom/components/card/prop-card/index.jsx
index b3ff9a4..7073848 100644
--- a/src/tabviews/custom/components/card/prop-card/index.jsx
+++ b/src/tabviews/custom/components/card/prop-card/index.jsx
@@ -23,14 +23,32 @@
 
   state = {
     config: null,              // 鍥捐〃閰嶇疆淇℃伅
-    loading: true,             // 鏁版嵁鍔犺浇鐘舵��
+    loading: false,            // 鏁版嵁鍔犺浇鐘舵��
     activeKey: '',             // 閫変腑鏁版嵁
+    sync: false,               // 鏄惁缁熶竴璇锋眰鏁版嵁
     data: null,                // 鏁版嵁
   }
 
   UNSAFE_componentWillMount () {
+    const { data } = this.props
     let _config = fromJS(this.props.config).toJS()
     let _cols = new Map()
+
+    let _data = null
+    let _sync = false
+    if (_config.setting && _config.wrap.datatype !== 'static') {
+      _sync = _config.setting.sync === 'true'
+
+      if (_config.setting.sync === 'true' && data) {
+        _data = data[_config.dataName]
+        if (_data && Array.isArray(_data)) {
+          _data = _data[0]
+        }
+        _sync = false
+      }
+    } else {
+      _data = []
+    }
 
     _config.columns.forEach(item => {
       _cols.set(item.field, item)
@@ -52,10 +70,18 @@
     })
 
     this.setState({
+      sync: _sync,
+      data: _data,
       config: _config,
       arr_field: _config.columns.map(col => col.field).join(','),
     }, () => {
-      this.loadData()
+      if (_config.wrap.datatype !== 'static' && _config.setting && _config.setting.sync !== 'true' && _config.setting.onload === 'true') {
+        this.loadData()
+      } else if (_sync && !_data) {
+        this.setState({
+          loading: true
+        })
+      }
     })
   }
 
@@ -74,6 +100,31 @@
     MKEmitter.removeListener('syncRefreshComponentId', this.reload)
   }
 
+  /**
+   * @description 鍥捐〃鏁版嵁鏇存柊锛屽埛鏂板唴瀹�
+   */
+  UNSAFE_componentWillReceiveProps (nextProps) {
+    const { sync, config } = this.state
+
+    if (sync && !is(fromJS(this.props.data), fromJS(nextProps.data))) {
+      let _data = {}
+      if (nextProps.data && nextProps.data[config.dataName]) {
+        _data = nextProps.data[config.dataName]
+        if (_data && Array.isArray(_data)) {
+          _data = _data[0]
+        }
+      }
+
+      this.setState({sync: false, loading: false, data: _data})
+    } else if (!is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
+      if (config.wrap.datatype !== 'static' && config.setting.syncRefresh === 'true') {
+        this.setState({}, () => {
+          this.loadData()
+        })
+      }
+    }
+  }
+
   reload = (syncId) => {
     const { config } = this.state
 
@@ -85,16 +136,21 @@
   async loadData () {
     const { mainSearch, BID, menuType, dataManager } = this.props
     const { config, arr_field } = this.state
-    
+
     let searches = []
     if (mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢
-      searches = [...mainSearch, ...searches]
+      let keys = searches.map(item => item.key)
+      mainSearch.forEach(item => {
+        if (!keys.includes(item.key)) {
+          searches.push(item)
+        }
+      })
     }
 
     if (config.wrap.datatype === 'static') {
       this.setState({
         loading: false,
-        data: []
+        data: {}
       })
       return
     } else {
@@ -110,7 +166,7 @@
     if (result.status) {
       this.setState({
         activeKey: '',
-        data: result.data,
+        data: result.data && result.data[0] ? result.data[0] : {},
         loading: false
       })
     } else {
@@ -154,7 +210,7 @@
     const { config, loading, data, activeKey } = this.state
 
     return (
-      <div className="custom-prop-card-box" style={config.style}>
+      <div className="custom-prop-card-box" style={{...config.style, minHeight: config.wrap.minHeight}}>
         {loading ?
           <div className="loading-mask">
             <div className="ant-spin-blur"></div>
@@ -164,7 +220,7 @@
         {data ? <div className="card-row-list">
           {config.subcards.map((item, index) => (
             <Col className={activeKey === index ? 'active' : ''} key={index} span={item.setting.width || 6} onClick={() => {this.changeCard(index, item)}}>
-              <CardItem BID={BID} card={item} cards={config} data={data[0] || {}} updateStatus={this.updateStatus}/>
+              <CardItem BID={BID} card={item} cards={config} data={data} updateStatus={this.updateStatus}/>
             </Col>
           ))}
         </div> : null}

--
Gitblit v1.8.0