From 131bc212f0cfe964c9a38bbe6178aca4f4a16677 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期六, 03 二月 2024 17:50:30 +0800
Subject: [PATCH] Merge branch 'master' into positec

---
 src/tabviews/zshare/topSearch/index.jsx |  179 ++++++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 150 insertions(+), 29 deletions(-)

diff --git a/src/tabviews/zshare/topSearch/index.jsx b/src/tabviews/zshare/topSearch/index.jsx
index eda97f6..c3cfc0b 100644
--- a/src/tabviews/zshare/topSearch/index.jsx
+++ b/src/tabviews/zshare/topSearch/index.jsx
@@ -25,8 +25,8 @@
 
 class MainSearch extends Component {
   static propTpyes = {
-    BID: PropTypes.any,          // 鐖剁骇Id锛岀敤浜庢煡璇笅鎷夐�夋嫨椤�
-    config: PropTypes.object,    // 缁勪欢閰嶇疆淇℃伅
+    BID: PropTypes.any,
+    config: PropTypes.object
   }
 
   state = {
@@ -121,6 +121,40 @@
         item.advanced = false
       }
 
+      if (item.checkShift && !item.initval) {
+        let d = ''
+        if (window.GLOB.CacheData.has(item.$supId)) {
+          d = window.GLOB.CacheData.get(item.$supId)
+          d = d[item.dateShift] || ''
+          if (d) {
+            d = moment(d).format('YYYY-MM-DD')
+            d = d === 'Invalid date' ? '' : d
+          }
+        }
+
+        if (d) {
+          if (item.type === 'daterange') {
+            if (item.$initval === 'week') {
+              item.initval = [moment(d).startOf('week').format(item.format), moment(d).endOf('week').format(item.format)].join(',')
+            } else if (item.$initval === 'month') {
+              item.initval = [moment(d).startOf('month').format(item.format), moment(d).endOf('month').format(item.format)].join(',')
+            } else if (item.$initval === 'lastMonth') {
+              item.initval = [moment(d).subtract(1, 'months').startOf('month').format(item.format), moment(d).subtract(1, 'months').endOf('month').format(item.format)].join(',')
+            } else {
+              try {
+                let _initval = JSON.parse(item.$initval)
+                let _vals = [moment(d).subtract(_initval[0], 'days').format(item.format), moment(d).subtract(_initval[1], 'days').format(item.format)]
+                item.initval = _vals.join(',')
+              } catch (e) {
+                item.initval = ''
+              }
+            }
+          } else {
+            item.initval = moment(d).subtract(item.$initval, 'month').format('YYYY-MM')
+          }
+        }
+      }
+
       if (item.type === 'group') {
         record[item.field] = item.initType
         record[item.datefield] = item.initval
@@ -144,24 +178,34 @@
         if (item.resourceType === '1' && item.dataSource) {
           let _option = Utils.getSelectQueryOptions(item)
 
-          _option.sql = _option.sql.replace(/@BID@/ig, `'${BID || ''}'`)
+          let exec = true
+          if (item.checkBid) {
+            item.sql = _option.sql
+            item.arr_field = _option.field
 
-          if (window.GLOB.debugger === true) {
-            console.info(_option.sql)
+            exec = !!BID
           }
 
-          // 娴嬭瘯绯荤粺鍗曚釜璇锋眰
-          if (!window.GLOB.mkHS && window.GLOB.sysType === 'local' && !window.GLOB.systemType) {
-            deForms.push({
-              ...item,
-              arr_field: _option.field,
-              data_sql: Utils.formatOptions(_option.sql)
-            })
-          } else { // 鍚堝苟璇锋眰锛屽尯鍒嗘湰鍦板強绯荤粺
-            if (item.database === 'sso') {
-              mainItems.push(`select '${item.field}' as obj_name,'${_option.field}' as arr_field,'${window.btoa(window.encodeURIComponent(_option.sql.replace(/%/ig, ' mpercent ')))}' as LText`)
-            } else {
-              localItems.push(`select '${item.field}' as obj_name,'${_option.field}' as arr_field,'${window.btoa(window.encodeURIComponent(_option.sql.replace(/%/ig, ' mpercent ')))}' as LText`)
+          if (exec) {
+            _option.sql = _option.sql.replace(/@BID@/ig, `'${BID || ''}'`)
+  
+            if (window.GLOB.debugger === true) {
+              console.info(_option.sql)
+            }
+  
+            // 娴嬭瘯绯荤粺鍗曚釜璇锋眰
+            if (!window.GLOB.mkHS && window.GLOB.sysType === 'local' && !window.GLOB.systemType) {
+              deForms.push({
+                ...item,
+                arr_field: _option.field,
+                data_sql: Utils.formatOptions(_option.sql)
+              })
+            } else { // 鍚堝苟璇锋眰锛屽尯鍒嗘湰鍦板強绯荤粺
+              if (item.database === 'sso') {
+                mainItems.push(`select '${item.field}' as obj_name,'${_option.field}' as arr_field,'${window.btoa(window.encodeURIComponent(_option.sql.replace(/%/ig, ' mpercent ')))}' as LText`)
+              } else {
+                localItems.push(`select '${item.field}' as obj_name,'${_option.field}' as arr_field,'${window.btoa(window.encodeURIComponent(_option.sql.replace(/%/ig, ' mpercent ')))}' as LText`)
+              }
             }
           }
         }
@@ -233,11 +277,84 @@
       searchlist: _list
     }, () => {
       if (!window.GLOB.mkHS && window.GLOB.sysType === 'local' && window.GLOB.systemType !== 'production') {
-        this.improveSimpleSearch(deForms)
+        this.improveSimpleSearch(deForms, false)
       } else if (mainItems.length > 0 || localItems.length > 0) {
         this.improveSearch(mainItems, localItems)
       }
     })
+  }
+
+  UNSAFE_componentWillReceiveProps(nextProps) {
+    const { config, BID } = this.props
+
+    if (config.checkBid && nextProps.BID !== BID) {
+      this.resetOptions(nextProps.BID)
+    }
+  }
+
+  resetOptions = (BID) => {
+    let deForms = []
+    let searchlist = fromJS(this.state.searchlist).toJS().map(item => {
+      if (item.checkBid) {
+        let sql = item.sql.replace(/@BID@/ig, `'${BID || ''}'`)
+  
+        if (window.GLOB.debugger === true) {
+          console.info(sql)
+        }
+
+        deForms.push({
+          ...item,
+          arr_field: item.arr_field,
+          data_sql: Utils.formatOptions(sql)
+        })
+      } else if (item.checkShift) {
+        let d = ''
+        if (window.GLOB.CacheData.has(item.$supId)) {
+          d = window.GLOB.CacheData.get(item.$supId)
+          d = d[item.dateShift] || ''
+          if (d) {
+            d = moment(d).format('YYYY-MM-DD')
+            d = d === 'Invalid date' ? '' : d
+          }
+        }
+
+        if (d) {
+          if (item.type === 'daterange') {
+            if (item.$initval === 'week') {
+              item.initval = [moment(d).startOf('week').format(item.format), moment(d).endOf('week').format(item.format)].join(',')
+            } else if (item.$initval === 'month') {
+              item.initval = [moment(d).startOf('month').format(item.format), moment(d).endOf('month').format(item.format)].join(',')
+            } else if (item.$initval === 'lastMonth') {
+              item.initval = [moment(d).subtract(1, 'months').startOf('month').format(item.format), moment(d).subtract(1, 'months').endOf('month').format(item.format)].join(',')
+            } else {
+              try {
+                let _initval = JSON.parse(item.$initval)
+                let _vals = [moment(d).subtract(_initval[0], 'days').format(item.format), moment(d).subtract(_initval[1], 'days').format(item.format)]
+                item.initval = _vals.join(',')
+              } catch (e) {
+                item.initval = ''
+              }
+            }
+          } else {
+            item.initval = moment(d).subtract(item.$initval, 'month').format('YYYY-MM')
+          }
+        }
+      }
+
+      return item
+    })
+
+    if (deForms.length > 0) {
+      this.improveSimpleSearch(deForms, true, searchlist)
+    } else {
+      this.setState({
+        searchlist: searchlist
+      })
+      
+      setTimeout(() => {
+        this.handleSubmit()
+      }, 20)
+    }
   }
 
   resetCheckcard = (item) => {
@@ -364,12 +481,12 @@
       delete result.message
       delete result.status
 
-      this.resetSearch(result)
+      this.resetSearch(result, false)
     })
   }
 
   // 娴嬭瘯绯荤粺鍗曚釜璇锋眰涓嬫媺閫夐」
