Browse Source

巡检计划完善

master
liujiangyong 2 years ago
parent
commit
c5f893741d
  1. 4
      api/app/lib/controllers/patrolPlan/patrolPlan.js
  2. 52
      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 = '修改巡检计划失败';
const models = ctx.fs.dc.models;
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) {
await models.PatrolPlan.update(plan, {

52
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 { 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,12 @@ 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
}}
disabled={type === 'view'}
>
<Form.Item
name="structureId"
@ -80,9 +103,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 +119,7 @@ const PlanModal = ({ visible, onCreate, onCancel, dispatch, userLoading, userLis
{ required: true, message: '请输入巡检任务名称' },
]}
>
<Input />
<Input disabled={type === 'view'} />
</Form.Item>
<Form.Item
name="way"
@ -103,7 +127,7 @@ const PlanModal = ({ visible, onCreate, onCancel, dispatch, userLoading, userLis
rules={[
{ required: true, message: '请选择巡检方式' },
]}
initialValue='周期巡检'
initialValue='周期巡检'
>
<Select options={[{
label: '周期巡检',
@ -117,7 +141,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 +150,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 +159,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 +168,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 +184,7 @@ const PlanModal = ({ visible, onCreate, onCancel, dispatch, userLoading, userLis
<Input disabled />
</Form.Item>
</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 PlanModal from '../components/planModal';
import { createPatrolPlan, delPatrolPlan, updatePatrolPlan, getPatrolPlan } from '../actions/plan';
import moment from 'moment';
function PatrolPlan(props) {
const { dispatch, user } = props;
const tableRef = useRef();
const [dataSource, setDataSource] = useState([{}]);
const [visible, setVisible] = useState(false);
const [type, setType] = useState();
const [curRecord, setCurRecord] = useState();
const onCreate = (values) => {
console.log(values, 'values')
dispatch(createPatrolPlan(values)).then(res => {
if (res.success) {
tableRef.current.reload();
}
})
if (type === 'create') {
dispatch(createPatrolPlan(values)).then(res => {
if (res.success) {
tableRef.current.reload();
}
})
} else {
dispatch(updatePatrolPlan({ ...values, id: curRecord.id })).then(res => {
if (res.success) {
tableRef.current.reload();
}
})
}
setVisible(false);
};
@ -25,7 +35,10 @@ function PatrolPlan(props) {
title: '结构物名称',
dataIndex: 'struName',
key: 'struName',
ellipsis: true
ellipsis: true,
render: (_, record) => {
return <div>{record?.project?.name}</div>
}
}, {
title: '巡检任务名称',
dataIndex: 'name',
@ -36,11 +49,14 @@ function PatrolPlan(props) {
dataIndex: 'startTime',
key: 'startTime',
ellipsis: true,
render: (_, record) => moment(record.startTime).format('YYYY-MM-DD')
}, {
title: '结束时间',
dataIndex: 'endTime',
key: 'endTime',
ellipsis: true,
render: (_, record) => moment(record.endTime).format('YYYY-MM-DD')
}, {
title: '巡检频次',
dataIndex: 'frequency',
@ -51,12 +67,13 @@ function PatrolPlan(props) {
dataIndex: 'patrolPoints',
key: 'patrolPoints',
ellipsis: true,
render: (_, record) => <div>{record?.points?.length ? record?.points?.map(p => p.name).join() : '-'}</div>
}, {
title: '巡检人',
dataIndex: 'patrolPerson',
key: 'patrolPerson',
ellipsis: true,
render: (_, record) => <div></div>
render: (_, record) => <div>{record?.user?.name}</div>
}, {
title: '巡检次数统计',
dataIndex: 'patrolCount',
@ -69,8 +86,16 @@ function PatrolPlan(props) {
search: false,
render: (_, record) => {
return <>
<Button type="link">修改</Button>
<Button type="link">查看</Button>
<Button type="link" onClick={() => {
setType('edit')
setCurRecord(record)
setVisible(true)
}}>修改</Button>
<Button type="link" onClick={() => {
setType('view')
setCurRecord(record)
setVisible(true)
}}>查看</Button>
<Popconfirm
title="确认删除?"
onConfirm={() => {
@ -106,7 +131,10 @@ function PatrolPlan(props) {
<Button
type="primary"
key="primary"
onClick={() => { setVisible(true) }}
onClick={() => {
setType('create')
setVisible(true)
}}
>新增巡检计划</Button>
]}
/>
@ -115,6 +143,8 @@ function PatrolPlan(props) {
<PlanModal
visible={visible}
onCreate={onCreate}
type={type}
curRecord={curRecord}
onCancel={() => {
setVisible(false);
}}

Loading…
Cancel
Save