|
|
@@ -2,9 +2,11 @@ import React, { useCallback, useMemo } from 'react'
|
|
|
import classNames from 'classnames'
|
|
|
import dayjs from 'dayjs'
|
|
|
import { useInfo } from '../InfoContext'
|
|
|
-import { Cascader, DatePicker, Input, Select } from 'antd'
|
|
|
+import { Cascader, DatePicker, Input, Radio, Select } from 'antd'
|
|
|
import TextArea from 'antd/es/input/TextArea'
|
|
|
|
|
|
+const { RangePicker } = DatePicker
|
|
|
+
|
|
|
type Props = {
|
|
|
item: any
|
|
|
isLook: boolean
|
|
|
@@ -39,6 +41,22 @@ function EditInput({ item, isLook, isTow }: Props) {
|
|
|
setInfoFu({ ...infoRes, dictIdApply: val ? val.join(',') : '' }, isTow)
|
|
|
} else if (type === 'Select') {
|
|
|
setInfoFu({ ...infoRes, [key]: val }, isTow)
|
|
|
+ } else if (type === 'DatePicker2') {
|
|
|
+ const keys = Array.isArray(key) ? key : [key]
|
|
|
+ const modeKey = item.modeKey
|
|
|
+ if (val?.type === 'longterm') {
|
|
|
+ const update: any = { [keys[0]]: '', [keys[1]]: '' }
|
|
|
+ if (modeKey) update[modeKey] = 'longterm'
|
|
|
+ setInfoFu({ ...infoRes, ...update }, isTow)
|
|
|
+ } else if (val?.type === 'range') {
|
|
|
+ const [start, end] = val?.dates || [null, null]
|
|
|
+ const update: any = {
|
|
|
+ [keys[0]]: start ? dayjs(start).format('YYYY-MM-DD') : '',
|
|
|
+ [keys[1]]: end ? dayjs(end).format('YYYY-MM-DD') : ''
|
|
|
+ }
|
|
|
+ if (modeKey) update[modeKey] = 'range'
|
|
|
+ setInfoFu({ ...infoRes, ...update }, isTow)
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
[infoRes, isTow, setInfoFu]
|
|
|
@@ -109,6 +127,46 @@ function EditInput({ item, isLook, isTow }: Props) {
|
|
|
options={item.options}
|
|
|
allowClear={!item.must}
|
|
|
/>
|
|
|
+ ) : item.type === 'DatePicker2' ? (
|
|
|
+ (() => {
|
|
|
+ const keys = Array.isArray(item.key) ? item.key : [item.key]
|
|
|
+ const modeKey = item.modeKey as string | undefined
|
|
|
+ const startVal = infoRes[keys[0] as keyof typeof infoRes]
|
|
|
+ const endVal = infoRes[keys[1] as keyof typeof infoRes]
|
|
|
+ const modeVal = modeKey ? infoRes[modeKey as keyof typeof infoRes] : null
|
|
|
+ const isLongterm = modeVal === 'longterm' || (!modeVal && !startVal && !endVal)
|
|
|
+ const rangeValue = startVal && endVal ? [dayjs(startVal), dayjs(endVal)] : null
|
|
|
+ return (
|
|
|
+ <div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
|
|
|
+ <Radio.Group
|
|
|
+ disabled={isLook}
|
|
|
+ value={isLongterm ? 'longterm' : 'range'}
|
|
|
+ onChange={e => {
|
|
|
+ const v = e.target.value
|
|
|
+ dataChangeFu(
|
|
|
+ v === 'longterm'
|
|
|
+ ? { type: 'longterm' }
|
|
|
+ : { type: 'range', dates: [null, null] },
|
|
|
+ item
|
|
|
+ )
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <Radio value='longterm'>长期</Radio>
|
|
|
+ <Radio value='range'>定期</Radio>
|
|
|
+ </Radio.Group>
|
|
|
+ {!isLongterm && (
|
|
|
+ <RangePicker
|
|
|
+ disabled={isLook}
|
|
|
+ allowClear={!item.must}
|
|
|
+ value={rangeValue as [dayjs.Dayjs, dayjs.Dayjs]}
|
|
|
+ onChange={dates =>
|
|
|
+ dataChangeFu({ type: 'range', dates: dates || [null, null] }, item)
|
|
|
+ }
|
|
|
+ />
|
|
|
+ )}
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+ })()
|
|
|
) : null}
|
|
|
</div>
|
|
|
</div>
|