import React, { useEffect, useState, useRef, useMemo } from 'react'; import { connect } from 'react-redux'; import { Table, Button, Pagination, Skeleton, Form, Tooltip } from '@douyinfe/semi-ui'; import { IconSearch } from '@douyinfe/semi-icons'; import { SkeletonScreen } from "$components"; import '../style.less' import { Setup } from "$components"; import moment from 'moment' import { set } from 'nprogress'; const leaveStatistics = (props) => { const { dispatch, actions, history, user, loading, socket, xqMembers } = props const { humanAffairs } = actions; const form = useRef();//表单 let [archivesList, setArchivesList] = useState([]);//人员列表 let [mytypeList, setTypeList] = useState([]);//请假类型列表 const [setup, setSetup] = useState(false);//表格设置是否显现 const [setupp, setSetupp] = useState([]);//实际显示的表格列表 const [lookup, setLookup] = useState({});//搜索 const [query, setQuery] = useState({ limit: 10, page: 0 }); //页码信息 const [order, setOrder] = useState({ orderBy: 'code', orderDirection: 'DESC' }); //页码信息 const [limits, setLimits] = useState()//每页实际条数 const [downloadUrl, setDownloadUrl] = useState('')//下载pdf const LEAVESTATISTICS = "leaveStatistics"; const page = useRef(query.page);//哪一页 const [tableList, setTableList] = useState([{ title: '展示信息', list: [ { name: "姓名", value: "userName" }, { name: "所属部门", value: "departmrnt" }, { name: "职位", value: "roleName" }, { name: "合计请假时长", value: "vacateDayStatisticDuration" }, { name: "合计请假次数", value: "vacateCount" }, ] }]);//表格属性 useEffect(() => { localStorage.getItem(LEAVESTATISTICS) == null ? localStorage.setItem( LEAVESTATISTICS, JSON.stringify(['userName', 'departmrnt', 'roleName', 'vacateCount', 'vacateDayStatisticDuration']) ) : ""; getAttendanceVacateTypeList() }, []) useEffect(() => { getAttendanceVacateList()//查询人员列表 }, [query, order]) function getAttendanceVacateList () {//查询人员列表 let obj = lookup if (lookup.entryTime?.length > 1) { obj.startDate = moment(lookup.entryTime[0]).format('YYYY-MM-DD') obj.endDate = moment(lookup.entryTime[1]).format('YYYY-MM-DD') } else { obj.startDate = '' obj.endDate = '' } dispatch(humanAffairs.getAttendanceVacate({ ...obj, ...query, ...order })).then((res) => {//查询人员列表 if (res.success) { setArchivesList(res.payload?.data?.rows) setLimits(res.payload?.data?.count) } }) } function getAttendanceVacateTypeList () { dispatch(humanAffairs.getAttendanceVacateType()).then((res) => {//查询人员列表 if (res.success) { let myTableList = tableList for (let i = 0; i < res.payload?.data?.length; i++) { myTableList[0].list.push({ name: res.payload?.data[i].type, value: res.payload?.data[i].type },) } setTypeList(res.payload?.data) setTableList(myTableList) attribute(res.payload?.data); } }) } const columns = [ { title: ( 员工编号 ), width: 200, dataIndex: "userCode", key: "userCode", sorter: (a, b) => { }, render: (_, r, index) => { return (r.userCode ? r.userCode : '-'); }, }, ]; //获取表格属性设置 function attribute (typeList) { const arr = localStorage.getItem(LEAVESTATISTICS) ? JSON.parse(localStorage.getItem(LEAVESTATISTICS)) : []; let column = [ { title: (
姓名
), width: 100, dataIndex: "userName", key: "userName", render: (_, r, index) => { return (r.userName ? r.userName : '-'); }, }, { title: (
所属部门
), width: 200, dataIndex: "departmrnt", key: "departmrnt", render: (_, r, index) => { return (
{ r.departmrnt.map((ite, idx) => { let departmentsArr = [] for (let i = 0; i < r.departmrnt.length; i++) { departmentsArr.push(r.departmrnt[i].name) } return (
{idx == 0 ? (
{ite.name}
) : ('') } { r.departmrnt.length > 1 && idx == 1 ? (
+{r.departmrnt.length - 1}
) : ('') }
) }) }
) }, }, { title: (
职位
), width: 150, dataIndex: "roleName", key: "roleName", render: (_, r, index) => { return (
{ r.role.map((ite, idx) => { let roleArr = [] for (let i = 0; i < r.role.length; i++) { roleArr.push(r.role[i].name) } return (
{idx == 0 ? (ite.name) : ('') } { r.role.length > 1 && idx == 1 ? (
+{r.role.length - 1}
) : ('') }
) }) }
); }, }, ]; for (let j = 0; j < typeList.length; j++) { column.push({ title: (typeList[j].type + '/h'), width: 160, dataIndex: typeList[j].type, key: typeList[j].type, render: (_, r, index) => { return (r.vacateStatistic.findIndex(((ev) => { return ev.type == typeList[j].type })) !== -1 ? r.vacateStatistic[r.vacateStatistic.findIndex(((ev) => { return ev.type == typeList[j].type }))].duration / 3600 : '0') }, }) } column.push({ title: '合计请假时长/h', width: 160, dataIndex: "vacateDayStatisticDuration", key: "vacateDayStatisticDuration", sorter: (a, b) => { }, render: (_, r, index) => { return (r.vacateDayStatisticDuration ? r.vacateDayStatisticDuration / 3600 : '0') }, }) column.push({ title: '合计请假次数/次', width: 160, dataIndex: "vacateCount", key: "vacateCount", sorter: (a, b) => { }, render: (_, r, index) => { return (r.vacateCount ? r.vacateCount : '0') }, }) for (let i = 0; i < arr.length; i++) { let colum = column.filter((item) => { return item.key === arr[i]; }); columns.splice(i + 2, 0, colum[0]); } setSetupp(columns); } function handleRow (record, index) {//斑马条纹 // 给偶数行设置斑马纹 if (index % 2 === 0) { return { style: { background: '#FAFCFF', } }; } else { return {}; } } const scroll = useMemo(() => ({}), []); return ( <>
人事管理
/
假勤管理
/
请假统计
请假统计
LEAVE STATISTICS
{ // console.log('values', values); }} getFormApi={(formApi) => (form.current = formApi)} >
职位 部门 编号 姓名 } field="keyword" pure showClear style={{ width: 346, marginLeft: 12, marginRight: 12 }} placeholder="请输入或选择关键词" />
{ let obj = form.current.getValues() if (form.current.getValues().entryTime?.length > 1) { obj.startDate = moment(form.current.getValues().entryTime[0]).format('YYYY-MM-DD') obj.endDate = moment(form.current.getValues().entryTime[1]).format('YYYY-MM-DD') } else { obj.startDate = '' obj.endDate = '' } setDownloadUrl(`attendance/vacate/export?token=${user.token}&keywordTarget=${obj.keywordTarget ? obj.keywordTarget : ''}&keyword=${obj.keyword ? obj.keyword : ''}&startDate=${obj.startDate}&endDate=${obj.endDate}&limit=${query.limit}&page=${query.page}}`) }}> { downloadUrl ?