ソースを参照

feat: 人资修改更换部门上司+删除部门上司

outaozhen 5 年 前
コミット
420cf47eb2

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

@@ -1,17 +1,32 @@
 import React from 'react'
-import { Switch } from '@icon-park/react'
+import { Switch, LinkInterrupt, LinkOne } from '@icon-park/react'
 import { useModal } from '@/components/Modal'
 import { Card, Tooltip } from 'antd'
 import consts from '@/basic/consts'
 import { useDispatch } from 'dva'
 import StaffModal from '@/pages/Staff/Employee/components/StaffModal'
 import styles from './index.less'
+import { apiChangeSupervisor } from '@/services/staff'
+
+export const ChangeCompMap = {
+  STAFF: {
+    key: 'staff',
+    title: '员工'
+  }
+}
 
 const ChangeSupervisor = props => {
   const dispatch = useDispatch()
   const { toggleModal, setModalProps } = useModal()
   const {
-    dataSource: { staffId, clientId, staffName }
+    dataSource: {
+      staffId,
+      clientId,
+      staffName,
+      targetName,
+      actionPayload = ChangeCompMap.STAFF.key,
+      title = '员工'
+    }
   } = props
   const refreshStaff = () => {
     dispatch({
@@ -22,7 +37,35 @@ const ChangeSupervisor = props => {
   const handleConnectStaff = () => {
     setModalProps({
       width: '60vw',
-      modalRender: () => <StaffModal onSelect={refreshStaff} id={clientId} />,
+      modalRender: () => (
+        <StaffModal onSelect={refreshStaff} id={clientId} postUrl={actionPayload} />
+      ),
+      onCancel: () => toggleModal()
+    })
+    toggleModal()
+  }
+  const notValueRender = (
+    <div onClick={handleConnectStaff} className={styles.notCompanyContent}>
+      <LinkOne size="14" />
+      <span className="ml-5px">关联客户</span>
+    </div>
+  )
+
+  const removeSupervisor = () => {
+    setModalProps({
+      title: '确认移除',
+      children: (
+        <p>
+          为{title}
+          <span className="mr-3px ml-3px font-600">{targetName}</span>移除
+          <span className="mr-3px ml-3px font-600">{staffName}</span>
+        </p>
+      ),
+      onOk: async () => {
+        await apiChangeSupervisor(actionPayload, { id: clientId, dataId: '0' })
+        refreshStaff()
+        toggleModal()
+      },
       onCancel: () => toggleModal()
     })
     toggleModal()
@@ -31,7 +74,12 @@ const ChangeSupervisor = props => {
     <Card size="small">
       <div className="flex justify-between">
         <div className={styles.nameContent}>{staffName}</div>
-        <div className="w-30px">
+        <div className="w-55px">
+          <Tooltip placement="right" title="移除上司">
+            <span className={styles.unlinkIcon} onClick={removeSupervisor}>
+              <LinkInterrupt />
+            </span>
+          </Tooltip>
           <Tooltip
             placement="right"
             title="更换上司"
@@ -47,7 +95,8 @@ const ChangeSupervisor = props => {
   )
   return (
     <div className={styles.companyInput}>
-      {staffId === consts.ENCRYPTION_ZERO && normalValueRender}
+      {staffId !== consts.ENCRYPTION_ZERO ? normalValueRender : notValueRender}
+      {/* {staffId === consts.ENCRYPTION_ZERO && normalValueRender} */}
     </div>
   )
 }

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

@@ -7,7 +7,7 @@ const EmployeeForm = props => {
   const { staff } = props
   const changeCopInputData = {
     staffName: staff.supervisorName,
-    staffId: staff.staffId,
+    staffId: staff.id,
     clientId: staff.id
   }
   const columns = [

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

@@ -4,11 +4,11 @@ import consts from '@/basic/consts'
 import { useDispatch } from 'dva'
 import { useDebounceFn } from 'ahooks'
 import { SearchOutlined, CloseOutlined } from '@ant-design/icons'
-import { queryStaff } from '@/services/staff'
+import { queryStaff, apiChangeSupervisor } from '@/services/staff'
 import styles from './index.less'
-import request from '@/basic/utils/request'
+// import request from '@/basic/utils/request'
 
-const StaffModal = ({ id, onSelect, postUrl = '/staff/change/supervisor' }) => {
+const StaffModal = ({ id, onSelect, postUrl }) => {
   const scrollRef = useRef()
   const dispatch = useDispatch()
   const [state, setState] = useState({
@@ -56,7 +56,7 @@ const StaffModal = ({ id, onSelect, postUrl = '/staff/change/supervisor' }) => {
 
   // 关联上司
   const connectStaff = async dataId => {
-    const { code = -1 } = await request.post(postUrl, { data: { id, dataId } })
+    const { code = -1 } = await apiChangeSupervisor(postUrl, { id, dataId })
     if (code === consts.RET_CODE.SUCCESS) {
       onSelect()
       closeModal()

+ 2 - 2
src/services/staff.js

@@ -23,7 +23,7 @@ export async function apiStaffDetail(id) {
 }
 
 /** 员工更换上司 */
-export async function apiChangeSupervisor(payload) {
-  const data = await request.post('/staff/change/supervisor', { data: { ...payload } })
+export async function apiChangeSupervisor(postUrl, payload) {
+  const data = await request.post(`/${postUrl}/change/supervisor`, { data: { ...payload } })
   return data
 }