9 天以前 10dd6590cea8f20eff21025ee71c8a614a48cdb7
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
<script lang="ts" setup>
  import type { VxeTableGridOptions } from '#/adapter/vxe-table';
  import type { MesTraceCrossRegionApi } from '#/api/mes/trace/crossregion';
 
  import { gsap } from 'gsap';
 
  import { nextTick, onMounted, onUnmounted, ref } from 'vue';
 
  import { useAccess } from '@vben/access';
  import { CountTo, Page } from '@vben/common-ui';
  import { IconifyIcon } from '@vben/icons';
 
  import {
    Card,
    Col,
    message,
    Modal,
    Row,
    Segmented,
    Skeleton,
    Tag,
  } from 'ant-design-vue';
 
  import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
  import {
    getTraceCrossRegionConfig,
    getTraceCrossRegionPage,
    getTraceCrossRegionSummary,
    handleTraceCrossRegion,
    updateTraceCrossRegionConfig,
  } from '#/api/mes/trace/crossregion';
 
  import {
    WARNING_LEVEL_OPTIONS,
    useGridColumns,
    useGridFormSchema,
  } from './data';
 
  defineOptions({ name: 'MesTraceCrossRegion' });
 
  const { hasAccessByCodes } = useAccess();
  const canHandle = hasAccessByCodes(['mes:trace-cross-region:handle']);
 
  /** 汇总数据 */
  const summary = ref<MesTraceCrossRegionApi.Summary>({});
  const summaryLoading = ref(false);
 
  /** 判定粒度配置 */
  const warningLevel = ref('PROVINCE');
 
  /** 处理弹窗状态 */
  const handleVisible = ref(false);
  const handleLoading = ref(false);
 
  /** GSAP 入场动画上下文(卸载时自动还原) */
  let animationContext: gsap.Context | undefined;
  const handleForm = ref<{
    id?: number;
    status: number;
    handleRemark?: string;
  }>({
    id: undefined,
    status: 20,
    handleRemark: '',
  });
 
  /** 汇总卡片配置 */
  const summaryCards = [
    {
      label: '预警总数',
      value: 'total',
      icon: 'lucide:alert-triangle',
      color: '#409eff',
      bg: 'linear-gradient(135deg, #409eff, #66b1ff)',
    },
    {
      label: '待处理',
      value: 'pending',
      icon: 'lucide:clock',
      color: '#e6a23c',
      bg: 'linear-gradient(135deg, #e6a23c, #ebb563)',
    },
    {
      label: '已处理',
      value: 'handled',
      icon: 'lucide:circle-check',
      color: '#67c23a',
      bg: 'linear-gradient(135deg, #67c23a, #85ce61)',
    },
    {
      label: '误报',
      value: 'falseAlarm',
      icon: 'lucide:shield-x',
      color: '#909399',
      bg: 'linear-gradient(135deg, #909399, #b1b3b8)',
    },
    {
      label: '跨省窜货',
      value: 'crossProvince',
      icon: 'lucide:map-pin-off',
      color: '#f56c6c',
      bg: 'linear-gradient(135deg, #f56c6c, #f78989)',
    },
    {
      label: '跨市窜货',
      value: 'crossCity',
      icon: 'lucide:map-pin',
      color: '#7c3aed',
      bg: 'linear-gradient(135deg, #7c3aed, #9461f5)',
    },
  ];
 
  /** 加载汇总 */
  async function loadSummary() {
    summaryLoading.value = true;
    try {
      summary.value = await getTraceCrossRegionSummary();
    } finally {
      summaryLoading.value = false;
    }
  }
 
  /** 加载判定粒度配置 */
  async function loadConfig() {
    const config = await getTraceCrossRegionConfig();
    warningLevel.value = config.warningLevel || 'PROVINCE';
  }
 
  /** 切换判定粒度 */
  async function handleLevelChange(value: string | number) {
    try {
      const level = String(value);
      await updateTraceCrossRegionConfig(level);
      message.success(
        `判定粒度已切换为${
          WARNING_LEVEL_OPTIONS.find((opt) => opt.value === level)?.label
        }`,
      );
    } catch {
      loadConfig();
    }
  }
 
  /** 打开处理弹窗 */
  function openHandle(row: MesTraceCrossRegionApi.Warning) {
    handleForm.value = { id: row.id, status: 20, handleRemark: '' };
    handleVisible.value = true;
  }
 
  /** 提交处理 */
  async function submitHandle() {
    if (!handleForm.value.id || handleLoading.value) return;
    handleLoading.value = true;
    try {
      await handleTraceCrossRegion({
        id: handleForm.value.id,
        status: handleForm.value.status,
        handleRemark: handleForm.value.handleRemark,
      });
      message.success('预警已处理');
      handleVisible.value = false;
      handleRefresh();
    } catch {
      message.error('处理失败,请重试');
    } finally {
      handleLoading.value = false;
    }
  }
 
  /** 刷新列表与汇总 */
  function handleRefresh() {
    gridApi.query();
    loadSummary();
  }
 
  /** 展示地区组合 */
  function regionText(province?: string, city?: string) {
    return [province, city].filter(Boolean).join('·') || '-';
  }
 
  const [Grid, gridApi] = useVbenVxeGrid({
    formOptions: {
      schema: useGridFormSchema(),
    },
    gridOptions: {
      columns: useGridColumns(),
      height: 'auto',
      keepSource: true,
      proxyConfig: {
        ajax: {
          query: async ({ page }, formValues) => {
            return await getTraceCrossRegionPage({
              pageNo: page.currentPage,
              pageSize: page.pageSize,
              ...formValues,
            });
          },
        },
      },
      rowConfig: {
        keyField: 'id',
        isHover: true,
      },
      toolbarConfig: {
        refresh: true,
        search: true,
      },
    } as VxeTableGridOptions<MesTraceCrossRegionApi.Warning>,
  });
 
  onMounted(() => {
    loadSummary();
    loadConfig();
    initEntranceAnimation();
  });
 
  /** 入场动画:尊重 prefers-reduced-motion */
  async function initEntranceAnimation() {
    await nextTick();
    animationContext = gsap.context(() => {
      const reduceMotion = window.matchMedia(
        '(prefers-reduced-motion: reduce)',
      ).matches;
      gsap.from('.mes-cr-summary, .mes-cr-grid', {
        autoAlpha: reduceMotion ? 1 : 0,
        y: reduceMotion ? 0 : 14,
        duration: reduceMotion ? 0 : 0.45,
        stagger: reduceMotion ? 0 : 0.08,
        ease: 'power2.out',
      });
    });
  }
 
  onUnmounted(() => {
    animationContext?.revert();
  });
