outaozhen 5 лет назад
Родитель
Сommit
fa02e104bd

+ 3 - 3
src/pages/Staff/Employee/components/ChangeSupervisor/index.jsx

@@ -1,5 +1,5 @@
 import React from 'react'
-import { LinkOne, Switch } from '@icon-park/react'
+import { Switch } from '@icon-park/react'
 import { useModal } from '@/components/Modal'
 import { Card, Tooltip } from 'antd'
 import consts from '@/basic/consts'
@@ -13,7 +13,7 @@ const ChangeSupervisor = props => {
   const {
     dataSource: { staffId, clientId, staffName }
   } = props
-  const refreshClient = () => {
+  const refreshStaff = () => {
     dispatch({
       type: 'refresh/commitAction',
       payload: 'stafflist'
@@ -22,7 +22,7 @@ const ChangeSupervisor = props => {
   const handleConnectStaff = () => {
     setModalProps({
       width: '60vw',
-      modalRender: node => <StaffModal onSelect={refreshClient} node={node} clientId={clientId} />,
+      modalRender: node => <StaffModal onSelect={refreshStaff} node={node} clientId={clientId} />,
       onCancel: () => toggleModal()
     })
     toggleModal()

+ 2 - 3
src/pages/Staff/Employee/components/EmployeeDetail/EmployeeForm.jsx

@@ -6,9 +6,8 @@ import ChangeSupervisor from '@/pages/staff/Employee/components/ChangeSupervisor
 const EmployeeForm = props => {
   const { staff } = props
   const changeCopInputData = {
-    staffName: staff.username,
+    staffName: staff.supervisorName,
     staffId: staff.staffId,
-    clientName: staff.clientName,
     clientId: staff.id
   }
   const columns = [
@@ -29,7 +28,7 @@ const EmployeeForm = props => {
       editCellType: 'treeSelect'
     },
     {
-      dataIndex: 'departmentName',
+      dataIndex: 'supervisorName',
       label: '部门上司',
       editCellType: 'custom',
       customCell: <ChangeSupervisor dataSource={changeCopInputData} />,

+ 19 - 6
src/pages/Staff/Employee/components/StaffModal/index.jsx

@@ -5,9 +5,10 @@ import { useDispatch } from 'dva'
 import { useDebounceFn } from 'ahooks'
 import { SearchOutlined, CloseOutlined } from '@ant-design/icons'
 import { queryStaff } from '@/services/staff'
+import { apiChangeSupervisor } from '@/services/staff'
 import styles from './index.less'
 
-const StaffModal = () => {
+const StaffModal = ({ clientId, onSelect }) => {
   const scrollRef = useRef()
   const dispatch = useDispatch()
   const [state, setState] = useState({
@@ -21,15 +22,17 @@ const StaffModal = () => {
     const { data: { list, total } = { list: [], total: 0 }, code = -1 } = await queryStaff(params)
     if (code === consts.RET_CODE.SUCCESS) {
       if (params?.page === 1) {
+        scrollRef.current?.scrollTo({ top: 0 })
         // 请求的是第一页
-        setState({ ...state, list, total, loading: false })
+        setState({ ...state, list, total, loading: false, searchVal: params?.search })
       } else {
         setState({
           ...state,
           list: state.list.concat(list),
           total,
+          searchVal: params?.search,
           loading: false,
-          pageSize: params?.pageSize || 1
+          current: params?.current || 1
         })
       }
     }
@@ -40,7 +43,7 @@ const StaffModal = () => {
   }, [])
   const onChange = e => {
     const { value = '' } = e.target || e.currentTarget
-    initData({ search: value, current: state.current, pageSize: state.pageSize })
+    initData({ search: value, current: 1, pageSize: state.pageSize })
   }
 
   const { run: handleInputChange } = useDebounceFn(onChange)
@@ -51,6 +54,15 @@ const StaffModal = () => {
     })
   }
 
+  // 关联上司
+  const connectStaff = async supervisorId => {
+    const { code = -1 } = await apiChangeSupervisor({ id: clientId, supervisorId })
+    if (code === consts.RET_CODE.SUCCESS) {
+      onSelect()
+      closeModal()
+    }
+  }
+
   const handleListScroll = () => {
     // 未滚动到底部
     if (
@@ -58,7 +70,8 @@ const StaffModal = () => {
       scrollRef.current.scrollTop
     ) {
       // 已到底部
-      initData({ current: state.current + 1, pageSize: state.pageSize })
+      state.current * state.pageSize < state.total &&
+        initData({ current: state.current + 1, pageSize: state.pageSize, search: state.searchVal })
     }
   }
   return (
@@ -83,7 +96,7 @@ const StaffModal = () => {
               <span className="w-1/6">{item.position}</span>
               <span className="w-1/2 zh-justify-between">
                 <span>{item.emergencyContacts}</span>
-                <Button type="primary" size="small">
+                <Button type="primary" size="small" onClick={() => connectStaff(item.id)}>
                   关联
                 </Button>
               </span>