|
@@ -1,35 +1,28 @@
|
|
|
import { useRequest } from 'umi'
|
|
|
import { Input, message, Modal } from 'antd'
|
|
|
+import type { PropsWithChildren } from 'react'
|
|
|
import React, { useState, useRef, useEffect } from 'react'
|
|
|
-import Icon from '@/components/IconPark'
|
|
|
import { fetchStaffList } from '@/services/user/api'
|
|
|
-import { linkAttendance } from '@/services/user/system'
|
|
|
+import { linkAttendance, addAttendance } from '@/services/user/system'
|
|
|
import '@/pages/Role/System/components/ConnectModal/index.less'
|
|
|
import { LoadingOutlined, MoreOutlined } from '@ant-design/icons'
|
|
|
+import { addType } from '../..'
|
|
|
|
|
|
-interface ConnectModalProps {
|
|
|
- title: string
|
|
|
+interface ConnectModalProps extends PropsWithChildren {
|
|
|
dataId: string
|
|
|
+ visible: boolean
|
|
|
+ onCancel: () => void
|
|
|
}
|
|
|
-const ApplicantModal: React.FC<ConnectModalProps> = ({ dataId }) => {
|
|
|
+const ApplicantModal: React.FC<ConnectModalProps> = ({
|
|
|
+ type,
|
|
|
+ dataId,
|
|
|
+ visible,
|
|
|
+ onCancel,
|
|
|
+ children
|
|
|
+}) => {
|
|
|
const containerRef = useRef<HTMLDivElement>(null)
|
|
|
- const [visible, setVisible] = useState(false)
|
|
|
const [searchVal, setSearchVal] = useState('')
|
|
|
|
|
|
- const { run: tryLinkAttendance } = useRequest(
|
|
|
- (params: API.LinkAttendance) => linkAttendance(params),
|
|
|
- {
|
|
|
- manual: true,
|
|
|
- onSuccess: () => {
|
|
|
- message.success('关联成功')
|
|
|
- setVisible(false)
|
|
|
- },
|
|
|
- onError: e => {
|
|
|
- message.error(e.message)
|
|
|
- }
|
|
|
- }
|
|
|
- )
|
|
|
-
|
|
|
const {
|
|
|
run: tryQueryStaffList,
|
|
|
data,
|
|
@@ -51,7 +44,40 @@ const ApplicantModal: React.FC<ConnectModalProps> = ({ dataId }) => {
|
|
|
refreshDeps: [searchVal]
|
|
|
}
|
|
|
)
|
|
|
+ const { run: tryLinkAttendance } = useRequest(
|
|
|
+ (params: API.LinkAttendance) => linkAttendance(params),
|
|
|
+ {
|
|
|
+ manual: true,
|
|
|
+ onSuccess: () => {
|
|
|
+ message.success('关联成功')
|
|
|
+ onCancel()
|
|
|
+ },
|
|
|
+ onError: e => {
|
|
|
+ message.error(e.message)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ )
|
|
|
+ const { run: tryAddAttendance } = useRequest(
|
|
|
+ (params: API.Addattendance) => addAttendance(params),
|
|
|
+ {
|
|
|
+ manual: true,
|
|
|
+ onSuccess: () => {
|
|
|
+ message.success('关联成功')
|
|
|
+ onCancel()
|
|
|
+ },
|
|
|
+ onError: e => {
|
|
|
+ message.error(e.message)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ )
|
|
|
|
|
|
+ const AddTypeModal = (staffId: string, applicantStaffId: string) => {
|
|
|
+ if (type === addType.addobjectModal) {
|
|
|
+ tryLinkAttendance({ id: dataId, staffId })
|
|
|
+ } else {
|
|
|
+ tryAddAttendance({ applicantStaffId })
|
|
|
+ }
|
|
|
+ }
|
|
|
const handleSearch = (value: string) => {
|
|
|
setSearchVal(value)
|
|
|
setTimeout(() => {
|
|
@@ -66,20 +92,19 @@ const ApplicantModal: React.FC<ConnectModalProps> = ({ dataId }) => {
|
|
|
}
|
|
|
}, [visible])
|
|
|
|
|
|
- const itemSelectHandler = (staffId: string) => {
|
|
|
- tryLinkAttendance({ id: dataId, staffId })
|
|
|
- }
|
|
|
+ // const itemSelectHandler = (staffId: string) => {
|
|
|
+ // if (type === addType.addobjectModal) {
|
|
|
+
|
|
|
+ // } else {
|
|
|
+
|
|
|
+ // }
|
|
|
+ // }
|
|
|
return (
|
|
|
<>
|
|
|
- <span
|
|
|
- className="hover:text-hex-886ab5 cursor-pointer text-purple-500"
|
|
|
- onClick={() => setVisible(true)}>
|
|
|
- <Icon type="plus" />
|
|
|
- 添加
|
|
|
- </span>
|
|
|
+ {children}
|
|
|
<Modal
|
|
|
visible={visible}
|
|
|
- onCancel={() => setVisible(false)}
|
|
|
+ onCancel={onCancel}
|
|
|
getContainer={false}
|
|
|
width="60vw"
|
|
|
title={
|
|
@@ -100,7 +125,7 @@ const ApplicantModal: React.FC<ConnectModalProps> = ({ dataId }) => {
|
|
|
<span className="w-1/5">{item.category}</span>
|
|
|
</div>
|
|
|
<div className="w-1/4 flex justify-end">
|
|
|
- <span className="btn-outline" onClick={() => itemSelectHandler(item.id)}>
|
|
|
+ <span className="btn-outline" onClick={() => AddTypeModal(item.id)}>
|
|
|
选择ta
|
|
|
</span>
|
|
|
</div>
|