Commit 7440e1c0 authored by 前端-黄佳鑫's avatar 前端-黄佳鑫

🐞 fix(平台营销活动管理): 修复修改活动报名结束时间不能大于活动开始时间

parent 11cdc33d
......@@ -70,6 +70,38 @@ const ModalBox: React.FC<ModalBoxProps> = ({
}
}, [params])
const startTimeDisabled = (current, name) => {
const _endTime = form.getFieldValue(name);
if (_endTime) {
return (
current &&
(current <
moment()
.max(_endTime)
.startOf('hour') ||
moment(current).diff(moment(_endTime), 'hour'))
);
} else {
return current && current < moment().startOf('hour');
}
};
const endTimeDisabled = (current, name) => {
const _startTime = form.getFieldValue(name);
if (_startTime) {
return (
current &&
(current <
moment()
.min(_startTime)
.startOf('hour') ||
moment(current).diff(moment(_startTime), 'hour') < 1)
);
} else {
return current && current < moment().startOf('hour');
}
};
return (
<Modal
width={600}
......@@ -92,64 +124,75 @@ const ModalBox: React.FC<ModalBoxProps> = ({
<Space style={{ display: 'flex' }} align='baseline'>
<Form.Item
name='startTime'
validateFirst
dependencies={['signUpStartTime', 'endTime', 'signUpEndTime']}
rules={[
() => ({
async validator(_, value) {
let _exVal = await form.getFieldValue('endTime');
if (!value) {
return Promise.reject(new Error('请选择活动开始时间!'));
rules={[{
required: true,
message: '请选择活动开始时间'
},
({ getFieldValue }) => ({
validator: (_rule, value) => {
const _endTime = getFieldValue('endTime');
const _signUpStartTime = getFieldValue('signUpStartTime');
const _signUpEndTime = getFieldValue('signUpEndTime');
if (_endTime && !moment(value).isBefore(_endTime)) {
return Promise.reject(new Error('活动开始时间必须小于活动结束时间'));
}
if (_exVal && moment(value).isAfter(_exVal)) {
return Promise.reject(new Error('活动开始时间需要早于活动结束时间'));
if (_signUpStartTime && !moment(value).isAfter(_signUpStartTime)) {
return Promise.reject(new Error('活动开始时间必须大于报名开始时间'));
}
if (_signUpEndTime && !moment(value).isAfter(_signUpEndTime)) {
return Promise.reject(new Error('活动开始时间必须大于报名结束时间'));
}
return Promise.resolve();
}
})
]}>
]}
>
<DatePicker
showTime
showNow={false}
allowClear
disabledDate={(current) => {
const _endTime = form.getFieldValue('endTime');
if (_endTime) {
return current && ((moment(current).diff(moment(_endTime), 'day') > 0) || current < moment().startOf('second'))
} else {
return current && current < moment().startOf('second')
}
}} />
disabledDate={(current) => startTimeDisabled(current, 'endTime')}
/>
</Form.Item>
~
<Form.Item
name='endTime'
validateFirst
dependencies={['signUpStartTime', 'startTime', 'signUpEndTime']}
rules={[
() => ({
async validator(_, value) {
let _exVal = await form.getFieldValue('startTime');
if (!value) {
return Promise.reject(new Error('请选择活动结束时间!'));
rules={[{
required: true,
message: '请选择活动结束时间'
},
({ getFieldValue }) => ({
validator: (_rule, value) => {
const _startTime = getFieldValue('startTime');
const _signUpStartTime = getFieldValue('signUpStartTime');
const _signUpEndTime = getFieldValue('signUpEndTime');
if (_startTime && !moment(value).isAfter(_startTime)) {
return Promise.reject(new Error('活动结束时间必须大于活动开始时间'));
}
if (_signUpStartTime && !moment(value).isAfter(_signUpStartTime)) {
return Promise.reject(new Error('活动结束时间必须大于报名开始时间'));
}
if (_exVal && moment(value).isBefore(_exVal)) {
return Promise.reject(new Error('活动结束时间需要晚于活动开始时间'));
if (_signUpEndTime && !moment(value).isAfter(_signUpEndTime)) {
return Promise.reject(new Error('活动结束时间必须大于报名结束时间'));
}
if (!moment(value).isAfter(moment(new Date()))) {
return Promise.reject(new Error('活动结束时间必须大于当前时间'));
}
return Promise.resolve();
}
})
]}>
]}
>
<DatePicker
showTime
showNow={false}
allowClear
disabledDate={(current) => {
const _startTime = form.getFieldValue('startTime');
if (_startTime) {
return current && current < moment(_startTime).startOf('second')
} else {
return current && current < moment().startOf('second')
}
}} />
disabledDate={(current) => endTimeDisabled(current, 'startTime')}
/>
</Form.Item>
</Space>
</Form.Item>
......@@ -162,64 +205,72 @@ const ModalBox: React.FC<ModalBoxProps> = ({
<Space style={{ display: 'flex' }} align='baseline'>
<Form.Item
name='signUpStartTime'
validateFirst
dependencies={['endTime', 'startTime', 'signUpEndTime']}
rules={[
() => ({
async validator(_, value) {
let _exVal = await form.getFieldValue('signUpEndTime');
if (!value) {
return Promise.reject(new Error('请选择要求报名时间!'));
rules={[{
required: true,
message: '请选择报名开始时间'
},
({ getFieldValue }) => ({
validator: (_rule, value) => {
const _startTime = getFieldValue('startTime');
const _endTime = getFieldValue('endTime');
const _signUpEndTime = getFieldValue('signUpEndTime');
if (_startTime && !moment(value).isBefore(_startTime)) {
return Promise.reject(new Error('报名开始时间必须小于于活动开始时间'));
}
if (_endTime && !moment(value).isBefore(_endTime)) {
return Promise.reject(new Error('报名开始时间必须小于活动结束时间'));
}
if (_exVal && moment(value).isAfter(_exVal)) {
return Promise.reject(new Error('要求报名时间需要早于活动结束时间'));
if (_signUpEndTime && !moment(value).isBefore(_signUpEndTime)) {
return Promise.reject(new Error('报名开始时间必须小于报名结束时间'));
}
return Promise.resolve();
}
})
]}>
]}
>
<DatePicker
showTime
showNow={false}
allowClear
disabledDate={(current) => {
const _endTime = form.getFieldValue('signUpEndTime');
if (_endTime) {
return current && ((moment(current).diff(moment(_endTime), 'day') > 0) || current < moment().startOf('second'))
} else {
return current && current < moment().startOf('second')
}
}} />
disabledDate={(current) => startTimeDisabled(current, 'signUpEndTime')}
/>
</Form.Item>
~
<Form.Item
name='signUpEndTime'
validateFirst
dependencies={['endTime', 'startTime', 'signUpStartTime']}
rules={[
() => ({
async validator(_, value) {
let _exVal = await form.getFieldValue('signUpStartTime');
if (!value) {
return Promise.reject(new Error('活请选择活动结束时间!'));
rules={[{
required: true,
message: '请选择报名结束时间!'
},
({ getFieldValue }) => ({
validator: (_rule, value) => {
const _startTime = getFieldValue('startTime');
const _endTime = getFieldValue('endTime');
const _signUpStartTime = getFieldValue('signUpStartTime');
if (_startTime && !moment(value).isBefore(_startTime)) {
return Promise.reject(new Error('报名结束时间必须小于于活动开始时间'));
}
if (_exVal && moment(value).isBefore(_exVal)) {
return Promise.reject(new Error('活动结束时间需要晚于要求报名时间'));
if (_endTime && !moment(value).isBefore(_endTime)) {
return Promise.reject(new Error('报名结束时间必须小于活动结束时间'));
}
if (_signUpStartTime && !moment(value).isAfter(_signUpStartTime)) {
return Promise.reject(new Error('报名结束时间必须大于报名开始时间'));
}
return Promise.resolve();
}
})
]}>
]}
>
<DatePicker
showTime
showNow={false}
allowClear
disabledDate={(current) => {
const _startTime = form.getFieldValue('signUpStartTime');
if (_startTime) {
return current && current < moment(_startTime).startOf('second')
} else {
return current && current < moment().startOf('second')
}
}} />
disabledDate={(current) => endTimeDisabled(current, 'signUpStartTime')}
/>
</Form.Item>
</Space>
</Form.Item>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment