|
|
@@ -1,17 +1,22 @@
|
|
|
-import React, { useCallback } from 'react'
|
|
|
+import React, { useCallback, useMemo } from 'react'
|
|
|
import classNames from 'classnames'
|
|
|
import dayjs from 'dayjs'
|
|
|
import { useInfo } from '../InfoContext'
|
|
|
-import { Cascader, DatePicker, Input } from 'antd'
|
|
|
+import { Cascader, DatePicker, Input, Select } from 'antd'
|
|
|
import TextArea from 'antd/es/input/TextArea'
|
|
|
|
|
|
type Props = {
|
|
|
item: any
|
|
|
isLook: boolean
|
|
|
+ isTow?: boolean //是否是第二个模块
|
|
|
}
|
|
|
|
|
|
-function EditInput({ item, isLook }: Props) {
|
|
|
- const { info, setInfoFu } = useInfo()
|
|
|
+function EditInput({ item, isLook, isTow }: Props) {
|
|
|
+ const { info, info2, setInfoFu } = useInfo()
|
|
|
+
|
|
|
+ const infoRes = useMemo(() => {
|
|
|
+ return isTow ? info2 : info
|
|
|
+ }, [info, info2, isTow])
|
|
|
|
|
|
// 数据改变
|
|
|
const dataChangeFu = useCallback(
|
|
|
@@ -20,37 +25,43 @@ function EditInput({ item, isLook }: Props) {
|
|
|
const key = item.key
|
|
|
|
|
|
if (type === 'DatePicker') {
|
|
|
- setInfoFu({ ...info, [key]: dayjs(val).format('YYYY-MM-DD') })
|
|
|
+ setInfoFu({ ...infoRes, [key]: dayjs(val).format('YYYY-MM-DD') }, isTow)
|
|
|
} else if (['TextArea', 'Input'].includes(type)) {
|
|
|
const varRes = item.noNull ? val.replace(/\s+/g, '') : val
|
|
|
- setInfoFu({
|
|
|
- ...info,
|
|
|
- [key]: varRes
|
|
|
- })
|
|
|
+ setInfoFu(
|
|
|
+ {
|
|
|
+ ...infoRes,
|
|
|
+ [key]: varRes
|
|
|
+ },
|
|
|
+ isTow
|
|
|
+ )
|
|
|
} else if (type === 'Cascader') {
|
|
|
- setInfoFu({ ...info, dictIdApply: val ? val.join(',') : '' })
|
|
|
+ setInfoFu({ ...infoRes, dictIdApply: val ? val.join(',') : '' }, isTow)
|
|
|
+ } else if (type === 'Select') {
|
|
|
+ setInfoFu({ ...infoRes, [key]: val }, isTow)
|
|
|
}
|
|
|
},
|
|
|
- [info, setInfoFu]
|
|
|
+ [infoRes, isTow, setInfoFu]
|
|
|
)
|
|
|
|
|
|
return (
|
|
|
<div className={classNames('Edtop1row', item.full ? 'Edtop1rowFull' : '')}>
|
|
|
<div className='Edtop1ll'>
|
|
|
{item.must ? <span>* </span> : null}
|
|
|
- {item.name}:
|
|
|
+ <i dangerouslySetInnerHTML={{ __html: item.name + ':' }}></i>
|
|
|
</div>
|
|
|
|
|
|
<div className='Edtop1rr'>
|
|
|
{item.type === 'txt' ? (
|
|
|
<>
|
|
|
- {dayjs(info.createTime).format('YYYY年MM月DD日')}-{info.deptName}-{info.creatorName}
|
|
|
+ {dayjs(infoRes.createTime).format('YYYY年MM月DD日')}-{infoRes.deptName}-
|
|
|
+ {infoRes.creatorName}
|
|
|
</>
|
|
|
) : item.type === 'DatePicker' ? (
|
|
|
<DatePicker
|
|
|
disabled={isLook}
|
|
|
allowClear={!item.must}
|
|
|
- value={dayjs(info[item.key as 'date'])}
|
|
|
+ value={dayjs(infoRes[item.key as 'date'])}
|
|
|
onChange={e => dataChangeFu(e, item)}
|
|
|
disabledDate={current => current && current > dayjs().endOf('day')}
|
|
|
/>
|
|
|
@@ -58,7 +69,7 @@ function EditInput({ item, isLook }: Props) {
|
|
|
<Input
|
|
|
readOnly={isLook}
|
|
|
placeholder={isLook ? '(空)' : '请输入'}
|
|
|
- value={info[item.key as 'date']}
|
|
|
+ value={infoRes[item.key as 'date']}
|
|
|
onChange={e => dataChangeFu(e.target.value, item)}
|
|
|
maxLength={item.maxLength || 30}
|
|
|
showCount
|
|
|
@@ -71,18 +82,32 @@ function EditInput({ item, isLook }: Props) {
|
|
|
placeholder={isLook ? '(空)' : '请选择'}
|
|
|
fieldNames={{ label: 'name', value: 'id', children: 'children' }}
|
|
|
allowClear={!item.must}
|
|
|
- value={info[item.key as 'date'] ? (info[item.key as 'date'] as string).split(',') : []}
|
|
|
+ value={
|
|
|
+ infoRes[item.key as 'date'] ? (infoRes[item.key as 'date'] as string).split(',') : []
|
|
|
+ }
|
|
|
onChange={e => dataChangeFu(e, item)}
|
|
|
/>
|
|
|
) : item.type === 'TextArea' ? (
|
|
|
<TextArea
|
|
|
readOnly={isLook}
|
|
|
placeholder={isLook ? '(空)' : '请输入'}
|
|
|
- value={info[item.key as 'date']}
|
|
|
+ value={infoRes[item.key as 'date']}
|
|
|
onChange={e => dataChangeFu(e.target.value, item)}
|
|
|
maxLength={item.maxLength || 500}
|
|
|
showCount
|
|
|
/>
|
|
|
+ ) : item.type === 'Select' ? (
|
|
|
+ <Select
|
|
|
+ disabled={isLook}
|
|
|
+ showSearch // 启用搜索功能
|
|
|
+ filterOption={(input: any, option: any) =>
|
|
|
+ (option?.label ?? '').toLowerCase().includes(input.toLowerCase())
|
|
|
+ }
|
|
|
+ placeholder={(isLook ? '(空)' : item.placeholder) || '请选择'}
|
|
|
+ onChange={e => dataChangeFu(e, item)}
|
|
|
+ options={item.options}
|
|
|
+ allowClear={!item.must}
|
|
|
+ />
|
|
|
) : null}
|
|
|
</div>
|
|
|
</div>
|