瀏覽代碼

fix: 统计的时间转换

outaozhen 4 年之前
父節點
當前提交
4a133ddeef
共有 1 個文件被更改,包括 35 次插入3 次删除
  1. 35 3
      src/pages/Statistic/Product/CustomerAdditions/index.jsx

+ 35 - 3
src/pages/Statistic/Product/CustomerAdditions/index.jsx

@@ -21,9 +21,32 @@ const CustomerAdditions = () => {
   })
 
   const [type, setType] = useState('month')
+  const [dates, setDates] = useState([])
+  const [hackValue, setHackValue] = useState()
+  const [value, setValue] = useState()
   const tRef = useRef(null)
   const handleOptionChange = (type, ids) =>
     setState({ ...state, params: { ...state.params, optionType: type, dataIds: ids } })
+  const disabledDate = current => {
+    if (!dates || dates.length === 0) {
+      return false
+    }
+    const tooLate = dates[0] && current.diff(dates[0], 'days') > 7
+    const tooEarly = dates[1] && dates[1].diff(current, 'days') > 7
+    // const tooLate = weeks[0] && current.diff(weeks[0], 'weeks') > 12
+    // const tooEarly = weeks[1] && weeks[1].diff(current, 'weeks') > 12
+    // const tooLate = months[0] && current.diff(months[0], 'months') > 12
+    // const tooEarly = months[1] && months[1].diff(current, 'months') > 12
+    return tooEarly || tooLate
+  }
+  const onOpenChange = open => {
+    if (open) {
+      setHackValue([])
+      setDates([])
+    } else {
+      setHackValue(undefined)
+    }
+  }
   const columns = [
     {
       dataIndex: 'name',
@@ -71,10 +94,19 @@ const CustomerAdditions = () => {
               </Select>
               <RangePicker
                 picker={type}
-                allowClear={false}
+                // allowClear={false}
                 value={state.params.startMonth}
-                // onChange={val => console.log(dayjs(val).format())}
-                onChange={val => setState({ ...state, params: { ...state.params, startMonth: val, dateType: type } })}
+                disabledDate={disabledDate}
+                onCalendarChange={val => setDates(val)}
+                onChange={() => {
+                  if (type === 'week' || (type === 'date' && state.params.startMonth?.length === 2)) {
+                    return console.log('转化周、日')
+                  } else {
+                    return console.log('转化月')
+                  }
+                }}
+                onOpenChange={onOpenChange}
+                // onChange={val => setState({ ...state, params: { ...state.params, startMonth: val, dateType: type } })}
               />
             </Space>
           ]