|
@ -1,34 +1,27 @@ |
|
|
import { Button, Form, Input, Modal, Select } from 'antd'; |
|
|
import { Button, Form, Input, Modal, Select } 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 { getCheckItemsGroup } from '../actions/checkItems'; |
|
|
import { getCheckItemsGroup } from '../actions/checkItems'; |
|
|
import moment from 'moment'; |
|
|
import moment from 'moment'; |
|
|
|
|
|
|
|
|
const CheckItemsModal = ({ visible, onCreate, onCancel, dispatch, type, curRecord }) => { |
|
|
const CheckItemsModal = ({ visible, onOk, onCancel, curRecord, dispatch }) => { |
|
|
const [pointOpt, setPointOpt] = useState(); |
|
|
const [group, setGroup] = useState([]); |
|
|
const [points, setPoints] = useState(); |
|
|
|
|
|
const [isNewGroup, setIsNewGroup] = useState(false); |
|
|
const [isNewGroup, setIsNewGroup] = useState(false); |
|
|
const [form] = Form.useForm(); |
|
|
const [form] = Form.useForm(); |
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
useEffect(() => { |
|
|
dispatch(getCheckItemsGroup()); |
|
|
dispatch(getCheckItemsGroup()).then(res => { |
|
|
if (type === 'create') { |
|
|
if (res.success) { |
|
|
dispatch(getUserList()) |
|
|
const opt = res.payload.data?.map(g => ({ value: g.id, label: g.name })); |
|
|
} else { |
|
|
setGroup(opt); |
|
|
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 }))) |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
}, []) |
|
|
}, []) |
|
|
|
|
|
|
|
|
return ( |
|
|
return ( |
|
|
<Modal |
|
|
<Modal |
|
|
visible={visible} |
|
|
visible={visible} |
|
|
title="新增巡检计划" |
|
|
title={curRecord ? "检查项修改" : "检查项添加"} |
|
|
okText="确定" |
|
|
okText="确定" |
|
|
cancelText="取消" |
|
|
cancelText="取消" |
|
|
onCancel={() => { |
|
|
onCancel={() => { |
|
@ -36,22 +29,15 @@ const CheckItemsModal = ({ visible, onCreate, onCancel, dispatch, type, curRecor |
|
|
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, |
|
|
...values, |
|
|
startTime: values.time[0], |
|
|
isNewGroup |
|
|
endTime: values.time[1], |
|
|
|
|
|
points: points[0]?.points?.filter(p => values?.points?.includes(p.id)) |
|
|
|
|
|
} |
|
|
} |
|
|
onCreate(params); |
|
|
onOk(params); |
|
|
}) |
|
|
}) |
|
|
.catch((info) => { |
|
|
.catch((info) => { |
|
|
console.log('Validate Failed:', info); |
|
|
console.log('Validate Failed:', info); |
|
@ -64,10 +50,8 @@ const CheckItemsModal = ({ visible, onCreate, onCancel, dispatch, type, curRecor |
|
|
name="form_in_modal" |
|
|
name="form_in_modal" |
|
|
initialValues={{ |
|
|
initialValues={{ |
|
|
...curRecord, |
|
|
...curRecord, |
|
|
points: curRecord?.points?.map(p => p.id), |
|
|
|
|
|
userDept: curRecord?.user?.department?.name, |
|
|
userDept: curRecord?.user?.department?.name, |
|
|
}} |
|
|
}} |
|
|
disabled={type === 'view'} |
|
|
|
|
|
> |
|
|
> |
|
|
<Form.Item |
|
|
<Form.Item |
|
|
name="name" |
|
|
name="name" |
|
@ -79,34 +63,30 @@ const CheckItemsModal = ({ visible, onCreate, onCancel, dispatch, type, curRecor |
|
|
<Input /> |
|
|
<Input /> |
|
|
</Form.Item> |
|
|
</Form.Item> |
|
|
<Form.Item |
|
|
<Form.Item |
|
|
name="groupName" |
|
|
name="group" |
|
|
label="分组名称" |
|
|
label="分组名称" |
|
|
rules={[ |
|
|
rules={[ |
|
|
{ required: true, message: '请选择分组' }, |
|
|
{ required: true, message: '请选择分组' }, |
|
|
]} |
|
|
]} |
|
|
> |
|
|
> |
|
|
{ |
|
|
{ |
|
|
isNewGroup ? |
|
|
isNewGroup |
|
|
<Select options={pointOpt} disabled={!pointOpt || type === 'view'} /> : |
|
|
? <Input /> |
|
|
<Input /> |
|
|
: <Select options={group} loading={!group?.length} /> |
|
|
} |
|
|
} |
|
|
</Form.Item> |
|
|
</Form.Item> |
|
|
</Form> |
|
|
</Form> |
|
|
<Button type='link' onClick={() => { |
|
|
<Button type='link' onClick={() => { |
|
|
setIsNewGroup(!isNewGroup); |
|
|
setIsNewGroup(!isNewGroup); |
|
|
}}>创建分组</Button> |
|
|
}}>{isNewGroup ? '选择已有' : '创建分组'}</Button> |
|
|
</Modal > |
|
|
</Modal > |
|
|
); |
|
|
); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
function mapStateToProps(state) { |
|
|
function mapStateToProps(state) { |
|
|
const { auth, userList, structureList } = state |
|
|
const { auth } = state |
|
|
return { |
|
|
return { |
|
|
user: auth.user, |
|
|
user: auth.user, |
|
|
userList: userList.data || [], |
|
|
|
|
|
structureList: structureList.data || [], |
|
|
|
|
|
userLoading: userList.isRequesting, |
|
|
|
|
|
struLoading: structureList.isRequesting |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
export default connect(mapStateToProps)(CheckItemsModal); |
|
|
export default connect(mapStateToProps)(CheckItemsModal); |