liu
4 天以前 749cb2f4ad815c5a68c19fe961d5ca2149a84dd4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<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>