更新混炼示方功能,优化胶料信息同步与删除逻辑,新增胶料类别名称匹配支持,调整选料弹窗以支持胶料查询,提升用户体验。

This commit is contained in:
geht
2026-06-01 11:30:07 +08:00
parent 0ff4a201b0
commit bfb00804e6
7 changed files with 438 additions and 187 deletions

View File

@@ -1,7 +1,7 @@
<template>
<BasicModal
v-bind="$attrs"
title="选择密炼物料"
title="选择物料"
:width="1280"
:zIndex="1500"
wrapClassName="mixing-material-picker-modal-wrap"
@@ -13,12 +13,14 @@
<a-input
v-model:value="keyword"
allow-clear
placeholder="关键字(物料编码/名称/描述)"
placeholder="关键字(编码/名称/描述)"
style="width: 280px"
@pressEnter="reloadTable"
/>
<a-button type="primary" @click="reloadTable">搜索</a-button>
<!--update-begin---author:cursor ---date:20260601 forXSLMES-20260601-A62仅密炼物料页签展示小类设置------------->
<MesXslMixingMaterialCategorySetting
v-if="pickerType === 'mixer'"
v-model:hiddenCategoryIds="hiddenCategoryIds"
:categories="allMinorCategories"
:loading="treeLoading"
@@ -26,20 +28,42 @@
@change="handleCategoryVisibilityChange"
@refresh="handleRefreshCategoryTree"
/>
<!--update-end---author:cursor ---date:20260601 forXSLMES-20260601-A62仅密炼物料页签展示小类设置------------->
</div>
<div class="mixing-material-picker-body">
<aside class="mixing-material-picker-sider">
<div class="mixing-material-picker-sider-title">物料小类</div>
<Spin :spinning="treeLoading">
<BasicTree
:treeData="visibleCategoryTree"
:selectedKeys="selectedCategoryKeys"
:expandedKeys="expandedCategoryKeys"
defaultExpandLevel="2"
@update:selectedKeys="onCategorySelect"
@update:expandedKeys="onExpandedKeysChange"
/>
</Spin>
<!--update-begin---author:cursor ---date:20260601 forXSLMES-20260601-A62选料弹窗左侧密炼物料/胶料页签------------->
<a-radio-group v-model:value="pickerType" button-style="solid" size="small" class="mixing-material-picker-tabs" @change="handleSwitchPickerType">
<a-radio-button value="mixer">密炼物料</a-radio-button>
<a-radio-button value="rubber">胶料</a-radio-button>
</a-radio-group>
<template v-if="pickerType === 'mixer'">
<div class="mixing-material-picker-sider-title">物料小类</div>
<Spin :spinning="treeLoading">
<BasicTree
:treeData="visibleCategoryTree"
:selectedKeys="selectedCategoryKeys"
:expandedKeys="expandedCategoryKeys"
defaultExpandLevel="2"
@update:selectedKeys="onCategorySelect"
@update:expandedKeys="onExpandedKeysChange"
/>
</Spin>
</template>
<template v-else>
<div class="mixing-material-picker-sider-title">胶料类别</div>
<Spin :spinning="rubberTreeLoading">
<BasicTree
:treeData="visibleRubberTree"
:selectedKeys="selectedRubberCategoryKeys"
:expandedKeys="expandedRubberCategoryKeys"
defaultExpandLevel="2"
@update:selectedKeys="onRubberCategorySelect"
@update:expandedKeys="onRubberExpandedKeysChange"
/>
</Spin>
</template>
<!--update-end---author:cursor ---date:20260601 forXSLMES-20260601-A62选料弹窗左侧密炼物料/胶料页签------------->
</aside>
<div class="mixing-material-picker-main">
<BasicTable @register="registerTable">
@@ -77,11 +101,20 @@
import { BasicTree } from '/@/components/Tree';
import { loadMesMaterialCategoryTreeData, hasMesMaterialCategoryTreeCache } from '/@/views/system/category/category.constants';
import { list as mixerList, queryById as queryMixerById } from '/@/views/mes/material/MesMixerMaterial.api';
//update-begin---author:cursor ---date:20260601 for【XSLMES-20260601-A62】胶料页签查询胶料信息(mes_material)------------->
import { list as rubberList, queryById as queryRubberById } from '/@/views/mes/material/MesMaterial.api';
import { loadTreeData } from '/@/api/common/api';
//update-end---author:cursor ---date:20260601 for【XSLMES-20260601-A62】胶料页签查询胶料信息(mes_material)------------->
import { useMessage } from '/@/hooks/web/useMessage';
import JDictSelectTag from '/@/components/Form/src/jeecg/components/JDictSelectTag.vue';
import MesXslMixingMaterialCategorySetting from './MesXslMixingMaterialCategorySetting.vue';
import {
applyMixingMaterialFromSelection,
//update-begin---author:cursor ---date:20260601 for【XSLMES-20260601-A62】引入胶料页签列与回填------------->
applyMixingRubberFromSelection,
mixingRubberPickerTableColumns,
resolveMixingRubberKindForPicker,
//update-end---author:cursor ---date:20260601 for【XSLMES-20260601-A62】引入胶料页签列与回填------------->
EMPTY_MIXER_MATERIAL_KIND_LOOKUP,
loadMixingMaterialKindLookup,
loadMixingMaterialPickerHiddenCategoryIds,
@@ -96,6 +129,34 @@
import type { KeyType } from '/@/components/Tree/src/types/tree';
const TREE_ALL = 'ALL';
//update-begin---author:cursor ---date:20260601 for【XSLMES-20260601-A62】选料弹窗数据源类型与胶料类别树------------->
const RUBBER_TREE_ALL = 'ALL';
const RUBBER_CATEGORY_PCODE = 'XSLMES_RUBBER';
const pickerType = ref<'mixer' | 'rubber'>('mixer');
const rubberTreeLoading = ref(false);
const rubberCategoryTree = ref<Recordable[]>([]);
/** 胶料类别 id -> { code, title },用于按种类配置编码匹配 */
const rubberCategoryMetaMap = ref<Map<string, { code?: string; title?: string }>>(new Map());
const selectedRubberCategoryKeys = ref<KeyType[]>([RUBBER_TREE_ALL]);
const expandedRubberCategoryKeys = ref<KeyType[]>([RUBBER_TREE_ALL]);
const visibleRubberTree = computed(() => [
{
key: RUBBER_TREE_ALL,
title: '全部胶料类别',
children: rubberCategoryTree.value || [],
},
]);
const selectedRubberCategoryFilter = computed(() => {
const key = selectedRubberCategoryKeys.value[0];
if (!key || key === RUBBER_TREE_ALL) {
return {};
}
return { categoryId: String(key) };
});
//update-end---author:cursor ---date:20260601 for【XSLMES-20260601-A62】选料弹窗数据源类型与胶料类别树------------->
const emit = defineEmits(['register', 'select']);
const { createMessage } = useMessage();
@@ -177,8 +238,13 @@
return { minorCategoryId: keyStr };
});
const [registerTable, { reload, getSelectRowKeys, getSelectRows, clearSelectedRowKeys }] = useTable({
api: mixerList,
//update-begin---author:cursor ---date:20260601 for【XSLMES-20260601-A62】右侧列表按页签切换数据源------------->
function pickerListApi(params: Recordable) {
return pickerType.value === 'rubber' ? rubberList(params) : mixerList(params);
}
const [registerTable, { reload, getSelectRowKeys, getSelectRows, clearSelectedRowKeys, setColumns }] = useTable({
api: pickerListApi,
columns: mixingMaterialPickerTableColumns,
rowKey: 'id',
useSearchForm: false,
@@ -187,13 +253,22 @@
showIndexColumn: true,
immediate: false,
beforeFetch: (params) => {
const next = { ...params, ...selectedCategoryFilter.value };
const kw = keyword.value?.trim();
if (pickerType.value === 'rubber') {
const rubberParams = { ...params, ...selectedRubberCategoryFilter.value };
if (kw) {
rubberParams.materialName = `*${kw}*`;
}
return rubberParams;
}
const next = { ...params, ...selectedCategoryFilter.value };
if (kw) {
next.materialName = `*${kw}*`;
}
return next;
},
//update-end---author:cursor ---date:20260601 for【XSLMES-20260601-A62】右侧列表按页签切换数据源------------->
rowSelection: {
type: 'radio',
columnWidth: 48,
@@ -218,11 +293,18 @@
clearSelectedRowKeys?.();
hiddenCategoryIds.value = loadMixingMaterialPickerHiddenCategoryIds();
selectedCategoryKeys.value = [TREE_ALL];
//update-begin---author:cursor ---date:20260601 for【XSLMES-20260601-A62】每次打开默认密炼物料页签------------->
pickerType.value = 'mixer';
selectedRubberCategoryKeys.value = [RUBBER_TREE_ALL];
setColumns(mixingMaterialPickerTableColumns);
//update-end---author:cursor ---date:20260601 for【XSLMES-20260601-A62】每次打开默认密炼物料页签------------->
setModalProps({ confirmLoading: false });
//update-begin---author:cursor ---date:20260525 for【XSLMES-20260525-A52】选料弹窗先加载左侧树再查右侧列表-----------
try {
await loadMaterialCategoryTree();
kindLookup.value = await loadMixingMaterialKindLookup(false);
//update-begin---author:cursor ---date:20260601 for【XSLMES-20260601-A62】打开弹窗刷新种类配置避免缓存旧数据-----------
kindLookup.value = await loadMixingMaterialKindLookup(true);
//update-end---author:cursor ---date:20260601 for【XSLMES-20260601-A62】打开弹窗刷新种类配置避免缓存旧数据-----------
reloadTable();
} finally {
pickerInitializing.value = false;
@@ -231,6 +313,64 @@
}
//update-end---author:cursor ---date:20260525 for【XSLMES-20260525-A50】选料弹窗打开时初始化对齐其他SelectModal-----------
//update-begin---author:cursor ---date:20260601 for【XSLMES-20260601-A62】页签切换 + 胶料类别树加载/选择------------->
async function handleSwitchPickerType() {
selectedRow.value = null;
clearSelectedRowKeys?.();
setColumns(pickerType.value === 'rubber' ? mixingRubberPickerTableColumns : mixingMaterialPickerTableColumns);
if (pickerType.value === 'rubber' && !rubberCategoryTree.value.length) {
await loadRubberCategoryTree();
}
reloadTable();
}
function flattenRubberCategoryTree(nodes: Recordable[], map: Map<string, { code?: string; title?: string }>) {
for (const node of nodes || []) {
const key = node?.key != null ? String(node.key) : '';
if (key) {
map.set(key, {
code: node.code != null ? String(node.code) : undefined,
title: node.title != null ? String(node.title) : undefined,
});
}
if (node?.children?.length) {
flattenRubberCategoryTree(node.children, map);
}
}
}
async function loadRubberCategoryTree() {
rubberTreeLoading.value = true;
try {
const res: any = await loadTreeData({ pcode: RUBBER_CATEGORY_PCODE });
const treeNodes = Array.isArray(res) ? res : res?.result || [];
rubberCategoryTree.value = treeNodes;
const metaMap = new Map<string, { code?: string; title?: string }>();
flattenRubberCategoryTree(treeNodes, metaMap);
rubberCategoryMetaMap.value = metaMap;
} catch {
rubberCategoryTree.value = [];
rubberCategoryMetaMap.value = new Map();
createMessage.warning('加载胶料类别失败,请检查分类根编码 XSLMES_RUBBER 是否存在。');
} finally {
rubberTreeLoading.value = false;
}
}
function onRubberCategorySelect(keys: KeyType[]) {
selectedRubberCategoryKeys.value = keys?.length ? keys : [RUBBER_TREE_ALL];
if (pickerInitializing.value) {
return;
}
reloadTable();
}
function onRubberExpandedKeysChange(keys: KeyType[]) {
expandedRubberCategoryKeys.value = keys?.length ? keys : [RUBBER_TREE_ALL];
}
//update-end---author:cursor ---date:20260601 for【XSLMES-20260601-A62】页签切换 + 胶料类别树加载/选择------------->
async function loadMaterialCategoryTree(forceReload = false) {
const hasCachedTree = !forceReload && (hasMesMaterialCategoryTreeCache() || rawCategoryTree.value.length > 0);
if (forceReload || !hasCachedTree) {
@@ -363,6 +503,15 @@
}
function resolvePickerMaterialKind(material: Recordable) {
//update-begin---author:cursor ---date:20260601 for【XSLMES-20260601-A62】胶料页签种类/自动人工称量解析------------->
if (pickerType.value === 'rubber') {
const weighMode = getPickerWeighMode(material?.id);
const catId = material?.categoryId ? String(material.categoryId) : '';
const catName = material?.categoryId_dictText || '';
const catCode = rubberCategoryMetaMap.value.get(catId)?.code || '';
return resolveMixingRubberKindForPicker(kindLookup.value, weighMode, catId, catName, catCode);
}
//update-end---author:cursor ---date:20260601 for【XSLMES-20260601-A62】胶料页签种类/自动人工称量解析------------->
const weighMode = getPickerWeighMode(material?.id);
const minorId = material?.minorCategoryId ? String(material.minorCategoryId) : '';
const minorName = material?.minorCategoryId_dictText || '';
@@ -380,12 +529,37 @@
let row = selectedRow.value || ((getSelectRows?.() || []) as Recordable[])[0];
if (!row && keys.length) {
try {
const raw = await queryMixerById({ id: keys[0] });
//update-begin---author:cursor ---date:20260601 for【XSLMES-20260601-A62】按页签查询选中行详情------------->
const queryById = pickerType.value === 'rubber' ? queryRubberById : queryMixerById;
const raw = await queryById({ id: keys[0] });
//update-end---author:cursor ---date:20260601 for【XSLMES-20260601-A62】按页签查询选中行详情------------->
row = (raw as any)?.id != null ? raw : (raw as any)?.result;
} catch {
// ignore
}
}
//update-begin---author:cursor ---date:20260601 for【XSLMES-20260601-A62】胶料页签选中回填明细------------->
if (pickerType.value === 'rubber') {
if (!row?.id) {
createMessage.warning('请选择一条胶料');
return;
}
const weighMode = getPickerWeighMode(row.id);
const catId = row.categoryId ? String(row.categoryId) : '';
const catName = row.categoryId_dictText || '';
const catCode = rubberCategoryMetaMap.value.get(catId)?.code || '';
const rubberKind = resolveMixingRubberKindForPicker(kindLookup.value, weighMode, catId, catName, catCode);
if (!rubberKind) {
createMessage.warning('未匹配到种类,请检查种类配置(胶料类别或「胶料」兜底种类)');
return;
}
const rubberPayload: Recordable = { ...row, pickerWeighMode: weighMode };
applyMixingRubberFromSelection(rubberPayload, row, rubberKind);
emit('select', rubberPayload);
closeModal();
return;
}
//update-end---author:cursor ---date:20260601 for【XSLMES-20260601-A62】胶料页签选中回填明细------------->
if (!row?.id) {
createMessage.warning('请选择一条密炼物料');
return;
@@ -439,6 +613,17 @@
margin-bottom: 8px;
}
/* 选料弹窗左侧密炼物料/胶料页签 */
.mixing-material-picker-tabs {
display: flex;
margin-bottom: 10px;
}
.mixing-material-picker-tabs :deep(.ant-radio-button-wrapper) {
flex: 1;
text-align: center;
}
.mixing-material-picker-main {
flex: 1;
min-width: 0;