wenlele 2 years ago
parent
commit
5031e58cd0
  1. 4
      api/app/lib/controllers/patrolPlan/patrolPlan.js
  2. 53
      web/client/src/sections/patrolManage/components/planModal.js
  3. 52
      web/client/src/sections/patrolManage/containers/patrolPlan.js

4
api/app/lib/controllers/patrolPlan/patrolPlan.js

@ -63,9 +63,9 @@ async function updatePatrolPlan(ctx, next) {
let errMsg = '修改巡检计划失败'; let errMsg = '修改巡检计划失败';
const models = ctx.fs.dc.models; const models = ctx.fs.dc.models;
const data = ctx.request.body; const data = ctx.request.body;
const { name, startTime, endTime, frequency, patrolPerson } = data; const { name, way, structureId, startTime, endTime, frequency, points, userId } = data;
let plan = { name, startTime, endTime, frequency, patrolPerson }; let plan = { name, way, structureId, startTime, endTime, frequency, points, userId };
if (data && data.id) { if (data && data.id) {
await models.PatrolPlan.update(plan, { await models.PatrolPlan.update(plan, {

53
web/client/src/sections/patrolManage/components/planModal.js

@ -2,19 +2,33 @@ import { Button, Form, Input, Modal, Select, DatePicker } from 'antd';
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { getUserList, getProjectList, positionList } from '../actions/plan'; import { getUserList, getProjectList, positionList } from '../actions/plan';
import moment from 'moment';
const { RangePicker } = DatePicker; 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 [userOpt, setUserOpt] = useState();
const [struOpt, setStruOpt] = useState(); const [struOpt, setStruOpt] = useState();
const [pointOpt, setPointOpt] = useState(); const [pointOpt, setPointOpt] = useState();
const [points, setPoints] = useState();
const [unit, setUnit] = useState('次/天'); const [unit, setUnit] = useState('次/天');
const [form] = Form.useForm(); const [form] = Form.useForm();
useEffect(() => { useEffect(() => {
dispatch(getUserList()) if (type === 'view') {
dispatch(getProjectList())
} 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(() => { useEffect(() => {
@ -47,16 +61,21 @@ const PlanModal = ({ visible, onCreate, onCancel, dispatch, userLoading, userLis
onCancel(); onCancel();
}} }}
onOk={() => { onOk={() => {
if (type === 'view') {
form.resetFields();
onCancel();
return;
}
form form
.validateFields() .validateFields()
.then((values) => { .then((values) => {
form.resetFields(); form.resetFields();
const params = { const params = {
...values,
frequency: values.frequency + unit, frequency: values.frequency + unit,
startTime: values.time[0], startTime: values.time[0],
endTime: values.time[1], endTime: values.time[1],
points: pointOpt.filter(p => p.id == values.points), points: points[0]?.points?.filter(p => values?.points?.includes(p.id))
...values
} }
onCreate(params); onCreate(params);
}) })
@ -70,8 +89,13 @@ const PlanModal = ({ visible, onCreate, onCancel, dispatch, userLoading, userLis
layout="vertical" layout="vertical"
name="form_in_modal" name="form_in_modal"
initialValues={{ 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 <Form.Item
name="structureId" name="structureId"
@ -80,9 +104,10 @@ const PlanModal = ({ visible, onCreate, onCancel, dispatch, userLoading, userLis
{ required: true, message: '请选择结构物' }, { 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 => { dispatch(positionList({ projectId: value })).then(res => {
if (res.success) { if (res.success) {
setPoints(res.payload.data?.rows)
setPointOpt(res.payload.data?.rows[0]?.points?.map(p => ({ label: p.name, value: p.id }))) 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: '请输入巡检任务名称' }, { required: true, message: '请输入巡检任务名称' },
]} ]}
> >
<Input /> <Input disabled={type === 'view'} />
</Form.Item> </Form.Item>
<Form.Item <Form.Item
name="way" name="way"
@ -103,7 +128,7 @@ const PlanModal = ({ visible, onCreate, onCancel, dispatch, userLoading, userLis
rules={[ rules={[
{ required: true, message: '请选择巡检方式' }, { required: true, message: '请选择巡检方式' },
]} ]}
initialValue='周期巡检' initialValue='周期巡检'
> >
<Select options={[{ <Select options={[{
label: '周期巡检', label: '周期巡检',
@ -117,7 +142,7 @@ const PlanModal = ({ visible, onCreate, onCancel, dispatch, userLoading, userLis
{ required: true, message: '请选择巡检频次' }, { required: true, message: '请选择巡检频次' },
]} ]}
> >
<Input addonAfter={selectAfter} /> <Input addonAfter={selectAfter} disabled={type === 'view'} />
</Form.Item> </Form.Item>
<Form.Item <Form.Item
name="time" name="time"
@ -126,7 +151,7 @@ const PlanModal = ({ visible, onCreate, onCancel, dispatch, userLoading, userLis
{ required: true, message: '请选择任务周期' }, { required: true, message: '请选择任务周期' },
]} ]}
> >
<RangePicker /> <RangePicker disabled={type === 'view'} />
</Form.Item> </Form.Item>
<Form.Item <Form.Item
name="points" name="points"
@ -135,7 +160,7 @@ const PlanModal = ({ visible, onCreate, onCancel, dispatch, userLoading, userLis
{ required: true, message: '请选择巡检点' }, { required: true, message: '请选择巡检点' },
]} ]}
> >
<Select options={pointOpt} disabled={!pointOpt} /> <Select mode="multiple" options={pointOpt} disabled={!pointOpt || type === 'view'} />
</Form.Item> </Form.Item>
<Form.Item <Form.Item
name="userId" name="userId"
@ -144,7 +169,7 @@ const PlanModal = ({ visible, onCreate, onCancel, dispatch, userLoading, userLis
{ required: true, message: '请选择巡检人员' }, { 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) const curUser = userList.filter(u => u.id == value)
if (curUser.length) { if (curUser.length) {
form.setFieldsValue({ form.setFieldsValue({
@ -160,7 +185,7 @@ const PlanModal = ({ visible, onCreate, onCancel, dispatch, userLoading, userLis
<Input disabled /> <Input disabled />
</Form.Item> </Form.Item>
</Form> </Form>
</Modal> </Modal >
); );
}; };

52
web/client/src/sections/patrolManage/containers/patrolPlan.js

@ -4,20 +4,30 @@ import { Button, Popconfirm } from 'antd';
import ProTable from '@ant-design/pro-table'; import ProTable from '@ant-design/pro-table';
import PlanModal from '../components/planModal'; import PlanModal from '../components/planModal';
import { createPatrolPlan, delPatrolPlan, updatePatrolPlan, getPatrolPlan } from '../actions/plan'; import { createPatrolPlan, delPatrolPlan, updatePatrolPlan, getPatrolPlan } from '../actions/plan';
import moment from 'moment';
function PatrolPlan(props) { function PatrolPlan(props) {
const { dispatch, user } = props; const { dispatch, user } = props;
const tableRef = useRef(); const tableRef = useRef();
const [dataSource, setDataSource] = useState([{}]); const [dataSource, setDataSource] = useState([{}]);
const [visible, setVisible] = useState(false); const [visible, setVisible] = useState(false);
const [type, setType] = useState();
const [curRecord, setCurRecord] = useState();
const onCreate = (values) => { const onCreate = (values) => {
console.log(values, 'values') if (type === 'create') {
dispatch(createPatrolPlan(values)).then(res => { dispatch(createPatrolPlan(values)).then(res => {
if (res.success) { if (res.success) {
tableRef.current.reload(); tableRef.current.reload();
} }
}) })
} else {
dispatch(updatePatrolPlan({ ...values, id: curRecord.id })).then(res => {
if (res.success) {
tableRef.current.reload();
}
})
}
setVisible(false); setVisible(false);
}; };
@ -25,7 +35,10 @@ function PatrolPlan(props) {
title: '结构物名称', title: '结构物名称',
dataIndex: 'struName', dataIndex: 'struName',
key: 'struName', key: 'struName',
ellipsis: true ellipsis: true,
render: (_, record) => {
return <div>{record?.project?.name}</div>
}
}, { }, {
title: '巡检任务名称', title: '巡检任务名称',
dataIndex: 'name', dataIndex: 'name',
@ -36,11 +49,14 @@ function PatrolPlan(props) {
dataIndex: 'startTime', dataIndex: 'startTime',
key: 'startTime', key: 'startTime',
ellipsis: true, ellipsis: true,
render: (_, record) => moment(record.startTime).format('YYYY-MM-DD')
}, { }, {
title: '结束时间', title: '结束时间',
dataIndex: 'endTime', dataIndex: 'endTime',
key: 'endTime', key: 'endTime',
ellipsis: true, ellipsis: true,
render: (_, record) => moment(record.endTime).format('YYYY-MM-DD')
}, { }, {
title: '巡检频次', title: '巡检频次',
dataIndex: 'frequency', dataIndex: 'frequency',
@ -51,12 +67,13 @@ function PatrolPlan(props) {
dataIndex: 'patrolPoints', dataIndex: 'patrolPoints',
key: 'patrolPoints', key: 'patrolPoints',
ellipsis: true, ellipsis: true,
render: (_, record) => <div>{record?.points?.length ? record?.points?.map(p => p.name).join() : '-'}</div>
}, { }, {
title: '巡检人', title: '巡检人',
dataIndex: 'patrolPerson', dataIndex: 'patrolPerson',
key: 'patrolPerson', key: 'patrolPerson',
ellipsis: true, ellipsis: true,
render: (_, record) => <div></div> render: (_, record) => <div>{record?.user?.name}</div>
}, { }, {
title: '巡检次数统计', title: '巡检次数统计',
dataIndex: 'patrolCount', dataIndex: 'patrolCount',
@ -69,8 +86,16 @@ function PatrolPlan(props) {
search: false, search: false,
render: (_, record) => { render: (_, record) => {
return <> return <>
<Button type="link">修改</Button> <Button type="link" onClick={() => {
<Button type="link">查看</Button> setType('edit')
setCurRecord(record)
setVisible(true)
}}>修改</Button>
<Button type="link" onClick={() => {
setType('view')
setCurRecord(record)
setVisible(true)
}}>查看</Button>
<Popconfirm <Popconfirm
title="确认删除?" title="确认删除?"
onConfirm={() => { onConfirm={() => {
@ -106,7 +131,10 @@ function PatrolPlan(props) {
<Button <Button
type="primary" type="primary"
key="primary" key="primary"
onClick={() => { setVisible(true) }} onClick={() => {
setType('create')
setVisible(true)
}}
>新增巡检计划</Button> >新增巡检计划</Button>
]} ]}
/> />
@ -115,6 +143,8 @@ function PatrolPlan(props) {
<PlanModal <PlanModal
visible={visible} visible={visible}
onCreate={onCreate} onCreate={onCreate}
type={type}
curRecord={curRecord}
onCancel={() => { onCancel={() => {
setVisible(false); setVisible(false);
}} }}

Loading…
Cancel
Save