index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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>
  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. :data="treeList"
  34. :props="defaultProps"
  35. ref="treeRef"
  36. :default-expanded-keys="current && current.id ? [current.id] : []"
  37. :highlight-current="true"
  38. node-key="id"
  39. @node-click="handleNodeClick"
  40. ></el-tree>
  41. </div>
  42. </div>
  43. <template v-slot:content>
  44. <item-list :current="current" />
  45. </template>
  46. </ele-split-layout>
  47. </el-card>
  48. </div>
  49. </template>
  50. <script>
  51. import itemList from './components/item-list';
  52. import AssetTree from '@/components/AssetTree';
  53. import { getTreeByGroup } from '@/api/classifyManage';
  54. export default {
  55. components: { itemList, AssetTree },
  56. data() {
  57. return {
  58. treeData: [],
  59. current: {},
  60. defaultProps: {
  61. children: 'children',
  62. label: 'name'
  63. },
  64. treeList: [],
  65. treeLoading: false,
  66. };
  67. },
  68. created() {
  69. this.getTreeData();
  70. },
  71. methods: {
  72. async getTreeData() {
  73. try {
  74. this.treeLoading = true;
  75. const res = await getTreeByGroup({ type: 2 });
  76. this.treeLoading = false;
  77. if (res?.code === '0') {
  78. this.treeList = res.data;
  79. this.$nextTick(() => {
  80. // 默认高亮第一级树节点
  81. if (this.treeList[0]) {
  82. // this.getDetail(this.treeList[0].id);
  83. }
  84. });
  85. return this.treeList;
  86. }
  87. } catch (error) {}
  88. this.treeLoading = false;
  89. },
  90. onNodeClick(data, node) {
  91. this.current = node;
  92. },
  93. openEdit() {
  94. const data = this.$refs.commonTree.getSelectList();
  95. if (data?.id) {
  96. let node = this.$refs.commonTree.getInstance().getNode(data.id);
  97. const urlIdList = [data.id];
  98. while (node.parent?.data?.id) {
  99. urlIdList.unshift(node.parent?.data?.id);
  100. node = node.parent;
  101. }
  102. data.urlIdList = urlIdList.filter((i) => i !== '0');
  103. }
  104. this.$router.push({
  105. path: '/classifyManage/itemInformation/add',
  106. query: {
  107. pageTitle: '新建物品',
  108. selectNode: JSON.stringify(data)
  109. }
  110. });
  111. }
  112. }
  113. };
  114. </script>
  115. <style lang="scss" scoped>
  116. .sys-organization-list {
  117. height: calc(100vh - 264px);
  118. box-sizing: border-box;
  119. border-width: 1px;
  120. border-style: solid;
  121. overflow: auto;
  122. }
  123. .sys-organization-list :deep(.el-tree-node__content) {
  124. height: 40px;
  125. & > .el-tree-node__expand-icon {
  126. margin-left: 10px;
  127. }
  128. }
  129. </style>