index.tsx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. import React, { useState, useEffect } from 'react'
  2. import ShowTitleMenu from './components/ShowTitleMenu'
  3. import { useRequest } from 'umi'
  4. import { Plus, Delete } from '@icon-park/react'
  5. import { Table, Tag, Popconfirm, Popover, Button, Alert } from 'antd'
  6. import { fetchAttendanceList, unlinkAttendance, deleteAttendance } from '@/services/user/system'
  7. import ConnectModal from '@/pages/role/System/components/ConnectModal'
  8. import ProForm, { ProFormText } from '@ant-design/pro-form'
  9. const titleOptions = [
  10. { label: '加班申请人', value: '0' },
  11. { label: '销假参数', value: '1' }
  12. ]
  13. export enum modalType {
  14. addobjectModal = 0,
  15. linkAttendance = 1
  16. }
  17. const Attendance: React.FC = () => {
  18. const [state, setState] = useState({
  19. id: '0',
  20. attendanceList: [],
  21. visible: false,
  22. type: modalType.addobjectModal
  23. })
  24. const onSelect = (id: string) => {
  25. setState({ ...state, id })
  26. }
  27. const { run: tryGetRoleStaffList } = useRequest(fetchAttendanceList, {
  28. manual: true,
  29. onSuccess: result => {
  30. setState({ ...state, attendanceList: result })
  31. }
  32. })
  33. const { run: tryunlinkAttendance } = useRequest(
  34. (params: API.LinkAttendance) => {
  35. return unlinkAttendance(params)
  36. },
  37. {
  38. manual: true,
  39. onSuccess: () => {
  40. tryGetRoleStaffList(state.id)
  41. }
  42. }
  43. )
  44. const { run: tryDeleteAttendance } = useRequest(
  45. (params: API.DeleteAttendance) => {
  46. return deleteAttendance(params)
  47. },
  48. {
  49. manual: true,
  50. onSuccess: () => {
  51. tryGetRoleStaffList(state.id)
  52. }
  53. }
  54. )
  55. useEffect(() => {
  56. if (state.id) {
  57. tryGetRoleStaffList(state.id)
  58. }
  59. }, [state.id])
  60. const columns: ColumnsType<API.AttendanceItem> = [
  61. {
  62. title: '申请人名称',
  63. dataIndex: 'applicantStaffName',
  64. width: '15%'
  65. },
  66. {
  67. title: '申请对象',
  68. dataIndex: 'staff',
  69. align: 'left',
  70. width: '70%',
  71. render: (_, record: API.AttendanceItem) => {
  72. return (
  73. <div>
  74. {record.staff.map(item => (
  75. <Tag
  76. key={item.staffId}
  77. closable={true}
  78. onClose={() => tryunlinkAttendance({ staffId: item.staffId, id: record.id })}>
  79. {item.staffName}
  80. </Tag>
  81. ))}
  82. <span
  83. className="hover:text-hex-886ab5 cursor-pointer text-purple-500"
  84. onClick={() =>
  85. setState({
  86. ...state,
  87. id: record.id,
  88. visible: true,
  89. type: modalType.linkAttendance
  90. })
  91. }>
  92. <Plus />
  93. 添加
  94. </span>
  95. </div>
  96. )
  97. }
  98. },
  99. {
  100. title: '操作',
  101. dataIndex: 'opreate',
  102. width: '10%',
  103. render: (_, record) => (
  104. // console.log(record.id)
  105. <Popover>
  106. <Popconfirm
  107. title="确认删除吗?"
  108. okText="确认"
  109. cancelText="取消"
  110. onConfirm={() => tryDeleteAttendance({ id: record.id })}>
  111. <span className="hover:text-hex-e7026e cursor-pointer">
  112. <Delete fill="#fd3995" />
  113. </span>
  114. </Popconfirm>
  115. </Popover>
  116. )
  117. }
  118. ]
  119. return (
  120. <div className="h-full w-full flex flex-row">
  121. <ShowTitleMenu onSelect={onSelect} option={titleOptions} selectDefaultValue="0" />
  122. <div className="w-max-3/4">
  123. <div className="ml-8 bg-white p-4 shadow-md shadow-hex-3e2c5a relative">
  124. {state.id === '0' ? (
  125. <>
  126. <div className="absolute right-7 top-7 z-100">
  127. <Button
  128. type="primary"
  129. onClick={() =>
  130. setState({ ...state, visible: true, type: modalType.addobjectModal })
  131. }>
  132. 添加新申请人
  133. </Button>
  134. <ConnectModal
  135. dataId={state.id}
  136. show={state.visible}
  137. onShowChange={(visible: boolean) => setState({ ...state, visible })}
  138. onReload={() => tryGetRoleStaffList(state.id)}
  139. postUrl={
  140. state.type === modalType.addobjectModal
  141. ? '/attendance/add'
  142. : '/attendance/linkStaff'
  143. }
  144. showButton={false}
  145. />
  146. </div>
  147. <Table
  148. bordered
  149. title={() => '加班申请人'}
  150. columns={columns}
  151. dataSource={state.attendanceList}
  152. rowKey={row => row.id}
  153. />
  154. </>
  155. ) : null}
  156. {state.id === '1' ? (
  157. <>
  158. <div>
  159. <ProForm onFinish={async values => console.log(values)}>
  160. <h3 className="font-bold">销假参数</h3>
  161. <div className="mt-4 mb-4">
  162. <Alert
  163. type="warning"
  164. message="超过当前设置销假参数(不包含当前所写的)不计算考勤"
  165. />
  166. </div>
  167. <ProForm.Group>
  168. <span>每月</span>
  169. <ProFormText name="CLD_parameters" label="" initialValue={5} />
  170. <span>号</span>
  171. </ProForm.Group>
  172. </ProForm>
  173. </div>
  174. </>
  175. ) : null}
  176. </div>
  177. </div>
  178. </div>
  179. )
  180. }
  181. export default Attendance