From dc258e4600bea2fba1e25054d163a2f4b1326a85 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 08 八月 2023 10:23:38 +0800
Subject: [PATCH] 2023-08-08

---
 src/tabviews/custom/components/calendar/index.jsx |  136 ++++++++++++++++++++++++++++++++++-----------
 1 files changed, 102 insertions(+), 34 deletions(-)

diff --git a/src/tabviews/custom/components/calendar/index.jsx b/src/tabviews/custom/components/calendar/index.jsx
index c9ba92b..43b7021 100644
--- a/src/tabviews/custom/components/calendar/index.jsx
+++ b/src/tabviews/custom/components/calendar/index.jsx
@@ -4,28 +4,26 @@
 import { Spin, notification, Modal } from 'antd'
 
 import Api from '@/api'
-import Utils from '@/utils/utils.js'
 import asyncComponent from '@/utils/asyncComponent'
 import UtilsDM from '@/utils/utils-datamanage.js'
 import MKEmitter from '@/utils/events.js'
+import CalendarBoard from './board'
 import './index.scss'
 
 const NormalHeader = asyncComponent(() => import('@/tabviews/custom/components/share/normalheader'))
 const MainSearch = asyncComponent(() => import('@/tabviews/zshare/topSearch'))
 const PopupButton = asyncComponent(() => import('@/tabviews/zshare/actionList/popupbutton'))
