update 配方信息明细维护

master
yinq 3 days ago
parent a662bfa16d
commit e0bcd07b89

@ -60,9 +60,9 @@ export interface RecipeWeightVO {
unitId: string | number;
/**
*
* ID
*/
childCode: string;
childCode: number;
/**
* 使
@ -138,9 +138,9 @@ export interface RecipeWeightForm extends BaseEntity {
unitId?: string | number;
/**
*
* ID
*/
childCode?: string;
childCode?: number;
/**
* 使
@ -217,9 +217,9 @@ export interface RecipeWeightQuery extends PageQuery {
unitId?: string | number;
/**
*
* ID
*/
childCode?: string;
childCode?: number;
/**
* 使

@ -3,12 +3,8 @@
<div class="page-header">
<span class="page-title">配方明细信息</span>
<div class="header-actions">
<el-button type="primary" :icon="isEdit ? 'Select' : 'Edit'" @click="toggleEdit">
{{ isEdit ? '取消编辑' : '编辑' }}
</el-button>
<el-button type="success" icon="Select" :loading="saveLoading" :disabled="!isEdit" @click="handleSave">
保存
</el-button>
<el-button @click="goBack"></el-button>
<el-button type="primary" :loading="saveLoading" @click="handleSave"></el-button>
</div>
</div>
@ -16,7 +12,7 @@
<el-tab-pane label="基本信息" name="basic">
<el-card shadow="never" class="mb-4">
<template #header>配方基本信息</template>
<el-form ref="basicFormRef" :model="recipeInfo" :disabled="!isEdit" label-width="140px" class="form-grid">
<el-form ref="basicFormRef" :model="recipeInfo" label-width="140px" class="form-grid">
<el-row :gutter="16">
<el-col :span="8">
<el-form-item label="配方代码" prop="recipeCode">
@ -36,8 +32,18 @@
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="物料名称" prop="recipeCode">
<el-input v-model="recipeInfo.recipeCode" placeholder="物料名称" />
<el-form-item label="物料" prop="materialId">
<el-input
:model-value="recipeMaterialDisplay"
placeholder="请选择物料"
readonly
style="width: 100%"
@click="openMaterialSelect"
>
<template #append>
<el-button :icon="'Search'" @click.stop="openMaterialSelect">选择</el-button>
</template>
</el-input>
</el-form-item>
<el-form-item label="超温温度(℃)" prop="overtempTemp">
<el-input-number v-model="recipeInfo.overtempTemp" :min="0" controls-position="right" style="width: 100%" />
@ -74,47 +80,70 @@
<el-tab-pane label="称量信息" name="weight">
<div class="tab-toolbar mb-3">
<el-button type="primary" size="small" @click="calcWeight"></el-button>
<el-button type="primary" size="small" @click="addWeightRowEnd"></el-button>
<el-button size="small" @click="refreshWeight"></el-button>
</div>
<el-card shadow="never" class="mb-3">
<template #header>称量明细</template>
<el-table :data="weightList" border>
<el-table-column type="index" label="序号" width="60" align="center" />
<el-table-column label="物料名称/炭黑名称" prop="childCode" min-width="120">
<el-table-column label="称量类型" prop="weightType" width="100" align="center">
<template #default="{ row }">
<el-input v-if="isEdit" v-model="row.childCode" size="small" placeholder="物料编码" />
<span v-else>{{ row.childCode || '-' }}</span>
<el-select v-model="row.weightType" size="small" placeholder="类型" clearable style="width: 100%">
<el-option v-for="d in weight_type" :key="d.value" :label="d.label" :value="d.value" />
</el-select>
</template>
</el-table-column>
<el-table-column label="物料编码" prop="fatherCode" min-width="100">
<el-table-column label="物料名称" prop="childCode" min-width="160">
<template #default="{ row }">
<el-input v-if="isEdit" v-model="row.fatherCode" size="small" />
<span v-else>{{ row.fatherCode || '-' }}</span>
<el-select
v-model="row.childCode"
size="small"
placeholder="请选择物料"
clearable
filterable
style="width: 100%"
>
<el-option
v-for="m in materialOptions"
:key="m.materialId"
:label="`${m.materialName || ''} (${m.materialCode || ''})`"
:value="Number(m.materialId)"
/>
</el-select>
</template>
</el-table-column>
<el-table-column label="称量动作" prop="actCode" width="100">
<el-table-column label="动作" prop="actCode" width="120" align="center">
<template #default="{ row }">
<el-input v-if="isEdit" v-model="row.actCode" size="small" />
<span v-else>{{ row.actCode || '-' }}</span>
<el-select
v-model="row.actCode"
size="small"
placeholder="请选择动作"
clearable
filterable
style="width: 100%"
>
<el-option
v-for="d in actCodeOptions"
:key="d.dataDetailCode"
:label="d.dataDetailName"
:value="d.dataDetailCode"
/>
</el-select>
</template>
</el-table-column>
<el-table-column label="设定重量(千克)" prop="setWeight" width="140">
<el-table-column label="设定重量" prop="setWeight" width="120" align="center">
<template #default="{ row }">
<el-input-number v-if="isEdit" v-model="row.setWeight" :min="0" :precision="3" size="small" controls-position="right" style="width: 100%" />
<span v-else>{{ row.setWeight ?? '-' }}</span>
<el-input-number v-model="row.setWeight" :min="0" :precision="3" size="small" controls-position="right" style="width: 100%" />
</template>
</el-table-column>
<el-table-column label="允许误差(千克)" prop="errorAllow" width="140">
<el-table-column label="误差允许" prop="errorAllow" width="120" align="center">
<template #default="{ row }">
<el-input-number v-if="isEdit" v-model="row.errorAllow" :min="0" :precision="3" size="small" controls-position="right" style="width: 100%" />
<span v-else>{{ row.errorAllow ?? '-' }}</span>
<el-input-number v-model="row.errorAllow" :min="0" :precision="3" size="small" controls-position="right" style="width: 100%" />
</template>
</el-table-column>
<el-table-column v-if="isEdit" label="操作" width="180" fixed="right" align="center">
<el-table-column label="操作" width="80" fixed="right" align="center">
<template #default="{ $index }">
<el-button link type="primary" size="small" @click="addWeightRow($index)"></el-button>
<el-button link type="primary" size="small" @click="insertWeightRow($index)"></el-button>
<el-button link type="danger" size="small" @click="removeWeightRow($index)"></el-button>
</template>
</el-table-column>
@ -127,63 +156,93 @@
<el-tab-pane label="混炼信息" name="mixing">
<div class="tab-toolbar mb-3">
<el-button type="primary" size="small" @click="refreshMixing"></el-button>
<el-button type="primary" size="small" @click="addMixingRowEnd"></el-button>
<el-button size="small" @click="refreshMixing"></el-button>
</div>
<el-card shadow="never">
<template #header>混炼信息</template>
<el-table :data="mixingList" border>
<el-table-column type="index" label="步骤" width="70" align="center" />
<el-table-column label="动作" prop="actCode" min-width="120">
<el-table-column label="动作" prop="actCode" width="140" align="center">
<template #default="{ row }">
<el-input v-if="isEdit" v-model="row.actCode" size="small" />
<span v-else>{{ row.actCode || '-' }}</span>
<el-select
v-model="row.actCode"
size="small"
placeholder="请选择动作"
clearable
filterable
style="width: 100%"
>
<el-option
v-for="d in actCodeOptions"
:key="d.dataDetailCode"
:label="d.dataDetailName"
:value="d.dataDetailCode"
/>
</el-select>
</template>
</el-table-column>
<el-table-column label="条件" prop="condCode" width="100">
<el-table-column label="条件" prop="condCode" width="140" align="center">
<template #default="{ row }">
<el-input v-if="isEdit" v-model="row.condCode" size="small" />
<span v-else>{{ row.condCode || '-' }}</span>
<el-select
v-model="row.condCode"
size="small"
placeholder="请选择条件"
clearable
filterable
style="width: 100%"
>
<el-option
v-for="d in condCodeOptions"
:key="d.dataDetailCode"
:label="d.dataDetailName"
:value="d.dataDetailCode"
/>
</el-select>
</template>
</el-table-column>
<el-table-column label="时间(s)" prop="setTime" width="90">
<el-table-column label="设定时间(s)" prop="setTime" width="100" align="center">
<template #default="{ row }">
<el-input-number v-if="isEdit" v-model="row.setTime" :min="0" size="small" controls-position="right" style="width: 100%" />
<span v-else>{{ row.setTime ?? '-' }}</span>
<el-input-number v-model="row.setTime" :min="0" size="small" controls-position="right" style="width: 100%" />
</template>
</el-table-column>
<el-table-column label="温度(°C)" prop="setTemp" width="90">
<el-table-column label="设定温度(°C)" prop="setTemp" width="110" align="center">
<template #default="{ row }">
<el-input-number v-if="isEdit" v-model="row.setTemp" :min="0" size="small" controls-position="right" style="width: 100%" />
<span v-else>{{ row.setTemp ?? '-' }}</span>
<el-input-number v-model="row.setTemp" :min="0" size="small" controls-position="right" style="width: 100%" />
</template>
</el-table-column>
<el-table-column label="能量(kw/h)" prop="setEnergy" width="100">
<el-table-column label="混炼时间" prop="mixingTime" width="90" align="center">
<template #default="{ row }">
<el-input-number v-if="isEdit" v-model="row.setEnergy" :min="0" size="small" controls-position="right" style="width: 100%" />
<span v-else>{{ row.setEnergy ?? '-' }}</span>
<el-input-number v-model="row.mixingTime" :min="0" size="small" controls-position="right" style="width: 100%" />
</template>
</el-table-column>
<el-table-column label="功率(kw)" prop="setPower" width="90">
<el-table-column label="混炼温度" prop="mixingTemp" width="90" align="center">
<template #default="{ row }">
<el-input-number v-if="isEdit" v-model="row.setPower" :min="0" size="small" controls-position="right" style="width: 100%" />
<span v-else>{{ row.setPower ?? '-' }}</span>
<el-input-number v-model="row.mixingTemp" :min="0" size="small" controls-position="right" style="width: 100%" />
</template>
</el-table-column>
<el-table-column label="压力" prop="setPres" width="80">
<el-table-column label="设定能量" prop="setEnergy" width="95" align="center">
<template #default="{ row }">
<el-input-number v-if="isEdit" v-model="row.setPres" :min="0" size="small" controls-position="right" style="width: 100%" />
<span v-else>{{ row.setPres ?? '-' }}</span>
<el-input-number v-model="row.setEnergy" :min="0" size="small" controls-position="right" style="width: 100%" />
</template>
</el-table-column>
<el-table-column label="转速(rpm)" prop="setRota" width="100">
<el-table-column label="设定功率" prop="setPower" width="95" align="center">
<template #default="{ row }">
<el-input-number v-if="isEdit" v-model="row.setRota" :min="0" size="small" controls-position="right" style="width: 100%" />
<span v-else>{{ row.setRota ?? '-' }}</span>
<el-input-number v-model="row.setPower" :min="0" size="small" controls-position="right" style="width: 100%" />
</template>
</el-table-column>
<el-table-column v-if="isEdit" label="操作" width="120" fixed="right" align="center">
<el-table-column label="设定压力" prop="setPres" width="95" align="center">
<template #default="{ row }">
<el-input-number v-model="row.setPres" :min="0" size="small" controls-position="right" style="width: 100%" />
</template>
</el-table-column>
<el-table-column label="设定转速" prop="setRota" width="95" align="center">
<template #default="{ row }">
<el-input-number v-model="row.setRota" :min="0" size="small" controls-position="right" style="width: 100%" />
</template>
</el-table-column>
<el-table-column label="操作" width="80" fixed="right" align="center">
<template #default="{ $index }">
<el-button link type="primary" size="small" @click="insertMixingRow($index)"></el-button>
<el-button link type="danger" size="small" @click="removeMixingRow($index)"></el-button>
</template>
</el-table-column>
@ -192,6 +251,15 @@
</el-card>
</el-tab-pane>
</el-tabs>
<!-- 选择物料对话框 -->
<el-dialog title="选择物料" v-model="materialSelectVisible" width="700px" append-to-body>
<MaterialSelect ref="materialSelectRef" v-if="materialSelectVisible" />
<template #footer>
<el-button type="primary" @click="confirmMaterialSelect"> </el-button>
<el-button @click="materialSelectVisible = false"> </el-button>
</template>
</el-dialog>
</div>
</template>
@ -200,19 +268,23 @@ import { getRecipeInfo, saveRecipeDetail } from '@/api/mes/recipeInfo';
import { listRecipeWeight } from '@/api/mes/recipeWeight';
import { listRecipeMixing } from '@/api/mes/recipeMixing';
import { getProdBaseMachineInfoList } from '@/api/mes/prodBaseMachineInfo';
import { getBaseMaterialInfoList } from '@/api/mes/baseMaterialInfo';
import type { RecipeInfoForm } from '@/api/mes/recipeInfo/types';
import type { RecipeWeightForm } from '@/api/mes/recipeWeight/types';
import type { RecipeMixingForm } from '@/api/mes/recipeMixing/types';
import type { ProdBaseMachineInfoVO } from '@/api/mes/prodBaseMachineInfo/types';
import type { BaseMaterialInfoVO } from '@/api/mes/baseMaterialInfo/types';
import { listMasterDataDetail } from '@/api/system/masterDataDetail';
import type { MasterDataDetailVO } from '@/api/system/masterDataDetail/types';
import MaterialSelect from './components/MaterialSelect.vue';
const route = useRoute();
const router = useRouter();
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const { recipe_state } = toRefs<any>(proxy?.useDict('recipe_state'));
const { recipe_state, weight_type } = toRefs<any>(proxy?.useDict('recipe_state', 'weight_type'));
const recipeId = computed(() => route.query.recipeId as string || '');
const activeTab = ref('basic');
const isEdit = ref(false);
const saveLoading = ref(false);
const basicFormRef = ref<ElFormInstance>();
@ -220,6 +292,24 @@ const recipeInfo = ref<RecipeInfoForm>({});
const weightList = ref<RecipeWeightForm[]>([]);
const mixingList = ref<RecipeMixingForm[]>([]);
const machineOptions = ref<ProdBaseMachineInfoVO[]>([]);
const materialOptions = ref<BaseMaterialInfoVO[]>([]);
const materialSelectVisible = ref(false);
const materialSelectRef = ref<InstanceType<typeof MaterialSelect>>();
const selectedMaterial = ref<BaseMaterialInfoVO | null>(null);
const actCodeOptions = ref<MasterDataDetailVO[]>([]);
const condCodeOptions = ref<MasterDataDetailVO[]>([]);
const recipeMaterialDisplay = computed(() => {
const id = recipeInfo.value.materialId;
if (id == null || id === '') return '';
const fromOptions = materialOptions.value.find((m) => Number(m.materialId) === Number(id));
if (fromOptions) return `${fromOptions.materialName || ''} (${fromOptions.materialCode || ''})`.trim() || String(id);
if (selectedMaterial.value && Number(selectedMaterial.value.materialId) === Number(id)) {
const m = selectedMaterial.value;
return `${m.materialName || ''} (${m.materialCode || ''})`.trim() || String(id);
}
return String(id);
});
const weightTotalWeight = computed(() =>
weightList.value.reduce((s, r) => s + (Number(r.setWeight) || 0), 0).toFixed(3)
@ -228,8 +318,23 @@ const weightTotalError = computed(() =>
weightList.value.reduce((s, r) => s + (Number(r.errorAllow) || 0), 0).toFixed(3)
);
function toggleEdit() {
isEdit.value = !isEdit.value;
function goBack() {
router.back();
}
function openMaterialSelect() {
materialSelectVisible.value = true;
}
function confirmMaterialSelect() {
const row = materialSelectRef.value?.getSelected();
if (!row) {
proxy?.$modal.msgWarning('请先选择一条物料');
return;
}
recipeInfo.value.materialId = row.materialId;
selectedMaterial.value = row;
materialSelectVisible.value = false;
}
async function loadData() {
@ -245,9 +350,20 @@ async function loadData() {
]);
const infoData = (infoRes as any).data ?? infoRes;
recipeInfo.value = { ...infoData };
weightList.value = (weightRes.rows || []).map((r: any) => ({ ...r }));
const mixRows = mixingRes.rows || [];
mixingList.value = mixRows.map((r: any) => ({ ...r }));
const wData = (weightRes as any).data ?? weightRes;
const wRows = wData?.rows ?? (Array.isArray(wData) ? wData : []);
weightList.value = wRows.map((r: any) => ({
...r,
childCode: r.childCode != null && r.childCode !== '' ? Number(r.childCode) : undefined,
actCode: r.actCode != null && r.actCode !== '' ? String(r.actCode) : ''
}));
const mData = (mixingRes as any).data ?? mixingRes;
const mRows = mData?.rows ?? (Array.isArray(mData) ? mData : []);
mixingList.value = mRows.map((r: any) => ({
...r,
condCode: r.condCode != null && r.condCode !== '' ? String(r.condCode) : '',
actCode: r.actCode != null && r.actCode !== '' ? String(r.actCode) : ''
}));
} catch (e) {
proxy?.$modal.msgError('加载失败');
}
@ -262,57 +378,73 @@ async function loadMachines() {
}
}
function addWeightRow(index: number) {
const base = weightList.value[index] || {};
weightList.value.splice(index + 1, 0, {
recipeId: recipeId.value,
machineId: recipeInfo.value.machineId,
edtCode: recipeInfo.value.edtCode,
weightSeq: (weightList.value.length + 1) as any,
weightType: base.weightType || '',
scaleCode: base.scaleCode,
actCode: base.actCode || '称量',
setWeight: undefined,
errorAllow: undefined,
fatherCode: '',
unitId: undefined,
childCode: '',
ifUseBat: '',
maxRate: ''
} as RecipeWeightForm);
async function loadMaterials() {
try {
const res = await getBaseMaterialInfoList({ pageNum: 1, pageSize: 9999 });
const list = (res as any).data ?? (res as any).rows ?? [];
materialOptions.value = Array.isArray(list) ? list : [];
} catch {
materialOptions.value = [];
}
}
function insertWeightRow(index: number) {
const base = weightList.value[index] || {};
weightList.value.splice(index, 0, {
recipeId: recipeId.value,
machineId: recipeInfo.value.machineId,
edtCode: recipeInfo.value.edtCode,
weightSeq: (index + 1) as any,
weightType: base.weightType || '',
scaleCode: base.scaleCode,
actCode: base.actCode || '称量',
setWeight: undefined,
errorAllow: undefined,
fatherCode: '',
unitId: undefined,
childCode: '',
ifUseBat: '',
maxRate: ''
} as RecipeWeightForm);
/** 加载动作选项(称量/混炼动作masterDataId: 10009 */
async function loadActCodeOptions() {
try {
const res = await listMasterDataDetail({
masterDataId: 10009,
pageNum: 1,
pageSize: 9999
});
const list = (res as any).rows ?? (res as any).data ?? [];
actCodeOptions.value = Array.isArray(list) ? list : [];
} catch {
actCodeOptions.value = [];
}
}
/** 加载条件选项混炼条件masterDataId: 10010 */
async function loadCondCodeOptions() {
try {
const res = await listMasterDataDetail({
masterDataId: 10010,
pageNum: 1,
pageSize: 9999
});
const list = (res as any).rows ?? (res as any).data ?? [];
condCodeOptions.value = Array.isArray(list) ? list : [];
} catch {
condCodeOptions.value = [];
}
}
function addWeightRowEnd() {
const idx = weightList.value.length - 1;
const base = weightList.value[idx] || {};
weightList.value.push({
recipeId: recipeId.value,
machineId: recipeInfo.value.machineId,
edtCode: recipeInfo.value.edtCode,
weightSeq: (weightList.value.length + 1) as any,
weightType: base.weightType || '',
actCode: base.actCode ?? '',
setWeight: undefined,
errorAllow: undefined,
childCode: undefined
} as RecipeWeightForm);
}
function removeWeightRow(index: number) {
weightList.value.splice(index, 1);
}
function insertMixingRow(index: number) {
const base = mixingList.value[index] || {};
mixingList.value.splice(index, 0, {
function addMixingRowEnd() {
const base = mixingList.value[mixingList.value.length - 1] || {};
mixingList.value.push({
recipeId: recipeId.value,
machineId: recipeInfo.value.machineId,
edtCode: recipeInfo.value.edtCode,
mixId: index + 1,
mixId: mixingList.value.length + 1,
condCode: base.condCode || '',
actCode: base.actCode || '',
setTime: undefined,
@ -321,9 +453,15 @@ function insertMixingRow(index: number) {
setPower: undefined,
setPres: undefined,
setRota: undefined,
fatherCode: '',
childCode: '',
termCode: ''
mixingTime: undefined,
mixingTemp: undefined,
mixingEnergy: undefined,
mixingPower: undefined,
mixingPress: undefined,
mixingSpeed: undefined,
fatherCode: base.fatherCode || '',
childCode: base.childCode || '',
termCode: base.termCode || ''
} as RecipeMixingForm);
}
@ -331,10 +469,6 @@ function removeMixingRow(index: number) {
mixingList.value.splice(index, 1);
}
function calcWeight() {
proxy?.$modal.msg('计算重量功能可按业务规则扩展');
}
async function refreshWeight() {
await loadData();
activeTab.value = 'weight';
@ -346,29 +480,37 @@ async function refreshMixing() {
}
async function handleSave() {
if (!recipeId.value) return;
if (!recipeId.value) {
proxy?.$modal.msgWarning('缺少配方ID');
return;
}
saveLoading.value = true;
try {
const payload = {
recipeInfo: { ...recipeInfo.value, recipeId: recipeId.value },
weightList: weightList.value.map((w, i) => ({
...w,
recipeId: recipeId.value,
machineId: recipeInfo.value.machineId ?? w.machineId,
edtCode: recipeInfo.value.edtCode ?? w.edtCode,
weightSeq: (w.weightSeq ?? i + 1) as number
})),
mixingList: mixingList.value.map((m, i) => ({
...m,
recipeId: recipeId.value,
machineId: recipeInfo.value.machineId ?? m.machineId,
edtCode: recipeInfo.value.edtCode ?? m.edtCode,
mixId: (m.mixId ?? i + 1) as number
}))
};
await saveRecipeDetail(payload);
const recipeIdVal = recipeId.value;
const recipe = { ...recipeInfo.value, recipeId: recipeIdVal };
const weights = weightList.value.map((w, i) => ({
...w,
recipeId: recipeIdVal,
machineId: recipeInfo.value.machineId ?? w.machineId,
edtCode: recipeInfo.value.edtCode ?? w.edtCode,
weightSeq: (w.weightSeq ?? i + 1) as number,
actCode: w.actCode ?? ''
}));
const mixings = mixingList.value.map((m, i) => ({
...m,
recipeId: recipeIdVal,
machineId: recipeInfo.value.machineId ?? m.machineId,
edtCode: recipeInfo.value.edtCode ?? m.edtCode,
mixId: (m.mixId ?? i + 1) as number,
actCode: m.actCode ?? '',
condCode: m.condCode ?? ''
}));
await saveRecipeDetail({
recipeInfo: recipe,
weightList: weights,
mixingList: mixings
});
proxy?.$modal.msgSuccess('保存成功');
isEdit.value = false;
await loadData();
} catch (e) {
proxy?.$modal.msgError('保存失败');
@ -377,9 +519,10 @@ async function handleSave() {
}
}
onMounted(() => {
loadMachines();
loadData();
onMounted(async () => {
await loadMaterials();
await Promise.all([loadActCodeOptions(), loadCondCodeOptions()]);
await Promise.all([loadMachines(), loadData()]);
});
</script>

Loading…
Cancel
Save