outaozhen преди 4 години
родител
ревизия
d7cee2f98d

+ 0 - 120
src/pages/Business/Attendance/components/AddObjectModal/index.tsx

@@ -1,120 +0,0 @@
-import { useRequest } from 'umi'
-import { Button, Input, message, Modal } from 'antd'
-import React, { useState, useRef, useEffect } from 'react'
-import { fetchStaffList } from '@/services/user/api'
-import { addAttendance } from '@/services/user/system'
-import '@/pages/Role/System/components/ConnectModal/index.less'
-import { LoadingOutlined, MoreOutlined } from '@ant-design/icons'
-
-interface AddObjectModalProps {
-  title: string
-}
-const AddObjectModal: React.FC<AddObjectModalProps> = ({ title }) => {
-  const containerRef = useRef<HTMLDivElement>(null)
-  const [visible, setVisible] = useState(false)
-  const [searchVal, setSearchVal] = useState('')
-
-  const { run: tryAddAttendance } = useRequest(
-    (params: API.Addattendance) => addAttendance(params),
-    {
-      manual: true,
-      onSuccess: () => {
-        message.success('关联成功')
-        setVisible(false)
-      },
-      onError: e => {
-        message.error(e.message)
-      }
-    }
-  )
-
-  const {
-    run: tryQueryStaffList,
-    data,
-    noMore,
-    loadMore,
-    loadingMore
-  } = useRequest(
-    result =>
-      fetchStaffList({
-        current: result?.list.length / 10 + 1 || 1,
-        pageSize: 10,
-        search: searchVal
-      }),
-    {
-      manual: true,
-      loadMore: true,
-      ref: containerRef,
-      isNoMore: (res: API.BasicFetchResult<API.StaffItem>) => res.list.length >= res.total,
-      refreshDeps: [searchVal]
-    }
-  )
-
-  const handleSearch = (value: string) => {
-    setSearchVal(value)
-    setTimeout(() => {
-      tryQueryStaffList()
-    }, 250)
-  }
-
-  const { list = [] }: { list: API.StaffItem[] } = data || {}
-  useEffect(() => {
-    if (visible) {
-      tryQueryStaffList()
-    }
-  }, [visible])
-
-  const itemSelectHandler = (applicantStaffId: string) => {
-    tryAddAttendance({ applicantStaffId })
-  }
-  return (
-    <>
-      <Button type="primary" onClick={() => setVisible(true)}>
-        {title}
-      </Button>
-      <Modal
-        visible={visible}
-        onCancel={() => setVisible(false)}
-        getContainer={false}
-        width="60vw"
-        title={
-          <Input.Search
-            placeholder="搜索员工(姓名)"
-            onSearch={value => handleSearch(value)}
-            onPressEnter={e => handleSearch(e.currentTarget.value)}
-            style={{ width: '95%' }}
-            allowClear={true}></Input.Search>
-        }>
-        <div ref={containerRef} className="h-60vh overflow-y-auto overflow-x-hidden modal-content">
-          {list.map(item => (
-            <div className="card" key={item.id}>
-              <div className="w-4/3 flex justify-between">
-                <span className="w-1/5">{item.username}</span>
-                <span className="w-2/5">{item.phone}</span>
-                <span className="w-1/5">{item.position}</span>
-                <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)}>
-                  选择ta
-                </span>
-              </div>
-            </div>
-          ))}
-          {noMore && <div className="text-center text-gray-400">已到底部</div>}
-          {!noMore && (
-            <div className="text-center mt-3 cursor-pointer">
-              {loadingMore ? (
-                <LoadingOutlined />
-              ) : (
-                <MoreOutlined rotate={90} style={{ fontSize: 24 }} onClick={loadMore} />
-              )}
-            </div>
-          )}
-        </div>
-      </Modal>
-    </>
-  )
-}
-
-export default AddObjectModal

+ 4 - 4
src/pages/Business/Attendance/components/ApplicantModal/index.tsx

@@ -13,7 +13,7 @@ interface ConnectModalProps extends PropsWithChildren {
   visible: boolean
   onCancel: () => void
 }
-const ApplicantModal: React.FC<ConnectModalProps> = ({
+const ConnectModal: React.FC<ConnectModalProps> = ({
   type,
   dataId,
   visible,
@@ -73,9 +73,9 @@ const ApplicantModal: React.FC<ConnectModalProps> = ({
 
   const connectHandler = (staffId: string) => {
     if (type === modalType.addobjectModal) {
-      tryAddAttendance({ applicantStaffId: staffId })
-    } else {
       tryLinkAttendance({ id: dataId, staffId })
+    } else {
+      tryAddAttendance({ applicantStaffId: staffId })
     }
   }
   const handleSearch = (value: string) => {
@@ -147,4 +147,4 @@ const ApplicantModal: React.FC<ConnectModalProps> = ({
   )
 }
 
-export default ApplicantModal
+export default ConnectModal

+ 5 - 4
src/pages/Business/Attendance/index.tsx

@@ -3,7 +3,7 @@ import AttendanceMenu from './components/AttendanceMenu/attendanceMenu'
 import { useRequest } from 'umi'
 import Icon from '@/components/IconPark'
 // import AddObjectModal from './components/AddObjectModal'
-import ApplicantModal from './components/ApplicantModal'
+import ConnectModal from './components/ConnectModal'
 import { Table, Tag, Popconfirm, Popover, Button } from 'antd'
 import { fetchAttendanceList, unlinkAttendance, deleteAttendance } from '@/services/user/system'
 
@@ -14,6 +14,7 @@ export enum modalType {
 const Attendance = () => {
   const [state, setState] = useState({
     id: '',
+    modalId: '',
     attendanceList: [],
     visible: false,
     type: modalType.addobjectModal
@@ -86,7 +87,7 @@ const Attendance = () => {
             onClick={() =>
               setState({
                 ...state,
-                id: record.id,
+                modalId: record.id,
                 visible: true,
                 type: modalType.addobjectModal
               })
@@ -129,9 +130,9 @@ const Attendance = () => {
               onClick={() => setState({ ...state, visible: true, type: modalType.linkAttendance })}>
               添加新申请人
             </Button>
-            <ApplicantModal
+            <ConnectModal
               type={modalType}
-              dataId={state.id}
+              dataId={state.modalId}
               visible={state.visible}
               onCancel={() => setState({ ...state, visible: false })}
             />