<script lang="ts" setup>
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
import type { MesCalScheduleDetailApi } from '#/api/mes/cal/scheduleDetail';
|
|
import { onMounted, ref } from 'vue';
|
|
import { Page, useVbenModal } from '@vben/common-ui';
|
|
import { Tag } from 'ant-design-vue';
|
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
import { getDetailPage } from '#/api/mes/cal/scheduleDetail';
|
|
import {
|
fetchPlanOptions,
|
fetchTeamOptions,
|
fetchUserOptions,
|
SOURCE_MANUAL,
|
useGridColumns,
|
useGridFormSchema,
|
} from './data';
|
import CheckView from './modules/check-view.vue';
|
import Form from './modules/form.vue';
|
import GenerateForm from './modules/generate-form.vue';
|
|
const [FormModal, formModalApi] = useVbenModal({
|
connectedComponent: Form,
|
destroyOnClose: true,
|
});
|
|
const [GenerateModal, generateModalApi] = useVbenModal({
|
connectedComponent: GenerateForm,
|
destroyOnClose: true,
|
});
|
|
const [CheckModal, checkModalApi] = useVbenModal({
|
connectedComponent: CheckView,
|
destroyOnClose: true,
|
});
|
|
/** 计划/班组/员工编号 -> 名称 的映射,用于列表回显 */
|
const planNameMap = ref<Record<number, string>>({});
|
const teamNameMap = ref<Record<number, string>>({});
|
const userNameMap = ref<Record<number, string>>({});
|
|
onMounted(async () => {
|
const [plans, teams, users] = await Promise.all([
|
fetchPlanOptions(),
|
fetchTeamOptions(),
|
fetchUserOptions(),
|
]);
|
planNameMap.value = Object.fromEntries(
|
plans.map((item) => [item.value, item.label]),
|
);
|
teamNameMap.value = Object.fromEntries(
|
teams.map((item) => [item.value, item.label]),
|
);
|
userNameMap.value = Object.fromEntries(
|
users.map((item) => [item.value, item.label]),
|
);
|
});
|
|
/** 刷新表格 */
|
function handleRefresh() {
|
gridApi.query();
|
}
|
|
/** 生成排班明细 */
|
function handleGenerate() {
|
generateModalApi.open();
|
}
|
|
/** 调整排班明细 */
|
function handleEdit(row: MesCalScheduleDetailApi.Detail) {
|
formModalApi.setData({ row }).open();
|
}
|
|
/** 合规校验(默认不带人员,弹窗内自选) */
|
function handleCheck() {
|
checkModalApi.open();
|
}
|
|
/** 合规校验指定员工 */
|
function handleCheckUser(row: MesCalScheduleDetailApi.Detail) {
|
checkModalApi.setData({ userId: row.userId }).open();
|
}
|
|
const [Grid, gridApi] = useVbenVxeGrid({
|
formOptions: {
|
schema: useGridFormSchema(),
|
},
|
gridOptions: {
|
columns: useGridColumns(),
|
height: 'auto',
|
keepSource: true,
|
proxyConfig: {
|
ajax: {
|
query: async ({ page }, formValues) => {
|
const { day, ...rest } = formValues as { day?: string[] };
|
return await getDetailPage({
|
pageNo: page.currentPage,
|
pageSize: page.pageSize,
|
...(rest as MesCalScheduleDetailApi.DetailPageParam),
|
startDay: day?.[0],
|
endDay: day?.[1],
|
});
|
},
|
},
|
},
|
rowConfig: {
|
keyField: 'id',
|
isHover: true,
|
},
|
toolbarConfig: {
|
refresh: true,
|
search: true,
|
},
|
} as VxeTableGridOptions<MesCalScheduleDetailApi.Detail>,
|
});
|
</script>
|
|
<template>
|
<Page auto-content-height>
|
<FormModal @success="handleRefresh" />
|
<GenerateModal @success="handleRefresh" />
|
<CheckModal />
|
<Grid table-title="员工排班明细列表">
|
<template #toolbar-tools>
|
<TableAction
|
:actions="[
|
{
|
label: '生成排班明细',
|
type: 'primary',
|
icon: ACTION_ICON.ADD,
|
auth: ['mes:cal-schedule-detail:generate'],
|
onClick: handleGenerate,
|
},
|
{
|
label: '合规校验',
|
type: 'primary',
|
icon: ACTION_ICON.SEARCH,
|
auth: ['mes:cal-schedule-detail:query'],
|
onClick: handleCheck,
|
},
|
]"
|
/>
|
</template>
|
<template #planId="{ row }">
|
{{ planNameMap[row.planId] ?? row.planId }}
|
</template>
|
<template #teamId="{ row }">
|
{{ teamNameMap[row.teamId] ?? row.teamId }}
|
</template>
|
<template #userId="{ row }">
|
{{ userNameMap[row.userId] ?? row.userId }}
|
</template>
|
<template #source="{ row }">
|
<Tag :color="row.source === SOURCE_MANUAL ? 'orange' : 'blue'">
|
{{ row.source === SOURCE_MANUAL ? '人工调整' : '自动生成' }}
|
</Tag>
|
</template>
|
<template #actions="{ row }">
|
<TableAction
|
:actions="[
|
{
|
label: '调整',
|
type: 'link',
|
icon: ACTION_ICON.EDIT,
|
auth: ['mes:cal-schedule-detail:update'],
|
onClick: handleEdit.bind(null, row),
|
},
|
{
|
label: '合规校验',
|
type: 'link',
|
auth: ['mes:cal-schedule-detail:query'],
|
onClick: handleCheckUser.bind(null, row),
|
},
|
]"
|
/>
|
</template>
|
</Grid>
|
</Page>
|
</template>
|