diff --git a/src/views/EquipmentLedger/index.vue b/src/views/EquipmentLedger/index.vue
index ffe0a740..90344df4 100644
--- a/src/views/EquipmentLedger/index.vue
+++ b/src/views/EquipmentLedger/index.vue
@@ -7,18 +7,66 @@
装备分类
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
@@ -103,12 +151,12 @@
-
+
-
+
@@ -124,7 +172,7 @@
@change="majorChange"
style="width: 100%"
>
-
+
@@ -152,7 +200,7 @@
-
+
@@ -208,12 +256,12 @@
-
+
-
+
@@ -235,12 +283,12 @@
-
+
-
+
@@ -254,6 +302,7 @@
@@ -306,15 +355,6 @@
>
装备退役
-
- 装备退库
-
-
-
+
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -510,57 +549,57 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -583,42 +622,42 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -653,17 +692,17 @@
-
+
-
+
-
+
@@ -679,22 +718,22 @@
-
+
-
+
-
+
-
+
@@ -710,10 +749,10 @@
-
+
-
+
@@ -737,7 +776,7 @@
-
+
@@ -764,14 +803,18 @@ import {
getDeviceDetailAPI,
getManufacturerSelectApi
} from '@/api/EquipmentLedger/index.js'
-import { firstLevel, secondAndThirdLevel } from '@/api/EquipmentEntryApply'
-import { getMaxFeatureAPI, getProvinceListAPI } from '@/api/EquipmentLedger/equ-out.js'
-import { deptTreeSelect } from '@/api/system/user'
+import {firstLevel, secondAndThirdLevel} from '@/api/EquipmentEntryApply'
+import {getMaxFeatureAPI, getProvinceListAPI} from '@/api/EquipmentLedger/equ-out.js'
+import {deptTreeSelect} from '@/api/system/user'
export default {
name: 'EquipmentLedger',
data() {
return {
+ treeSearchKey: '', //用于存储左侧树搜索框内容
+
+ defaultExpandedKeys: [], //用于存储需要默认展开的节点id
+
showSearch: true,
total: 0,
tableHeight: 510,
@@ -813,51 +856,51 @@ export default {
serviceLifeList: [], // 使用年限
manufacturerList: [], // 生产厂家
columns: [
- { key: 0, label: `所属省份`, prop: 'province', visible: true },
- { key: 1, label: `产权单位`, prop: 'propertyUnit', visible: true },
- { key: 2, label: `专业`, prop: 'major', visible: true },
- { key: 3, label: `工序`, prop: 'process', visible: true },
- { key: 4, label: `装备类目`, prop: 'devType', visible: true },
- { key: 5, label: `类型分支`, prop: 'name', visible: true },
- { key: 6, label: `规格型号`, prop: 'specificationModel', visible: true },
- { key: 7, label: `装备编码`, prop: 'code', visible: true },
- { key: 8, label: `装备状态`, prop: 'status', visible: true },
- { key: 44, label: `上下架状态`, prop: 'upDownStatus', visible: true },
- { key: 9, label: `使用年限`, prop: 'serviceLife', visible: true },
- { key: 10, label: `使用项目`, prop: 'usingProject', visible: true },
- { key: 11, label: `使用到期时间`, prop: 'expirationTime', visible: true },
- { key: 12, label: `使用次数`, prop: 'usageCount', visible: true },
- { key: 13, label: `维修次数`, prop: 'repairCount', visible: true },
- { key: 14, label: `装备原始编码`, prop: 'originalCode', visible: true },
- { key: 15, label: `计量单位`, prop: 'unit', visible: true },
- { key: 16, label: `生产厂家`, prop: 'manufacturer', visible: true },
- { key: 17, label: `出厂日期`, prop: 'productionDate', visible: true },
- { key: 18, label: `采购日期`, prop: 'purchaseDate', visible: true },
- { key: 19, label: `资产原值(元)`, prop: 'originalValue', visible: true },
- { key: 20, label: `最大使用年限(年)`, prop: 'maxServiceLifeYears', visible: true },
- { key: 21, label: `下次维保日期`, prop: 'nextMaintenanceDate', visible: true },
- { key: 22, label: `装备外观`, prop: 'appearanceImages', visible: true },
- { key: 23, label: `合格证`, prop: 'certificates', visible: true },
- { key: 24, label: `定期检验报告`, prop: 'inspectionReports', visible: true },
- { key: 25, label: `采购发票`, prop: 'purchaseInvoices', visible: true },
- { key: 26, label: `特征项1`, prop: 'featureItem1', visible: true },
- { key: 27, label: `特征值1`, prop: 'featureValue1', visible: true },
- { key: 28, label: `特征项2`, prop: 'featureItem2', visible: true },
- { key: 29, label: `特征值2`, prop: 'featureValue2', visible: true },
- { key: 30, label: `特征项3`, prop: 'featureItem3', visible: true },
- { key: 31, label: `特征值3`, prop: 'featureValue3', visible: true },
- { key: 32, label: `特征项4`, prop: 'featureItem4', visible: true },
- { key: 33, label: `特征值4`, prop: 'featureValue4', visible: true },
- { key: 34, label: `特征项5`, prop: 'featureItem5', visible: true },
- { key: 35, label: `特征值5`, prop: 'featureValue5', visible: true },
- { key: 36, label: `特征项6`, prop: 'featureItem6', visible: true },
- { key: 37, label: `特征值6`, prop: 'featureValue6', visible: true },
- { key: 38, label: `特征项7`, prop: 'featureItem7', visible: true },
- { key: 39, label: `特征值7`, prop: 'featureValue7', visible: true },
- { key: 40, label: `特征项8`, prop: 'featureItem8', visible: true },
- { key: 41, label: `特征值8`, prop: 'featureValue8', visible: true },
- { key: 42, label: `特征项9`, prop: 'featureItem9', visible: true },
- { key: 43, label: `特征值9`, prop: 'featureValue9', visible: true },
+ {key: 0, label: `所属省份`, prop: 'province', visible: true},
+ {key: 1, label: `产权单位`, prop: 'propertyUnit', visible: true},
+ {key: 2, label: `专业`, prop: 'major', visible: true},
+ {key: 3, label: `工序`, prop: 'process', visible: true},
+ {key: 4, label: `装备类目`, prop: 'devType', visible: true},
+ {key: 5, label: `类型分支`, prop: 'name', visible: true},
+ {key: 6, label: `规格型号`, prop: 'specificationModel', visible: true},
+ {key: 7, label: `装备编码`, prop: 'code', visible: true},
+ {key: 8, label: `装备状态`, prop: 'status', visible: true},
+ {key: 44, label: `上下架状态`, prop: 'upDownStatus', visible: true},
+ {key: 9, label: `使用年限`, prop: 'serviceLife', visible: true},
+ {key: 10, label: `使用项目`, prop: 'usingProject', visible: true},
+ {key: 11, label: `使用到期时间`, prop: 'expirationTime', visible: true},
+ {key: 12, label: `使用次数`, prop: 'usageCount', visible: true},
+ {key: 13, label: `维修次数`, prop: 'repairCount', visible: true},
+ {key: 14, label: `装备原始编码`, prop: 'originalCode', visible: true},
+ {key: 15, label: `计量单位`, prop: 'unit', visible: true},
+ {key: 16, label: `生产厂家`, prop: 'manufacturer', visible: true},
+ {key: 17, label: `出厂日期`, prop: 'productionDate', visible: true},
+ {key: 18, label: `采购日期`, prop: 'purchaseDate', visible: true},
+ {key: 19, label: `资产原值(元)`, prop: 'originalValue', visible: true},
+ {key: 20, label: `最大使用年限(年)`, prop: 'maxServiceLifeYears', visible: true},
+ {key: 21, label: `下次维保日期`, prop: 'nextMaintenanceDate', visible: true},
+ {key: 22, label: `装备外观`, prop: 'appearanceImages', visible: true},
+ {key: 23, label: `合格证`, prop: 'certificates', visible: true},
+ {key: 24, label: `定期检验报告`, prop: 'inspectionReports', visible: true},
+ {key: 25, label: `采购发票`, prop: 'purchaseInvoices', visible: true},
+ {key: 26, label: `特征项1`, prop: 'featureItem1', visible: true},
+ {key: 27, label: `特征值1`, prop: 'featureValue1', visible: true},
+ {key: 28, label: `特征项2`, prop: 'featureItem2', visible: true},
+ {key: 29, label: `特征值2`, prop: 'featureValue2', visible: true},
+ {key: 30, label: `特征项3`, prop: 'featureItem3', visible: true},
+ {key: 31, label: `特征值3`, prop: 'featureValue3', visible: true},
+ {key: 32, label: `特征项4`, prop: 'featureItem4', visible: true},
+ {key: 33, label: `特征值4`, prop: 'featureValue4', visible: true},
+ {key: 34, label: `特征项5`, prop: 'featureItem5', visible: true},
+ {key: 35, label: `特征值5`, prop: 'featureValue5', visible: true},
+ {key: 36, label: `特征项6`, prop: 'featureItem6', visible: true},
+ {key: 37, label: `特征值6`, prop: 'featureValue6', visible: true},
+ {key: 38, label: `特征项7`, prop: 'featureItem7', visible: true},
+ {key: 39, label: `特征值7`, prop: 'featureValue7', visible: true},
+ {key: 40, label: `特征项8`, prop: 'featureItem8', visible: true},
+ {key: 41, label: `特征值8`, prop: 'featureValue8', visible: true},
+ {key: 42, label: `特征项9`, prop: 'featureItem9', visible: true},
+ {key: 43, label: `特征值9`, prop: 'featureValue9', visible: true},
],
tableData: [],
tableColumns: 0,
@@ -905,9 +948,9 @@ export default {
},
// 表单验证规则
formRules: {
- name: [{ required: true, message: '请输入类型分支', trigger: 'blur' }],
- code: [{ required: true, message: '请输入装备编号', trigger: 'blur' }],
- changeStatus: [{ required: true, message: '请选择装备状态', trigger: 'change' }],
+ name: [{required: true, message: '请输入类型分支', trigger: 'blur'}],
+ code: [{required: true, message: '请输入装备编号', trigger: 'blur'}],
+ changeStatus: [{required: true, message: '请选择装备状态', trigger: 'change'}],
},
maxFeatureCount: 5, // 最大特征项数量限制
dialogVisible: false,
@@ -960,7 +1003,7 @@ export default {
this.processList = []
this.queryParams.process = ''
} else {
- secondAndThirdLevel({ firstLevelId: item }).then((res) => {
+ secondAndThirdLevel({firstLevelId: item}).then((res) => {
if (res.code === 200) {
this.processList = this.convertToSubTree(res.data)
}
@@ -1062,9 +1105,6 @@ export default {
onHandleRetire() {
this.$router.push('/equipment/equ-retire')
},
- onHandleReturn() {
- this.$router.push('/equipment/equStore')
- },
/**
* 导出数据
@@ -1075,7 +1115,7 @@ export default {
try {
let fileName = `装备台账_${new Date().getTime()}.xLsx`
let url = '/material-mall/device/export'
- const params = { ...this.queryParams }
+ const params = {...this.queryParams}
console.log('🚀 ~ 导出 ~ params:', params)
this.download(url, params, fileName)
} catch (error) {
@@ -1083,22 +1123,227 @@ export default {
}
},
+
/**
* 获取左侧树形结构数据
*/
async getDeviceTree() {
try {
- this.treeLoading = true
- const res = await getDeviceTreeAPI()
- this.treeData = res.data ? [res.data] : []
+ this.treeLoading = true;
+ const res = await getDeviceTreeAPI();
+ this.treeData = res.data ? [res.data] : [];
+
+// 👇 加这一行
+ console.log('treeData', JSON.stringify(this.treeData, null, 2));
+
+ // 重置默认展开的节点ID数组
+ this.defaultExpandedKeys = [];
+
+ // 只收集第一级和第二级节点的ID,第三级默认不展开
+ this.collectFirstAndSecondLevelKeys(this.treeData);
+ console.log('✅ defaultExpandedKeys:', this.defaultExpandedKeys);
+
+ // 3. 关键:等 DOM 渲染完再赋值
+ this.$nextTick(() => {
+ this.defaultExpandedKeys = [...this.defaultExpandedKeys];
+ });
+
+ console.log('默认展开的第一级和第二级节点ID:', this.defaultExpandedKeys);
} catch (error) {
- this.$message.error('获取树形结构失败:' + (error.message || '未知错误'))
- console.error(error)
+ this.$message.error('获取树形结构失败:' + (error.message || '未知错误'));
+ console.error(error);
} finally {
- this.treeLoading = false
+ this.treeLoading = false;
}
},
+ /**
+ * 收集第一级和第二级节点的ID,第三级默认不展开
+ */
+ collectFirstAndSecondLevelKeys(nodes) {
+ if (!nodes || !nodes.length) return;
+
+ nodes.forEach(firstLevelNode => {
+ // 展开第一级节点
+ if (firstLevelNode.id) {
+ this.defaultExpandedKeys.push(firstLevelNode.id);
+ console.log(`展开第一级节点: ${firstLevelNode.name}, ID: ${firstLevelNode.id}`);
+ }
+
+ // 检查是否有子节点(第二级节点)
+ if (firstLevelNode.children && firstLevelNode.children.length) {
+ // 遍历所有第二级节点
+ firstLevelNode.children.forEach(secondLevelNode => {
+ if (secondLevelNode.id) {
+ this.defaultExpandedKeys.push(secondLevelNode.id);
+ console.log(`展开第二级节点: ${secondLevelNode.name}, ID: ${secondLevelNode.id}`);
+ // 第三级及更深层级默认不展开(保持折叠状态)
+ }
+ });
+ }
+ });
+ },
+
+
+ /**
+ * 左侧树查询:匹配节点显示自身及下一级,但默认只显示到第二级
+ */
+ async getDeviceListByTreeSearch() {
+ try {
+ // 1. 获取输入的查询关键词(去空格)
+ const searchKey = this.treeSearchKey ? this.treeSearchKey.trim() : '';
+
+ // 如果没有搜索关键词,则重置为原始树(显示到第二级)
+ if (!searchKey) {
+ await this.resetTreeSearch();
+ return;
+ }
+
+ // 2. 重新获取原始树形数据
+ this.treeLoading = true;
+ const res = await getDeviceTreeAPI();
+ const originalTreeData = res.data ? [res.data] : [];
+
+ // 3. 筛选逻辑:匹配节点显示自身及下一级
+ const filteredTreeData = this.filterTreeWithNextLevel(originalTreeData, searchKey);
+
+ // 4. 收集所有匹配节点的ID,用于默认展开
+ const expandedIds = [];
+ this.collectMatchedNodeIds(filteredTreeData, searchKey, expandedIds);
+
+ // 5. 更新树形数据和默认展开节点
+ this.treeData = filteredTreeData;
+ this.defaultExpandedKeys = expandedIds;
+
+ // 6. 无匹配结果时提示
+ if (filteredTreeData.length === 0 || this.isTreeEmpty(filteredTreeData)) {
+ this.$message.info('未找到匹配的类型分支');
+ } else {
+ this.$message.success(`找到 ${expandedIds.length} 个匹配项`);
+ }
+ } catch (error) {
+ this.$message.error('树形查询失败:' + (error.message || '未知错误'));
+ console.error(error);
+ } finally {
+ this.treeLoading = false;
+ }
+ },
+
+ /**
+ * 辅助方法:筛选节点并包含下一级
+ */
+ filterTreeWithNextLevel(treeData, key) {
+ if (!treeData || !treeData.length) return [];
+
+ return treeData
+ .map(node => {
+ // 深拷贝节点
+ const newNode = {...node};
+
+ const isNodeMatch = key ? node.name.includes(key) : true;
+
+ if (isNodeMatch) {
+ // 匹配节点:保留所有直接子节点
+ if (newNode.children && newNode.children.length) {
+ // 保留第二级,但第三级及更深层级保持原样(默认不展开)
+ newNode.children = [...newNode.children];
+ }
+ return newNode;
+ } else {
+ // 不匹配节点:检查子节点是否有匹配的
+ if (newNode.children && newNode.children.length) {
+ const filteredChildren = this.filterTreeWithNextLevel(newNode.children, key);
+
+ if (filteredChildren.length > 0) {
+ newNode.children = filteredChildren;
+ return newNode;
+ }
+ }
+ return null;
+ }
+ })
+ .filter(node => node !== null);
+ },
+
+ /**
+ * 辅助方法:收集所有匹配关键词的节点ID(用于默认展开)
+ * @param {Array} treeData - 筛选后的树形数据
+ * @param {String} key - 查询关键词
+ * @param {Array} expandedIds - 存储展开节点ID的数组
+ */
+ collectMatchedNodeIds(treeData, key, expandedIds) {
+ if (!treeData || !treeData.length) return;
+
+ treeData.forEach(node => {
+ // 若当前节点匹配关键词,记录其ID(用于展开)
+ if (key ? node.name.includes(key) : true) {
+ if (node.id) expandedIds.push(node.id);
+ }
+
+ // 递归处理子级,确保深层子级的匹配节点也被收集
+ if (node.children && node.children.length) {
+ this.collectMatchedNodeIds(node.children, key, expandedIds);
+ }
+ });
+ },
+
+ /**
+ * 辅助方法:检查树是否为空(没有任何有效节点)
+ */
+ isTreeEmpty(treeData) {
+ if (!treeData || !treeData.length) return true;
+
+ // 递归检查所有节点
+ for (const node of treeData) {
+ if (node && node.id) {
+ return false; // 发现有效节点
+ }
+ if (node.children && node.children.length) {
+ if (!this.isTreeEmpty(node.children)) {
+ return false; // 子节点中有有效节点
+ }
+ }
+ }
+ return true;
+ },
+
+
+ /**
+ * 左侧树重置:仅恢复树形原始状态(不联动右侧列表)
+ */
+ /**
+ * 左侧树重置:恢复树形原始状态,默认显示到第二级
+ */
+ async resetTreeSearch() {
+ try {
+ // 1. 清空左侧表单输入和查询参数
+ if (this.$refs.queryFormLeft) {
+ this.$refs.queryFormLeft.resetFields();
+ }
+ this.treeSearchKey = ''; // 手动清空类型分支查询值
+ this.queryParams.typeId = undefined; // 清空可能存在的节点ID缓存
+
+ // 2. 恢复原始树形数据,默认显示到第二级
+ this.treeLoading = true;
+ const res = await getDeviceTreeAPI();
+ this.treeData = res.data ? [res.data] : [];
+
+ // 重置默认展开的节点ID数组
+ this.defaultExpandedKeys = [];
+
+ // 只展开第一级和第二级节点
+ this.collectFirstAndSecondLevelKeys(this.treeData);
+
+ this.$message.success('树形查询已重置');
+ } catch (error) {
+ this.$message.error('树形重置失败:' + (error.message || '未知错误'));
+ console.error(error);
+ } finally {
+ this.treeLoading = false;
+ }
+ },
+
+
/**
* 获取右侧列表数据
*/
@@ -1135,7 +1380,7 @@ export default {
async onHandlePreview(row) {
// this.formData = row
// this.previewDialogVisible = true
- this.$router.push({ path: '/equipment/details', query: { id: row.maId } })
+ this.$router.push({path: '/equipment/details', query: {id: row.maId}})
},
/**
@@ -1346,7 +1591,7 @@ export default {
async getDeviceStatusCount() {
try {
const res = await getDeviceStatusCountAPI()
- const { inStock, ownUse, share, underRepair } = res.data || {}
+ const {inStock, ownUse, share, underRepair} = res.data || {}
this.inStock = inStock || 0
this.ownUse = ownUse || 0
this.share = share || 0
@@ -1401,10 +1646,16 @@ export default {
// 最后加载列表数据
await this.getDeviceList()
},
+
+
}
-