Browse Source

(*) 检查项删除功能

master
liujiangyong 2 years ago
parent
commit
4c35e45f4c
  1. 6
      api/app/lib/controllers/patrolManage/checkItems.js
  2. 5
      web/client/src/sections/patrolManage/actions/checkItems.js
  3. 3
      web/client/src/sections/patrolManage/components/checkItemsModal.js
  4. 32
      web/client/src/sections/patrolManage/containers/checkItems.js

6
api/app/lib/controllers/patrolManage/checkItems.js

@ -38,8 +38,9 @@ async function createGroup(ctx, next) {
async function getCheckItems(ctx, next) { async function getCheckItems(ctx, next) {
try { try {
const models = ctx.fs.dc.models; const models = ctx.fs.dc.models;
const { limit, page } = ctx.query; const { limit, page, name } = ctx.query;
let options = { let options = {
where: {},
order: [['id', 'asc']], order: [['id', 'asc']],
include: [{ include: [{
required: true, required: true,
@ -47,6 +48,9 @@ async function getCheckItems(ctx, next) {
attributes: ['id', 'name'], attributes: ['id', 'name'],
}] }]
} }
if (name) {
options.where.name = { $like: `%${name}%` };
}
if (limit) { if (limit) {
options.limit = Number(limit); options.limit = Number(limit);
} }

5
web/client/src/sections/patrolManage/actions/checkItems.js

@ -24,10 +24,11 @@ export function createCheckItemsGroup(data) {
}); });
} }
export function getCheckItems() { export function getCheckItems(query) {
return dispatch => basicAction({ return dispatch => basicAction({
type: 'get', type: 'get',
dispatch: dispatch, dispatch: dispatch,
query: query,
actionType: 'GET_CHECK_ITEMS', actionType: 'GET_CHECK_ITEMS',
url: ApiTable.checkItems, url: ApiTable.checkItems,
msg: { error: '获取检查项失败' } msg: { error: '获取检查项失败' }
@ -61,7 +62,7 @@ export function delCheckItems(ids) {
type: 'del', type: 'del',
dispatch: dispatch, dispatch: dispatch,
actionType: 'DEL_CHECK_ITEMS', actionType: 'DEL_CHECK_ITEMS',
url: ApiTable.delUser.replace('{ids}', ids), url: ApiTable.delCheckItems.replace('{ids}', ids),
msg: { option: '删除检查项' }, msg: { option: '删除检查项' },
}); });
} }

3
web/client/src/sections/patrolManage/components/checkItemsModal.js

@ -2,7 +2,6 @@ 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 { getCheckItemsGroup } from '../actions/checkItems'; import { getCheckItemsGroup } from '../actions/checkItems';
import moment from 'moment';
const CheckItemsModal = ({ visible, onOk, onCancel, curRecord, dispatch }) => { const CheckItemsModal = ({ visible, onOk, onCancel, curRecord, dispatch }) => {
const [group, setGroup] = useState([]); const [group, setGroup] = useState([]);
@ -50,7 +49,7 @@ const CheckItemsModal = ({ visible, onOk, onCancel, curRecord, dispatch }) => {
name="form_in_modal" name="form_in_modal"
initialValues={{ initialValues={{
...curRecord, ...curRecord,
userDept: curRecord?.user?.department?.name, group: curRecord?.check_items_group?.id
}} }}
> >
<Form.Item <Form.Item

32
web/client/src/sections/patrolManage/containers/checkItems.js

@ -3,11 +3,10 @@ import { connect } from 'react-redux';
import { Button, Popconfirm } from 'antd'; import { Button, Popconfirm } from 'antd';
import ProTable from '@ant-design/pro-table'; import ProTable from '@ant-design/pro-table';
import CheckItemsModal from '../components/checkItemsModal'; import CheckItemsModal from '../components/checkItemsModal';
import { createPatrolPlan, delPatrolPlan, updatePatrolPlan } from '../actions/plan'; import { getCheckItems, createCheckItems, updateCheckItems, delCheckItems, createCheckItemsGroup } from '../actions/checkItems';
import { getCheckItems, createCheckItems, updateCheckItems, createCheckItemsGroup } from '../actions/checkItems';
function CheckItems(props) { function CheckItems(props) {
const { dispatch, user } = props; const { dispatch } = 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);
@ -45,6 +44,14 @@ function CheckItems(props) {
setVisible(false); setVisible(false);
}; };
function delItems(ids) {
dispatch(delCheckItems(ids)).then(res => {
if (res.success) {
tableRef.current.reload();
}
})
}
const columns = [{ const columns = [{
title: '检查项', title: '检查项',
dataIndex: 'name', dataIndex: 'name',
@ -75,13 +82,7 @@ function CheckItems(props) {
}}>修改</Button> }}>修改</Button>
<Popconfirm <Popconfirm
title="确认删除?" title="确认删除?"
onConfirm={() => { onConfirm={() => { delItems(record.id) }}>
dispatch(delPatrolPlan(record.id)).then(res => {
if (res.success) {
tableRef.current.reload();
}
})
}}>
<Button type="link" danger>删除</Button> <Button type="link" danger>删除</Button>
</Popconfirm> </Popconfirm>
</> </>
@ -98,7 +99,11 @@ function CheckItems(props) {
rowKey='id' rowKey='id'
pagination={{ pageSize: 10 }} pagination={{ pageSize: 10 }}
request={async (params = {}) => { request={async (params = {}) => {
const res = await dispatch(getCheckItems(params)); const res = await dispatch(getCheckItems({
limit: params.pageSize,
page: params.current - 1,
name: params?.name
}));
setDataSource(res?.payload.data?.rows); setDataSource(res?.payload.data?.rows);
return { ...res }; return { ...res };
}} }}
@ -118,9 +123,10 @@ function CheckItems(props) {
<Button <Button
key="del" key="del"
type='primary' type='primary'
disabled={!select?.length}
onClick={() => { onClick={() => {
// const values = searchConfig?.form?.getFieldsValue(); const ids = select?.map(s => s.id).join();
// console.log(values); delItems(ids);
}} }}
>批量删除</Button>, >批量删除</Button>,
], ],

Loading…
Cancel
Save