|
@@ -440,6 +440,7 @@
|
|
|
deviceBomSubmit,
|
|
deviceBomSubmit,
|
|
|
hasNewVersion
|
|
hasNewVersion
|
|
|
} from '@/api/material/BOM.js';
|
|
} from '@/api/material/BOM.js';
|
|
|
|
|
+ import { parameterGetByCode } from '@/api/system/dictionary-data';
|
|
|
|
|
|
|
|
import baseInfo from './components/baseInfo.vue';
|
|
import baseInfo from './components/baseInfo.vue';
|
|
|
import baseInfoSave from './components/baseInfoSave.vue';
|
|
import baseInfoSave from './components/baseInfoSave.vue';
|
|
@@ -691,12 +692,17 @@
|
|
|
this.treeLoading = false;
|
|
this.treeLoading = false;
|
|
|
if (res?.code === '0') {
|
|
if (res?.code === '0') {
|
|
|
if (res.data?.length > 0) {
|
|
if (res.data?.length > 0) {
|
|
|
- this.treeList = res.data;
|
|
|
|
|
|
|
+ let treeData = res.data;
|
|
|
|
|
+ // 润天:左侧树同级节点按 sn 升序(与右侧 PBOM 明细同一口径);非润天(无 sn)保持原顺序
|
|
|
|
|
+ if (this.treeHasSn(treeData) || (await this.isRuntianEnv())) {
|
|
|
|
|
+ treeData = this.sortTreeBySn(treeData);
|
|
|
|
|
+ }
|
|
|
|
|
+ this.treeList = treeData;
|
|
|
this.$nextTick(() => {
|
|
this.$nextTick(() => {
|
|
|
this.isNotData = true;
|
|
this.isNotData = true;
|
|
|
// 默认高亮第一个
|
|
// 默认高亮第一个
|
|
|
- this.$refs.treeRef.setCurrentKey(res.data[0].id);
|
|
|
|
|
- this.handleNodeClick(res.data[0]);
|
|
|
|
|
|
|
+ this.$refs.treeRef.setCurrentKey(treeData[0].id);
|
|
|
|
|
+ this.handleNodeClick(treeData[0]);
|
|
|
});
|
|
});
|
|
|
} else {
|
|
} else {
|
|
|
this.isNotData = false;
|
|
this.isNotData = false;
|
|
@@ -710,6 +716,56 @@
|
|
|
this.treeLoading = false;
|
|
this.treeLoading = false;
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
|
|
+ // 树里是否带 sn(润天同步的 BOM 才有)
|
|
|
|
|
+ treeHasSn(nodes) {
|
|
|
|
|
+ return (nodes || []).some(
|
|
|
|
|
+ (node) =>
|
|
|
|
|
+ (node.sn !== null && node.sn !== undefined && Number(node.sn) > 0) ||
|
|
|
|
|
+ this.treeHasSn(node.children)
|
|
|
|
|
+ );
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ // 是否润天环境(系统参数 is_runtian)
|
|
|
|
|
+ async isRuntianEnv() {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const data = await parameterGetByCode({ code: 'is_runtian' });
|
|
|
|
|
+ const val =
|
|
|
|
|
+ typeof data === 'object' && data !== null
|
|
|
|
|
+ ? data.value ?? data.paramValue ?? data.val
|
|
|
|
|
+ : data;
|
|
|
|
|
+ return val === '1' || val === 1 || val === true;
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ // 递归按 sn 升序(空/0 排最后,同 sn 按 id 兜底)
|
|
|
|
|
+ sortTreeBySn(nodes) {
|
|
|
|
|
+ if (!Array.isArray(nodes) || !nodes.length) {
|
|
|
|
|
+ return nodes;
|
|
|
|
|
+ }
|
|
|
|
|
+ const snOf = (node) => {
|
|
|
|
|
+ const sn = Number(node && node.sn);
|
|
|
|
|
+ return isNaN(sn) || sn <= 0 ? Number.MAX_SAFE_INTEGER : sn;
|
|
|
|
|
+ };
|
|
|
|
|
+ const sortRecursive = (list) => {
|
|
|
|
|
+ list.sort((a, b) => {
|
|
|
|
|
+ const diff = snOf(a) - snOf(b);
|
|
|
|
|
+ if (diff !== 0) {
|
|
|
|
|
+ return diff;
|
|
|
|
|
+ }
|
|
|
|
|
+ return String(a.id) < String(b.id) ? -1 : String(a.id) > String(b.id) ? 1 : 0;
|
|
|
|
|
+ });
|
|
|
|
|
+ list.forEach((item) => {
|
|
|
|
|
+ if (Array.isArray(item.children) && item.children.length) {
|
|
|
|
|
+ sortRecursive(item.children);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ };
|
|
|
|
|
+ sortRecursive(nodes);
|
|
|
|
|
+ return nodes;
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
handleNodeClick(data) {
|
|
handleNodeClick(data) {
|
|
|
this.treeId = data.id;
|
|
this.treeId = data.id;
|
|
|
this.resourceBomId =
|
|
this.resourceBomId =
|