index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <div class="ele-body">
  3. <el-card shadow="never">
  4. <ele-split-layout
  5. width="256px"
  6. allow-collapse
  7. :right-style="{ overflow: 'hidden' }"
  8. >
  9. <div class="el-tree_box">
  10. <div class="ele-border-lighter sys-organization-list">
  11. <!-- <asset-tree
  12. @handleNodeClick="onNodeClick"
  13. ref="commonTree"
  14. :treeFormate="
  15. (list) => {
  16. return [
  17. {
  18. children: list,
  19. id: '0',
  20. level: 0,
  21. name: '库存台账',
  22. originId: null,
  23. originType: {},
  24. parentId: null,
  25. type: '',
  26. weight: 0
  27. }
  28. ];
  29. }
  30. "
  31. /> -->
  32. <el-tree
  33. style="height: 100%"
  34. :data="treeList"
  35. :props="defaultProps"
  36. ref="treeRef"
  37. :default-expanded-keys="current && current.id ? [current.id] : []"
  38. :highlight-current="true"
  39. node-key="id"
  40. @node-click="handleNodeClick"
  41. ></el-tree>
  42. </div>
  43. </div>
  44. <template v-slot:content>
  45. <item-list :current="current" />
  46. </template>
  47. </ele-split-layout>
  48. </el-card>
  49. </div>
  50. </template>
  51. <script>
  52. import itemList from './components/item-list';
  53. import AssetTree from '@/components/AssetTree';
  54. import { getTreeByGroup } from '@/api/classifyManage';
  55. export default {
  56. components: { itemList, AssetTree },
  57. data() {
  58. return {
  59. treeData: [],
  60. current: {},
  61. defaultProps: {
  62. children: 'children',
  63. label: 'name'
  64. },
  65. treeList: [],
  66. treeLoading: false
  67. };
  68. },
  69. async created() {
  70. this.getTreeData();
  71. },
  72. methods: {
  73. async getTreeData() {
  74. try {
  75. this.treeLoading = true;
  76. const res = await getTreeByGroup({ type: 2 });
  77. this.treeLoading = false;
  78. if (res?.code === '0') {
  79. this.treeList = res.data;
  80. this.$nextTick(() => {
  81. // 默认高亮第一级树节点
  82. if (this.treeList[0]) {
  83. this.$refs.treeRef.setCurrentKey(this.treeList[0].id);
  84. this.current = this.treeList[0];
  85. }
  86. });
  87. return this.treeList;
  88. }
  89. } catch (error) {}
  90. this.treeLoading = false;
  91. },
  92. handleNodeClick(data, node) {
  93. this.current = node;
  94. },
  95. openEdit() {
  96. const data = this.$refs.commonTree.getSelectList();
  97. if (data?.id) {
  98. let node = this.$refs.commonTree.getInstance().getNode(data.id);
  99. const urlIdList = [data.id];
  100. while (node.parent?.data?.id) {
  101. urlIdList.unshift(node.parent?.data?.id);
  102. node = node.parent;
  103. }
  104. data.urlIdList = urlIdList.filter((i) => i !== '0');
  105. }
  106. this.$router.push({
  107. path: '/classifyManage/itemInformation/add',
  108. query: {
  109. pageTitle: '新建物品',
  110. selectNode: JSON.stringify(data)
  111. }
  112. });
  113. }
  114. }
  115. };
  116. </script>
  117. <style lang="scss" scoped>
  118. .el-tree_box {
  119. height: 100%;
  120. > div {
  121. height: 100%;
  122. }
  123. }
  124. .ele-body {
  125. padding: 6px;
  126. }
  127. .sys-organization-list {
  128. height: calc(100vh - 264px);
  129. box-sizing: border-box;
  130. border-width: 1px;
  131. border-style: solid;
  132. overflow: auto;
  133. }
  134. .sys-organization-list :deep(.el-tree-node__content) {
  135. height: 40px;
  136. & > .el-tree-node__expand-icon {
  137. margin-left: 10px;
  138. }
  139. }
  140. </style>