123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- import React, { useState, useEffect } from 'react'
- import ShowTitleMenu from './components/ShowTitleMenu'
- import { useRequest } from 'umi'
- import { Plus, Delete } from '@icon-park/react'
- import { Table, Tag, Popconfirm, Popover, Button, Alert } from 'antd'
- import { fetchAttendanceList, unlinkAttendance, deleteAttendance } from '@/services/user/system'
- import ConnectModal from '@/pages/role/System/components/ConnectModal'
- import ProForm, { ProFormText } from '@ant-design/pro-form'
- const titleOptions = [
- { label: '加班申请人', value: '0' },
- { label: '销假参数', value: '1' }
- ]
- export enum modalType {
- addobjectModal = 0,
- linkAttendance = 1
- }
- const Attendance: React.FC = () => {
- const [state, setState] = useState({
- id: '0',
- attendanceList: [],
- visible: false,
- type: modalType.addobjectModal
- })
- const onSelect = (id: string) => {
- setState({ ...state, id })
- }
- const { run: tryGetRoleStaffList } = useRequest(fetchAttendanceList, {
- manual: true,
- onSuccess: result => {
- setState({ ...state, attendanceList: result })
- }
- })
- const { run: tryunlinkAttendance } = useRequest(
- (params: API.LinkAttendance) => {
- return unlinkAttendance(params)
- },
- {
- manual: true,
- onSuccess: () => {
- tryGetRoleStaffList(state.id)
- }
- }
- )
- const { run: tryDeleteAttendance } = useRequest(
- (params: API.DeleteAttendance) => {
- return deleteAttendance(params)
- },
- {
- manual: true,
- onSuccess: () => {
- tryGetRoleStaffList(state.id)
- }
- }
- )
- useEffect(() => {
- if (state.id) {
- tryGetRoleStaffList(state.id)
- }
- }, [state.id])
- const columns: ColumnsType<API.AttendanceItem> = [
- {
- title: '申请人名称',
- dataIndex: 'applicantStaffName',
- width: '15%'
- },
- {
- title: '申请对象',
- dataIndex: 'staff',
- align: 'left',
- width: '70%',
- render: (_, record: API.AttendanceItem) => {
- return (
- <div>
- {record.staff.map(item => (
- <Tag
- key={item.staffId}
- closable={true}
- onClose={() => tryunlinkAttendance({ staffId: item.staffId, id: record.id })}>
- {item.staffName}
- </Tag>
- ))}
- <span
- className="hover:text-hex-886ab5 cursor-pointer text-purple-500"
- onClick={() =>
- setState({
- ...state,
- id: record.id,
- visible: true,
- type: modalType.linkAttendance
- })
- }>
- <Plus />
- 添加
- </span>
- </div>
- )
- }
- },
- {
- title: '操作',
- dataIndex: 'opreate',
- width: '10%',
- render: (_, record) => (
- // console.log(record.id)
- <Popover>
- <Popconfirm
- title="确认删除吗?"
- okText="确认"
- cancelText="取消"
- onConfirm={() => tryDeleteAttendance({ id: record.id })}>
- <span className="hover:text-hex-e7026e cursor-pointer">
- <Delete fill="#fd3995" />
- </span>
- </Popconfirm>
- </Popover>
- )
- }
- ]
- return (
- <div className="h-full w-full flex flex-row">
- <ShowTitleMenu onSelect={onSelect} option={titleOptions} selectDefaultValue="0" />
- <div className="w-max-3/4">
- <div className="ml-8 bg-white p-4 shadow-md shadow-hex-3e2c5a relative">
- {state.id === '0' ? (
- <>
- <div className="absolute right-7 top-7 z-100">
- <Button
- type="primary"
- onClick={() =>
- setState({ ...state, visible: true, type: modalType.addobjectModal })
- }>
- 添加新申请人
- </Button>
- <ConnectModal
- dataId={state.id}
- show={state.visible}
- onShowChange={(visible: boolean) => setState({ ...state, visible })}
- onReload={() => tryGetRoleStaffList(state.id)}
- postUrl={
- state.type === modalType.addobjectModal
- ? '/attendance/add'
- : '/attendance/linkStaff'
- }
- showButton={false}
- />
- </div>
- <Table
- bordered
- title={() => '加班申请人'}
- columns={columns}
- dataSource={state.attendanceList}
- rowKey={row => row.id}
- />
- </>
- ) : null}
- {state.id === '1' ? (
- <>
- <div>
- <ProForm onFinish={async values => console.log(values)}>
- <h3 className="font-bold">销假参数</h3>
- <div className="mt-4 mb-4">
- <Alert
- type="warning"
- message="超过当前设置销假参数(不包含当前所写的)不计算考勤"
- />
- </div>
- <ProForm.Group>
- <span>每月</span>
- <ProFormText name="CLD_parameters" label="" initialValue={5} />
- <span>号</span>
- </ProForm.Group>
- </ProForm>
- </div>
- </>
- ) : null}
- </div>
- </div>
- </div>
- )
- }
- export default Attendance
|