update 配方左侧树结构

master
yinq 5 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 * @param recipeId

@ -106,9 +106,9 @@
> >
<el-option <el-option
v-for="m in materialOptions" v-for="m in materialOptions"
:key="m.materialId" :key="String(m.materialId)"
:label="`${m.materialName || ''} (${m.materialCode || ''})`" :label="`${m.materialName || ''} (${m.materialCode || ''})`"
:value="Number(m.materialId)" :value="m.materialId"
/> />
</el-select> </el-select>
</template> </template>
@ -298,9 +298,9 @@ const condCodeOptions = ref<MasterDataDetailVO[]>([]);
const recipeMaterialDisplay = computed(() => { const recipeMaterialDisplay = computed(() => {
const id = recipeInfo.value.materialId; const id = recipeInfo.value.materialId;
if (id == null || id === '') return ''; 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 (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; const m = selectedMaterial.value;
return `${m.materialName || ''} (${m.materialCode || ''})`.trim() || String(id); return `${m.materialName || ''} (${m.materialCode || ''})`.trim() || String(id);
} }
@ -353,7 +353,7 @@ async function loadData() {
const wRows = wData?.rows ?? (Array.isArray(wData) ? wData : []); const wRows = wData?.rows ?? (Array.isArray(wData) ? wData : []);
weightList.value = wRows.map((r: any) => ({ weightList.value = wRows.map((r: any) => ({
...r, ...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) : '' actCode: r.actCode != null && r.actCode !== '' ? String(r.actCode) : ''
})); }));
const mData = (mixingRes as any).data ?? mixingRes; const mData = (mixingRes as any).data ?? mixingRes;

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