liu
2 天以前 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
<script lang="ts" setup>
import type { MesCalScheduleDetailApi } from '#/api/mes/cal/scheduleDetail';
 
import { onMounted, ref } from 'vue';
 
import { useVbenModal } from '@vben/common-ui';
 
import dayjs from 'dayjs';
 
import {
  Button,
  Empty,
  Form,
  FormItem,
  message,
  RangePicker,
  Select,
  Spin,
  Table,
  Tag,
} from 'ant-design-vue';
 
import { checkCompliance } from '#/api/mes/cal/scheduleDetail';
import { getRangePickerDefaultProps } from '#/utils';
 
import { fetchUserOptions, issueTypeMap, type OptionItem } from '../data';
 
const userId = ref<number>();
const day = ref<string[]>();
const userOptions = ref<OptionItem[]>([]);
 
const loading = ref(false);
const checked = ref(false);
const items = ref<MesCalScheduleDetailApi.CheckItem[]>([]);
 
/** 执行合规校验 */
async function doCheck() {
  if (!userId.value) {
    message.warning('请选择员工');
    return;
  }
  loading.value = true;
  try {
    items.value = await checkCompliance({
      userId: userId.value,
      startDay: day.value?.[0],
      endDay: day.value?.[1],
    });
    checked.value = true;
  } finally {
    loading.value = false;
  }
}
 
const columns = [
  {
    title: '日期',
    dataIndex: 'day',
    key: 'day',
    width: 110,
    customRender: ({ text }: { text?: string }) =>
      text ? dayjs(text).format('YYYY-MM-DD') : '-',
  },
  { title: '班次', dataIndex: 'shiftName', key: 'shiftName', width: 100 },
  {
    title: '时间',
    key: 'time',
    width: 120,
    customRender: ({ record }: { record: MesCalScheduleDetailApi.CheckItem }) =>
      `${record.startTime ?? '-'} ~ ${record.endTime ?? '-'}`,
  },
  {
    title: '违规类型',
    dataIndex: 'issueType',
    key: 'issueType',
    width: 100,
  },
  { title: '问题描述', dataIndex: 'issue', key: 'issue' },
];
 
/** 同日可能多班次,用行号作为 key */
function rowIndexKey(_record: MesCalScheduleDetailApi.CheckItem, index?: number) {
  return index ?? 0;
}
 
const [Modal, modalApi] = useVbenModal({
  showConfirmButton: false,
  cancelText: '关闭',
  onOpenChange(isOpen: boolean) {
    if (!isOpen) {
      checked.value = false;
      items.value = [];
      return;
    }
    // 支持从列表行传入员工编号,自动发起校验
    const data = modalApi.getData<{ userId?: number }>();
    if (data?.userId) {
      userId.value = data.userId;
      doCheck();
    }
  },
});
 
onMounted(async () => {
  userOptions.value = await fetchUserOptions();
});
</script>
 
<template>
  <Modal title="员工排班合规校验" class="w-3/5">
    <Form layout="inline" class="mb-2.5">
      <FormItem label="员工">
        <Select
          v-model:value="userId"
          allow-clear
          show-search
          placeholder="请选择员工"
          class="!w-[200px]"
          :options="userOptions"
          :filter-option="
            (input: string, option: OptionItem) =>
              (option?.label ?? '').includes(input)
          "
        />
      </FormItem>
      <FormItem label="日期">
        <RangePicker
          v-model:value="day"
          class="!w-[260px]"
          v-bind="getRangePickerDefaultProps()"
        />
      </FormItem>
      <FormItem>
        <Button type="primary" :loading="loading" @click="doCheck">校验</Button>
      </FormItem>
    </Form>
    <Spin :spinning="loading">
      <Table
        v-if="!checked || items.length > 0"
        size="small"
        :row-key="rowIndexKey"
        :columns="columns"
        :data-source="items"
        :pagination="false"
        :scroll="{ y: 360 }"
      >
        <template #bodyCell="{ column, record }">
          <template v-if="column.key === 'issueType'">
            <Tag v-if="record.issueType" :color="record.issueType === 1 ? 'red' : 'orange'">
              {{ issueTypeMap[record.issueType as number] }}
            </Tag>
            <Tag v-else color="green">合规</Tag>
          </template>
          <template v-else-if="column.key === 'issue'">
            {{ record.issue || '无异常' }}
          </template>
        </template>
      </Table>
      <Empty v-else description="未发现违规排班记录,该员工排班合规" />
    </Spin>
  </Modal>
</template>