|
@@ -1,18 +1,23 @@
|
|
|
import MemberItem from '../components/MemberItem'
|
|
|
import consts from '@/utils/consts'
|
|
|
-import { useState } from 'react'
|
|
|
import { useRequest } from 'ahooks'
|
|
|
import {
|
|
|
addExecutor,
|
|
|
delExecutor,
|
|
|
queryExecutorList,
|
|
|
- queryMatterList,
|
|
|
+ queryMatterTree,
|
|
|
updateExecutor
|
|
|
} from '@/services/api/business'
|
|
|
import { ExecutorSetType } from '@/enums/gc'
|
|
|
import { QuestionCircleFilled } from '@ant-design/icons'
|
|
|
-import { Form, message, Tooltip } from 'antd'
|
|
|
-import ProForm, { ProFormDependency, ProFormRadio, ProFormSelect, ProFormText } from '@ant-design/pro-form'
|
|
|
+import { Form, message, Tooltip, TreeNodeProps } from 'antd'
|
|
|
+import ProForm, {
|
|
|
+ ProFormDependency,
|
|
|
+ ProFormRadio,
|
|
|
+ ProFormSelect,
|
|
|
+ ProFormText,
|
|
|
+ ProFormTreeSelect
|
|
|
+} from '@ant-design/pro-form'
|
|
|
|
|
|
import type { ModalAction } from '@/components/Modal'
|
|
|
import { useDispatch } from '@umijs/max'
|
|
@@ -42,15 +47,19 @@ const setTypeOptions = [
|
|
|
}
|
|
|
]
|
|
|
|
|
|
-type iState = {
|
|
|
- total: number
|
|
|
+function transformMatterTree(tree: API.MatterTreeItem[]): TreeNodeProps[] {
|
|
|
+ return tree.map(item => {
|
|
|
+ const newItem: TreeNodeProps = { key: item.ID, title: item.name, value: item.ID, isLeaf: true }
|
|
|
+ if (item.children) {
|
|
|
+ newItem.isLeaf = false
|
|
|
+ newItem.disabled = true
|
|
|
+ newItem.children = transformMatterTree(item.children)
|
|
|
+ }
|
|
|
+ return newItem
|
|
|
+ })
|
|
|
}
|
|
|
-
|
|
|
export default function useScripts(modal: ModalAction, subject: string) {
|
|
|
const dispatch = useDispatch()
|
|
|
- const [state, seState] = useState<iState>({
|
|
|
- total: 0
|
|
|
- })
|
|
|
const {
|
|
|
run: query,
|
|
|
refresh,
|
|
@@ -59,7 +68,6 @@ export default function useScripts(modal: ModalAction, subject: string) {
|
|
|
manual: true,
|
|
|
onSuccess: (result, params) => {
|
|
|
const { gatherID, businessType } = params[0]
|
|
|
- seState({ total: result.data.total })
|
|
|
dispatch({
|
|
|
type: 'business/updateExecutorMap',
|
|
|
payload: {
|
|
@@ -70,82 +78,80 @@ export default function useScripts(modal: ModalAction, subject: string) {
|
|
|
}
|
|
|
})
|
|
|
|
|
|
- const { data: { data: { items: matters = [] } = {} } = {} } = useRequest(
|
|
|
- () => {
|
|
|
- if (!subject) return
|
|
|
- const [gatherID, businessType] = subject.split('_')
|
|
|
-
|
|
|
- return queryMatterList({ gatherID, businessType, pageSize: 214000, matterType: 'matter' })
|
|
|
- },
|
|
|
- { refreshDeps: [subject] }
|
|
|
- )
|
|
|
+ const addOrEdit = async (mode: 'add' | 'edit', initialValues?: API.ExecutorItem) => {
|
|
|
+ const [gatherID, businessType] = subject.split('_')
|
|
|
+ console.log(subject)
|
|
|
|
|
|
- const addOrEdit = (mode: 'add' | 'edit', initialValues?: API.ExecutorItem) => {
|
|
|
- const text = mode === 'add' ? '新增执行者' : '编辑执行者'
|
|
|
- modal.open({
|
|
|
- title: text,
|
|
|
- okText: '确定',
|
|
|
- cancelText: '取消',
|
|
|
- type: 'form',
|
|
|
- initialValues: initialValues ?? {
|
|
|
- setType: ExecutorSetType.PERSET
|
|
|
- },
|
|
|
- children: (
|
|
|
- <ProForm submitter={false} layout="horizontal" labelCol={{ span: 5 }} isKeyPressSubmit>
|
|
|
- <ProFormText hidden name="ID" />
|
|
|
- <ProFormText
|
|
|
- label="执行者名称"
|
|
|
- name="name"
|
|
|
- rules={[{ required: true, message: '请输入' }]}
|
|
|
- placeholder="请输入"
|
|
|
- />
|
|
|
- <ProFormRadio.Group
|
|
|
- label="配置方式"
|
|
|
- name="setType"
|
|
|
- options={setTypeOptions}
|
|
|
- rules={[{ required: true, message: '请选择' }]}
|
|
|
- />
|
|
|
- <ProFormDependency name={['setType']}>
|
|
|
- {({ setType }) => {
|
|
|
- if (setType === ExecutorSetType.PERSET)
|
|
|
+ const { code = -1, data } = await queryMatterTree({ gatherID, businessType, pageSize: 214000 })
|
|
|
+ if (code === consts.RET_CODE.SUCCESS) {
|
|
|
+ const matterTree = transformMatterTree(data || [])
|
|
|
+ console.log(matterTree)
|
|
|
+ const text = mode === 'add' ? '新增执行者' : '编辑执行者'
|
|
|
+ modal.open({
|
|
|
+ title: text,
|
|
|
+ okText: '确定',
|
|
|
+ cancelText: '取消',
|
|
|
+ type: 'form',
|
|
|
+ initialValues: initialValues ?? {
|
|
|
+ setType: ExecutorSetType.PERSET
|
|
|
+ },
|
|
|
+ children: (
|
|
|
+ <ProForm submitter={false} layout="horizontal" labelCol={{ span: 5 }} isKeyPressSubmit>
|
|
|
+ <ProFormText hidden name="ID" />
|
|
|
+ <ProFormText
|
|
|
+ label="执行者名称"
|
|
|
+ name="name"
|
|
|
+ rules={[{ required: true, message: '请输入' }]}
|
|
|
+ placeholder="请输入"
|
|
|
+ />
|
|
|
+ <ProFormRadio.Group
|
|
|
+ label="配置方式"
|
|
|
+ name="setType"
|
|
|
+ options={setTypeOptions}
|
|
|
+ rules={[{ required: true, message: '请选择' }]}
|
|
|
+ />
|
|
|
+ <ProFormDependency name={['setType']}>
|
|
|
+ {({ setType }) => {
|
|
|
+ if (setType === ExecutorSetType.PERSET)
|
|
|
+ return (
|
|
|
+ <Form.Item label="成员" name="members" rules={[{ required: true, message: '请选择' }]}>
|
|
|
+ <MemberItem />
|
|
|
+ </Form.Item>
|
|
|
+ )
|
|
|
return (
|
|
|
- <Form.Item label="成员" name="members" rules={[{ required: true, message: '请选择' }]}>
|
|
|
- <MemberItem />
|
|
|
- </Form.Item>
|
|
|
+ <ProFormSelect name="scope" label="范围选择" options={[{ label: '全部', value: 'all' }]} />
|
|
|
)
|
|
|
- return (
|
|
|
- <ProFormSelect name="scope" label="范围选择" options={[{ label: '全部', value: 'all' }]} />
|
|
|
- )
|
|
|
- }}
|
|
|
- </ProFormDependency>
|
|
|
- <ProFormSelect
|
|
|
- name="approvaledPermission"
|
|
|
- label="事项权限"
|
|
|
- placeholder="请选择"
|
|
|
- rules={[{ required: true, message: '请选择' }]}
|
|
|
- fieldProps={{ mode: 'multiple' }}
|
|
|
- options={matters.map(item => ({ label: item.name, value: item.ID }))}
|
|
|
- />
|
|
|
- </ProForm>
|
|
|
- ),
|
|
|
- onOk: async (values: API.ExecutorItem) => {
|
|
|
- const [gatherID, businessType] = subject.split('_')
|
|
|
- values.gatherID = gatherID
|
|
|
- values.businessType = businessType
|
|
|
- let requestFn: Nullable<() => Promise<viod>> = null
|
|
|
- if (mode === 'add') {
|
|
|
- requestFn = addExecutor
|
|
|
- } else {
|
|
|
- requestFn = updateExecutor
|
|
|
+ }}
|
|
|
+ </ProFormDependency>
|
|
|
+ <ProFormTreeSelect
|
|
|
+ name="approvaledPermission"
|
|
|
+ label="事项权限"
|
|
|
+ placeholder="请选择"
|
|
|
+ rules={[{ required: true, message: '请选择' }]}
|
|
|
+ fieldProps={{ multiple: true }}
|
|
|
+ request={() => matterTree}
|
|
|
+ />
|
|
|
+ </ProForm>
|
|
|
+ ),
|
|
|
+ onOk: async (values: API.ExecutorItem) => {
|
|
|
+ const [gatherID, businessType] = subject.split('_')
|
|
|
+ values.gatherID = gatherID
|
|
|
+ values.businessType = businessType
|
|
|
+ let requestFn: Nullable<() => Promise<viod>> = null
|
|
|
+ if (mode === 'add') {
|
|
|
+ requestFn = addExecutor
|
|
|
+ } else {
|
|
|
+ requestFn = updateExecutor
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ await requestFn?.(values)
|
|
|
+ refresh()
|
|
|
+ modal.close()
|
|
|
+ message.success(text + '成功')
|
|
|
+ } catch (error) {}
|
|
|
}
|
|
|
- try {
|
|
|
- await requestFn?.(values)
|
|
|
- refresh()
|
|
|
- modal.close()
|
|
|
- message.success(text + '成功')
|
|
|
- } catch (error) {}
|
|
|
- }
|
|
|
- })
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
const del = (ID: string) => {
|
|
@@ -166,5 +172,5 @@ export default function useScripts(modal: ModalAction, subject: string) {
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
- return { query, total: state.total, loading, addOrEdit, del }
|
|
|
+ return { query, loading, addOrEdit, del }
|
|
|
}
|