<script lang="ts" setup>
|
import type { FormType } from '../data';
|
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
import type { MesWmMiscIssueLineApi } from '#/api/mes/wm/miscissue/line';
|
|
import type { TraceResult } from '#/utils/traceLookup';
|
|
import { computed } from 'vue';
|
|
import { useVbenModal } from '@vben/common-ui';
|
|
import { message } from 'ant-design-vue';
|
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
import {
|
deleteMiscIssueLine,
|
getMiscIssueLinePage,
|
} from '#/api/mes/wm/miscissue/line';
|
import TraceScanPanel from '#/components/TraceScanPanel.vue';
|
import { $t } from '#/locales';
|
import { findMaterialStocks, traceQuantity } from '#/utils/traceLookup';
|
|
import { useLineGridColumns } from '../data';
|
import LineForm from './line-form.vue';
|
|
const props = defineProps<{
|
formType: FormType;
|
issueId: number;
|
}>();
|
|
const isEditable = computed(() =>
|
// 是否可编辑明细行
|
['create', 'update'].includes(props.formType),
|
);
|
|
const [LineFormModal, lineFormModalApi] = useVbenModal({
|
connectedComponent: LineForm,
|
destroyOnClose: true,
|
});
|
|
/** 刷新表格 */
|
function handleRefresh() {
|
gridApi.query();
|
}
|
|
/** 添加物料 */
|
function handleCreate() {
|
lineFormModalApi.setData({ issueId: props.issueId }).open();
|
}
|
|
/** 扫码带出:按追溯码匹配库存记录后打开新增行表单 */
|
async function handleTraceConfirm(trace: TraceResult) {
|
try {
|
const stocks = await findMaterialStocks(trace);
|
const stock = stocks.find((item) => (item.quantity ?? 0) > 0) ?? stocks[0];
|
if (!stock) {
|
message.warning('未找到该追溯码对应的库存记录');
|
return;
|
}
|
const quantity = traceQuantity(trace);
|
lineFormModalApi
|
.setData({
|
defaults: {
|
areaId: stock.areaId,
|
batchCode: stock.batchCode,
|
itemId: stock.itemId,
|
locationId: stock.locationId,
|
materialStockId: stock.id,
|
quantity:
|
quantity && stock.quantity
|
? Math.min(quantity, stock.quantity)
|
: (quantity ?? stock.quantity),
|
quantityMax: stock.quantity,
|
warehouseId: stock.warehouseId,
|
},
|
issueId: props.issueId,
|
})
|
.open();
|
} catch (e) {
|
message.error(e instanceof Error ? e.message : '扫码带出失败');
|
}
|
}
|
|
/** 编辑物料 */
|
function handleEdit(row: MesWmMiscIssueLineApi.MiscIssueLine) {
|
lineFormModalApi.setData({ id: row.id, issueId: props.issueId }).open();
|
}
|
|
/** 删除物料 */
|
async function handleDelete(row: MesWmMiscIssueLineApi.MiscIssueLine) {
|
const hideLoading = message.loading({
|
content: $t('ui.actionMessage.deleting', [row.itemName]),
|
duration: 0,
|
});
|
try {
|
await deleteMiscIssueLine(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.issueId) {
|
return { list: [], total: 0 };
|
}
|
return await getMiscIssueLinePage({
|
issueId: props.issueId,
|
pageNo: page.currentPage,
|
pageSize: page.pageSize,
|
});
|
},
|
},
|
},
|
rowConfig: {
|
keyField: 'id',
|
isHover: true,
|
},
|
toolbarConfig: {
|
refresh: true,
|
},
|
} as VxeTableGridOptions<MesWmMiscIssueLineApi.MiscIssueLine>,
|
});
|
</script>
|
|
<template>
|
<div>
|
<LineFormModal @success="handleRefresh" />
|
<TraceScanPanel
|
v-if="isEditable"
|
title="扫码带出出库明细"
|
@confirm="handleTraceConfirm"
|
/>
|
<Grid table-title="物料信息">
|
<template v-if="isEditable" #toolbar-tools>
|
<TableAction
|
:actions="[
|
{
|
label: '添加物料',
|
type: 'primary',
|
icon: ACTION_ICON.ADD,
|
onClick: handleCreate,
|
},
|
]"
|
/>
|
</template>
|
<template #actions="{ row }">
|
<TableAction
|
:actions="[
|
{
|
label: $t('common.edit'),
|
type: 'link',
|
icon: ACTION_ICON.EDIT,
|
ifShow: isEditable,
|
onClick: handleEdit.bind(null, row),
|
},
|
{
|
label: $t('common.delete'),
|
type: 'link',
|
danger: true,
|
icon: ACTION_ICON.DELETE,
|
ifShow: isEditable,
|
popConfirm: {
|
title: $t('ui.actionMessage.deleteConfirm', [row.itemName]),
|
confirm: handleDelete.bind(null, row),
|
},
|
},
|
]"
|
/>
|
</template>
|
</Grid>
|
</div>
|
</template>
|