新增混炼示方生成预览与批量创建功能,优化相关字段及用户交互,修复界面显示问题,增强系统稳定性和用户体验。
This commit is contained in:
@@ -10,6 +10,13 @@ import { BasicModal, useModalInner } from '/@/components/Modal';
|
||||
import { BasicForm, useForm } from '/@/components/Form';
|
||||
import { defHttp } from '/@/utils/http/axios';
|
||||
import { loadTreeData } from '/@/views/system/category/category.api';
|
||||
import {
|
||||
MATERIAL_RAW_AUX_CODE,
|
||||
materialRawAuxCategoryId,
|
||||
isMaterialRawAuxSubCategory,
|
||||
toIsRubberFlag,
|
||||
fromIsRubberFlag,
|
||||
} from '/@/views/system/category/category.constants';
|
||||
import { useMessage } from '/@/hooks/web/useMessage';
|
||||
import type { FormSchema } from '/@/components/Form';
|
||||
import type { Recordable } from '/@/types/global';
|
||||
@@ -34,6 +41,15 @@ const schemas: FormSchema[] = [
|
||||
required: true,
|
||||
componentProps: { maxlength: 50, placeholder: '请输入分类名称' },
|
||||
},
|
||||
{
|
||||
label: ' ',
|
||||
field: 'isRubber',
|
||||
component: 'Checkbox',
|
||||
defaultValue: false,
|
||||
renderComponentContent: '胶料',
|
||||
colProps: { span: 24 },
|
||||
ifShow: ({ values }) => isMaterialRawAuxSubCategory(values.pid),
|
||||
},
|
||||
];
|
||||
|
||||
const [registerForm, { resetFields, setFieldsValue, validate, updateSchema, scrollToField }] = useForm({
|
||||
@@ -64,10 +80,30 @@ async function buildPidTree(): Promise<Recordable[]> {
|
||||
];
|
||||
}
|
||||
|
||||
async function ensureMaterialRawAuxCategoryId() {
|
||||
if (materialRawAuxCategoryId.value) {
|
||||
return;
|
||||
}
|
||||
const res = await defHttp.get(
|
||||
{ url: '/sys/category/loadOne', params: { field: 'code', val: MATERIAL_RAW_AUX_CODE } },
|
||||
{ isTransformResponse: false },
|
||||
);
|
||||
if (res?.success && res?.result?.id) {
|
||||
materialRawAuxCategoryId.value = res.result.id;
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeSubmitValues(values: Recordable) {
|
||||
const payload = { ...values };
|
||||
payload.isRubber = isMaterialRawAuxSubCategory(payload.pid) ? toIsRubberFlag(payload.isRubber) : '0';
|
||||
return payload;
|
||||
}
|
||||
|
||||
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
|
||||
await resetFields();
|
||||
setModalProps({ confirmLoading: false });
|
||||
isUpdate.value = !!data?.isUpdate;
|
||||
await ensureMaterialRawAuxCategoryId();
|
||||
const tree = await buildPidTree();
|
||||
if (!tree.length) {
|
||||
createMessage.warning('未加载到物料分类树,请确认分类字典根编码 XSLMES_MATERIAL 已存在');
|
||||
@@ -89,7 +125,7 @@ const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data
|
||||
|
||||
if (unref(isUpdate) && data?.record?.id) {
|
||||
const cat = await defHttp.get<Recordable>({ url: '/sys/category/queryById', params: { id: data.record.id } });
|
||||
await setFieldsValue({ id: cat.id, pid: cat.pid, name: cat.name });
|
||||
await setFieldsValue({ id: cat.id, pid: cat.pid, name: cat.name, isRubber: fromIsRubberFlag(cat.isRubber) });
|
||||
} else {
|
||||
const pid = data?.parentId != null && data.parentId !== '' ? String(data.parentId) : '';
|
||||
await setFieldsValue({ pid: pid || undefined, name: '' });
|
||||
@@ -100,13 +136,13 @@ const title = computed(() => (unref(isUpdate) ? '编辑物料分类' : '新增
|
||||
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
const values = await validate();
|
||||
const values = normalizeSubmitValues(await validate());
|
||||
setModalProps({ confirmLoading: true });
|
||||
if (unref(isUpdate)) {
|
||||
const full = await defHttp.get<Recordable>({ url: '/sys/category/queryById', params: { id: values.id } });
|
||||
await editMaterialSysCategory({ ...full, pid: values.pid, name: values.name });
|
||||
await editMaterialSysCategory({ ...full, pid: values.pid, name: values.name, isRubber: values.isRubber });
|
||||
} else {
|
||||
await saveMaterialSysCategory({ pid: values.pid, name: values.name });
|
||||
await saveMaterialSysCategory({ pid: values.pid, name: values.name, isRubber: values.isRubber });
|
||||
}
|
||||
closeModal();
|
||||
emit('success');
|
||||
|
||||
Reference in New Issue
Block a user