|
|
@ -2,19 +2,33 @@ 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 }) => { |
|
|
|
const PlanModal = ({ visible, onCreate, onCancel, dispatch, userLoading, userList, structureList, struLoading, type, curRecord }) => { |
|
|
|
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(() => { |
|
|
|
dispatch(getUserList()) |
|
|
|
dispatch(getProjectList()) |
|
|
|
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(() => { |
|
|
@ -47,16 +61,21 @@ const PlanModal = ({ visible, onCreate, onCancel, dispatch, userLoading, userLis |
|
|
|
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: pointOpt.filter(p => p.id == values.points), |
|
|
|
...values |
|
|
|
points: points[0]?.points?.filter(p => values?.points?.includes(p.id)) |
|
|
|
} |
|
|
|
onCreate(params); |
|
|
|
}) |
|
|
@ -70,8 +89,13 @@ const PlanModal = ({ visible, onCreate, onCancel, dispatch, userLoading, userLis |
|
|
|
layout="vertical" |
|
|
|
name="form_in_modal" |
|
|
|
initialValues={{ |
|
|
|
modifier: 'public', |
|
|
|
...curRecord, |
|
|
|
time: [moment(curRecord?.startTime), moment(curRecord?.startTime)], |
|
|
|
points: curRecord?.points?.map(p => p.id), |
|
|
|
userDept: curRecord?.user?.department?.name, |
|
|
|
frequency: curRecord?.frequency?.split('次')[0] |
|
|
|
}} |
|
|
|
disabled={type === 'view'} |
|
|
|
> |
|
|
|
<Form.Item |
|
|
|
name="structureId" |
|
|
@ -80,9 +104,10 @@ const PlanModal = ({ visible, onCreate, onCancel, dispatch, userLoading, userLis |
|
|
|
{ required: true, message: '请选择结构物' }, |
|
|
|
]} |
|
|
|
> |
|
|
|
<Select options={struOpt} loading={struLoading} onChange={(value) => { |
|
|
|
<Select disabled={type === 'view'} options={struOpt} loading={struLoading} onChange={(value) => { |
|
|
|
dispatch(positionList({ projectId: value })).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 }))) |
|
|
|
} |
|
|
|
}) |
|
|
@ -95,7 +120,7 @@ const PlanModal = ({ visible, onCreate, onCancel, dispatch, userLoading, userLis |
|
|
|
{ required: true, message: '请输入巡检任务名称' }, |
|
|
|
]} |
|
|
|
> |
|
|
|
<Input /> |
|
|
|
<Input disabled={type === 'view'} /> |
|
|
|
</Form.Item> |
|
|
|
<Form.Item |
|
|
|
name="way" |
|
|
@ -117,7 +142,7 @@ const PlanModal = ({ visible, onCreate, onCancel, dispatch, userLoading, userLis |
|
|
|
{ required: true, message: '请选择巡检频次' }, |
|
|
|
]} |
|
|
|
> |
|
|
|
<Input addonAfter={selectAfter} /> |
|
|
|
<Input addonAfter={selectAfter} disabled={type === 'view'} /> |
|
|
|
</Form.Item> |
|
|
|
<Form.Item |
|
|
|
name="time" |
|
|
@ -126,7 +151,7 @@ const PlanModal = ({ visible, onCreate, onCancel, dispatch, userLoading, userLis |
|
|
|
{ required: true, message: '请选择任务周期' }, |
|
|
|
]} |
|
|
|
> |
|
|
|
<RangePicker /> |
|
|
|
<RangePicker disabled={type === 'view'} /> |
|
|
|
</Form.Item> |
|
|
|
<Form.Item |
|
|
|
name="points" |
|
|
@ -135,7 +160,7 @@ const PlanModal = ({ visible, onCreate, onCancel, dispatch, userLoading, userLis |
|
|
|
{ required: true, message: '请选择巡检点' }, |
|
|
|
]} |
|
|
|
> |
|
|
|
<Select options={pointOpt} disabled={!pointOpt} /> |
|
|
|
<Select mode="multiple" options={pointOpt} disabled={!pointOpt || type === 'view'} /> |
|
|
|
</Form.Item> |
|
|
|
<Form.Item |
|
|
|
name="userId" |
|
|
@ -144,7 +169,7 @@ const PlanModal = ({ visible, onCreate, onCancel, dispatch, userLoading, userLis |
|
|
|
{ required: true, message: '请选择巡检人员' }, |
|
|
|
]} |
|
|
|
> |
|
|
|
<Select options={userOpt} loading={userLoading} onChange={(value) => { |
|
|
|
<Select disabled={type === 'view'} options={userOpt} loading={userLoading} onChange={(value) => { |
|
|
|
const curUser = userList.filter(u => u.id == value) |
|
|
|
if (curUser.length) { |
|
|
|
form.setFieldsValue({ |
|
|
@ -160,7 +185,7 @@ const PlanModal = ({ visible, onCreate, onCancel, dispatch, userLoading, userLis |
|
|
|
<Input disabled /> |
|
|
|
</Form.Item> |
|
|
|
</Form> |
|
|
|
</Modal> |
|
|
|
</Modal > |
|
|
|
); |
|
|
|
}; |
|
|
|
|
|
|
|