|
@@ -1,6 +1,6 @@
|
|
|
import BasicTable from '@/components/Table'
|
|
import BasicTable from '@/components/Table'
|
|
|
import consts from '@/consts'
|
|
import consts from '@/consts'
|
|
|
-import React, { useRef, useState } from 'react'
|
|
|
|
|
|
|
+import React, { useRef, useState, useEffect } from 'react'
|
|
|
import { DatePicker, Select, Space } from 'antd'
|
|
import { DatePicker, Select, Space } from 'antd'
|
|
|
import { Column } from '@ant-design/charts'
|
|
import { Column } from '@ant-design/charts'
|
|
|
import dayjs from 'dayjs'
|
|
import dayjs from 'dayjs'
|
|
@@ -10,54 +10,61 @@ import { queryCustomerAdditionList } from '@/services/statistic'
|
|
|
import { PageContainer } from '@ant-design/pro-layout'
|
|
import { PageContainer } from '@ant-design/pro-layout'
|
|
|
|
|
|
|
|
const { Option } = Select
|
|
const { Option } = Select
|
|
|
-const { RangePicker } = DatePicker
|
|
|
|
|
const columnGroupMap = {
|
|
const columnGroupMap = {
|
|
|
client: '客户',
|
|
client: '客户',
|
|
|
company: '单位'
|
|
company: '单位'
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+const dateTypeOptions = [
|
|
|
|
|
+ { label: '月', value: 'month' },
|
|
|
|
|
+ { label: '周', value: 'week' },
|
|
|
|
|
+ { label: '日', value: 'day' }
|
|
|
|
|
+]
|
|
|
|
|
+
|
|
|
const CustomerAdditions = () => {
|
|
const CustomerAdditions = () => {
|
|
|
const [state, setState] = useState({
|
|
const [state, setState] = useState({
|
|
|
params: {
|
|
params: {
|
|
|
optionType: 'singleStaff',
|
|
optionType: 'singleStaff',
|
|
|
dataIds: [],
|
|
dataIds: [],
|
|
|
dateType: 'month',
|
|
dateType: 'month',
|
|
|
- startMonth: [dayjs(new Date()), dayjs(new Date())]
|
|
|
|
|
|
|
+ startMonth: null
|
|
|
},
|
|
},
|
|
|
- data: [],
|
|
|
|
|
- type: 'month'
|
|
|
|
|
|
|
+ data: []
|
|
|
})
|
|
})
|
|
|
- const [dates, setDates] = useState([])
|
|
|
|
|
- const [hackValue, setHackValue] = useState()
|
|
|
|
|
- const tRef = useRef(null)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+ setState({ ...state, params: { ...state.params, startMonth: [dayjs(new Date()), dayjs(new Date())] } })
|
|
|
|
|
+ console.log(state.params.startMonth)
|
|
|
|
|
+ }, [])
|
|
|
|
|
+
|
|
|
|
|
+ const [dates, setDates] = useState(null)
|
|
|
|
|
+ const [hackValue, setHackValue] = useState(null)
|
|
|
const handleOptionChange = (type, ids) =>
|
|
const handleOptionChange = (type, ids) =>
|
|
|
setState({ ...state, params: { ...state.params, optionType: type, dataIds: ids } })
|
|
setState({ ...state, params: { ...state.params, optionType: type, dataIds: ids } })
|
|
|
|
|
+
|
|
|
const disabledDate = current => {
|
|
const disabledDate = current => {
|
|
|
if (!dates || dates.length === 0) {
|
|
if (!dates || dates.length === 0) {
|
|
|
return false
|
|
return false
|
|
|
}
|
|
}
|
|
|
- if (state.type === 'month') {
|
|
|
|
|
- const tooLate = dates[0] && current.diff(dates[0], 'month') > 10
|
|
|
|
|
- const tooEarly = dates[1] && dates[1].diff(current, 'month') > 10
|
|
|
|
|
- return tooEarly || tooLate
|
|
|
|
|
- }
|
|
|
|
|
- if (state.type === 'week') {
|
|
|
|
|
- const tooLate = dates[0] && current.diff(dates[0], 'weeks') > 11
|
|
|
|
|
- const tooEarly = dates[1] && dates[1].diff(current, 'weeks') > 11
|
|
|
|
|
- return tooEarly || tooLate
|
|
|
|
|
- }
|
|
|
|
|
- if (state.type === 'date') {
|
|
|
|
|
- const tooLate = dates[0] && current.diff(dates[0], 'days') > 29
|
|
|
|
|
- const tooEarly = dates[1] && dates[1].diff(current, 'days') > 29
|
|
|
|
|
- return tooEarly || tooLate
|
|
|
|
|
|
|
+ let tooLate, tooEarly
|
|
|
|
|
+ if (state.params.dateType === 'month') {
|
|
|
|
|
+ tooLate = dates[0] && current.diff(dates[0], 'month') > 10
|
|
|
|
|
+ tooEarly = dates[1] && dates[1].diff(current, 'month') > 10
|
|
|
|
|
+ } else if (state.params.dateType === 'week') {
|
|
|
|
|
+ tooLate = dates[0] && current.diff(dates[0], 'weeks') > 11
|
|
|
|
|
+ tooEarly = dates[1] && dates[1].diff(current, 'weeks') > 11
|
|
|
|
|
+ } else {
|
|
|
|
|
+ tooLate = dates[0] && current.diff(dates[0], 'days') > 29
|
|
|
|
|
+ tooEarly = dates[1] && dates[1].diff(current, 'days') > 29
|
|
|
}
|
|
}
|
|
|
- // return tooEarly || tooLate
|
|
|
|
|
|
|
+ return !!tooEarly || !!tooLate
|
|
|
}
|
|
}
|
|
|
const onOpenChange = open => {
|
|
const onOpenChange = open => {
|
|
|
if (open) {
|
|
if (open) {
|
|
|
- setHackValue([])
|
|
|
|
|
- setDates([])
|
|
|
|
|
|
|
+ setHackValue([null, null])
|
|
|
|
|
+ setDates([null, null])
|
|
|
} else {
|
|
} else {
|
|
|
- setHackValue(undefined)
|
|
|
|
|
|
|
+ setHackValue(null)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
const columns = [
|
|
const columns = [
|
|
@@ -80,28 +87,23 @@ const CustomerAdditions = () => {
|
|
|
}
|
|
}
|
|
|
]
|
|
]
|
|
|
|
|
|
|
|
- const dateTypeOptions = [
|
|
|
|
|
- { label: '月', value: 'month' },
|
|
|
|
|
- { label: '周', value: 'week' },
|
|
|
|
|
- { label: '日', value: 'date' }
|
|
|
|
|
- ]
|
|
|
|
|
const handleOnChange = val => {
|
|
const handleOnChange = val => {
|
|
|
// console.log(state.type)
|
|
// console.log(state.type)
|
|
|
if (val?.length !== 2) return
|
|
if (val?.length !== 2) return
|
|
|
- if (state.type === 'month') {
|
|
|
|
|
|
|
+ console.log(val)
|
|
|
|
|
+ if (state.params.dateType === 'month') {
|
|
|
const [startTime, endTime] = val
|
|
const [startTime, endTime] = val
|
|
|
setState({
|
|
setState({
|
|
|
...state,
|
|
...state,
|
|
|
params: {
|
|
params: {
|
|
|
...state.params,
|
|
...state.params,
|
|
|
- startMonth: [startTime.startOf('month'), endTime.endOf('month')],
|
|
|
|
|
- dateType: state.type
|
|
|
|
|
|
|
+ startMonth: [startTime.startOf('month'), endTime.endOf('month')]
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
} else {
|
|
} else {
|
|
|
setState({
|
|
setState({
|
|
|
...state,
|
|
...state,
|
|
|
- params: { ...state.params, startMonth: val, dateType: state.type === 'date' ? 'day' : state.type }
|
|
|
|
|
|
|
+ params: { ...state.params, startMonth: val }
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -143,10 +145,8 @@ const CustomerAdditions = () => {
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
<BasicTable
|
|
<BasicTable
|
|
|
- // manualRequest
|
|
|
|
|
search={false}
|
|
search={false}
|
|
|
columns={columns}
|
|
columns={columns}
|
|
|
- actionRef={tRef}
|
|
|
|
|
rowkey="id"
|
|
rowkey="id"
|
|
|
params={state.params}
|
|
params={state.params}
|
|
|
pagination={false}
|
|
pagination={false}
|
|
@@ -163,19 +163,14 @@ const CustomerAdditions = () => {
|
|
|
actions: [
|
|
actions: [
|
|
|
<Space key="id">
|
|
<Space key="id">
|
|
|
<Select
|
|
<Select
|
|
|
- value={state.type}
|
|
|
|
|
|
|
+ defaultValue="month"
|
|
|
options={dateTypeOptions}
|
|
options={dateTypeOptions}
|
|
|
- onChange={value => setState({ ...state, type: value })}
|
|
|
|
|
|
|
+ onChange={value => setState({ ...state, params: { ...state.params, dateType: value } })}
|
|
|
/>
|
|
/>
|
|
|
- {/* <Option value="month">月</Option>
|
|
|
|
|
- <Option value="week">周</Option>
|
|
|
|
|
- <Option value="date">日</Option> */}
|
|
|
|
|
- {/* </Select> */}
|
|
|
|
|
- <RangePicker
|
|
|
|
|
- picker={state.type}
|
|
|
|
|
|
|
+ <DatePicker.RangePicker
|
|
|
|
|
+ picker={state.params.dateType}
|
|
|
disabledDate={disabledDate}
|
|
disabledDate={disabledDate}
|
|
|
// allowClear={false}
|
|
// allowClear={false}
|
|
|
- // value={state.params.startMonth}
|
|
|
|
|
value={hackValue || state.params.startMonth}
|
|
value={hackValue || state.params.startMonth}
|
|
|
onCalendarChange={val => setDates(val)}
|
|
onCalendarChange={val => setDates(val)}
|
|
|
onOpenChange={onOpenChange}
|
|
onOpenChange={onOpenChange}
|