<script lang="ts" setup>
|
import type { FormType } from '../data';
|
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
import type { MesWmArrivalNoticeLineApi } from '#/api/mes/wm/arrivalnotice/line';
|
|
import { computed } from 'vue';
|
|
import { useRouter } from 'vue-router';
|
|
import { useVbenModal } from '@vben/common-ui';
|
|
import { Button, message, Tag } from 'ant-design-vue';
|
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
import {
|
deleteArrivalNoticeLine,
|
getArrivalNoticeLinePage,
|
} from '#/api/mes/wm/arrivalnotice/line';
|
import { $t } from '#/locales';
|
|
import { useLineGridColumns } from '../data';
|
import LineForm from './line-form.vue';
|
|
const props = defineProps<{
|
formType: FormType;
|
noticeId: number;
|
}>();
|
|
const router = useRouter();
|
|
const isEditable = computed(() =>
|
// 是否可编辑明细行
|
['create', 'update'].includes(props.formType),
|
);
|
|
const [LineFormModal, lineFormModalApi] = useVbenModal({
|
connectedComponent: LineForm,
|
destroyOnClose: true,
|
});
|
|
/** 刷新表格 */
|
function handleRefresh() {
|
gridApi.query();
|
}
|
|
/** 添加物料 */
|
function handleCreate() {
|
lineFormModalApi.setData({ noticeId: props.noticeId }).open();
|
}
|
|
/** 编辑物料 */
|
function handleEdit(row: MesWmArrivalNoticeLineApi.ArrivalNoticeLine) {
|
lineFormModalApi.setData({ id: row.id, noticeId: props.noticeId }).open();
|
}
|
|
/** 删除物料 */
|
async function handleDelete(row: MesWmArrivalNoticeLineApi.ArrivalNoticeLine) {
|
const hideLoading = message.loading({
|
content: $t('ui.actionMessage.deleting', [row.itemName]),
|
duration: 0,
|
});
|
try {
|
await deleteArrivalNoticeLine(row.id!);
|
message.success($t('ui.actionMessage.deleteSuccess', [row.itemName]));
|
handleRefresh();
|
} finally {
|
hideLoading();
|
}
|
}
|
|
/** 跳转 IQC 检验单详情 */
|
function handleOpenIqc(row: MesWmArrivalNoticeLineApi.ArrivalNoticeLine) {
|
if (row.iqcId) {
|
router.push({ path: '/mes/qc/iqc', query: { id: row.iqcId } });
|
}
|
}
|
|
const [Grid, gridApi] = useVbenVxeGrid({
|
gridOptions: {
|
columns: useLineGridColumns(isEditable.value),
|
height: 400,
|
keepSource: true,
|
proxyConfig: {
|
ajax: {
|
query: async ({ page }) => {
|
if (!props.noticeId) {
|
return { list: [], total: 0 };
|
}
|
return await getArrivalNoticeLinePage({
|
noticeId: props.noticeId,
|
pageNo: page.currentPage,
|
pageSize: page.pageSize,
|
});
|
},
|
},
|
},
|
rowConfig: {
|
keyField: 'id',
|
isHover: true,
|
},
|
toolbarConfig: {
|
refresh: true,
|
},
|
} as VxeTableGridOptions<MesWmArrivalNoticeLineApi.ArrivalNoticeLine>,
|
});
|
</script>
|
|
<template>
|
<div>
|
<LineFormModal @success="handleRefresh" />
|
<Grid table-title="物料信息">
|
<template v-if="isEditable" #toolbar-tools>
|
<TableAction
|
:actions="[
|
{
|
label: '添加物料',
|
type: 'primary',
|
icon: ACTION_ICON.ADD,
|
onClick: handleCreate,
|
},
|
]"
|
/>
|
</template>
|
<template #iqcCode="{ row }">
|
<Button
|
v-if="row.iqcCode"
|
size="small"
|
type="link"
|
@click="handleOpenIqc(row)"
|
>
|
{{ row.iqcCode }}
|
</Button>
|
<span v-else>-</span>
|
</template>
|
<template #iqcCheckResult="{ row }">
|
<Tag v-if="row.iqcCheckResult === 1" color="success">合格</Tag>
|
<Tag v-else-if="row.iqcCheckResult === 2" color="warning">特采</Tag>
|
<Tag v-else-if="row.iqcCheckResult === 3" color="error">不合格退货</Tag>
|
<Tag v-else-if="row.iqcCheckResult === 4" color="error">不合格报废</Tag>
|
<span v-else>-</span>
|
</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>
|