<script lang="ts" setup>
|
import type { VbenFormSchema } from '#/adapter/form';
|
import type { MesPdProductApi } from '#/api/mes/pd/product';
|
|
import { computed, ref } from 'vue';
|
|
import { useVbenModal } from '@vben/common-ui';
|
import { $t } from '@vben/locales';
|
|
import { message } from 'ant-design-vue';
|
|
import { useVbenForm } from '#/adapter/form';
|
import { auditProduct } from '#/api/mes/pd/product';
|
|
const emit = defineEmits(['success']);
|
const pass = ref(true); // true=通过 / false=驳回
|
const rowData = ref<MesPdProductApi.Product>();
|
const getTitle = computed(() => (pass.value ? '审核通过' : '审核驳回'));
|
|
const [Form, formApi] = useVbenForm({
|
commonConfig: {
|
componentProps: {
|
class: 'w-full',
|
},
|
formItemClass: 'col-span-1',
|
labelWidth: 130,
|
},
|
wrapperClass: 'grid-cols-1',
|
layout: 'horizontal',
|
schema: [],
|
showDefaultActions: false,
|
});
|
|
/** 审核表单字段 */
|
function useAuditSchema(): VbenFormSchema[] {
|
return [
|
{
|
fieldName: 'auditRemark',
|
label: '审批意见',
|
component: 'Textarea',
|
formItemClass: 'col-span-1',
|
componentProps: {
|
rows: 3,
|
placeholder: pass.value
|
? '请输入审批意见(可选)'
|
: '请输入驳回原因(必填)',
|
},
|
rules: pass.value ? '' : 'required',
|
},
|
];
|
}
|
|
const [Modal, modalApi] = useVbenModal({
|
async onConfirm() {
|
const { valid } = await formApi.validate();
|
if (!valid) {
|
return;
|
}
|
modalApi.lock();
|
const values = await formApi.getValues();
|
try {
|
await auditProduct({
|
id: rowData.value!.id!,
|
pass: pass.value,
|
auditRemark: values.auditRemark,
|
});
|
await modalApi.close();
|
emit('success');
|
message.success(pass.value ? '审批通过' : '审批驳回');
|
} finally {
|
modalApi.unlock();
|
}
|
},
|
async onOpenChange(isOpen: boolean) {
|
if (!isOpen) {
|
return;
|
}
|
const data = modalApi.getData<{
|
row: MesPdProductApi.Product;
|
pass: boolean;
|
}>();
|
rowData.value = data.row;
|
pass.value = data.pass;
|
formApi.setState({ schema: useAuditSchema() });
|
formApi.resetForm();
|
},
|
});
|
</script>
|
|
<template>
|
<Modal :title="getTitle" class="w-2/5">
|
<Form class="mx-4" />
|
</Modal>
|
</template>
|