update 配方左侧树结构

master
yinq 4 days ago
parent 2ff7c4608d
commit 051cd8a1e5

@ -18,6 +18,29 @@ export const listRecipeInfo = (query?: RecipeInfoQuery): AxiosPromise<RecipeInfo
});
};
/** 配方树节点 */
export interface RecipeTreeNodeVO {
id: string;
label: string;
recipeCode?: string;
recipeId?: number;
materialId?: number;
materialName?: string;
data?: RecipeInfoVO;
children?: RecipeTreeNodeVO[];
}
/**
*
*/
export const getRecipeTree = (params?: RecipeInfoQuery): AxiosPromise<RecipeTreeNodeVO[]> => {
return request({
url: '/mes/recipeInfo/tree',
method: 'get',
params
});
};
/**
* -
* @param recipeId

@ -106,9 +106,9 @@
>
<el-option
v-for="m in materialOptions"
:key="m.materialId"
:key="String(m.materialId)"
:label="`${m.materialName || ''} (${m.materialCode || ''})`"
:value="Number(m.materialId)"
:value="m.materialId"
/>
</el-select>
</template>
@ -298,9 +298,9 @@ 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));
const fromOptions = materialOptions.value.find((m) => String(m.materialId) === String(id));
if (fromOptions) return `${fromOptions.materialName || ''} (${fromOptions.materialCode || ''})`.trim() || String(id);
if (selectedMaterial.value && Number(selectedMaterial.value.materialId) === Number(id)) {
if (selectedMaterial.value && String(selectedMaterial.value.materialId) === String(id)) {
const m = selectedMaterial.value;
return `${m.materialName || ''} (${m.materialCode || ''})`.trim() || String(id);
}
@ -353,7 +353,7 @@ async function loadData() {
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,
childCode: r.childCode != null && r.childCode !== '' ? r.childCode : undefined,
actCode: r.actCode != null && r.actCode !== '' ? String(r.actCode) : ''
}));
const mData = (mixingRes as any).data ?? mixingRes;

@ -151,8 +151,8 @@
<template #default="scope">
<el-button link type="primary" @click="handleDetail(scope.row)"
v-hasPermi="['mes:recipeInfo:query']">配方明细</el-button>
<el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)"
v-hasPermi="['mes:recipeInfo:edit']">修改</el-button>
<!-- <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)"
v-hasPermi="['mes:recipeInfo:edit']">修改</el-button> -->
<el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)"
v-hasPermi="['mes:recipeInfo:remove']">删除</el-button>
</template>
@ -292,7 +292,7 @@
<script setup name="RecipeInfo" lang="ts">
import type { ElTree } from 'element-plus';
import { listRecipeInfo, getRecipeInfo, delRecipeInfo, addRecipeInfo, updateRecipeInfo } from '@/api/mes/recipeInfo';
import { listRecipeInfo, getRecipeInfo, delRecipeInfo, addRecipeInfo, updateRecipeInfo, getRecipeTree } from '@/api/mes/recipeInfo';
import { RecipeInfoVO, RecipeInfoQuery, RecipeInfoForm } from '@/api/mes/recipeInfo/types';
import { getProdBaseMachineInfoList } from '@/api/mes/prodBaseMachineInfo';
import { getBaseMaterialInfoList } from '@/api/mes/baseMaterialInfo';
@ -515,29 +515,15 @@ watch(treeFilterText, (val) => {
treeRef.value?.filter(val);
});
//
function buildTreeFromList(list: RecipeInfoVO[]) {
const codeSet = new Set<string>();
const children: any[] = [];
list.forEach((row) => {
const code = row.recipeCode || String(row.materialId) || '未命名';
if (!codeSet.has(code)) {
codeSet.add(code);
children.push({
id: row.recipeId + '_' + code,
label: `${code}[${code}]`,
recipeCode: code,
recipeId: row.recipeId,
data: row
});
}
});
const rootCode = queryParams.value.recipeCode || '配方列表';
return [{
id: 'root',
label: rootCode,
children: children.length ? children : [{ id: 'empty', label: '暂无数据', disabled: true }]
}];
/** 加载树数据(父级:配方代号,子级:称量物料名称) */
async function loadTreeData() {
try {
const res = await getRecipeTree(queryParams.value as any);
const list = res.data || [];
treeData.value = list.length ? list : [{ id: 'empty', label: '暂无数据', disabled: true }];
} catch {
treeData.value = [{ id: 'empty', label: '暂无数据', disabled: true }];
}
}
/** 查询列表 */
@ -547,7 +533,7 @@ const getList = async () => {
const res = await listRecipeInfo(queryParams.value);
recipeInfoList.value = res.rows || [];
total.value = res.total || 0;
treeData.value = buildTreeFromList(recipeInfoList.value);
await loadTreeData();
if (recipeInfoList.value.length && !currentTableRow.value) {
currentTableRow.value = recipeInfoList.value[0];
detailForm.value = { ...currentTableRow.value };
@ -557,14 +543,21 @@ const getList = async () => {
}
};
/** 树节点点击 */
/** 树节点点击(父级配方代号 / 子级物料名称 均关联到对应配方) */
function handleTreeNodeClick(node: any) {
if (node.id === 'empty' || node.disabled) return;
selectedTreeNode.value = node;
selectedTreeLabel.value = node.label?.split('[')[0] || node.recipeCode || '';
selectedTreeLabel.value = node.label || node.recipeCode || '';
const recipeId = node.recipeId;
if (node.data) {
currentTableRow.value = node.data;
detailForm.value = { ...node.data };
} else if (recipeId && recipeInfoList.value.length) {
const row = recipeInfoList.value.find((r) => r.recipeId === recipeId);
if (row) {
currentTableRow.value = row;
detailForm.value = { ...row };
}
}
}

Loading…
Cancel
Save