lanjianrong vor 4 Jahren
Ursprung
Commit
433d93637f
1 geänderte Dateien mit 21 neuen und 20 gelöschten Zeilen
  1. 21 20
      src/pages/Statistic/Product/CustomerAdditions/index.jsx

+ 21 - 20
src/pages/Statistic/Product/CustomerAdditions/index.jsx

@@ -14,10 +14,10 @@ const CustomerAdditions = () => {
     params: {
       optionType: 'singleStaff',
       dataIds: [],
-      startMonth: [dayjs(new Date()), dayjs(new Date())],
-      dateType: 'month'
+      startMonth: [dayjs(new Date()), dayjs(new Date())]
     },
-    list: []
+    chart: {},
+    type: 'month'
   })
 
   const [type, setType] = useState('month')
@@ -31,12 +31,8 @@ const CustomerAdditions = () => {
     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
+    const tooLate = dates[0] && current.diff(dates[0], 'month') > 10
+    const tooEarly = dates[1] && dates[1].diff(current, 'month') > 10
     return tooEarly || tooLate
   }
   const onOpenChange = open => {
@@ -66,6 +62,20 @@ const CustomerAdditions = () => {
       render: text => <div className="text-right">{text}</div>
     }
   ]
+
+  const handleOnChange = val => {
+    console.log(state.type)
+    if (val?.length !== 2) return
+    if (state.type === 'month') {
+      const [startTime, endTime] = val
+      setState({
+        ...state,
+        params: { ...state.params, startMonth: [startTime.startOf('month'), endTime.endOf('month')] }
+      })
+    } else {
+      setState({ ...state, params: { ...state.params, startMonth: val } })
+    }
+  }
   return (
     <div className="flex flex-col">
       <div className="flex flex-row justify-between mb-4">
@@ -87,26 +97,17 @@ const CustomerAdditions = () => {
           title: [<OptionSelect onChange={handleOptionChange} type="CustomerAdditions" key="op" multiple={false} />],
           actions: [
             <Space key="id">
-              <Select value={type} onChange={setType}>
+              <Select value={state.type} onChange={value => setState({ ...state, type: value })}>
                 <Option value="month">月</Option>
                 <Option value="week">周</Option>
                 <Option value="date">日</Option>
               </Select>
               <RangePicker
                 picker={type}
-                // allowClear={false}
-                value={state.params.startMonth}
                 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 } })}
+                onChange={val => handleOnChange(val)}
               />
             </Space>
           ]