|
@@ -1,4 +1,4 @@
|
|
|
-import React, { useCallback, useEffect, useRef } from 'react'
|
|
|
+import React, { useCallback, useEffect, useRef, useState } from 'react'
|
|
|
import styles from './index.module.scss'
|
|
|
import { Button, Form, FormInstance, Input, Modal, Radio, Select } from 'antd'
|
|
|
import TextArea from 'antd/es/input/TextArea'
|
|
@@ -8,6 +8,7 @@ import { getUserListAPI } from '@/store/action/Z6user'
|
|
|
import { RootState } from '@/store'
|
|
|
import { D2_APIedit, D2_APIgetInfo } from '@/store/action/D2storSet'
|
|
|
import { MessageFu } from '@/utils/message'
|
|
|
+import { findMissingIds } from '@/pages/Z_system/Z3flowSet/Z3edit/data'
|
|
|
|
|
|
type Props = {
|
|
|
sId: number
|
|
@@ -19,13 +20,21 @@ type Props = {
|
|
|
function D2edit({ sId, succToLookFu, closeFu, isLook }: Props) {
|
|
|
// 获取用户列表
|
|
|
const dispatch = useDispatch()
|
|
|
+
|
|
|
+ const [loding, setLoding] = useState(false)
|
|
|
+
|
|
|
useEffect(() => {
|
|
|
dispatch(
|
|
|
- getUserListAPI({
|
|
|
- pageNum: 1,
|
|
|
- pageSize: 99999,
|
|
|
- searchKey: ''
|
|
|
- })
|
|
|
+ getUserListAPI(
|
|
|
+ {
|
|
|
+ pageNum: 1,
|
|
|
+ pageSize: 99999,
|
|
|
+ searchKey: ''
|
|
|
+ },
|
|
|
+ () => {
|
|
|
+ setLoding(true)
|
|
|
+ }
|
|
|
+ )
|
|
|
)
|
|
|
}, [dispatch])
|
|
|
|
|
@@ -34,15 +43,39 @@ function D2edit({ sId, succToLookFu, closeFu, isLook }: Props) {
|
|
|
// 设置表单ref
|
|
|
const FormBoxRef = useRef<FormInstance>(null)
|
|
|
|
|
|
- const getInfoFu = useCallback(async (id: number) => {
|
|
|
- const res = await D2_APIgetInfo(id)
|
|
|
- const obj = res.data
|
|
|
+ const getInfoFu = useCallback(
|
|
|
+ async (id: number) => {
|
|
|
+ if (loding) {
|
|
|
+ const res = await D2_APIgetInfo(id)
|
|
|
|
|
|
- if (obj.memberUserIds)
|
|
|
- obj.memberUserIds = obj.memberUserIds.split(',').map((v: string) => Number(v))
|
|
|
- else obj.memberUserIds = []
|
|
|
- if (res.code === 0) FormBoxRef.current?.setFieldsValue(res.data)
|
|
|
- }, [])
|
|
|
+ if (res.code === 0) {
|
|
|
+ const obj = res.data
|
|
|
+
|
|
|
+ if (obj.memberUserIds)
|
|
|
+ obj.memberUserIds = obj.memberUserIds.split(',').map((v: string) => Number(v))
|
|
|
+ else obj.memberUserIds = []
|
|
|
+
|
|
|
+ // console.log('---------', obj)
|
|
|
+
|
|
|
+ if (!userList.some(v => v.id === obj.managerUserId)) {
|
|
|
+ obj.managerUserId = null
|
|
|
+ }
|
|
|
+
|
|
|
+ if (obj.memberUserIds && obj.memberUserIds.length) {
|
|
|
+ const isDelIdArrRef = findMissingIds(userList, obj.memberUserIds)
|
|
|
+ if (isDelIdArrRef && isDelIdArrRef.length) {
|
|
|
+ const userIds = new Set(isDelIdArrRef.map(u => u))
|
|
|
+ const copyUserIds = obj.memberUserIds.filter((id: any) => !userIds.has(id))
|
|
|
+ obj.memberUserIds = copyUserIds
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ FormBoxRef.current?.setFieldsValue(res.data)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ [loding, userList]
|
|
|
+ )
|
|
|
|
|
|
useEffect(() => {
|
|
|
if (sId > 0) getInfoFu(sId)
|
|
@@ -114,7 +147,7 @@ function D2edit({ sId, succToLookFu, closeFu, isLook }: Props) {
|
|
|
>
|
|
|
<Select
|
|
|
disabled={isLook}
|
|
|
- placeholder='请选择'
|
|
|
+ placeholder={isLook ? '(空)' : '请选择'}
|
|
|
options={userList.map(v => ({ value: v.id, label: v.realName || v.userName }))}
|
|
|
/>
|
|
|
</Form.Item>
|