</script>
 
<template>
  <Page auto-content-height>
    <Card class="mes-cr-summary mb-4">
      <template #title>
        <div class="flex items-center justify-between">
          <span>窜货预警</span>
          <span class="flex items-center gap-2 text-sm">
            <span class="text-muted-foreground">判定粒度</span>
            <Segmented
              v-model:value="warningLevel"
              :disabled="!canHandle"
              :options="WARNING_LEVEL_OPTIONS"
              @change="handleLevelChange"
            />
          </span>
        </div>
      </template>
      <Row :gutter="16">
        <Col
          v-for="card in summaryCards"
          :key="card.value"
          :lg="4"
          :md="8"
          :sm="12"
          :xs="24"
          class="mb-4"
        >
          <Card class="kpi-card">
            <div class="flex items-center gap-4">
              <div
                class="flex size-14 flex-shrink-0 items-center justify-center rounded-xl text-white"
                :style="{ background: card.bg }"
              >
                <IconifyIcon class="size-7" :icon="card.icon" />
              </div>
              <div>
                <div class="text-muted-foreground mb-1 text-sm">
                  {{ card.label }}
                </div>
                <Skeleton.Input
                  v-if="summaryLoading"
                  :size="'small'"
                  active
                  style="width: 4rem"
                />
                <CountTo
                  v-else
                  class="text-2xl font-bold leading-tight"
                  :style="{ color: card.color }"
                  :end-val="summary[card.value] || 0"
                  :duration="1200"
                />
              </div>
            </div>
          </Card>
        </Col>
      </Row>
    </Card>
 
    <Grid class="mes-cr-grid" table-title="窜货预警列表">
      <template #bagCode="{ row }">
        <Tag v-if="row.bagCode" color="blue">{{ row.bagCode }}</Tag>
        <Tag v-else-if="row.palletCode" color="purple">
          {{ row.palletCode }}
        </Tag>
        <span v-else>-</span>
      </template>
      <template #dealerRegion="{ row }">
        {{ regionText(row.dealerProvince, row.dealerCity) }}
      </template>
      <template #scanRegion="{ row }">
        <span class="text-[#dc2626] font-medium">
          {{ regionText(row.scanProvince, row.scanCity) }}
        </span>
      </template>
      <template #warningType="{ row }">
        <Tag
          :color="row.warningType === 'CROSS_PROVINCE' ? 'red' : 'orange'"
        >
          {{ row.warningTypeName }}
        </Tag>
      </template>
      <template #status="{ row }">
        <Tag
          :color="
            row.status === 10
              ? 'orange'
              : row.status === 20
                ? 'green'
                : 'default'
          "
        >
          {{ row.statusName }}
        </Tag>
      </template>
      <template #actions="{ row }">
        <TableAction
          :actions="[
            {
              label: '处理',
              type: 'link',
              icon: ACTION_ICON.EDIT,
              auth: ['mes:trace-cross-region:handle'],
              ifShow: row.status === 10,
              onClick: openHandle.bind(null, row),
            },
          ]"
        />
      </template>
    </Grid>
 
    <Modal
      v-model:open="handleVisible"
      title="处理窜货预警"
      :confirm-loading="handleLoading"
      ok-text="确认处理"
      cancel-text="取消"
      @ok="submitHandle"
    >
      <a-form layout="vertical">
        <a-form-item label="处理结果">
          <a-radio-group v-model:value="handleForm.status">
            <a-radio :value="20">已处理</a-radio>
            <a-radio :value="30">误报</a-radio>
          </a-radio-group>
        </a-form-item>
        <a-form-item label="处理备注">
          <a-textarea
            v-model:value="handleForm.handleRemark"
            :rows="3"
            placeholder="请输入处理备注(如:确认为物流中转)"
          />
        </a-form-item>
      </a-form>
    </Modal>
  </Page>
</template>