Commit 0f16ee87 authored by 邓超's avatar 邓超

fix: 日历交互优化及问题修改

parent d2c4b872
Pipeline #65352 passed with stages
import React, { useState, useEffect, useRef } from 'react';
import { Form, Modal, Input, message, Radio, Select, AutoComplete } from 'antd';
import { ExclamationCircleOutlined } from '@ant-design/icons';
import { AddFlowHoliday, DeleteFlowHoliday } from '@/services/holidays/holidays';
const { confirm } = Modal;
const holidaysList = new Set(['元旦', '春节', '清明节', '劳动节', '端午节', '中秋节', '国庆节']);
const HolidayConfig = props => {
const { visible, onSubumit, handleCancel, msg } = props;
const [options, setOptions] = useState([]);
const [flag, setFlag] = useState(0);
const [form] = Form.useForm();
const [formRest] = Form.useForm();
useEffect(() => {
if (visible) {
let obj = msg.msg;
console.log(msg.holidayOptions);
let list = [...holidaysList].map(item => ({ value: item, label: item }));
if (obj.nWeek === 6) {
list.push({ value: '周六', label: '周六' });
}
if (obj.nWeek === 7) {
list.push({ value: '周日', label: '周日' });
}
console.log(list, 'list');
setOptions(list);
if (!msg.isRest) {
confirm({
title: '确定要改为休息吗?',
icon: <ExclamationCircleOutlined />,
content: (
<div>
<div>{`${msg.msg.date}(${obj.ncWeek})`}</div>
<Form
form={form}
preserve={false}
labelCol={{ span: 6 }}
wrapperCol={{ span: 18 }}
initialValues={{ remember: true }}
labelAlign="left"
>
<Form.Item
label="假期名称"
name="dayName"
style={{
margin: '10px 0 0 0',
}}
>
{obj.nWeek === 6 || obj.nWeek === 7 ? (
<Select placeholder="请选择假日名称" options={msg.holidayOptions} />
) : (
<AutoComplete placeholder="请输入假日名称" options={msg.holidayOptions} />
)}
</Form.Item>
</Form>
</div>
),
okText: '是',
okType: 'primary',
cancelText: '否',
onOk() {
return new Promise((resolve, reject) => {
form.validateFields().then(validate => {
let name;
name = validate.dayName;
// if (validate.dayName === '周六') {
// name = '周六';
// }
// if (validate.dayName === '周日') {
// name = '周日';
// }
let dayType = 1;
if (validate.dayName === '周六' || validate.dayName === '周日') {
dayType = 2;
}
if (holidaysList.has(validate.dayName)) {
dayType = 3;
}
if (validate.dayName) {
AddFlowHoliday({
dayName: name,
dayType,
startDate: msg.date,
endDate: msg.date,
}).then(res => {
if (res.code === 0) {
message.success('修改成功');
onSubumit();
resolve();
} else {
message.error(res.msg);
reject();
}
});
} else {
message.error('请填写假期名称');
reject();
}
});
});
},
onCancel() {
handleCancel();
},
});
} else if (obj.nWeek !== 6 && obj.nWeek !== 7) {
confirm({
title: '确定要改为工作吗?',
icon: <ExclamationCircleOutlined />,
content: `${msg.date}(${obj.ncWeek})`,
okText: '是',
okType: 'primary',
cancelText: '否',
onOk() {
// setCanSelect(true);
DeleteFlowHoliday({ dayDate: msg.date }).then(res => {
if (res.code === 0) {
message.success('删除成功');
onSubumit();
} else {
message.error(res.msg);
}
});
},
onCancel() {
handleCancel();
},
});
}
}
}, [visible]);
const onFinish = () => {
formRest.validateFields().then(values => {
console.log(values);
if (values.dayType === 1) {
DeleteFlowHoliday({ dayDate: msg.date }).then(res => {
if (res.code === 0) {
message.success('删除成功');
onSubumit();
} else {
message.error(res.msg);
}
});
} else {
AddFlowHoliday({
dayName: values.dayName,
dayType: values.dayName === '周日' || values.dayName === '周六' ? 2 : 3,
startDate: msg.date,
endDate: msg.date,
}).then(res => {
if (res.code === 0) {
message.success('修改成功');
onSubumit();
} else {
message.error(res.msg);
}
});
}
});
};
const onFieldsChange = changedFields => {
if (changedFields[0].name[0] === 'dayType') {
setFlag(flag + 1);
}
};
return (
<div>
<Modal
title={null}
visible={visible && (msg.msg.nWeek === 6 || msg.msg.nWeek === 7)}
onOk={onFinish}
onCancel={handleCancel}
maskClosable={false}
destroyOnClose
width={416}
>
<Form
form={formRest}
preserve={false}
labelCol={{ span: 6 }}
wrapperCol={{ span: 18 }}
initialValues={{ remember: true }}
onFieldsChange={onFieldsChange}
labelAlign="left"
>
<Form.Item
label="操作类型"
name="dayType"
style={{ margin: '10px 0 0 0' }}
initialValue={1}
>
<Radio.Group>
<Radio value={1}>改为上班</Radio>
<Radio value={2}>改为节假日</Radio>
</Radio.Group>
</Form.Item>
<Form.Item
label="假期名称"
name="dayName"
rules={[
{
required: formRest.getFieldValue('dayType') === 2,
},
]}
style={{
margin: '10px 0 0 0',
display: formRest.getFieldValue('dayType') === 2 ? 'flex' : 'none',
}}
>
{msg.msg.nWeek === 6 || msg.msg.nWeek === 7 ? (
<Select placeholder="请选择假日名称" options={options} />
) : (
<AutoComplete placeholder="请输入假日名称" options={options} />
)}
</Form.Item>
</Form>
</Modal>
</div>
);
};
export default HolidayConfig;
...@@ -18,7 +18,7 @@ const WorkTiemConfig = props => { ...@@ -18,7 +18,7 @@ const WorkTiemConfig = props => {
const getFormData = () => { const getFormData = () => {
console.log(msg, 'msg'); console.log(msg, 'msg');
form.setFieldsValue({ form.setFieldsValue({
workTime: [moment(msg.from, 'HH:mm:ss'), moment(msg.to, 'HH:mm:ss')], workTime: [moment(msg.from, 'HH:mm'), moment(msg.to, 'HH:mm')],
}); });
}; };
// 时间段是否重叠 // 时间段是否重叠
...@@ -34,9 +34,9 @@ const WorkTiemConfig = props => { ...@@ -34,9 +34,9 @@ const WorkTiemConfig = props => {
let obj = {}; let obj = {};
console.log(modalType); console.log(modalType);
console.log(validate); console.log(validate);
console.log(moment(validate.workTime[0]._d).format('HH:mm:ss')); console.log(moment(validate.workTime[0]._d).format('HH:mm'));
let startTime = moment(validate.workTime[0]._d).format('HH:mm:ss'); let startTime = moment(validate.workTime[0]._d).format('HH:mm');
let endTime = moment(validate.workTime[1]._d).format('HH:mm:ss'); let endTime = moment(validate.workTime[1]._d).format('HH:mm');
for (let i = 0; i < allTime.length; i++) { for (let i = 0; i < allTime.length; i++) {
if (allTime[i].name !== msg.name) { if (allTime[i].name !== msg.name) {
console.log(`${moment().format('YYYY-MM-DD')} ${allTime[i].from}`); console.log(`${moment().format('YYYY-MM-DD')} ${allTime[i].from}`);
...@@ -79,7 +79,7 @@ const WorkTiemConfig = props => { ...@@ -79,7 +79,7 @@ const WorkTiemConfig = props => {
initialValues={{ remember: true }} initialValues={{ remember: true }}
> >
<Form.Item label="工作时间" name="workTime"> <Form.Item label="工作时间" name="workTime">
<TimePicker.RangePicker /> <TimePicker.RangePicker format="HH:mm" />
</Form.Item> </Form.Item>
</Form> </Form>
</Modal> </Modal>
......
...@@ -13,6 +13,7 @@ import { ...@@ -13,6 +13,7 @@ import {
Input, Input,
Radio, Radio,
Upload, Upload,
AutoComplete,
} from 'antd'; } from 'antd';
import { import {
ImportOutlined, ImportOutlined,
...@@ -39,8 +40,11 @@ import classNames from 'classnames'; ...@@ -39,8 +40,11 @@ import classNames from 'classnames';
import WorkTiemConfig from './components/WorkTiemConfig'; import WorkTiemConfig from './components/WorkTiemConfig';
import AddModal from './components/AddModal'; import AddModal from './components/AddModal';
import Synchronize from './components/Synchronize'; import Synchronize from './components/Synchronize';
import HolidayConfig from './components/HolidayConfig';
import styles from './holidays.less'; import styles from './holidays.less';
const { confirm } = Modal; const { confirm } = Modal;
const holidaysList = new Set(['元旦', '春节', '清明节', '劳动节', '端午节', '中秋节', '国庆节']);
moment.updateLocale('zh-cn', { moment.updateLocale('zh-cn', {
weekdaysMin: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'], weekdaysMin: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
}); });
...@@ -83,7 +87,9 @@ const Holidays = () => { ...@@ -83,7 +87,9 @@ const Holidays = () => {
holiday: false, holiday: false,
workTime: false, workTime: false,
synchronize: false, synchronize: false,
calendar: false,
}); });
const workTime = useRef([ const workTime = useRef([
{ {
icon: require('../../../../assets/images/holidays/icon1.png'), icon: require('../../../../assets/images/holidays/icon1.png'),
...@@ -111,8 +117,10 @@ const Holidays = () => { ...@@ -111,8 +117,10 @@ const Holidays = () => {
const calendarHoliday = useRef(new Map()); // 日历上得假期 const calendarHoliday = useRef(new Map()); // 日历上得假期
const queryData = useRef({ year: new Date().getFullYear(), month: new Date().getMonth() + 1 }); const queryData = useRef({ year: new Date().getFullYear(), month: new Date().getMonth() + 1 });
const tableData = useRef([]); const tableData = useRef([]);
const editDateMsg = useRef({ isRest: '', date: '', msg: '', holidayOptions: '' });
const [currentDate, setCurrentDate] = useState(moment().format('YYYY-MM-DD')); const [currentDate, setCurrentDate] = useState(moment().format('YYYY-MM-DD'));
const [form] = Form.useForm(); const [form] = Form.useForm();
const [formRest] = Form.useForm();
useEffect(() => { useEffect(() => {
document.querySelector('.ant-picker-content').setAttribute('border', 1); document.querySelector('.ant-picker-content').setAttribute('border', 1);
let year = new Date().getFullYear(); let year = new Date().getFullYear();
...@@ -146,16 +154,16 @@ const Holidays = () => { ...@@ -146,16 +154,16 @@ const Holidays = () => {
workTime.current.forEach(item => { workTime.current.forEach(item => {
switch (item.name) { switch (item.name) {
case '上午': case '上午':
item.from = res.data.WorkTime.WORKTIME_MOR_FROM; item.from = res.data.WorkTime ? res.data.WorkTime.WORKTIME_MOR_FROM : '00:00';
item.to = res.data.WorkTime.WORKTIME_MOR_TO; item.to = res.data.WorkTime ? res.data.WorkTime.WORKTIME_MOR_TO : '00:00';
break; break;
case '下午': case '下午':
item.from = res.data.WorkTime.WORKTIME_AFT_FROM; item.from = res.data.WorkTime ? res.data.WorkTime.WORKTIME_AFT_FROM : '00:00';
item.to = res.data.WorkTime.WORKTIME_AFT_TO; item.to = res.data.WorkTime ? res.data.WorkTime.WORKTIME_AFT_TO : '00:00';
break; break;
case '晚上': case '晚上':
item.from = res.data.WorkTime.WORKTIME_EVE_FROM; item.from = res.data.WorkTime ? res.data.WorkTime.WORKTIME_EVE_FROM : '00:00';
item.to = res.data.WorkTime.WORKTIME_EVE_TO; item.to = res.data.WorkTime ? res.data.WorkTime.WORKTIME_EVE_TO : '00:00';
break; break;
default: default:
...@@ -164,11 +172,10 @@ const Holidays = () => { ...@@ -164,11 +172,10 @@ const Holidays = () => {
}); });
console.log(workTime.current, 'workTime.current'); console.log(workTime.current, 'workTime.current');
const obj = JSON.parse(JSON.stringify(holidayStatistics)); const obj = JSON.parse(JSON.stringify(holidayStatistics));
obj.Holidays.value = res.data.HolidayStatistics?.Holidays;
obj.Holidays.value = res.data.HolidayStatistics.Holidays; obj.SumDays.value = res.data.HolidayStatistics?.SumDays;
obj.SumDays.value = res.data.HolidayStatistics.SumDays; obj.TakeDays.value = res.data.HolidayStatistics?.TakeDays;
obj.TakeDays.value = res.data.HolidayStatistics.TakeDays; obj.WeekendDays.value = res.data.HolidayStatistics?.WeekendDays;
obj.WeekendDays.value = res.data.HolidayStatistics.WeekendDays;
setHolidayStatistics(obj); setHolidayStatistics(obj);
// setFlag(flag + 1); // setFlag(flag + 1);
} }
...@@ -176,9 +183,8 @@ const Holidays = () => { ...@@ -176,9 +183,8 @@ const Holidays = () => {
}; };
// 删除节假日 // 删除节假日
const delRow = record => { const delRow = record => {
let dayDate = record.DayDate.split(',') console.log(record, 'record');
.map(item => `${queryData.current.year}-${item}`) let dayDate = record.DayDate;
.join(',');
DeleteFlowHoliday({ dayDate }).then(res => { DeleteFlowHoliday({ dayDate }).then(res => {
if (res.code === 0) { if (res.code === 0) {
message.success('删除成功'); message.success('删除成功');
...@@ -201,109 +207,21 @@ const Holidays = () => { ...@@ -201,109 +207,21 @@ const Holidays = () => {
queryData.current.month = month; queryData.current.month = month;
getData(year, month); getData(year, month);
}; };
// 点击到的日期 // 点击到的日期
const onSelect = (value, obj) => { const onSelect = (value, obj) => {
let date = value.format('YYYY-MM-DD'); let date = value.format('YYYY-MM-DD');
if (calendarHoliday.current.has(date)) { let options = tableData.current.map(item => ({
confirm({ value: item.DayName,
title: '确定要改为工作吗?', label: item.DayName,
icon: <ExclamationCircleOutlined />, }));
content: `${date}(${obj.ncWeek})`, editDateMsg.current = {
okText: '是', isRest: calendarHoliday.current.has(date),
okType: 'primary', date,
cancelText: '否', msg: obj,
onOk() { holidayOptions: options,
// setCanSelect(true); };
DeleteFlowHoliday({ dayDate: date }).then(res => { setVisible({ ...visible, calendar: true });
if (res.code === 0) {
message.success('删除成功');
getData(queryData.current.year, queryData.current.month);
} else {
message.error(res.msg);
}
});
},
onCancel() {},
});
} else {
confirm({
title: '确定要改为休息吗?',
icon: <ExclamationCircleOutlined />,
content: (
<div>
<div>{`${date}(${obj.ncWeek})`}</div>
<Form
form={form}
preserve={false}
labelCol={{ span: 6 }}
wrapperCol={{ span: 18 }}
initialValues={{ remember: true }}
labelAlign="left"
>
<Form.Item
label="假期名称"
name="dayName"
style={{
display: obj.nWeek === 6 || obj.nWeek === 7 ? 'none' : 'flex',
margin: '10px 0 0 0',
}}
>
<Input placeholder="请输入假日名称" />
</Form.Item>
{/* <Form.Item
label="节假日类型"
name="dayType"
style={{ margin: '10px 0 0 0' }}
initialValue={1}
>
<Radio.Group>
<Radio value={1}>调休</Radio>
<Radio value={3}>法定</Radio>
</Radio.Group>
</Form.Item> */}
</Form>
</div>
),
okText: '是',
okType: 'primary',
cancelText: '否',
onOk() {
return new Promise((resolve, reject) => {
form.validateFields().then(validate => {
let name;
name = validate.dayName;
if (obj.nWeek === 6) {
name = '周六';
}
if (obj.nWeek === 7) {
name = '周日';
}
if (validate.dayName || obj.nWeek === 6 || obj.nWeek === 7) {
AddFlowHoliday({
dayName: name,
dayType: obj.nWeek === 7 || obj.nWeek === 6 ? 2 : 1,
startDate: date,
endDate: date,
}).then(res => {
if (res.code === 0) {
message.success('修改成功');
getData(queryData.current.year, queryData.current.month);
resolve();
} else {
message.error(res.msg);
reject();
}
});
} else {
message.error('请填写假期名称');
reject();
}
});
});
},
onCancel() {},
});
}
}; };
// 日历渲染替换 // 日历渲染替换
const dateCellRender = value => { const dateCellRender = value => {
...@@ -552,6 +470,11 @@ const Holidays = () => { ...@@ -552,6 +470,11 @@ const Holidays = () => {
value > moment(`${queryData.current.year}-${queryData.current.month}`).endOf('month') value > moment(`${queryData.current.year}-${queryData.current.month}`).endOf('month')
); );
}; };
// 日历保存回调
const calendarSubmit = () => {
setVisible({ ...visible, calendar: false });
getData(queryData.current.year, queryData.current.month);
};
return ( return (
<div <div
...@@ -581,8 +504,9 @@ const Holidays = () => { ...@@ -581,8 +504,9 @@ const Holidays = () => {
</div> </div>
</div> </div>
<div className={styles.content}> <div className={styles.content}>
{workTime.current.map(item => ( {workTime.current?.map(item => (
<div <div
title="点击修改工作时间"
className={classNames(styles.workTimeBox, { className={classNames(styles.workTimeBox, {
[styles.mor]: item.name === '上午', [styles.mor]: item.name === '上午',
[styles.aft]: item.name === '下午', [styles.aft]: item.name === '下午',
...@@ -646,6 +570,15 @@ const Holidays = () => { ...@@ -646,6 +570,15 @@ const Holidays = () => {
<div className={styles.header}> <div className={styles.header}>
<div className={styles.title}> <div className={styles.title}>
{item.DayName}({item.DayDate?.split(',').length}天) {item.DayName}({item.DayDate?.split(',').length}天)
<img
src={require('/src/assets/images/holidays/Holiday.png')}
alt=""
style={{
width: '25px',
marginLeft: '10px',
display: holidaysList.has(item.DayName) ? 'inline-block' : 'none',
}}
/>
</div> </div>
<div <div
className={styles.del} className={styles.del}
...@@ -694,6 +627,12 @@ const Holidays = () => { ...@@ -694,6 +627,12 @@ const Holidays = () => {
onSubumit={startSynchronize} onSubumit={startSynchronize}
handleCancel={() => setVisible({ ...visible, synchronize: false })} handleCancel={() => setVisible({ ...visible, synchronize: false })}
/> />
<HolidayConfig
visible={visible.calendar}
onSubumit={calendarSubmit}
msg={editDateMsg.current}
handleCancel={() => setVisible({ ...visible, calendar: false })}
/>
</div> </div>
); );
}; };
......
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