Jelajahi Sumber

fix: cld2通讯录的调整

outaozhen 4 tahun lalu
induk
melakukan
5cc183f591
1 mengubah file dengan 20 tambahan dan 20 penghapusan
  1. 20 20
      src/pages/Hr/AddressBook/index.jsx

+ 20 - 20
src/pages/Hr/AddressBook/index.jsx

@@ -1,27 +1,37 @@
 import BasicTable from '@/components/Table'
-import consts from '@/consts'
 import { PageContainer } from '@ant-design/pro-layout'
-import React, { useEffect, useState } from 'react'
+import React, { useEffect, useMemo, useState } from 'react'
 import { connect } from 'umi'
 import Organization from './components/Organization'
 
-const AddressBook = props => {
+export type AddressBookProps = {
+  allStaffList: any[]
+}
+
+const AddressBook: React.FC<AddressBookProps> = props => {
   const { dispatch, allStaffList = [] } = props
   const [state, setState] = useState({
-    params: { id: '0' }
+    departmentId: '0'
   })
   const initData = () => {
     dispatch({
       type: 'staff/fetchStaffList'
     })
   }
+  const dataSource = useMemo(() => {
+    if (state.departmentId === '0') {
+      return allStaffList
+    }
+    return allStaffList.filter(item => item.departmentId === state.departmentId)
+  }, [state.departmentId, allStaffList])
+
   useEffect(() => {
     if (!allStaffList.length) {
       initData()
     }
   }, [])
-  const onSelect = id => {
-    setState({ ...state, params: { id } })
+  const onSelect = departmentId => {
+    setState({ ...state, departmentId })
   }
   const columns = [
     {
@@ -79,26 +89,16 @@ const AddressBook = props => {
         <Organization onSelect={onSelect} />
         <div style={{ width: 'calc(100% - 12rem)' }}>
           <div className="ml-6 shadow-hex-3e2c5a">
-            {state.params.id && (
+            {allStaffList.length ? (
               <BasicTable
                 mainMenuType="hr"
                 columnStateType="ADDRESSBOOK"
-                params={{ departmentId: state.params.id }}
-                rowKey={record => record.id}
+                rowKey={'id'}
                 columns={columns}
-                dataSource={allStaffList}
-                // request={async params => {
-                //   const { code = -1, data: { list = [], total = 0 } = { list: [], total: 0 } } =
-                //     await queryStaff({ ...params })
-                //   return {
-                //     data: list,
-                //     success: code === consts.RET_CODE.SUCCESS,
-                //     total
-                //   }
-                // }}
+                dataSource={dataSource}
                 search={false}
               />
-            )}
+            ) : null}
           </div>
         </div>
       </div>