index.tsx 3.2 KB

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