gaoluyang
2026-11-02 2fe330a44f9e8bdd8a1afd6124c57851f2a5b7ea
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
<script lang="ts" setup>
import type { MesWmSortTaskApi } from '#/api/mes/wm/sorting';
 
import { ref } from 'vue';
 
import { useVbenModal } from '@vben/common-ui';
 
import { Input, message, Table } from 'ant-design-vue';
 
import {
  createSortTaskFromNotice,
  getPendingNoticeList,
} from '#/api/mes/wm/sorting';
 
defineOptions({ name: 'MesWmSortNoticeSelect' });
 
const emit = defineEmits<{ success: [] }>();
 
const noticeCode = ref('');
const loading = ref(false);
const notices = ref<MesWmSortTaskApi.PendingNotice[]>([]);
const selectedId = ref<number>();
 
const columns = [
  { title: '发货通知单号', dataIndex: 'noticeCode', width: 170 },
  { title: '销售订单号', dataIndex: 'saleOrderCode', width: 170 },
  { title: '收货人', dataIndex: 'recipientName', width: 110 },
  { title: '联系电话', dataIndex: 'recipientTelephone', width: 130 },
  { title: '收货地址', dataIndex: 'recipientAddress' },
  { title: '发货日期', dataIndex: 'deliveryDate', width: 180 },
];
 
/** 查询可生成分拣任务的发货通知单 */
async function loadNotices() {
  loading.value = true;
  try {
    notices.value = await getPendingNoticeList(
      noticeCode.value.trim() || undefined,
    );
  } finally {
    loading.value = false;
  }
}
 
async function handleCreate() {
  if (!selectedId.value) {
    message.warning('请先选择一张发货通知单');
    return;
  }
  const notice = notices.value.find(
    (item) => item.noticeId === selectedId.value,
  );
  await createSortTaskFromNotice(selectedId.value);
  message.success(
    `已按发货通知单[${notice?.noticeCode ?? ''}]生成分拣任务,可按货位指引执行分拣`,
  );
  emit('success');
  await modalApi.close();
}
 
const [Modal, modalApi] = useVbenModal({
  title: '选择发货通知单生成分拣任务',
  confirmText: '生成分拣任务',
  onConfirm: handleCreate,
  async onOpenChange(isOpen: boolean) {
    if (!isOpen) {
      noticeCode.value = '';
      notices.value = [];
      selectedId.value = undefined;
      return;
    }
    await loadNotices();
  },
});
</script>
 
<template>
  <Modal class="w-[1000px]">
    <div class="mb-3 flex items-center gap-2">
      <Input
        v-model:value="noticeCode"
        class="w-[240px]"
        placeholder="按发货通知单号筛选"
        allow-clear
        @press-enter="loadNotices"
      />
      <button class="text-blue-500" type="button" @click="loadNotices">
        查询
      </button>
      <span class="ml-auto text-xs text-gray-500">
        仅列出「待出库」且尚未生成分拣任务的发货通知单
      </span>
    </div>
    <Table
      :columns="columns"
      :data-source="notices"
      :loading="loading"
      :pagination="false"
      :row-selection="{
        type: 'radio',
        selectedRowKeys: selectedId ? [selectedId] : [],
        onChange: (keys) => {
          selectedId = Number(keys[0]);
        },
      }"
      :scroll="{ y: 360 }"
      row-key="noticeId"
      size="small"
      bordered
    />
  </Modal>
</template>