index.jsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. import React, { useState } from 'react'
  2. import consts from '@/consts'
  3. import { Button, Popconfirm, message } from 'antd'
  4. import { useModal } from '@/components/Modal'
  5. import RoleMenu from '@/pages/Hr/Employee/components/RoleMenu'
  6. import { queryStaff } from '@/services/staff'
  7. import EmployeeDetail from '@/pages/Hr/Employee/components/EmployeeDetail'
  8. import { delDepartment } from '@/services/department'
  9. import { connect, useAccess } from 'umi'
  10. import BasicTable from '@/components/Table'
  11. const Employee = props => {
  12. const { dispatch } = props
  13. const [state, setState] = useState({
  14. params: { id: '0' }
  15. })
  16. const initData = () => {
  17. dispatch({
  18. type: 'staff/fetchDepartments'
  19. })
  20. }
  21. const { toggleDrawer, setDrawerProps } = useModal()
  22. // 展示员工详情
  23. const showDrawer = id => {
  24. setDrawerProps({
  25. closable: true,
  26. onClose: () => toggleDrawer(),
  27. bodyStyle: {
  28. height: '100vh',
  29. overflowY: 'hidden'
  30. },
  31. children: <EmployeeDetail dataId={id} />
  32. })
  33. toggleDrawer()
  34. }
  35. const columns = [
  36. {
  37. title: '工号',
  38. dataIndex: 'jobNumber',
  39. search: false,
  40. width: 50
  41. },
  42. {
  43. title: '姓名',
  44. dataIndex: 'username',
  45. search: false,
  46. width: 50,
  47. render: (username, record) => (
  48. <span
  49. onClick={() => showDrawer(record.id)}
  50. className="text-primary cursor-pointer hover:text-[#967bbd]"
  51. >
  52. {username}
  53. </span>
  54. )
  55. },
  56. {
  57. title: '手机',
  58. dataIndex: 'telephone',
  59. search: false,
  60. width: 50
  61. },
  62. {
  63. title: 'QQ',
  64. dataIndex: 'qq',
  65. search: false,
  66. width: 50
  67. },
  68. {
  69. title: '部门',
  70. dataIndex: 'departmentName',
  71. search: false,
  72. width: 50
  73. },
  74. {
  75. title: '岗位',
  76. dataIndex: 'position',
  77. search: false,
  78. width: 50
  79. },
  80. {
  81. title: '聘用状态',
  82. dataIndex: 'nature',
  83. search: false,
  84. width: 50
  85. },
  86. {
  87. title: '入职时间',
  88. dataIndex: 'hiredate',
  89. search: false,
  90. width: 50
  91. },
  92. {
  93. title: '离职时间',
  94. dataIndex: 'dimissionDate',
  95. search: false,
  96. width: 50
  97. }
  98. ]
  99. const onSelect = id => {
  100. setState({ ...state, params: { id } })
  101. }
  102. const handleDelDepartment = async id => {
  103. const { code = -1 } = await delDepartment(id)
  104. if (code === consts.RET_CODE.SUCCESS) {
  105. message.success('删除成功')
  106. initData()
  107. }
  108. }
  109. const hasPerm = useAccess()?.validatePermByType('employee_del_department')
  110. return (
  111. <div className="h-full w-full flex flex-row">
  112. <RoleMenu onSelect={onSelect} />
  113. <div style={{ width: 'calc(100% - 12rem)' }}>
  114. <div className="ml-8 shadow-hex-3e2c5a">
  115. {/* <div className="absolute right-33 top-3 z-100">
  116. {hasPerm && state.params.id && (
  117. <Popconfirm
  118. title="确认删除吗?"
  119. onText="确认"
  120. cancelText="取消"
  121. // onConfirm={() => console.log(state.params.id)}
  122. onConfirm={() => handleDelDepartment(state.params.id)}
  123. >
  124. <Button danger size="small">
  125. 删除部门
  126. </Button>
  127. </Popconfirm>
  128. )}
  129. </div> */}
  130. {state.params.id && (
  131. <BasicTable
  132. columnStateType="EMPLOYEE"
  133. params={{ departmentId: state.params.id }}
  134. rowKey={record => record.id}
  135. columns={columns}
  136. request={async params => {
  137. const { code = -1, data: { list = [], total = 0 } = { list: [], total: 0 } } =
  138. await queryStaff({ ...params })
  139. return {
  140. data: list,
  141. success: code === consts.RET_CODE.SUCCESS,
  142. total
  143. }
  144. }}
  145. search={false}
  146. toolbar={{
  147. actions: [
  148. <>
  149. {hasPerm && state.params.id && (
  150. <Popconfirm
  151. title="确认删除吗?"
  152. onText="确认"
  153. cancelText="取消"
  154. // onConfirm={() => console.log(state.params.id)}
  155. onConfirm={() => handleDelDepartment(state.params.id)}
  156. >
  157. <Button danger size="small">
  158. 删除部门
  159. </Button>
  160. </Popconfirm>
  161. )}
  162. </>
  163. ]
  164. }}
  165. />
  166. )}
  167. </div>
  168. </div>
  169. </div>
  170. )
  171. }
  172. // export default Employee
  173. export default connect(({ staff }) => ({
  174. departments: staff.departments
  175. }))(Employee)