gaoluyang
2026-06-29 27cd042df9aca0383a49f3514bc21958dd890912
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
<script lang="ts" setup>
import type { FormType } from '../data';
 
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { MesWmMaterialStockApi } from '#/api/mes/wm/materialstock';
import type { MesWmStockTakingTaskLineApi } from '#/api/mes/wm/stocktaking/task/line';
 
import { computed, ref } from 'vue';
 
import { message } from 'ant-design-vue';
 
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import {
  createStockTakingTaskLine,
  deleteStockTakingTaskLine,
  getStockTakingTaskLinePage,
} from '#/api/mes/wm/stocktaking/task/line';
import { $t } from '#/locales';
import { WmMaterialStockSelectDialog } from '#/views/mes/wm/materialstock/components';
 
import { useLineGridColumns } from '../data';
 
const props = defineProps<{
  formType: FormType;
  taskId: number;
}>();
 
const isEditable = computed(() => props.formType === 'update'); // 仅编辑态可维护盘点清单
const dialogRef = ref<InstanceType<typeof WmMaterialStockSelectDialog>>();
 
/** 刷新表格 */
function handleRefresh() {
  gridApi.query();
}
 
/** 打开库存选择弹窗批量添加物料 */
function handleAdd() {
  dialogRef.value?.open([], { multiple: true });
}
 
/** 库存选择确认回调:将选中的库存记录批量创建为盘点行 */
async function handleStockSelected(
  rows: MesWmMaterialStockApi.MaterialStock[],
) {
  if (rows.length === 0) {
    return;
  }
  for (const stock of rows) {
    await createStockTakingTaskLine({
      areaId: stock.areaId,
      batchId: stock.batchId,
      itemId: stock.itemId,
      locationId: stock.locationId,
      materialStockId: stock.id,
      quantity: stock.quantity,
      taskId: props.taskId,
      warehouseId: stock.warehouseId,
    });
  }
  message.success(`成功添加 ${rows.length} 条盘点行`);
  handleRefresh();
}
 
/** 删除盘点行 */
async function handleDelete(
  row: MesWmStockTakingTaskLineApi.StockTakingTaskLine,
) {
  const hideLoading = message.loading({
    content: $t('ui.actionMessage.deleting', [row.itemName]),
    duration: 0,
  });
  try {
    await deleteStockTakingTaskLine(row.id!);
    message.success($t('ui.actionMessage.deleteSuccess', [row.itemName]));
    handleRefresh();
  } finally {
    hideLoading();
  }
}
 
const [Grid, gridApi] = useVbenVxeGrid({
  gridOptions: {
    columns: useLineGridColumns(isEditable.value),
    height: 360,
    keepSource: true,
    proxyConfig: {
      ajax: {
        query: async ({ page }) => {
          if (!props.taskId) {
            return { list: [], total: 0 };
          }
          return await getStockTakingTaskLinePage({
            pageNo: page.currentPage,
            pageSize: page.pageSize,
            taskId: props.taskId,
          });
        },
      },
    },
    rowConfig: {
      keyField: 'id',
      isHover: true,
    },
    toolbarConfig: {
      refresh: true,
    },
  } as VxeTableGridOptions<MesWmStockTakingTaskLineApi.StockTakingTaskLine>,
});
 
defineExpose({ refresh: handleRefresh });
</script>
 
<template>
  <div>
    <WmMaterialStockSelectDialog
      ref="dialogRef"
      @selected="handleStockSelected"
    />
    <Grid table-title="盘点清单">
      <template v-if="isEditable" #toolbar-tools>
        <TableAction
          :actions="[
            {
              label: '添加物料',
              type: 'primary',
              icon: ACTION_ICON.ADD,
              auth: ['mes:wm-stock-taking-task:update'],
              onClick: handleAdd,
            },
          ]"
        />
      </template>
      <template #actions="{ row }">
        <TableAction
          :actions="[
            {
              label: $t('common.delete'),
              type: 'link',
              danger: true,
              icon: ACTION_ICON.DELETE,
              popConfirm: {
                title: $t('ui.actionMessage.deleteConfirm', [row.itemName]),
                confirm: handleDelete.bind(null, row),
              },
            },
          ]"
        />
      </template>
    </Grid>
  </div>
</template>