考勤管理结合请假加班数据

This commit is contained in:
XaoLi717 2025-02-14 10:23:54 +08:00
parent fad3e7c369
commit 4a05c21035
2 changed files with 228 additions and 158 deletions

View File

@ -36,15 +36,18 @@
disabled
/>
</el-form-item>
<el-form-item label="考勤表单">
<el-form-item v-if="buttonShow" label="数据创建">
<el-button type="success" @click="createKqglFormData()">点击生成考勤表单数据</el-button>
</el-form-item>
<el-form-item label="考勤表单" v-loading="TableLoading" prop="tableDate">
<el-table :data="listData" border style="width: 100%">
<el-table-column fixed prop="userName" label="姓名" width="80" />
<!-- 动态生成 1-31 天的列 -->
<el-table-column
v-for="day in 31"
v-for="day in monthMaxDay"
:key="day"
:label="day.toString()+'号'"
width="60"
:label="textYearMonth+day.toString()+'号'"
width="120"
>
<template #default="{$index, row}">
<span
@ -89,6 +92,9 @@ import * as DefinitionApi from '@/api/bpm/definition'
import * as UserApi from '@/api/system/user'
import {useTagsViewStore} from "@/store/modules/tagsView";
import {FormProcessMappingApi} from "@/api/bpm/formprocessmapping";
import {CalendarApi} from "@/api/home/calendar";
import {QjglDataApi, QjglDataVO} from "@/api/home/qjgldata";
import {JbglDataApi, JbglDataVO} from "@/api/home/jbgldata";
/** 考勤管理 表单 */
defineOptions({ name: 'KqglCreate' })
@ -108,12 +114,14 @@ const formData = ref({
deptId: undefined,
deptName: undefined,
date: 0,
tableDate: undefined as boolean | undefined,
})
const formRules = reactive({
userId: [{ required: true, message: '用户id不能为空', trigger: 'blur' }],
title: [{ required: true, message: '标题不能为空', trigger: 'blur' }],
deptId: [{ required: true, message: '部门id不能为空', trigger: 'blur' }],
date: [{ required: true, message: '考勤日期不能为空', trigger: 'blur' }],
tableDate: [{ required: true, message: '考勤表单不能为空', trigger: 'blur' }],
})
const pop = ref(false)//spanpop
const dateKey = ref(0);
@ -145,7 +153,7 @@ const queryParamsUser = reactive({
createTime: []
})
//
const dayStatus = [
let monthDayStatus = [
1,1,1,1,1,3,3,1,1,1,1,1,3,3,
1,1,1,1,1,3,3,1,1,1,1,1,3,3,1,1,1
]
@ -172,7 +180,10 @@ const userInfo = ref('') // 用户名字
//
const computedDate = computed(() => {
return formData.value.date? formData.value.date : dateKey.value;
const date = formData.value.date || dateKey.value;
textYearMonth.value = getTextYearMonth(date);
monthMaxDay.value = getMonthMaxDay(date);
return date;
})
//
@ -235,44 +246,47 @@ const createUser = async ()=>{
queryParamsUser.deptId = formData.value.deptId
const user = await getUserPageKQ(queryParamsUser)
const dataUser = user.list
for (let item of dataUser){
const data : KqdataVO = {
id:null,
userId:item.id,
userName:item.nickname,
deptId:item.deptId,
deptName:item.deptName,
dayStatus:dayStatus.join(','),
tokey:dateKey.value,
for (const item of dataUser) {
await getMonthListDate();
await getQjglToData(item);
await getJbglToData(item);
await computeMonthlyWorkStatus();
const data = {
id: null,
userId: item.id,
userName: item.nickname,
deptId: item.deptId,
deptName: item.deptName,
dayStatus: monthDayStatus.join(','),
tokey: dateKey.value,
workDay: 0,
overDay: 0,
yoverDay: 0,
}
// console.log(data)
await KqdataApi.createKqdata(data)
};
await KqdataApi.createKqdata(data);
}
}
//
const updateUser = async ()=>{
for (let item of listData.value){
const data : KqdataVO = {
id:item.id,
userId:item.userId,
userName:item.userName,
deptId:item.deptId,
deptName:item.deptName,
dayStatus: Array.isArray(item.dayStatus)
? item.dayStatus.join(',')
: String(item.dayStatus), //
tokey:item.tokey,
workDay: item.workDay,
overDay: item.overDay,
yoverDay: item.yoverDay,
}
// console.log(data)
await KqdataApi.updateKqdata(data);
}
await Promise.all(
listData.value.map(item => {
const data: KqdataVO = {
id: item.id,
userId: item.userId,
userName: item.userName,
deptId: item.deptId,
deptName: item.deptName,
dayStatus: Array.isArray(item.dayStatus) ? item.dayStatus.join(',') : String(item.dayStatus),
tokey: item.tokey,
workDay: item.workDay,
overDay: item.overDay,
yoverDay: item.yoverDay,
};
return KqdataApi.updateKqdata(data);
}
)
);
}
/** 查询列表 */
@ -292,12 +306,158 @@ const changeStatus = async ()=>{
item.dayStatus = item.dayStatus.split(',').map(Number);
}
}
// console.log(listData.value)
} finally {
formLoading.value = false
}
};
//
interface WorkDay {
date: string; // date
isWorkDay: number; // isWorkDay
}
const textYearMonth = ref('') //
const monthMaxDay = ref(); //
const buttonShow = ref(false); //
const TableLoading = ref(false) //
const monthDataStatus = ref<WorkDay[]>([]); //
const MonthData = ref(); //
const queryParamsDate = reactive({
pageNo: 1,
pageSize: 1,
id: undefined,
date: [textYearMonth.value+"01",textYearMonth.value+"31"],//
isWorkday: undefined,
content: undefined,
createTime: [],
})
const qjglToData = ref<QjglDataVO[]>([]) //
const queryParamsQjglData = reactive({
pageNo: 1,
pageSize: 10,
id: undefined,
userName: undefined,
userId: undefined as number | undefined,
deptName: undefined,
deptId: undefined as number | undefined,
leaveDate: [textYearMonth.value+"01",textYearMonth.value+"31"],
leaveType: undefined,
leaveDays: undefined,
createTime: [],
})
const jbglToData = ref<JbglDataVO[]>([]) //
const queryParamsJbglData = reactive({
pageNo: 1,
pageSize: 10,
id: undefined,
userName: undefined,
userId: undefined as number | undefined,
deptName: undefined,
deptId: undefined as number | undefined,
overtimeDate: [textYearMonth.value+"01",textYearMonth.value+"31"],
overtimeType: undefined,
overtimeDays: undefined,
createTime: [],
})
/*创建表单数据*/
const createKqglFormData = async () => {
TableLoading.value = true
try {
await createUser();
await getList(dateKey.value);
await changeStatus(); //
await getWorkDay(); //
formData.value.tableDate = true
} catch (e) {
buttonShow.value = false
TableLoading.value = false
console.error(`createKqglFormDataErr: ${e}`);
} finally {
buttonShow.value = false
TableLoading.value = false
}
}
/** 查询当前月份工作数据列表 */
const getMonthListDate = async () => {
try {
//
queryParamsDate.date = [textYearMonth.value+"01",textYearMonth.value+"31"];
const data = await CalendarApi.getPublicCalendarPage(queryParamsDate);
MonthData.value = data.list
}catch (e) {
console.error(`getMonthListDateErr: ${e}`);
}
}
/*查询当前月份请假数据列表*/
const getQjglToData= async (item?) => {
try {
queryParamsQjglData.leaveDate = [textYearMonth.value + "01", textYearMonth.value + "31"];
queryParamsQjglData.userId = item.id; queryParamsQjglData.deptId = item.deptId;
const QjglData = await QjglDataApi.getPublicQjglDataPage(queryParamsQjglData)
qjglToData.value = QjglData.list
}catch (e) {
console.error(`getQjglToDataErr: ${e}`);
}
}
/*查询当前月份请假数据列表*/
const getJbglToData= async (item?) => {
try {
queryParamsJbglData.overtimeDate = [textYearMonth.value + "01", textYearMonth.value + "31"];
queryParamsJbglData.userId = item.id; queryParamsJbglData.deptId = item.deptId;
const JbglData = await JbglDataApi.getPublicJbglDataPage(queryParamsJbglData)
jbglToData.value = JbglData.list
}catch (e) {
console.error(`getJbglToDataErr: ${e}`);
}
}
/*处理工作数据请假数据加班数据方法*/
const computeMonthlyWorkStatus = async () => {
monthDayStatus = []; //
monthDataStatus.value = MonthData.value.map((item) => ({date: item.date, isWorkDay: item.isWorkday,}))
if (qjglToData.value) {
qjglToData.value.forEach(item => {
const matchingDate = monthDataStatus.value.find(status => status.date === item.leaveDate);
if (matchingDate && matchingDate.isWorkDay === 1) {
matchingDate.isWorkDay = 2;
}
});
}
if (jbglToData.value) {
jbglToData.value.forEach(item => {
const matchingDate = monthDataStatus.value.find(status => status.date === item.overtimeDate);
if (matchingDate && matchingDate.isWorkDay === 0) {
matchingDate.isWorkDay = 4;
}
})
}
//
monthDayStatus = monthDataStatus.value.map((item: WorkDay) => {return item.isWorkDay === 0 ? 3 : item.isWorkDay;});
//
monthDayStatus.reverse();
}
//
function getTextYearMonth(dat: number|Date) {
const date = new Date(dat)
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0'); // 01
return `${year}-${month}-`;
}
//
function getMonthMaxDay(dat: number|Date) {
const date = new Date(dat)
const year = date.getFullYear();
const firstDayNextMonth = new Date(year, date.getMonth() + 1, 1); //
const lastDayThisMonth = new Date(firstDayNextMonth.getTime() - 1); //
return lastDayThisMonth.getDate(); //
}
//
const { query } = useRoute() //
const queryId = query.id as unknown as number // URL id
@ -316,9 +476,7 @@ const open = async () => {
formData.value = await KqglApi.getKqgl(queryId)
await getList() //使
} else {
//,,
await createUser()
await getList(dateKey.value)
buttonShow.value = true
}
await changeStatus()//
await getWorkDay()//
@ -456,6 +614,7 @@ const resetForm = () => {
deptId: undefined,
deptName: undefined,
date: 0,
tableDate: undefined
}
formRef.value?.resetFields()
}

