<script lang="ts" setup>
|
import type { WmsApprovalApi } from '#/api/mes/wm/approval';
|
|
import { computed, ref, watch } from 'vue';
|
|
import { useVbenModal } from '@vben/common-ui';
|
|
import { message } from 'ant-design-vue';
|
|
import { useVbenForm } from '#/adapter/form';
|
import {
|
getAvailableProcessList,
|
getApprovalConfig,
|
saveApprovalConfig,
|
} from '#/api/mes/wm/approval';
|
|
import { BIZ_TYPE_OPTIONS, useProcessFormSchema } from '../data';
|
|
const emit = defineEmits<{ success: [] }>();
|
|
const [Form, formApi] = useVbenForm({
|
commonConfig: {
|
componentProps: {
|
class: 'w-full',
|
},
|
},
|
layout: 'horizontal',
|
schema: useProcessFormSchema(),
|
showDefaultActions: false,
|
});
|
|
const [Modal, modalApi] = useVbenModal({
|
async onConfirm() {
|
const values = await formApi.getValues();
|
if (!values.bizType) {
|
message.error('请选择业务类型');
|
return;
|
}
|
if (!values.processDefinitionKey) {
|
message.error('请选择审批流程');
|
return;
|
}
|
|
await saveApprovalConfig({
|
warehouseId: values.warehouseId,
|
bizType: values.bizType,
|
approvalEnabled: true,
|
processDefinitionKey: values.processDefinitionKey,
|
});
|
message.success('配置保存成功');
|
emit('success');
|
modalApi.close();
|
},
|
onOpenChange(isOpen) {
|
if (isOpen) {
|
const data = modalApi.getData() as {
|
warehouseId: number;
|
warehouseName: string;
|
};
|
if (data) {
|
formApi.setValues({
|
warehouseId: data.warehouseId,
|
warehouseName: data.warehouseName,
|
bizType: undefined,
|
processDefinitionKey: undefined,
|
});
|
}
|
}
|
},
|
});
|
|
/** 当前选中的业务类型 */
|
const currentBizType = computed(() => {
|
const values = formApi.getValues();
|
return values.bizType;
|
});
|
|
/** 监听业务类型变化,加载对应的流程列表 */
|
watch(currentBizType, async (bizType) => {
|
if (bizType) {
|
const data = modalApi.getData() as { warehouseId: number };
|
if (data?.warehouseId) {
|
try {
|
const config = await getApprovalConfig(data.warehouseId, bizType);
|
if (config) {
|
formApi.setValues({
|
processDefinitionKey: config.processDefinitionKey,
|
});
|
}
|
} catch {
|
// 忽略错误
|
}
|
|
formApi.updateSchema([
|
{
|
fieldName: 'processDefinitionKey',
|
componentProps: {
|
api: async () => {
|
return await getAvailableProcessList(data.warehouseId, bizType);
|
},
|
},
|
},
|
]);
|
}
|
}
|
});
|
</script>
|
|
<template>
|
<Modal title="配置审批流程" class="w-[500px]">
|
<Form />
|
</Modal>
|
</template>
|