<script lang="ts" setup>
|
import type { VbenFormSchema } from '#/adapter/form';
|
import type { MesWmMaterialStockApi } from '#/api/mes/wm/materialstock';
|
import type { MesWmReturnIssueLineApi } from '#/api/mes/wm/returnissue/line';
|
|
import { computed, markRaw, ref } from 'vue';
|
|
import { useVbenModal } from '@vben/common-ui';
|
|
import { message } from 'ant-design-vue';
|
|
import { z } from '#/adapter/form';
|
import { useVbenForm } from '#/adapter/form';
|
import {
|
createReturnIssueLine,
|
getReturnIssueLine,
|
updateReturnIssueLine,
|
} from '#/api/mes/wm/returnissue/line';
|
import { MdItemSelect } from '#/views/mes/md/item/components';
|
import { WmMaterialStockSelect } from '#/views/wls/materialstock/components';
|
|
const emit = defineEmits(['success']);
|
const formData = ref<MesWmReturnIssueLineApi.ReturnIssueLine>();
|
const issueId = ref<number>();
|
|
const getTitle = computed(() => {
|
return formData.value?.id ? '编辑物料' : '添加物料';
|
});
|
|
/** 物料行表单 schema */
|
function buildLineFormSchema(): VbenFormSchema[] {
|
return [
|
{
|
fieldName: 'materialStockId',
|
label: '库存记录',
|
component: markRaw(WmMaterialStockSelect),
|
componentProps: {
|
onChange: async (stock?: MesWmMaterialStockApi.MaterialStock) => {
|
await formApi.setValues({
|
batchCode: stock?.batchCode,
|
batchId: stock?.batchId,
|
itemId: stock?.itemId,
|
quantity: stock?.quantity,
|
quantityMax: stock?.quantity,
|
});
|
},
|
virtualFilter: 'only',
|
},
|
rules: 'selectRequired',
|
},
|
{
|
fieldName: 'quantityMax',
|
component: 'Input',
|
dependencies: { triggerFields: [''], show: () => false },
|
},
|
{
|
fieldName: 'quantity',
|
label: '退料数量',
|
component: 'InputNumber',
|
componentProps: {
|
class: '!w-full',
|
min: 0,
|
placeholder: '请输入退料数量',
|
precision: 2,
|
},
|
rules: 'required',
|
dependencies: {
|
triggerFields: ['quantityMax'],
|
componentProps: (values) => ({
|
class: '!w-full',
|
max: values.quantityMax,
|
min: 0,
|
placeholder: '请输入退料数量',
|
precision: 2,
|
}),
|
},
|
},
|
{
|
fieldName: 'rqcCheckFlag',
|
label: '需要质检',
|
component: 'Switch',
|
rules: z.boolean().default(false),
|
},
|
{
|
fieldName: 'itemId',
|
label: '物料',
|
component: markRaw(MdItemSelect),
|
componentProps: { disabled: true },
|
},
|
{
|
fieldName: 'batchCode',
|
label: '批次号',
|
component: 'Input',
|
componentProps: { disabled: true, placeholder: '选择库存后自动带出' },
|
},
|
{
|
fieldName: 'remark',
|
label: '备注',
|
component: 'Textarea',
|
formItemClass: 'col-span-3',
|
componentProps: { placeholder: '请输入备注', rows: 2 },
|
},
|
];
|
}
|
|
const [Form, formApi] = useVbenForm({
|
commonConfig: { componentProps: { class: 'w-full' }, formItemClass: 'col-span-1', labelWidth: 90 },
|
layout: 'horizontal',
|
schema: buildLineFormSchema(),
|
showDefaultActions: false,
|
wrapperClass: 'grid-cols-3',
|
});
|
|
const [Modal, modalApi] = useVbenModal({
|
async onConfirm() {
|
const { valid } = await formApi.validate();
|
if (!valid) return;
|
modalApi.lock();
|
const data = (await formApi.getValues()) as MesWmReturnIssueLineApi.ReturnIssueLine;
|
data.issueId = issueId.value;
|
try {
|
if (formData.value?.id) {
|
await updateReturnIssueLine({ ...data, id: formData.value.id });
|
} else {
|
await createReturnIssueLine(data);
|
}
|
await modalApi.close();
|
emit('success');
|
message.success('操作成功');
|
} finally {
|
modalApi.unlock();
|
}
|
},
|
async onOpenChange(isOpen: boolean) {
|
if (!isOpen) {
|
formData.value = undefined;
|
return;
|
}
|
const data = modalApi.getData<{ id?: number; issueId: number }>();
|
issueId.value = data.issueId;
|
if (!data.id) {
|
await formApi.resetForm();
|
return;
|
}
|
modalApi.lock();
|
try {
|
formData.value = await getReturnIssueLine(data.id);
|
await formApi.setValues(formData.value);
|
} finally {
|
modalApi.unlock();
|
}
|
},
|
});
|
</script>
|
|
<template>
|
<Modal :title="getTitle" class="w-3/5">
|
<Form class="mx-4" />
|
</Modal>
|
</template>
|