View File

@ -42,10 +42,10 @@
<el-table-column fixed prop="userName" label="姓名" width="80" />
<!-- 动态生成 1-31 天的列 -->
<el-table-column
v-for="day in 31"
v-for="day in monthMaxDay"
:key="day"
:label="day.toString()+'号'"
width="60"
:label="textYearMonth+day.toString()+'号'"
width="120"
>
<!-- <template #default="{$index, row}">-->
<template #default="{row}">
@ -150,6 +150,8 @@ const workType = ref({
const formRef = ref() // Ref
const deptInfo = ref('') //
const userInfo = ref('') //
const textYearMonth = ref('') //
const monthMaxDay = ref<number>(); //
//
const { query } = useRoute() //
const props = defineProps({
@ -158,9 +160,32 @@ const props = defineProps({
//
const computedDate = computed(() => {
return formData.value.date? formData.value.date : dateKey.value;
const date = formData.value.date? formData.value.date : dateKey.value
updateDateValues(date);
return date;
})
function updateDateValues(date) {
textYearMonth.value = getTextYearMonth(date);
monthMaxDay.value = getMonthMaxDay(date);
}
//
function getTextYearMonth(dat: number|Date) {
const date = new Date(dat)
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0'); // 01
return `${year}-${month}-`;
}
//
function getMonthMaxDay(dat: number|Date) {
const date = new Date(dat)
const year = date.getFullYear();
const firstDayNextMonth = new Date(year, date.getMonth() + 1, 1); //
const lastDayThisMonth = new Date(firstDayNextMonth.getTime() - 1); //
return lastDayThisMonth.getDate(); //
}
const queryId = query.id as unknown as number // URL id
/** 打开弹窗 设置时间戳为固定信息 */
const open = async () => {
@ -302,117 +327,3 @@ defineExpose({ updateForm }) // 提供 open 方法,用于打开弹窗
<style scoped lang="scss">
</style>
<!--//-->
<!--// const queryParamsUser = reactive({-->
<!--// pageNo: 1,-->
<!--// pageSize: undefined,-->
<!--// username: undefined,-->
<!--// mobile: undefined,-->
<!--// status: undefined,-->
<!--// deptId: undefined,-->
<!--// createTime: []-->
<!--// })-->
<!--//-->
<!--// const dayStatus = [-->
<!--// 1,1,1,1,1,3,3,1,1,1,1,1,3,3,-->
<!--// 1,1,1,1,1,3,3,1,1,1,1,1,3,3,3,3,3-->
<!--// ]-->
<!--//-->
<!--// const changeDay = async (index:number,day:number,val:number)=>{-->
<!--// let dayStatus = listData.value[index].dayStatus-->
<!--// if (Array.isArray(dayStatus)){-->
<!--// dayStatus[day - 1] = val-->
<!--// }else{-->
<!--// dayStatus = [];-->
<!--// dayStatus[day - 1] = val; // -->
<!--// }-->
<!--// await getWorkDay(index)-->
<!--// }-->
<!--//-->
<!--// const createUser = async ()=>{-->
<!--// queryParamsUser.deptId = formData.value.deptId-->
<!--// const user = await getUserPageKQ(queryParamsUser)-->
<!--// const dataUser = user.list-->
<!--// for (let item of dataUser){-->
<!--// const data : KqdataVO = {-->
<!--// id:null,-->
<!--// userId:item.id,-->
<!--// userName:item.nickname,-->
<!--// deptId:item.deptId,-->
<!--// deptName:item.deptName,-->
<!--// dayStatus:dayStatus.join(','),-->
<!--// tokey:dateKey.value,-->
<!--// workDay: 0,-->
<!--// overDay: 0,-->
<!--// yoverDay: 0,-->
<!--// }-->
<!--// // console.log(data)-->
<!--// await KqdataApi.createKqdata(data)-->
<!--// }-->
<!--// }-->
<!--//-->
<!--// const updateUser = async ()=>{-->
<!--// for (let item of listData.value){-->
<!--// const data : KqdataVO = {-->
<!--// id:item.id,-->
<!--// userId:item.userId,-->
<!--// userName:item.userName,-->
<!--// deptId:item.deptId,-->
<!--// deptName:item.deptName,-->
<!--// dayStatus: Array.isArray(item.dayStatus)-->
<!--// ? item.dayStatus.join(',')-->
<!--// : String(item.dayStatus), // -->
<!--// tokey:item.tokey,-->
<!--// workDay: item.workDay,-->
<!--// overDay: item.overDay,-->
<!--// yoverDay: item.yoverDay,-->
<!--// }-->
<!--// console.log(data)-->
<!--// await KqdataApi.updateKqdata(data);-->
<!--// }-->
<!--// }-->
<!--/** 获得数据 */-->
<!--// const getInfo = async () => {-->
<!--// pop.value=false//span-->
<!--// await getUserInfo()-->
<!--// formLoading.value = true-->
<!--// try {-->
<!--// formData.value = await KqglApi.getKqgl(props.id || queryId)-->
<!--// await getList() //使-->
<!--// await changeStatus()//-->
<!--// await getWorkDay()//-->
<!--// } finally {-->
<!--// formLoading.value = false-->
<!--// }-->
<!--// }-->
<!--// defineExpose({ open }) // open -->
<!--/** 提交表单 */-->
<!--// const emit = defineEmits(['success']) // success -->
<!--// const submitForm = async () => {-->
<!--// // -->
<!--// await formRef.value.validate()-->
<!--// // -->
<!--// formLoading.value = true-->
<!--// try {-->
<!--// const data = formData.value as unknown as KqglVO-->
<!--// if (formType.value === 'create') {-->
<!--// data.date = dateKey.value //-->
<!--// await KqglApi.createKqgl(data)-->
<!--// message.success(t('common.createSuccess'))-->
<!--// } else {-->
<!--// await KqglApi.updateKqgl(data)-->
<!--// message.success(t('common.updateSuccess'))-->
<!--// }-->
<!--// await updateUser() //-->
<!--// dialogVisible.value = false-->
<!--// // -->
<!--// emit('success')-->
<!--// } finally {-->
<!--// formLoading.value = false-->
<!--// }-->
<!--// }-->