index.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import React, { useState, useEffect } from 'react'
  2. import AttendanceMenu from './components/AttendanceMenu'
  3. import { useRequest } from 'umi'
  4. import { Plus, Delete } from '@icon-park/react'
  5. import ConnectModal from './components/ConnectModal'
  6. import { Table, Tag, Popconfirm, Popover, Button } from 'antd'
  7. import { fetchAttendanceList, unlinkAttendance, deleteAttendance } from '@/services/user/system'
  8. export enum modalType {
  9. addobjectModal = 0,
  10. linkAttendance = 1
  11. }
  12. const Attendance = () => {
  13. const [state, setState] = useState({
  14. id: '',
  15. modalId: '',
  16. attendanceList: [],
  17. visible: false,
  18. type: modalType.addobjectModal
  19. })
  20. const { run: tryGetRoleStaffList } = useRequest(fetchAttendanceList, {
  21. onSuccess: result => {
  22. setState({ ...state, attendanceList: result })
  23. }
  24. })
  25. const { run: tryunlinkAttendance } = useRequest(
  26. (params: API.LinkAttendance) => {
  27. return unlinkAttendance(params)
  28. },
  29. {
  30. manual: true,
  31. onSuccess: () => {
  32. tryGetRoleStaffList(state.id)
  33. }
  34. }
  35. )
  36. const { run: tryDeleteAttendance } = useRequest(
  37. (params: API.DeleteAttendance) => {
  38. return deleteAttendance(params)
  39. },
  40. {
  41. manual: true,
  42. onSuccess: () => {
  43. tryGetRoleStaffList(state.id)
  44. }
  45. }
  46. )
  47. useEffect(() => {
  48. if (state.id) {
  49. tryGetRoleStaffList(state.id)
  50. }
  51. return () => {
  52. // formRef.current?.resetFields()
  53. }
  54. }, [state.id])
  55. const columns: ColumnsType<API.AttendanceItem> = [
  56. {
  57. title: '申请人名称',
  58. dataIndex: 'applicantStaffName',
  59. width: '15%'
  60. },
  61. {
  62. title: '申请对象',
  63. dataIndex: 'staff',
  64. align: 'left',
  65. width: '70%',
  66. render: (_, record: API.AttendanceItem) => (
  67. <div>
  68. {record.staff.map(item => (
  69. // console.log(item.staffName)
  70. <span key={item.staffId} className="zh-mg-bottom-5 zh-block">
  71. <Tag
  72. closable={true}
  73. onClose={() => tryunlinkAttendance({ staffId: item.staffId, id: record.id })}>
  74. {item.staffName}
  75. </Tag>
  76. </span>
  77. ))}
  78. <span
  79. className="hover:text-hex-886ab5 cursor-pointer text-purple-500"
  80. onClick={() =>
  81. setState({
  82. ...state,
  83. modalId: record.id,
  84. visible: true,
  85. type: modalType.linkAttendance
  86. })
  87. }>
  88. <Plus />
  89. 添加
  90. </span>
  91. </div>
  92. )
  93. },
  94. {
  95. title: '操作',
  96. dataIndex: 'opreate',
  97. width: '10%',
  98. render: (_, record) => (
  99. // console.log(record.id)
  100. <Popover>
  101. <Popconfirm
  102. title="确认删除吗?"
  103. okText="确认"
  104. cancelText="取消"
  105. onConfirm={() => tryDeleteAttendance({ id: record.id })}>
  106. <span className="hover:text-hex-e7026e cursor-pointer">
  107. <Delete fill="#fd3995" />
  108. </span>
  109. </Popconfirm>
  110. </Popover>
  111. )
  112. }
  113. ]
  114. return (
  115. <div className="h-full w-full flex flex-row">
  116. <AttendanceMenu itemTitle="加班申请人" />
  117. <div className="w-max-3/4">
  118. <div className="ml-8 bg-white p-4 shadow-md shadow-hex-3e2c5a relative">
  119. <div className="absolute right-7 top-7 z-100">
  120. <Button
  121. type="primary"
  122. onClick={() => setState({ ...state, visible: true, type: modalType.addobjectModal })}>
  123. 添加新申请人
  124. </Button>
  125. <ConnectModal
  126. type={state.type}
  127. dataId={state.modalId}
  128. visible={state.visible}
  129. onCancel={() => setState({ ...state, visible: false })}
  130. onRefresh={() => {
  131. tryGetRoleStaffList(state.id)
  132. }}
  133. />
  134. </div>
  135. <Table
  136. bordered
  137. title={() => '加班申请人'}
  138. columns={columns}
  139. dataSource={state.attendanceList}
  140. rowKey={row => row.id}
  141. />
  142. </div>
  143. </div>
  144. </div>
  145. )
  146. }
  147. export default Attendance