|
|
|
|
@ -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 {
|
|
|
|
|
|