update 配方新增跳转维护页面

master
yinq 4 days ago
parent 6aba590198
commit 2ff7c4608d

@ -1,7 +1,7 @@
<template>
<div class="recipe-detail-page p-2">
<div class="page-header">
<span class="page-title">配方明细信息</span>
<span class="page-title">{{ isAddMode ? '新增配方明细' : '配方明细信息' }}</span>
<div class="header-actions">
<el-button @click="goBack"></el-button>
<el-button type="primary" :loading="saveLoading" @click="handleSave"></el-button>
@ -279,6 +279,7 @@ const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const { recipe_state, weight_type, act_code } = toRefs<any>(proxy?.useDict('recipe_state', 'weight_type', 'act_code'));
const recipeId = computed(() => route.query.recipeId as string || '');
const isAddMode = computed(() => route.query.mode === 'add' || !recipeId.value);
const activeTab = ref('basic');
const saveLoading = ref(false);
const basicFormRef = ref<ElFormInstance>();
@ -333,10 +334,13 @@ function confirmMaterialSelect() {
}
async function loadData() {
if (!recipeId.value) {
proxy?.$modal.msgWarning('缺少配方ID');
if (isAddMode.value) {
recipeInfo.value = { recipeState: '1' };
weightList.value = [];
mixingList.value = [];
return;
}
if (!recipeId.value) return;
try {
const [infoRes, weightRes, mixingRes] = await Promise.all([
getRecipeInfo(recipeId.value),
@ -417,7 +421,7 @@ function addWeightRowEnd() {
const idx = weightList.value.length - 1;
const base = weightList.value[idx] || {};
weightList.value.push({
recipeId: recipeId.value,
recipeId: recipeId.value || undefined,
machineId: recipeInfo.value.machineId,
edtCode: recipeInfo.value.edtCode,
weightSeq: (weightList.value.length + 1) as any,
@ -436,7 +440,7 @@ function removeWeightRow(index: number) {
function addMixingRowEnd() {
const base = mixingList.value[mixingList.value.length - 1] || {};
mixingList.value.push({
recipeId: recipeId.value,
recipeId: recipeId.value || undefined,
machineId: recipeInfo.value.machineId,
edtCode: recipeInfo.value.edtCode,
mixId: mixingList.value.length + 1,
@ -475,13 +479,17 @@ async function refreshMixing() {
}
async function handleSave() {
if (!recipeId.value) {
if (!isAddMode.value && !recipeId.value) {
proxy?.$modal.msgWarning('缺少配方ID');
return;
}
if (isAddMode.value && (!recipeInfo.value.recipeCode || !recipeInfo.value.machineId)) {
proxy?.$modal.msgWarning('新增时请填写配方代码并选择机台');
return;
}
saveLoading.value = true;
try {
const recipeIdVal = recipeId.value;
const recipeIdVal = recipeId.value || undefined;
const recipe = { ...recipeInfo.value, recipeId: recipeIdVal };
const weights = weightList.value.map((w, i) => ({
...w,
@ -500,13 +508,19 @@ async function handleSave() {
actCode: m.actCode ?? '',
condCode: m.condCode ?? ''
}));
await saveRecipeDetail({
const res = await saveRecipeDetail({
recipeInfo: recipe,
weightList: weights,
mixingList: mixings
});
const newRecipeId = (res as any)?.data;
proxy?.$modal.msgSuccess('保存成功');
await loadData();
if (isAddMode.value && newRecipeId) {
router.replace({ path: '/mes/recipeInfoDetail/index', query: { recipeId: newRecipeId } });
await loadData();
} else {
await loadData();
}
} catch (e) {
proxy?.$modal.msgError('保存失败');
} finally {

@ -609,11 +609,9 @@ const handleSelectionChange = (selection: RecipeInfoVO[]) => {
multiple.value = !selection.length;
};
/** 新增 */
/** 新增 - 跳转到明细页进行维护 */
const handleAdd = () => {
reset();
dialog.visible = true;
dialog.title = '新增工艺配方';
router.push({ path: '/mes/recipeInfoDetail/index', query: { mode: 'add' } });
};
/** 配方明细 */

Loading…
Cancel
Save