|
@@ -1,20 +1,14 @@
|
|
|
-import { useRef, useState, useMemo, useEffect, useContext } from 'react'
|
|
|
-import { Button, Drawer, Radio, Select, Spin, Tag } from 'antd'
|
|
|
+import { useState, useEffect, useContext } from 'react'
|
|
|
+import { Button, Drawer, Radio, Tag } from 'antd'
|
|
|
import { Actions, FlowContext } from '../../context'
|
|
|
-import debounce from 'lodash/debounce'
|
|
|
import type { RadioChangeEvent } from 'antd'
|
|
|
-import { queryAcountList } from '@/services/api/institution'
|
|
|
-import consts from '@/utils/consts'
|
|
|
import { ApprovalMethod, ApprovalType } from '../../enum'
|
|
|
import TreeNodeSelect from '@/pages/Project/Management/components/TreeNodeSelect'
|
|
|
-const debounceTimeout = 800
|
|
|
|
|
|
const FlowDrawer = () => {
|
|
|
const { flowState, dispatch } = useContext(FlowContext)
|
|
|
const { drawerConfig } = flowState
|
|
|
|
|
|
- const fetchRef = useRef(0)
|
|
|
-
|
|
|
const [state, setState] = useState({
|
|
|
approvalType: ApprovalType.TARGET,
|
|
|
fetching: false,
|
|
@@ -23,7 +17,7 @@ const FlowDrawer = () => {
|
|
|
})
|
|
|
useEffect(() => {
|
|
|
if (drawerConfig.nodeId && drawerConfig.visible) {
|
|
|
- const defaultStaffIds = flowState.flowData.get(drawerConfig.nodeId)?.staffOptions || []
|
|
|
+ const defaultStaffIds = flowState.flowData.get(drawerConfig.nodeId)?.approvalAccounts || []
|
|
|
setState({ ...state, staffOptions: defaultStaffIds })
|
|
|
}
|
|
|
}, [drawerConfig])
|
|
@@ -44,42 +38,14 @@ const FlowDrawer = () => {
|
|
|
setState({ ...state, approvalType: target.value })
|
|
|
}
|
|
|
}
|
|
|
- const fetchOptions = async params => {
|
|
|
- const { code = -1, data = {} } = await queryAcountList({
|
|
|
- ...params,
|
|
|
- current: 1,
|
|
|
- pageSize: 100,
|
|
|
- dataID: 'e01b8695-c43b-4d2d-8169-a021aa6b69ae'
|
|
|
- })
|
|
|
- if (code === consts.RET_CODE.SUCCESS) {
|
|
|
- return data.items.map(item => ({ label: item.name, value: item.ID }))
|
|
|
- }
|
|
|
- return []
|
|
|
- }
|
|
|
-
|
|
|
- const debounceFetcher = useMemo(() => {
|
|
|
- const loadOptions = params => {
|
|
|
- fetchRef.current += 1
|
|
|
- const fetchId = fetchRef.current
|
|
|
- setState({ ...state, options: [], fetching: true })
|
|
|
-
|
|
|
- fetchOptions(params).then(newOptions => {
|
|
|
- if (fetchId !== fetchRef.current) {
|
|
|
- // for fetch callback order
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- setState({ ...state, options: newOptions, fetching: false })
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- return debounce(loadOptions, debounceTimeout)
|
|
|
- }, [fetchOptions, debounceTimeout])
|
|
|
|
|
|
const staffIds = state.staffOptions.map(i => i.value)
|
|
|
const triggerChange = (val, option) => {
|
|
|
if (!staffIds.includes(val)) {
|
|
|
- setState({ ...state, staffOptions: [...state.staffOptions, option] })
|
|
|
+ setState({
|
|
|
+ ...state,
|
|
|
+ staffOptions: [option].map(item => ({ ID: item.value, name: item.label }))
|
|
|
+ })
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -88,7 +54,7 @@ const FlowDrawer = () => {
|
|
|
id: drawerConfig.nodeId,
|
|
|
node: {
|
|
|
approvalType: state.approvalType,
|
|
|
- approvalAccounts: state.staffOptions.map(item => ({ ID: item.value, name: item.label })),
|
|
|
+ approvalAccounts: state.staffOptions,
|
|
|
approvalMethod: ApprovalMethod.ORDER
|
|
|
}
|
|
|
}
|
|
@@ -113,7 +79,8 @@ const FlowDrawer = () => {
|
|
|
</div>
|
|
|
}
|
|
|
title={<span className="font-medium">设置审批人</span>}
|
|
|
- width="30%">
|
|
|
+ width="30%"
|
|
|
+ >
|
|
|
<div>
|
|
|
<Radio.Group
|
|
|
options={plainOptions}
|
|
@@ -125,12 +92,8 @@ const FlowDrawer = () => {
|
|
|
<span className="font-medium mr-1 text-14px">添加员工</span>
|
|
|
{/* <span className="text-hex-000000 text-opacity-45">不得超过20人</span> */}
|
|
|
</div>
|
|
|
- {/* <TreeNodeSelect
|
|
|
- showSearch
|
|
|
- onChange={triggerChange}
|
|
|
- treeData={state.options?.filter(item => !staffIds.includes(item.value))}
|
|
|
- /> */}
|
|
|
- <Select
|
|
|
+ <TreeNodeSelect onChange={triggerChange} />
|
|
|
+ {/* <Select
|
|
|
showSearch
|
|
|
disabled={state.staffOptions.length}
|
|
|
value={null}
|
|
@@ -139,10 +102,10 @@ const FlowDrawer = () => {
|
|
|
onSearch={v => debounceFetcher({ search: v })}
|
|
|
notFoundContent={state.fetching ? <Spin size="small" /> : null}
|
|
|
options={state.options?.filter(item => !staffIds.includes(item.value))}
|
|
|
- />
|
|
|
+ /> */}
|
|
|
<div className="mt-4">
|
|
|
{state.staffOptions.map(item => (
|
|
|
- <Tag key={item.value}>{item.label}</Tag>
|
|
|
+ <Tag key={item.ID}>{item.name}</Tag>
|
|
|
))}
|
|
|
</div>
|
|
|
</div>
|