From 920e94fc5483b081b3d43c86df8f56d838f2f14d Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期六, 06 一月 2024 22:07:15 +0800
Subject: [PATCH] 2024-01-06

---
 src/tabviews/custom/components/table/base-table/index.jsx         |    6 
 src/tabviews/zshare/topSearch/index.jsx                           |  171 ++++++++++++++++++++----
 src/templates/zshare/formconfig.jsx                               |    9 +
 src/tabviews/custom/components/card/double-data-card/index.jsx    |    4 
 src/menu/components/share/pasteforms/index.jsx                    |    2 
 src/tabviews/custom/components/table/normal-table/index.jsx       |    4 
 src/tabviews/zshare/topSearch/mkSelect/index.jsx                  |    4 
 src/tabviews/custom/popview/index.jsx                             |   14 +-
 src/tabviews/custom/components/table/edit-table/index.jsx         |    8 
 src/tabviews/basetable/index.jsx                                  |   10 
 src/tabviews/custom/index.jsx                                     |   14 +-
 src/tabviews/zshare/topSearch/mkDatePicker/index.jsx              |   38 ++--
 src/tabviews/custom/components/share/normalheader/index.jsx       |    9 +
 src/tabviews/custom/components/card/data-card/index.jsx           |    4 
 src/utils/utils.js                                                |   86 ++++++++++--
 src/templates/sharecomponent/searchcomponent/searchform/index.jsx |    6 
 16 files changed, 297 insertions(+), 92 deletions(-)

diff --git a/src/menu/components/share/pasteforms/index.jsx b/src/menu/components/share/pasteforms/index.jsx
index 6cf98a8..180304b 100644
--- a/src/menu/components/share/pasteforms/index.jsx
+++ b/src/menu/components/share/pasteforms/index.jsx
@@ -38,6 +38,8 @@
       if (res.copyType === 'form') {
         delete res.copyType
         res = {fields: [res]}
+      } else if (res.copyType === 'simpleform') {
+        res = {fields: res.subcards[0].fields}
       }
 
       res.fields = res.fields || []
diff --git a/src/tabviews/basetable/index.jsx b/src/tabviews/basetable/index.jsx
index 444c709..87436e1 100644
--- a/src/tabviews/basetable/index.jsx
+++ b/src/tabviews/basetable/index.jsx
@@ -346,11 +346,6 @@
         item.name = (MenuName || '')
       }
 
-      // 鎼滅储鏉′欢鍒濆鍖�
-      Utils.initSearchVal(item)
-
-      item.$searches = Utils.initMainSearch(item.search)
-
       if (item.setting.supModule) {
         let pid = item.setting.supModule.pop()
         if (pid && pid !== 'empty') {
@@ -360,6 +355,11 @@
         }
       }
 
+      // 鎼滅储鏉′欢鍒濆鍖�
+      Utils.initSearchVal(item)
+
+      item.$searches = Utils.initMainSearch(item.search)
+
       let statFields = []
       let getCols = (cols) => {
         return cols.filter(col => {
diff --git a/src/tabviews/custom/components/card/data-card/index.jsx b/src/tabviews/custom/components/card/data-card/index.jsx
index e281af7..1955b65 100644
--- a/src/tabviews/custom/components/card/data-card/index.jsx
+++ b/src/tabviews/custom/components/card/data-card/index.jsx
@@ -705,7 +705,9 @@
       if (!config.setting.supModule || config.setting.supModule !== MenuID) return
       if (id !== this.state.BID || id !== '') {
         this.setState({ BID: id, BData: data, pageIndex: 1 }, () => {
-          this.loadData()
+          if (!config.checkBid) {
+            this.loadData()
+          }
         })
       }
     }
diff --git a/src/tabviews/custom/components/card/double-data-card/index.jsx b/src/tabviews/custom/components/card/double-data-card/index.jsx
index 7fa1228..6ae8f77 100644
--- a/src/tabviews/custom/components/card/double-data-card/index.jsx
+++ b/src/tabviews/custom/components/card/double-data-card/index.jsx
@@ -546,7 +546,9 @@
     if (!config.setting.supModule || config.setting.supModule !== MenuID) return
     if (id !== this.state.BID || id !== '') {
       this.setState({ BID: id, BData: data, pageIndex: 1 }, () => {
-        this.loadData()
+        if (!config.checkBid) {
+          this.loadData()
+        }
       })
     }
   }
diff --git a/src/tabviews/custom/components/share/normalheader/index.jsx b/src/tabviews/custom/components/share/normalheader/index.jsx
index 0b19275..34f8a6b 100644
--- a/src/tabviews/custom/components/share/normalheader/index.jsx
+++ b/src/tabviews/custom/components/share/normalheader/index.jsx
@@ -27,7 +27,14 @@
     })
   }
 