-  improveSimpleSearch = (deForms) => {
+  improveSimpleSearch = (deForms, trigger, searchlist) => {
     if (deForms.length === 0) return
 
     let deffers = deForms.map((item, index) => {
@@ -421,13 +538,13 @@
       delete result.message
       delete result.status
 
-      this.resetSearch(result)
+      this.resetSearch(result, trigger, searchlist)
     })
   }
 
-  resetSearch = (result) => {
-    let trigger = false
-    let _searchlist = fromJS(this.state.searchlist).toJS().map(item => {
+  resetSearch = (result, submit, searchlist) => {
+    let trigger = submit
+    let _searchlist = fromJS(searchlist || this.state.searchlist).toJS().map(item => {
       if (['select', 'link', 'multiselect', 'checkcard', 'radio'].includes(item.type) && result[item.field] && result[item.field].length > 0) {
         let options = []
         let map = new Map()
@@ -492,9 +609,13 @@
         item.options = item.oriOptions
       }
 
-      if (item.$first && item.options.length > 0) {
-        item.initval = item.options[0].Value
-        trigger = true
+      if (item.$first) {
+        if (item.options.length > 0) {
+          item.initval = item.options[0].Value
+          trigger = true
+        } else {
+          item.initval = ''
+        }
       }
 
       return item
@@ -507,7 +628,7 @@
     if (trigger) {
       setTimeout(() => {
         this.handleSubmit()
-      }, 10)
+      }, 20)
     }
   }
 
@@ -567,7 +688,7 @@
       } else if (item.type === 'select' || item.type === 'link' || item.type === 'multiselect') {
         content = (<MKSelect config={item} onChange={(val, defer) => this.recordChange(val, defer, item)} />)
       } else if (item.type === 'date' || item.type === 'datemonth' || item.type === 'dateweek' || item.type === 'daterange') {
-        content = (<MKDatePicker config={item} onChange={(val) => this.recordChange(val, false, item)} />)
+        content = (<MKDatePicker config={item} onChange={(val, defer) => this.recordChange(val, defer, item)} />)
       } else if (item.type === 'group') {
         field = item.datefield
         content = <DateGroup position={index} config={item} onChange={(val, type) => this.dateGroupChange(val, type, item)} />

--
Gitblit v1.8.0