-const CalendarBoard = asyncComponent(() => import('./board'))
 
 class NormalCalendar extends Component {
   static propTpyes = {
     config: PropTypes.object,        // 缁勪欢閰嶇疆淇℃伅
-    mainSearch: PropTypes.any,       // 澶栧眰鎼滅储鏉′欢
   }
 
   state = {
     BID: '',                   // 涓婄骇ID
     config: null,              // 鍥捐〃閰嶇疆淇℃伅
     loading: false,            // 鏁版嵁鍔犺浇鐘舵��
-    data: null,                // 鏁版嵁
+    data: [],                // 鏁版嵁
     search: '',
     year: new Date().getFullYear(),
     BData: ''
@@ -55,12 +53,22 @@
       _config.setting.$re_year = true
     }
 
+    if (_config.wrap.colorField && (!_config.wrap.signs || _config.wrap.signs.length === 0)) {
+      _config.wrap.colorField = ''
+    }
+
+    if (_config.action[0] && _config.action[0].config && _config.action[0].config.enabled) {
+      _config.setting.linkbtn = _config.action[0].uuid
+    } else {
+      _config.action = []
+    }
+
     this.setState({
       BID: BData ? (BData.$BID || '') : '',
       BData: BData,
       config: _config,
       arr_field: _config.columns.map(col => col.field).join(','),
-      search: Utils.initMainSearch(_config.search) // 鎼滅储鏉′欢鍒濆鍖栵紙鍚湁鏃堕棿鏍煎紡锛岄渶瑕佽浆鍖栵級
+      search: _config.$searches
     }, () => {
       if (_config.setting.onload === 'true') {
         setTimeout(() => {
@@ -77,17 +85,27 @@
     MKEmitter.addListener('resetSelectLine', this.resetParentParam)
     MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult)
 
+    if (config.setting.useMSearch) {
+      MKEmitter.addListener('searchRefresh', this.searchRefresh)
+    }
+
     if (config.$cache && !this.loaded) {
       Api.getLCacheConfig(config.uuid).then(res => {
-        if (!res || this.loaded) return
+        if (!res.data || this.loaded) return
 
-        this.setState({data: res.map((item, index) => {
+        let data = []
+        res.data.forEach((item, index) => {
           item.key = index
           item.$$uuid = item[config.setting.primaryKey] || ''
-          item.$Index = index + 1 + ''
-          
-          return item
-        })})
+
+          let pass = this.resetLine(item)
+
+          if (pass) {
+            data.push(item)
+          }
+        })
+
+        this.setState({data: data})
       })
     }
   }
@@ -101,21 +119,19 @@
       return
     }
     MKEmitter.removeListener('reloadData', this.reloadData)
+    MKEmitter.removeListener('searchRefresh', this.searchRefresh)
     MKEmitter.removeListener('resetSelectLine', this.resetParentParam)
     MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult)
   }
 
-  /**
-   * @description 鍥捐〃鏁版嵁鏇存柊锛屽埛鏂板唴瀹�
-   */
-  UNSAFE_componentWillReceiveProps (nextProps) {
+  searchRefresh = (searchId) => {
     const { config } = this.state
 
-    if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
-      this.setState({}, () => {
-        this.loadData()
-      })
-    }
+    if (config.$searchId !== searchId) return
+    
+    this.setState({}, () => {
+      this.loadData()
+    })
   }
 
   /**
@@ -156,7 +172,6 @@
   }
 
   async loadData () {
-    const { mainSearch } = this.props
     const { config, arr_field, BID, search, year } = this.state
     
     if (config.setting.supModule && !BID) { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇�
@@ -168,17 +183,17 @@
     }
 
     let searches = fromJS(search).toJS()
-    if (config.setting.useMSearch && mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢
-      let keys = searches.map(item => item.key.toLowerCase())
+    if (config.setting.useMSearch) { // 涓昏〃鎼滅储鏉′欢
+      let mainSearch = window.GLOB.SearchBox.get(config.$searchId) || []
+      let keys = config.$s_keys || []
       mainSearch.forEach(item => {
-        if (!keys.includes(item.key.toLowerCase())) {
-          searches.push(item)
-        }
+        if (keys.includes(item.key.toLowerCase())) return
+
+        searches.push(item)
       })
     }
 
-    let requireFields = searches.filter(item => item.required && item.value === '')
-    if (requireFields.length > 0) {
+    if (config.$s_req && searches.filter(item => item.required && item.value === '').length > 0) {
       return
     }
 
@@ -193,22 +208,27 @@
     if (result.status) {
       this.loaded = true
       if (config.$cache && config.setting.onload !== 'false') {
-        Api.writeCacheConfig(config.uuid, result.data || '')
+        Api.writeCacheConfig(config.uuid, result.data || [])
       }
 
-      let data = result.data.map((item, index) => {
+      let data = []
+      result.data.forEach((item, index) => {
         item.key = index
         item.$$uuid = item[config.setting.primaryKey] || ''
         item.$$BID = BID || ''
 
-        return item
+        let pass = this.resetLine(item)
+
+        if (pass) {
+          data.push(item)
+        }
       })
 
       this.setState({
         data: data,
         loading: false
       })
-
+      
       if (result.message) {
         if (result.ErrCode === 'Y') {
           Modal.success({
@@ -242,9 +262,57 @@
     }
   }
 
+  resetLine = (item) => {
+    const { config: { wrap } } = this.state
+
+    let startTime = item[wrap.timeField] || ''
+    let endTime = item[wrap.endField || wrap.timeField] || ''
+
+    item.$message = item[wrap.remarkField]
+
+    if (!/^(1|2)\d{3}(-|\/)\d{2}(-|\/)\d{2}/.test(startTime)) return false
+    if (!/^(1|2)\d{3}(-|\/)\d{2}(-|\/)\d{2}/.test(endTime)) return false
+    if (!item.$message) return false
+
+    if (wrap.colorField) {
+      let sign = item[wrap.colorField] || ''
+
+      wrap.signs.forEach(cell => {
+        if (cell.sign !== sign) return
+
+        item.$style = cell.style
+        item.$color = cell.background
+        item.$level = cell.$index
+      })
+    }
+
+    let equal = endTime.substr(0, 4) === startTime.substr(0, 4)
+
+    item.$startM = +(startTime.substr(0, 4) + startTime.substr(5, 2))
+    item.$endM = +(endTime.substr(0, 4) + endTime.substr(5, 2))
+    item.$start = +(startTime.substr(0, 4) + startTime.substr(5, 2) + startTime.substr(8, 2))
+    item.$end = +(endTime.substr(0, 4) + endTime.substr(5, 2) + endTime.substr(8, 2))
+    item.$startTime = equal ? `${startTime.substr(5, 2)}-${startTime.substr(8, 2)}` : `${startTime.substr(0, 4)}-${startTime.substr(5, 2)}-${startTime.substr(8, 2)}`
+    item.$endTime = equal ?  `${endTime.substr(5, 2)}-${endTime.substr(8, 2)}` : `${endTime.substr(0, 4)}-${endTime.substr(5, 2)}-${endTime.substr(8, 2)}`
+    
+    return true
+  }
+
   refreshbysearch = (searches) => {
     this.setState({
       search: searches
+    }, () => {
+      this.loadData()
+    })
+  }
+
+  yearChange = (value) => {
+    const { config } = this.state
+
+    if (!config.setting.$re_year) return
+
+    this.setState({
+      year: value
     }, () => {
       this.loadData()
     })
@@ -257,7 +325,7 @@
       <div className="normal-calendar-box" id={'anchor' + config.uuid} style={{...config.style}}>
         {loading ?
           <div className="loading-mask">
-            {data ? <div className="ant-spin-blur"></div> : null}
+            <div className="ant-spin-blur"></div>
             <Spin />
           </div> : null
         }
@@ -268,7 +336,7 @@
         {config.action[0] ? 
           <PopupButton disabled={false} BID={BID} btn={config.action[0]} BData={BData} setting={config.setting} selectedData={[]}/> : null
         }
-        <CalendarBoard config={config} />
+        <CalendarBoard config={config} data={data} yearChange={this.yearChange}/>
       </div>
     )
   }

--
Gitblit v1.8.0