Files
admin-vben5/apps/web-antd/src/views/property/attendanceManagement/attendanceGroupSettings/group-modal.vue

492 lines
15 KiB
Vue
Raw Normal View History

2025-07-19 17:25:17 +08:00
<script setup lang="ts">
2025-07-23 20:57:17 +08:00
import {computed, reactive, ref} from 'vue';
2025-07-19 17:25:17 +08:00
import {useVbenModal} from '@vben/common-ui';
import {$t} from '@vben/locales';
import {cloneDeep} from '@vben/utils';
import {useVbenForm} from '#/adapter/form';
import {
groupAdd,
groupInfo,
groupUpdate
} from '#/api/property/attendanceManagement/attendanceGroupSettings';
import {defaultFormValueGetter, useBeforeCloseDiff} from '#/utils/popup';
2025-07-20 17:58:39 +08:00
import {
clockingColumns,
cycleColumns,
modalSchema,
noClockingColumns,
weekdayColumns
} from './data';
2025-07-23 20:57:17 +08:00
import {Tag, Button, Table, Checkbox, Select, SelectOption, message, Alert} from 'ant-design-vue'
2025-07-19 17:25:17 +08:00
import {getDictOptions} from "#/utils/dict";
2025-07-20 17:58:39 +08:00
import holidayCalendar from './holiday-calendar.vue'
2025-07-21 20:57:31 +08:00
import changeShiftSchedule from './change-shift-schedule.vue'
import checkInDate from './check-in-date.vue'
import {h} from 'vue';
import {PlusOutlined, MinusOutlined} from '@ant-design/icons-vue';
import type {ShiftVO} from "#/api/property/attendanceManagement/shiftSetting/model";
2025-07-19 17:25:17 +08:00
const emit = defineEmits<{ reload: [] }>();
const isUpdate = ref(false);
const title = computed(() => {
return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add');
});
2025-07-23 20:57:17 +08:00
const settingData = reactive({
2025-07-20 17:58:39 +08:00
isAutomatic: true,
2025-07-23 20:57:17 +08:00
weekdayData: [],
cycleData: [],
unCheckInData: [],
checkInData: [],
shiftId: ''
2025-07-20 17:58:39 +08:00
})
2025-07-19 17:25:17 +08:00
const [BasicForm, formApi] = useVbenForm({
commonConfig: {
// 默认占满两列
formItemClass: 'col-span-2',
// 默认label宽度 px
labelWidth: 80,
// 通用配置项 会影响到所有表单项
componentProps: {
class: 'w-full',
}
},
schema: modalSchema(),
showDefaultActions: false,
wrapperClass: 'grid-cols-2',
});
const {onBeforeClose, markInitialized, resetInitialized} = useBeforeCloseDiff(
{
initializedGetter: defaultFormValueGetter(formApi),
currentGetter: defaultFormValueGetter(formApi),
},
);
const [BasicModal, modalApi] = useVbenModal({
fullscreenButton: false,
2025-07-21 20:57:31 +08:00
fullscreen: true,
// class:'w-[80%]',
2025-07-19 17:25:17 +08:00
onBeforeClose,
onClosed: handleClosed,
onConfirm: handleConfirm,
onOpenChange: async (isOpen) => {
if (!isOpen) {
return null;
}
modalApi.modalLoading(true);
const {id} = modalApi.getData() as { id?: number | string };
isUpdate.value = !!id;
if (isUpdate.value && id) {
const record = await groupInfo(id);
await formApi.setValues(record);
2025-07-20 17:58:39 +08:00
} else {
2025-07-23 20:57:17 +08:00
const dictOptions = getDictOptions('wy_kqgzr');
console.log(dictOptions)
if (dictOptions) {
dictOptions.forEach(item => {
settingData.weekdayData.push({
dayOfWeek: item.value,
label: item.label,
shiftValue: '休息',
isRest: 1,
id: null,
})
2025-07-20 17:58:39 +08:00
})
2025-07-23 20:57:17 +08:00
}
settingData.cycleData = [{id: ''}, {id: ''}];
2025-07-19 17:25:17 +08:00
}
await markInitialized();
modalApi.modalLoading(false);
},
});
async function handleConfirm() {
try {
modalApi.lock(true);
const {valid} = await formApi.validate();
if (!valid) {
return;
}
// getValues获取为一个readonly的对象 需要修改必须先深拷贝一次
const data = cloneDeep(await formApi.getValues());
2025-07-23 20:57:17 +08:00
if (data.attendanceType == 1) {
let hasError = false;
settingData.cycleData.forEach((item, index) => {
if (!item.id) {
message.warning('请选择周期天数对应班次。');
return;
}
item.dayNumber = index + 1
})
if (!hasError) {
return;
}
data.numList = settingData.cycleData
} else {
data.weekSetList = settingData.weekdayData
data.clockDate = settingData.checkInData.concat(settingData.unCheckInData)
}
2025-07-19 17:25:17 +08:00
await (isUpdate.value ? groupUpdate(data) : groupAdd(data));
resetInitialized();
emit('reload');
modalApi.close();
} catch (error) {
console.error(error);
} finally {
modalApi.lock(false);
}
}
async function handleClosed() {
await formApi.resetForm();
resetInitialized();
2025-07-23 20:57:17 +08:00
Object.assign(settingData, {
isAutomatic: true,
weekdayData: [],
cycleData: [],
unCheckInData: [],
checkInData: [],
shiftId: '',
});
2025-07-19 17:25:17 +08:00
}
2025-07-20 17:58:39 +08:00
const [HolidayCalendar, holidayApi] = useVbenModal({
connectedComponent: holidayCalendar,
});
2025-07-21 20:57:31 +08:00
const [ChangeShiftSchedule, shiftApi] = useVbenModal({
connectedComponent: changeShiftSchedule,
});
const [CheckInDate, checkInDateApi] = useVbenModal({
connectedComponent: checkInDate,
});
2025-07-20 17:58:39 +08:00
/**
* 查看法定节假日日历
*/
2025-07-23 20:57:17 +08:00
function showHoliday() {
2025-07-20 17:58:39 +08:00
holidayApi.open()
}
2025-07-21 20:57:31 +08:00
/**
* 更改班次
* @param type 1.设置班次 2.选择班次
*/
2025-07-23 20:57:17 +08:00
function shiftScheduleHandle(type: number) {
2025-07-22 19:11:52 +08:00
shiftApi.setData({type})
shiftApi.open()
2025-07-21 20:57:31 +08:00
}
const shiftInfo = ref<ShiftVO>()
const shiftList = ref<ShiftVO[]>([])
2025-07-23 20:57:17 +08:00
function handleShiftInfo(info: ShiftVO) {
2025-07-22 19:11:52 +08:00
if (info) {
2025-07-23 20:57:17 +08:00
settingData.shiftId = info.id
2025-07-22 19:11:52 +08:00
shiftInfo.value = info;
2025-07-23 20:57:17 +08:00
settingData.weekdayData.forEach(item => {
item.id = info.id
2025-07-22 19:11:52 +08:00
let str = ''
if (info.isRest) {
str = `${info.name}${info.startTime}~${info.restStartTime} ${info.restEndTime}~${info.endTime}`;
} else {
str = `${info.name}${info.startTime}~${info.endTime}`;
}
item.shiftValue = str
2025-07-23 20:57:17 +08:00
item.isRest = 0
2025-07-22 19:11:52 +08:00
})
}
2025-07-23 20:57:17 +08:00
}
2025-07-21 20:57:31 +08:00
2025-07-23 20:57:17 +08:00
function handleShiftList(list: any[]) {
2025-07-21 20:57:31 +08:00
shiftList.value = list;
2025-07-23 20:57:17 +08:00
}
2025-07-21 20:57:31 +08:00
2025-07-23 20:57:17 +08:00
function addCycleHandle() {
if (settingData.cycleData.length < 31) {
settingData.cycleData.push({
id: '',
2025-07-22 19:11:52 +08:00
})
2025-07-23 20:57:17 +08:00
} else {
2025-07-22 19:11:52 +08:00
message.warning('周期天数最多31天。');
}
2025-07-21 20:57:31 +08:00
}
2025-07-23 20:57:17 +08:00
function deleteCycleHandle(index: number) {
if (settingData.cycleData.length > 2) {
settingData.cycleData.splice(index, 1)
} else {
2025-07-22 19:11:52 +08:00
message.warning('周期天数最少2天。');
}
2025-07-21 20:57:31 +08:00
}
2025-07-23 20:57:17 +08:00
function deleteUnCheckInHandle(index: number) {
settingData.unCheckInData.splice(index, 1)
2025-07-21 20:57:31 +08:00
}
2025-07-23 20:57:17 +08:00
function deleteCheckInHandle(index: number) {
settingData.checkInData.splice(index, 1)
2025-07-21 20:57:31 +08:00
}
2025-07-22 19:11:52 +08:00
const tableIndex = ref(-1)
2025-07-23 20:57:17 +08:00
function changeShiftHandle(type: number, index: number) {
2025-07-22 19:11:52 +08:00
tableIndex.value = index
shiftApi.setData({type})//3.更改班次
shiftApi.open()
}
2025-07-23 20:57:17 +08:00
function restHandle(index: number) {
settingData.weekdayData[index].isRest = 1
settingData.weekdayData[index].shiftValue = '休息'
settingData.weekdayData[index].id = null
2025-07-22 19:11:52 +08:00
}
2025-07-23 20:57:17 +08:00
function handleAfterValue(val: ShiftVO) {
2025-07-22 19:11:52 +08:00
if (tableIndex.value > -1 && val) {
2025-07-23 20:57:17 +08:00
settingData.weekdayData[tableIndex.value].id = val.id
2025-07-22 19:11:52 +08:00
let str = ''
if (val.isRest) {
str = `${val.name}${val.startTime}~${val.restStartTime} ${val.restEndTime}~${val.endTime}`;
} else {
str = `${val.name}${val.startTime}~${val.endTime}`;
}
2025-07-23 20:57:17 +08:00
settingData.weekdayData[tableIndex.value].shiftValue = str
settingData.weekdayData[tableIndex.value].isRest = 0
2025-07-22 19:11:52 +08:00
}
2025-07-23 20:57:17 +08:00
}
2025-07-22 19:11:52 +08:00
2025-07-23 20:57:17 +08:00
function closeTagHandle(i: number) {
2025-07-22 19:11:52 +08:00
shiftList.value.splice(i, 1)
2025-07-23 20:57:17 +08:00
}
2025-07-22 19:11:52 +08:00
const checkInIndex = ref(-1)
2025-07-23 20:57:17 +08:00
function addCheckInHandle(index: number) {
2025-07-22 19:11:52 +08:00
checkInIndex.value = index
checkInDateApi.setData({check: true})
checkInDateApi.open()
}
2025-07-23 20:57:17 +08:00
function getCheckInData(val: any) {
2025-07-22 19:11:52 +08:00
if (val) {
2025-07-23 20:57:17 +08:00
settingData.checkInData.push({
...val,
mustNoCheck: 1
})
2025-07-22 19:11:52 +08:00
}
}
2025-07-23 20:57:17 +08:00
2025-07-22 19:11:52 +08:00
const unCheckInIndex = ref(-1)
2025-07-21 20:57:31 +08:00
2025-07-23 20:57:17 +08:00
function addUnCheckInHandle(index: number) {
2025-07-22 19:11:52 +08:00
unCheckInIndex.value = index
checkInDateApi.setData({check: false})
checkInDateApi.open()
}
2025-07-23 20:57:17 +08:00
function getUnCheckInData(val: any) {
2025-07-22 19:11:52 +08:00
if (val) {
2025-07-23 20:57:17 +08:00
settingData.unCheckInData.push({
...val,
mustNoCheck: 0
})
2025-07-22 19:11:52 +08:00
}
2025-07-21 20:57:31 +08:00
}
2025-07-19 17:25:17 +08:00
</script>
<template>
2025-07-21 20:57:31 +08:00
<BasicModal :title="title+'考勤组'">
2025-07-23 20:57:17 +08:00
<BasicForm class="form-content">
2025-07-19 17:25:17 +08:00
<template #weekdaySetting>
2025-07-20 17:58:39 +08:00
<div class="item-font">
2025-07-19 17:25:17 +08:00
<span>快捷设置班次</span>
2025-07-21 20:57:31 +08:00
<Tag color="processing" v-if="shiftInfo">
<span>{{ shiftInfo.name }}</span>&nbsp;
<span v-if="shiftInfo.isRest">
{{ shiftInfo.startTime + '~' + shiftInfo.restStartTime }}&nbsp;
{{ shiftInfo.restEndTime + '~' + shiftInfo.endTime }}
</span>
<span v-else>
{{ shiftInfo.startTime + '~' + shiftInfo.endTime }}
</span>
</Tag>
<Button type="link" @click="shiftScheduleHandle(1)">设置班次</Button>
2025-07-19 17:25:17 +08:00
</div>
</template>
<template #settingItem>
2025-07-20 17:58:39 +08:00
<div class="item-font" style="width: 100%;">
2025-07-23 20:57:17 +08:00
<Table style="width: 90%" bordered :columns="weekdayColumns"
:data-source="settingData.weekdayData"
2025-07-20 17:58:39 +08:00
size="small" :pagination="false">
2025-07-21 20:57:31 +08:00
<template #bodyCell="{ column, record,index }">
<template v-if="column.dataIndex==='action'">
2025-07-22 19:11:52 +08:00
<Button type="link" size="small" @click="changeShiftHandle(3,index)">更改班次
</Button>
<Button type="link" size="small" @click="restHandle(index)" v-if="!record.isRest">
休息
</Button>
2025-07-21 20:57:31 +08:00
</template>
</template>
2025-07-20 17:58:39 +08:00
</Table>
<Checkbox class="item-padding-top" v-model:checked="settingData.isAutomatic">
法定节假日自动排休
</Checkbox>
<Button type="link" @click="showHoliday">查看法定节假日日历</Button>
<p class="item-padding-top item-font-weight">特殊日期</p>
<p class="item-padding">无需打卡日期</p>
2025-07-21 20:57:31 +08:00
<Table style="width: 75%" bordered :columns="noClockingColumns"
2025-07-23 20:57:17 +08:00
:data-source="settingData.unCheckInData"
2025-07-20 17:58:39 +08:00
size="small" :pagination="false">
2025-07-21 20:57:31 +08:00
<template #headerCell="{ column }">
<template v-if="column.dataIndex === 'action'">
<Button size="small" type="primary" shape="circle"
2025-07-22 19:11:52 +08:00
@click="addUnCheckInHandle"
2025-07-21 20:57:31 +08:00
:icon="h(PlusOutlined)">
</Button>
</template>
</template>
2025-07-22 19:11:52 +08:00
<template #bodyCell="{ column,record,index }">
2025-07-21 20:57:31 +08:00
<template v-if="column.dataIndex==='action'">
<Button size="small" type="primary" shape="circle"
danger :icon="h(MinusOutlined)" @click="deleteUnCheckInHandle(index)">
</Button>
</template>
2025-07-22 19:11:52 +08:00
<template v-if="column.dataIndex==='dateTime'">
<span v-if="record.dateType==0">{{ record.startDate }}</span>
<span v-else>{{ record.startDate + '~' + record.endDate }}</span>
</template>
2025-07-21 20:57:31 +08:00
</template>
2025-07-20 17:58:39 +08:00
</Table>
<p class="item-padding">必须打卡日期</p>
2025-07-23 20:57:17 +08:00
<Table style="width: 75%" bordered :columns="clockingColumns"
:data-source="settingData.checkInData"
2025-07-20 17:58:39 +08:00
size="small" :pagination="false">
2025-07-21 20:57:31 +08:00
<template #headerCell="{ column }">
<template v-if="column.dataIndex === 'action'">
<Button size="small" type="primary" shape="circle"
2025-07-22 19:11:52 +08:00
@click="addCheckInHandle"
2025-07-21 20:57:31 +08:00
:icon="h(PlusOutlined)">
</Button>
</template>
</template>
2025-07-22 19:11:52 +08:00
<template #bodyCell="{ column,record,index }">
<template v-if="column.dataIndex==='dateTime'">
<span v-if="record.dateType==0">{{ record.startDate }}</span>
<span v-else>{{ record.startDate + '~' + record.endDate }}</span>
</template>
2025-07-21 20:57:31 +08:00
<template v-if="column.dataIndex==='action'">
<Button size="small" type="primary" shape="circle"
danger :icon="h(MinusOutlined)" @click="deleteCheckInHandle(index)">
</Button>
</template>
</template>
2025-07-20 17:58:39 +08:00
</Table>
</div>
2025-07-19 17:25:17 +08:00
</template>
<template #attendanceShift>
2025-07-23 20:57:17 +08:00
<Button @click="shiftScheduleHandle(2)" type="primary">选择班次</Button>
<Alert type="info" message="请优先选择班次" banner/>
2025-07-20 17:58:39 +08:00
</template>
<template #shiftData>
2025-07-21 20:57:31 +08:00
<div v-if="shiftList">
2025-07-23 20:57:17 +08:00
<Tag closable color="processing" v-for="(item,i) in shiftList" @close="closeTagHandle(i)">
2025-07-21 20:57:31 +08:00
{{ item.name }}
</Tag>
</div>
2025-07-19 17:25:17 +08:00
</template>
<template #schedulingCycle>
2025-07-21 20:57:31 +08:00
<span class="item-font">周期天数
2025-07-23 20:57:17 +08:00
<span class="item-font-weight item-font-color">{{ settingData.cycleData.length }}</span>
2025-07-22 19:11:52 +08:00
<span style="color:#b2b0b0;">周期最少2天最多31天</span>
</span>
2025-07-20 17:58:39 +08:00
</template>
<template #cycleData>
2025-07-23 20:57:17 +08:00
<Table style="width: 80%" bordered :columns="cycleColumns"
:data-source="settingData.cycleData"
2025-07-20 17:58:39 +08:00
size="small" :pagination="false">
2025-07-21 20:57:31 +08:00
<template #headerCell="{ column }">
<template v-if="column.dataIndex === 'action'">
<Button size="small" type="primary" shape="circle"
:icon="h(PlusOutlined)" @click="addCycleHandle">
</Button>
</template>
</template>
2025-07-22 19:11:52 +08:00
<template #bodyCell="{ column,record,index }">
2025-07-21 20:57:31 +08:00
<template v-if="column.dataIndex==='action'">
<Button size="small" type="primary" shape="circle"
danger :icon="h(MinusOutlined)" @click="deleteCycleHandle(index)">
</Button>
</template>
2025-07-22 19:11:52 +08:00
<template v-if="column.dataIndex==='day'">
<span>{{ '第' + (index + 1) + '天' }}</span>
</template>
<template v-if="column.dataIndex==='shiftId'">
<Select
ref="select"
style="width: 100%"
v-model:value="record.shiftId"
placeholder="请选择班次"
>
<SelectOption v-for="item in shiftList" :value="item.id">
{{ item.name + '\xa0' }}
<span
2025-07-23 20:57:17 +08:00
v-if="item.isRest">{{
item.startTime + '~' + item.restStartTime + '\xa0' + item.restEndTime + '~' + item.endTime
}}</span>
2025-07-22 19:11:52 +08:00
<span v-else>{{ item.startTime + '~' + item.endTime }}</span>
</SelectOption>
</Select>
</template>
2025-07-21 20:57:31 +08:00
</template>
2025-07-20 17:58:39 +08:00
</Table>
2025-07-19 17:25:17 +08:00
</template>
</BasicForm>
2025-07-20 17:58:39 +08:00
<HolidayCalendar></HolidayCalendar>
2025-07-21 20:57:31 +08:00
<ChangeShiftSchedule @shiftInfo="handleShiftInfo"
@shiftList="handleShiftList"
@afterValue="handleAfterValue"
></ChangeShiftSchedule>
2025-07-22 19:11:52 +08:00
<CheckInDate @checkIn="getCheckInData"
@unCheckIn="getUnCheckInData"
></CheckInDate>
2025-07-19 17:25:17 +08:00
</BasicModal>
</template>
2025-07-20 17:58:39 +08:00
<style lang="scss" scoped>
2025-07-23 20:57:17 +08:00
.form-content {
.item-font {
font-size: 0.875rem;
}
2025-07-20 17:58:39 +08:00
2025-07-23 20:57:17 +08:00
.item-font-weight {
font-weight: 500;
}
2025-07-20 17:58:39 +08:00
2025-07-23 20:57:17 +08:00
.item-font-color {
color: red;
}
2025-07-22 19:11:52 +08:00
2025-07-23 20:57:17 +08:00
.item-padding-top {
padding-top: 1.1rem;
}
2025-07-20 17:58:39 +08:00
2025-07-23 20:57:17 +08:00
.item-padding {
padding: 1.1rem 0 0.5rem 0;
}
:deep(.ant-alert) {
padding: 5px 12px;
margin-left: 20px;
}
2025-07-20 17:58:39 +08:00
}
2025-07-23 20:57:17 +08:00
2025-07-20 17:58:39 +08:00
</style>
2025-07-19 17:25:17 +08:00