-  shouldComponentUpdate (nextProps, nextState) { return false }
+  shouldComponentUpdate (nextProps, nextState) {
+    const { config } = this.props
+
+    if (config.checkBid && this.props.BID !== nextProps.BID) {
+      return true
+    }
+    return false
+  }
 
   /**
    * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊锛屾竻闄ゅ揩鎹烽敭璁剧疆
diff --git a/src/tabviews/custom/components/table/base-table/index.jsx b/src/tabviews/custom/components/table/base-table/index.jsx
index 7f975c1..aca8592 100644
--- a/src/tabviews/custom/components/table/base-table/index.jsx
+++ b/src/tabviews/custom/components/table/base-table/index.jsx
@@ -566,8 +566,10 @@
         BID: id,
         BData: data
       }, () => {
-        this.loadmaindata(true, 'true')
-        this.getStatFieldsValue()
+        if (!setting.checkBid) {
+          this.loadmaindata(true, 'true')
+          this.getStatFieldsValue()
+        }
       })
     }
   }
diff --git a/src/tabviews/custom/components/table/edit-table/index.jsx b/src/tabviews/custom/components/table/edit-table/index.jsx
index d2f11ed..77c9061 100644
--- a/src/tabviews/custom/components/table/edit-table/index.jsx
+++ b/src/tabviews/custom/components/table/edit-table/index.jsx
@@ -584,9 +584,11 @@
         BID: id,
         BData: data
       }, () => {
-        setTimeout(() => {
-          this.loadmaindata(true, 'true')
-        }, setting.delay || 0)
+        if (!setting.checkBid) {
+          setTimeout(() => {
+            this.loadmaindata(true, 'true')
+          }, setting.delay || 0)
+        }
       })
     }
   }
diff --git a/src/tabviews/custom/components/table/normal-table/index.jsx b/src/tabviews/custom/components/table/normal-table/index.jsx
index 595c5e5..676488a 100644
--- a/src/tabviews/custom/components/table/normal-table/index.jsx
+++ b/src/tabviews/custom/components/table/normal-table/index.jsx
@@ -784,7 +784,9 @@
         BID: id,
         BData: data
       }, () => {
-        this.loadmaindata(true, 'true')
+        if (!setting.checkBid) {
+          this.loadmaindata(true, 'true')
+        }
       })
     }
   }
diff --git a/src/tabviews/custom/index.jsx b/src/tabviews/custom/index.jsx
index 7bc164c..c6c0b26 100644
--- a/src/tabviews/custom/index.jsx
+++ b/src/tabviews/custom/index.jsx
@@ -563,13 +563,6 @@
         item.type = 'card'
       }
 
-      // 鎼滅储鏉′欢鍒濆鍖�
-      if (item.search) {
-        Utils.initSearchVal(item)
-
-        item.$searches = Utils.initMainSearch(item.search)
-      }
-
       if (item.wrap && item.wrap.supType === 'multi') { // 鏁版嵁鍗″涓婄骇缁勪欢
         item.setting.supModule = item.supNodes[0].componentId
       } else if (item.setting && item.setting.supModule && typeof(item.setting.supModule) !== 'string') {
@@ -581,6 +574,13 @@
         }
       }
 
+      // 鎼滅储鏉′欢鍒濆鍖�
+      if (item.search) {
+        Utils.initSearchVal(item)
+
+        item.$searches = Utils.initMainSearch(item.search)
+      }
+
       let pass = skip
 
       if (item.wrap && item.wrap.permission === 'false') {
diff --git a/src/tabviews/custom/popview/index.jsx b/src/tabviews/custom/popview/index.jsx
index 2012480..2810e2b 100644
--- a/src/tabviews/custom/popview/index.jsx
+++ b/src/tabviews/custom/popview/index.jsx
@@ -323,13 +323,6 @@
         }
       }
 
-      // 鎼滅储鏉′欢鍒濆鍖�
-      if (item.search) {
-        Utils.initSearchVal(item)
-
-        item.$searches = Utils.initMainSearch(item.search)
-      }
-
       if (item.wrap && item.wrap.supType === 'multi') { // 鏁版嵁鍗″涓婄骇缁勪欢
         item.setting.supModule = item.supNodes[0].componentId
       } else if (item.setting && item.setting.supModule && typeof(item.setting.supModule) !== 'string') {
@@ -341,6 +334,13 @@
         }
       }
 
+      // 鎼滅储鏉′欢鍒濆鍖�
+      if (item.search) {
+        Utils.initSearchVal(item)
+
+        item.$searches = Utils.initMainSearch(item.search)
+      }
+
       // 鏉冮檺杩囨护
       if (item.action && item.action.length > 0) {
         item.action = item.action.filter(cell => {
diff --git a/src/tabviews/zshare/topSearch/index.jsx b/src/tabviews/zshare/topSearch/index.jsx
index eda97f6..02d9067 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,36 @@
         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.$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 = ''
+            }
+          }
+        }
+      }
+
       if (item.type === 'group') {
         record[item.field] = item.initType
         record[item.datefield] = item.initval
@@ -144,24 +174,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 +273,80 @@
       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.$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 = ''
+            }
+          }
+        }
+      }
+
+      return item
+    })
+
+    if (deForms.length > 0) {
+      this.improveSimpleSearch(deForms, true, searchlist)
+    } else {
+      this.setState({
+        searchlist: searchlist
+      })
+      
+      setTimeout(() => {
+        this.handleSubmit()
+      }, 20)
+    }
   }
 
   resetCheckcard = (item) => {
@@ -364,12 +473,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 +530,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 +601,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 +620,7 @@
     if (trigger) {
       setTimeout(() => {
         this.handleSubmit()
-      }, 10)
+      }, 20)
     }
   }
 
@@ -567,7 +680,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)} />
diff --git a/src/tabviews/zshare/topSearch/mkDatePicker/index.jsx b/src/tabviews/zshare/topSearch/mkDatePicker/index.jsx
index c086876..fc67c7d 100644
--- a/src/tabviews/zshare/topSearch/mkDatePicker/index.jsx
+++ b/src/tabviews/zshare/topSearch/mkDatePicker/index.jsx
@@ -15,28 +15,16 @@
     const config = props.config
 
     let mode = 'date'
-    let format = 'YYYY-MM-DD'
+    let format = config.format || 'YYYY-MM-DD'
 
     if (config.type === 'datemonth') {
       mode = 'month'
-      format = 'YYYY-MM'
     } else if (config.type === 'week') {
       mode = 'week'
-      format = 'YYYY-MM-DD'
-    } else {
-      if (config.type === 'daterange') {
-        mode = 'daterange'
-      }
-      if (config.precision === 'day') {
-        format = 'YYYY-MM-DD'
-      } else if (config.precision === 'hour') {
-        format = 'YYYY-MM-DD HH'
-      } else if (config.precision === 'minute') {
-        format = 'YYYY-MM-DD HH:mm'
-      } else if (config.precision === 'second') {
-        format = 'YYYY-MM-DD HH:mm:ss'
-      }
+    } else if (config.type === 'daterange') {
+      mode = 'daterange'
     }
+
     let value = config.initval || null
 
     if (mode === 'daterange') {
@@ -62,6 +50,20 @@
     return !is(fromJS(this.state), fromJS(nextState))
   }
 
+  UNSAFE_componentWillReceiveProps (nextProps) {
+    const { config } = this.props
+
+    if (config.checkShift && nextProps.config.initval && nextProps.config.initval !== config.initval) {
+      let val = nextProps.config.initval.split(',')
+
+      this.setState({
+        value: [moment(val[0], config.format), moment(val[1], config.format)]
+      })
+
+      this.props.onChange(nextProps.config.initval, true)
+    }
+  }
+
   componentWillUnmount () {
     this.setState = () => {
       return
@@ -78,9 +80,9 @@
       if (_val && !_val[0]) {
         _val = ''
       }
-      this.props.onChange(_val ? `${moment(_val[0]).format(format)},${moment(_val[1]).format(format)}` : '')
+      this.props.onChange(_val ? `${moment(_val[0]).format(format)},${moment(_val[1]).format(format)}` : '', false)
     } else {
-      this.props.onChange(val ? moment(val).format(format) : '')
+      this.props.onChange(val ? moment(val).format(format) : '', false)
     }
   }
 
diff --git a/src/tabviews/zshare/topSearch/mkSelect/index.jsx b/src/tabviews/zshare/topSearch/mkSelect/index.jsx
index 87000f4..4dcfe0a 100644
--- a/src/tabviews/zshare/topSearch/mkSelect/index.jsx
+++ b/src/tabviews/zshare/topSearch/mkSelect/index.jsx
@@ -47,10 +47,12 @@
         options: fromJS(nextProps.config.options).toJS()
       })
 
-      if (config.$first && nextProps.config.initval) {
+      if (config.type !== 'multiselect') {
         this.setState({
           value: nextProps.config.initval
         })
+
+        this.props.onChange(nextProps.config.initval, true)
       }
     }
   }
diff --git a/src/templates/sharecomponent/searchcomponent/searchform/index.jsx b/src/templates/sharecomponent/searchcomponent/searchform/index.jsx
index 2a87811..21a7065 100644
--- a/src/templates/sharecomponent/searchcomponent/searchform/index.jsx
+++ b/src/templates/sharecomponent/searchcomponent/searchform/index.jsx
@@ -240,6 +240,10 @@
       }
       shows.push('linkField')
       reRequired.linkField = false
+    } else if (type === 'daterange') {
+      if (this.record.initval) {
+        shows.push('dateShift')
+      }
     }
 
     if (dateOptions.hasOwnProperty(type)) { // 鏍规嵁鎼滅储鏉′欢绫诲瀷锛岄�夋嫨鍒濆鍊肩殑绫诲瀷鍙婃暟鎹�
@@ -509,7 +513,7 @@
         rules = [
           { required: item.required, message: '璇疯緭鍏�' + item.label + '!' }
         ]
-        if (item.key === 'field' || item.key === 'datefield') {
+        if (item.key === 'field' || item.key === 'datefield' || item.key === 'dateShift') {
           rules.push({
             pattern: (type === 'text' || type === 'select' || type === 'daterange') ? formRule.field.multipattern : formRule.field.pattern,
             message: formRule.field.message
diff --git a/src/templates/zshare/formconfig.jsx b/src/templates/zshare/formconfig.jsx
index c306270..6f2c88b 100644
--- a/src/templates/zshare/formconfig.jsx
+++ b/src/templates/zshare/formconfig.jsx
@@ -467,6 +467,15 @@
       forbid: appType === 'mob'
     },
     {
+      type: 'text',
+      key: 'dateShift',
+      label: '鏃ユ湡鍋忕Щ',
+      initVal: card.dateShift || '',
+      tooltip: '鍙互濉叆涓婄骇瀛楁锛岀敤浜庢帶鍒跺垵濮嬪�硷紝渚嬪锛氫笂绾у瓧娈靛�间负2023-12-10锛屽垵濮嬪�间负鏈湀锛屽垯鍒濆鍖洪棿涓� 2023-12-01 ~ 2023-12-31銆�',
+      required: false,
+      forbid: appType === 'mob'
+    },
+    {
       type: 'radio',
       key: 'precision',
       label: '绮剧‘搴�',
diff --git a/src/utils/utils.js b/src/utils/utils.js
index 3177c1d..f4dc5e3 100644
--- a/src/utils/utils.js
+++ b/src/utils/utils.js
@@ -260,10 +260,13 @@
           format = 'YYYY-MM-DD HH:mm:ss'
         }
 
+        item.format = format
         item.initval = item.initval ? moment().subtract(item.initval, 'days').format(format) : ''
       } else if (item.type === 'datemonth') {
+        item.format = 'YYYY-MM'
         item.initval = item.initval ? moment().subtract(item.initval, 'month').format('YYYY-MM') : ''
       } else if (item.type === 'dateweek') {
+        item.format = 'YYYY-MM-DD'
         item.initval = item.initval ? moment().subtract(item.initval * 7, 'days').format('YYYY-MM-DD') : ''
       } else if (item.type === 'daterange') {
         let format = 'YYYY-MM-DD'
@@ -276,19 +279,65 @@
         } else if (item.precision === 'second') {
           format = 'YYYY-MM-DD HH:mm:ss'
         }
-        if (item.initval === 'week') {
-          item.initval = [moment().startOf('week').format(format), moment().endOf('week').format(format)].join(',')
-        } else if (item.initval === 'month') {
-          item.initval = [moment().startOf('month').format(format), moment().endOf('month').format(format)].join(',')
-        } else if (item.initval === 'lastMonth') {
-          item.initval = [moment().subtract(1, 'months').startOf('month').format(format), moment().subtract(1, 'months').endOf('month').format(format)].join(',')
-        } else if (item.initval) {
-          try {
-            let _initval = JSON.parse(item.initval)
-            let _vals = [moment().subtract(_initval[0], 'days').format(format), moment().subtract(_initval[1], 'days').format(format)]
-            item.initval = _vals.join(',')
-          } catch (e) {
+
+        item.format = format
+
+        if (item.initval) {
+          if (!item.dateShift) {
+            if (item.initval === 'week') {
+              item.initval = [moment().startOf('week').format(format), moment().endOf('week').format(format)].join(',')
+            } else if (item.initval === 'month') {
+              item.initval = [moment().startOf('month').format(format), moment().endOf('month').format(format)].join(',')
+            } else if (item.initval === 'lastMonth') {
+              item.initval = [moment().subtract(1, 'months').startOf('month').format(format), moment().subtract(1, 'months').endOf('month').format(format)].join(',')
+            } else if (item.initval) {
+              try {
+                let _initval = JSON.parse(item.initval)
+                let _vals = [moment().subtract(_initval[0], 'days').format(format), moment().subtract(_initval[1], 'days').format(format)]
+                item.initval = _vals.join(',')
+              } catch (e) {
+                item.initval = ''
+              }
+            }
+          } else {
+            item.$initval = item.initval
+            item.$supId = config.$pageId
+            if (config.setting && config.setting.supModule) {
+              item.$supId = config.setting.supModule
+            }
+
+            config.checkBid = true
+            config.setting.checkBid = true
+            item.checkShift = true
             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.$initval === 'week') {
+                item.initval = [moment(d).startOf('week').format(format), moment(d).endOf('week').format(format)].join(',')
+              } else if (item.$initval === 'month') {
+                item.initval = [moment(d).startOf('month').format(format), moment(d).endOf('month').format(format)].join(',')
+              } else if (item.$initval === 'lastMonth') {
+                item.initval = [moment(d).subtract(1, 'months').startOf('month').format(format), moment(d).subtract(1, 'months').endOf('month').format(format)].join(',')
+              } else {
+                try {
+                  let _initval = JSON.parse(item.$initval)
+                  let _vals = [moment(d).subtract(_initval[0], 'days').format(format), moment(d).subtract(_initval[1], 'days').format(format)]
+                  item.initval = _vals.join(',')
+                } catch (e) {
+                  item.initval = ''
+                }
+              }
+            }
           }
         }
       } else if (item.type === 'group') {
@@ -348,9 +397,16 @@
           item.initval = ''
           item.initType = ''
         }
-      } else if ((item.type === 'select' || item.type === 'link') && item.initval === '$first' && item.resourceType === '1') {
-        item.initval = ''
-        item.$first = true
+      } else if ((item.type === 'select' || item.type === 'link') && item.resourceType === '1') {
+        if (/@BID@/ig.test(item.dataSource) && config.setting && config.setting.supModule) {
+          config.checkBid = true
+          config.setting.checkBid = true
+          item.checkBid = true
+        }
+        if (item.initval === '$first') {
+          item.initval = ''
+          item.$first = true
+        }
       }
       
       item.oriInitval = item.initval

--
Gitblit v1.8.0