import { Button, Form, Input, Modal, Select, DatePicker } from 'antd';
import React, { useState, useEffect } from 'react';
import { connect } from 'react-redux';
import { getUserList, getProjectList, positionList } from '../actions/plan';
import moment from 'moment';
const { RangePicker } = DatePicker;
const PlanModal = ({ visible, onCreate, onCancel, dispatch, userLoading, userList, structureList, struLoading, type, curRecord, templateLoading, patrolTemplate }) => {
const [userOpt, setUserOpt] = useState();
const [struOpt, setStruOpt] = useState();
const [pointOpt, setPointOpt] = useState();
const [points, setPoints] = useState();
const [unit, setUnit] = useState('次/天');
const [form] = Form.useForm();
useEffect(() => {
if (type === 'view') {
} else {
dispatch(getUserList())
dispatch(getProjectList())
}
if (type === 'edit') {
dispatch(positionList({ projectId: curRecord?.project?.id })).then(res => {
if (res.success) {
setPoints(res.payload.data?.rows)
setPointOpt(res.payload.data?.rows[0]?.points?.map(p => ({ label: p.name, value: p.id })))
}
})
}
}, [])
useEffect(() => {
if (userList.length) {
setUserOpt(userList.map(u => ({ label: u.name, value: u.id })))
}
}, [userList])
useEffect(() => {
if (structureList?.rows?.length) {
setStruOpt(structureList?.rows?.map(s => ({ label: s.name, value: s.id })))
}
}, [structureList])
const selectAfter = (
);
return (
{
form.resetFields();
onCancel();
}}
onOk={() => {
if (type === 'view') {
form.resetFields();
onCancel();
return;
}
form
.validateFields()
.then((values) => {
form.resetFields();
const params = {
...values,
frequency: values.frequency + unit,
startTime: values.time[0],
endTime: values.time[1],
points: points[0]?.points?.filter(p => values?.points?.includes(p.id))
}
onCreate(params);
})
.catch((info) => {
console.log('Validate Failed:', info);
});
}}
>
);
};
function mapStateToProps (state) {
const { auth, userList, structureList, patrolTemplate } = state
return {
user: auth.user,
userList: userList.data || [],
structureList: structureList.data || [],
patrolTemplate: (patrolTemplate.data || { rows: [] }).rows,
userLoading: userList.isRequesting,
struLoading: structureList.isRequesting,
templateLoading: patrolTemplate.isRequesting,
}
}
export default connect(mapStateToProps)(PlanModal);