diff --git a/api/app/lib/controllers/patrolManage/checkItems.js b/api/app/lib/controllers/patrolManage/checkItems.js index a6dca43..d9e6e7b 100644 --- a/api/app/lib/controllers/patrolManage/checkItems.js +++ b/api/app/lib/controllers/patrolManage/checkItems.js @@ -25,9 +25,9 @@ async function createGroup(ctx, next) { const models = ctx.fs.dc.models; try { const data = ctx.request.body; - await models.CheckItemsGroup.create(data) - ctx.status = 204; - ctx.body = { message: '新建分组成功' } + const rslt = await models.CheckItemsGroup.create(data); + ctx.status = 200; + ctx.body = { message: '新建分组成功', groupId: rslt.dataValues.id } } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; @@ -92,9 +92,7 @@ async function updateCheckItems(ctx, next) { const data = ctx.request.body; const { id } = ctx.params; - await models.CheckItems.update({ - name: data.name, - }, { + await models.CheckItems.update(data, { where: { id: id } diff --git a/web/client/src/sections/patrolManage/components/checkItemsModal.js b/web/client/src/sections/patrolManage/components/checkItemsModal.js index aaeb857..ebe6fab 100644 --- a/web/client/src/sections/patrolManage/components/checkItemsModal.js +++ b/web/client/src/sections/patrolManage/components/checkItemsModal.js @@ -1,34 +1,27 @@ import { Button, Form, Input, Modal, Select } from 'antd'; import React, { useState, useEffect } from 'react'; import { connect } from 'react-redux'; -import { getUserList, getProjectList, positionList } from '../actions/plan'; import { getCheckItemsGroup } from '../actions/checkItems'; import moment from 'moment'; -const CheckItemsModal = ({ visible, onCreate, onCancel, dispatch, type, curRecord }) => { - const [pointOpt, setPointOpt] = useState(); - const [points, setPoints] = useState(); +const CheckItemsModal = ({ visible, onOk, onCancel, curRecord, dispatch }) => { + const [group, setGroup] = useState([]); const [isNewGroup, setIsNewGroup] = useState(false); const [form] = Form.useForm(); useEffect(() => { - dispatch(getCheckItemsGroup()); - if (type === 'create') { - dispatch(getUserList()) - } else { - 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 }))) - } - }) - } + dispatch(getCheckItemsGroup()).then(res => { + if (res.success) { + const opt = res.payload.data?.map(g => ({ value: g.id, label: g.name })); + setGroup(opt); + } + }); }, []) - + return ( { @@ -36,22 +29,15 @@ const CheckItemsModal = ({ visible, onCreate, onCancel, dispatch, type, curRecor onCancel(); }} onOk={() => { - if (type === 'view') { - form.resetFields(); - onCancel(); - return; - } form .validateFields() .then((values) => { form.resetFields(); const params = { ...values, - startTime: values.time[0], - endTime: values.time[1], - points: points[0]?.points?.filter(p => values?.points?.includes(p.id)) + isNewGroup } - onCreate(params); + onOk(params); }) .catch((info) => { console.log('Validate Failed:', info); @@ -64,10 +50,8 @@ const CheckItemsModal = ({ visible, onCreate, onCancel, dispatch, type, curRecor name="form_in_modal" initialValues={{ ...curRecord, - points: curRecord?.points?.map(p => p.id), userDept: curRecord?.user?.department?.name, }} - disabled={type === 'view'} > { - isNewGroup ? - + isNewGroup + ? + :