update 配方新增跳转维护页面

master
yinq 4 days ago
parent 6aba590198
commit 2ff7c4608d

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

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

Loading…
Cancel
Save