|
|
@ -4,143 +4,153 @@ import { Button, Popconfirm } from 'antd'; |
|
|
|
import ProTable from '@ant-design/pro-table'; |
|
|
|
import CheckItemsModal from '../components/checkItemsModal'; |
|
|
|
import { createPatrolPlan, delPatrolPlan, updatePatrolPlan } from '../actions/plan'; |
|
|
|
import { getCheckItems } from '../actions/checkItems'; |
|
|
|
import moment from 'moment'; |
|
|
|
import { getCheckItems, createCheckItems, updateCheckItems, createCheckItemsGroup } from '../actions/checkItems'; |
|
|
|
|
|
|
|
function CheckItems(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 [select, setSelect] = useState([]); |
|
|
|
const { dispatch, user } = props; |
|
|
|
const tableRef = useRef(); |
|
|
|
const [dataSource, setDataSource] = useState([{}]); |
|
|
|
const [visible, setVisible] = useState(false); |
|
|
|
const [curRecord, setCurRecord] = useState(null); // 新增 or 修改
|
|
|
|
const [select, setSelect] = useState([]); |
|
|
|
|
|
|
|
const onCreate = (values) => { |
|
|
|
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); |
|
|
|
}; |
|
|
|
const onOk = async (values) => { |
|
|
|
let groupId = null; |
|
|
|
if (values.isNewGroup) { |
|
|
|
await dispatch(createCheckItemsGroup({ name: values.group })).then(res => { |
|
|
|
if (res.success) { |
|
|
|
groupId = res.payload.data?.groupId |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
if (!curRecord) { |
|
|
|
dispatch(createCheckItems({ |
|
|
|
name: values.name, |
|
|
|
groupId: groupId ? groupId : values.group |
|
|
|
})).then(res => { |
|
|
|
if (res.success) { |
|
|
|
tableRef.current.reload(); |
|
|
|
} |
|
|
|
}) |
|
|
|
} else { |
|
|
|
dispatch(updateCheckItems(curRecord.id, { |
|
|
|
name: values.name, |
|
|
|
groupId: groupId ? groupId : values.group |
|
|
|
})).then(res => { |
|
|
|
if (res.success) { |
|
|
|
tableRef.current.reload(); |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
setVisible(false); |
|
|
|
}; |
|
|
|
|
|
|
|
const columns = [{ |
|
|
|
title: '检查项', |
|
|
|
dataIndex: 'name', |
|
|
|
key: 'name', |
|
|
|
ellipsis: true, |
|
|
|
width: 150, |
|
|
|
}, { |
|
|
|
title: '分组名称', |
|
|
|
dataIndex: 'groupName', |
|
|
|
key: 'groupName', |
|
|
|
ellipsis: true, |
|
|
|
search: false, |
|
|
|
width: 150, |
|
|
|
render: (_, record) => { |
|
|
|
return <div>{record?.check_items_group?.name}</div> |
|
|
|
} |
|
|
|
}, { |
|
|
|
title: '操作', |
|
|
|
dataIndex: 'action', |
|
|
|
key: 'action', |
|
|
|
search: false, |
|
|
|
width: 200, |
|
|
|
render: (_, record) => { |
|
|
|
return <> |
|
|
|
<Button type="link" onClick={() => { |
|
|
|
setType('edit') |
|
|
|
setCurRecord(record) |
|
|
|
setVisible(true) |
|
|
|
}}>修改</Button> |
|
|
|
<Popconfirm |
|
|
|
title="确认删除?" |
|
|
|
onConfirm={() => { |
|
|
|
dispatch(delPatrolPlan(record.id)).then(res => { |
|
|
|
if (res.success) { |
|
|
|
tableRef.current.reload(); |
|
|
|
} |
|
|
|
}) |
|
|
|
}}> |
|
|
|
<Button type="link" danger>删除</Button> |
|
|
|
</Popconfirm> |
|
|
|
</> |
|
|
|
}, |
|
|
|
}]; |
|
|
|
const columns = [{ |
|
|
|
title: '检查项', |
|
|
|
dataIndex: 'name', |
|
|
|
key: 'name', |
|
|
|
ellipsis: true, |
|
|
|
width: 150, |
|
|
|
}, { |
|
|
|
title: '分组名称', |
|
|
|
dataIndex: 'groupName', |
|
|
|
key: 'groupName', |
|
|
|
ellipsis: true, |
|
|
|
search: false, |
|
|
|
width: 150, |
|
|
|
render: (_, record) => { |
|
|
|
return <div>{record?.check_items_group?.name}</div> |
|
|
|
} |
|
|
|
}, { |
|
|
|
title: '操作', |
|
|
|
dataIndex: 'action', |
|
|
|
key: 'action', |
|
|
|
search: false, |
|
|
|
width: 200, |
|
|
|
render: (_, record) => { |
|
|
|
return <> |
|
|
|
<Button type="link" onClick={() => { |
|
|
|
setCurRecord(record) |
|
|
|
setVisible(true) |
|
|
|
}}>修改</Button> |
|
|
|
<Popconfirm |
|
|
|
title="确认删除?" |
|
|
|
onConfirm={() => { |
|
|
|
dispatch(delPatrolPlan(record.id)).then(res => { |
|
|
|
if (res.success) { |
|
|
|
tableRef.current.reload(); |
|
|
|
} |
|
|
|
}) |
|
|
|
}}> |
|
|
|
<Button type="link" danger>删除</Button> |
|
|
|
</Popconfirm> |
|
|
|
</> |
|
|
|
}, |
|
|
|
}]; |
|
|
|
|
|
|
|
return ( |
|
|
|
<> |
|
|
|
<ProTable |
|
|
|
columns={columns} |
|
|
|
actionRef={tableRef} |
|
|
|
options={false} |
|
|
|
dataSource={dataSource || []} |
|
|
|
rowKey='id' |
|
|
|
pagination={{ pageSize: 10 }} |
|
|
|
request={async (params = {}) => { |
|
|
|
const res = await dispatch(getCheckItems(params)); |
|
|
|
setDataSource(res?.payload.data?.rows); |
|
|
|
return { ...res }; |
|
|
|
}} |
|
|
|
onReset={() => { }} |
|
|
|
search={{ |
|
|
|
defaultCollapsed: false, |
|
|
|
optionRender: (searchConfig, formProps, dom) => [ |
|
|
|
...dom.reverse(), |
|
|
|
<Button |
|
|
|
key="add" |
|
|
|
type='primary' |
|
|
|
onClick={() => { |
|
|
|
setType('create') |
|
|
|
setVisible(true) |
|
|
|
}} |
|
|
|
>新增</Button>, |
|
|
|
<Button |
|
|
|
key="del" |
|
|
|
type='primary' |
|
|
|
onClick={() => { |
|
|
|
const values = searchConfig?.form?.getFieldsValue(); |
|
|
|
console.log(values); |
|
|
|
}} |
|
|
|
>批量删除</Button>, |
|
|
|
], |
|
|
|
}} |
|
|
|
rowSelection={{ |
|
|
|
selectedRowKeys: select?.map(v => v.id) || [], |
|
|
|
onChange: (selectedRowKeys, selectedRows) => { |
|
|
|
setSelect(selectedRows) |
|
|
|
} |
|
|
|
}} |
|
|
|
/> |
|
|
|
{ |
|
|
|
visible ? |
|
|
|
<CheckItemsModal |
|
|
|
visible={visible} |
|
|
|
onCreate={onCreate} |
|
|
|
type={type} |
|
|
|
curRecord={curRecord} |
|
|
|
onCancel={() => { |
|
|
|
setVisible(false); |
|
|
|
}} |
|
|
|
/> : null |
|
|
|
} |
|
|
|
</> |
|
|
|
) |
|
|
|
return ( |
|
|
|
<> |
|
|
|
<ProTable |
|
|
|
columns={columns} |
|
|
|
actionRef={tableRef} |
|
|
|
options={false} |
|
|
|
dataSource={dataSource || []} |
|
|
|
rowKey='id' |
|
|
|
pagination={{ pageSize: 10 }} |
|
|
|
request={async (params = {}) => { |
|
|
|
const res = await dispatch(getCheckItems(params)); |
|
|
|
setDataSource(res?.payload.data?.rows); |
|
|
|
return { ...res }; |
|
|
|
}} |
|
|
|
onReset={() => { }} |
|
|
|
search={{ |
|
|
|
defaultCollapsed: false, |
|
|
|
optionRender: (searchConfig, formProps, dom) => [ |
|
|
|
...dom.reverse(), |
|
|
|
<Button |
|
|
|
key="add" |
|
|
|
type='primary' |
|
|
|
onClick={() => { |
|
|
|
setCurRecord(null) |
|
|
|
setVisible(true) |
|
|
|
}} |
|
|
|
>新增</Button>, |
|
|
|
<Button |
|
|
|
key="del" |
|
|
|
type='primary' |
|
|
|
onClick={() => { |
|
|
|
// const values = searchConfig?.form?.getFieldsValue();
|
|
|
|
// console.log(values);
|
|
|
|
}} |
|
|
|
>批量删除</Button>, |
|
|
|
], |
|
|
|
}} |
|
|
|
rowSelection={{ |
|
|
|
selectedRowKeys: select?.map(v => v.id) || [], |
|
|
|
onChange: (_, selectedRows) => { |
|
|
|
setSelect(selectedRows) |
|
|
|
} |
|
|
|
}} |
|
|
|
/> |
|
|
|
{ |
|
|
|
visible ? |
|
|
|
<CheckItemsModal |
|
|
|
visible={visible} |
|
|
|
onOk={onOk} |
|
|
|
curRecord={curRecord} |
|
|
|
onCancel={() => { |
|
|
|
setVisible(false); |
|
|
|
}} |
|
|
|
/> : null |
|
|
|
} |
|
|
|
</> |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
function mapStateToProps(state) { |
|
|
|
const { auth } = state |
|
|
|
return { |
|
|
|
user: auth.user |
|
|
|
} |
|
|
|
const { auth } = state |
|
|
|
return { |
|
|
|
user: auth.user |
|
|
|
} |
|
|
|
} |
|
|
|
export default connect(mapStateToProps)(CheckItems); |
|
|
|