index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <div id="stockLedger__index">
  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="tabs_box">
  11. <el-radio-group v-model="currentTab" @change="tabsChange">
  12. <el-radio-button label="products">分类维度</el-radio-button>
  13. <el-radio-button label="warehouse">仓库维度</el-radio-button>
  14. </el-radio-group>
  15. </div>
  16. <div class="ele-border-lighter sys-organization-list">
  17. <!-- <asset-tree
  18. @handleNodeClick="onNodeClick"
  19. ref="commonTree"
  20. :treeFormate="
  21. (list) => {
  22. return [
  23. {
  24. children: list,
  25. id: '0',
  26. level: 0,
  27. name: '库存台账',
  28. originId: null,
  29. originType: {},
  30. parentId: null,
  31. type: '',
  32. weight: 0
  33. }
  34. ];
  35. }
  36. "
  37. /> -->
  38. <el-tree
  39. :data="treeList"
  40. :props="defaultProps"
  41. ref="treeRef"
  42. :default-expanded-keys="current && current.id ? [current.id] : []"
  43. :highlight-current="true"
  44. node-key="id"
  45. :expand-on-click-node="false"
  46. @node-click="handleNodeClick"
  47. ><span class="custom-tree-node" slot-scope="{ node, data }">
  48. <span
  49. >{{ data.factoryName ? data.factoryName + '-' : ''
  50. }}{{ data.name }}</span
  51. >
  52. </span></el-tree
  53. >
  54. </div>
  55. </div>
  56. <template v-slot:content>
  57. <item-list ref="listRef" :current="current" :type="currentTab" />
  58. </template>
  59. </ele-split-layout>
  60. </el-card>
  61. </div>
  62. </template>
  63. <script>
  64. import itemList from './components/item-list';
  65. import AssetTree from '@/components/AssetTree';
  66. import { getTreeByGroup } from '@/api/classifyManage';
  67. import storageApi from '@/api/warehouseManagement';
  68. export default {
  69. components: { itemList, AssetTree },
  70. data() {
  71. return {
  72. currentTab: 'products',
  73. treeData: [],
  74. current: {},
  75. defaultProps: {
  76. children: 'children',
  77. label: 'name'
  78. },
  79. currentId: '',
  80. treeList: [],
  81. treeLoading: false,
  82. cacheKeyUrl: 'eos-439decaa-warehouseManagement-stockLedger-products2'
  83. };
  84. },
  85. async created() {
  86. this.getTreeData();
  87. },
  88. methods: {
  89. tabsChange(val) {
  90. this.currentTab = val;
  91. this.getTreeData();
  92. // //切换左侧维度,获取服务列表配置
  93. if (val === 'products') {
  94. this.cacheKeyUrl= "eos-439decaa-warehouseManagement-stockLedger-products2"
  95. } else if (val === 'warehouse') {
  96. this.cacheKeyUrl= "eos-439decaa-warehouseManagement-stockLedger-warehouse"
  97. }
  98. this.$refs.listRef.getTabColumns(this.cacheKeyUrl)
  99. },
  100. async getTreeData() {
  101. try {
  102. this.treeLoading = true;
  103. let res = null;
  104. if (this.currentTab === 'warehouse') {
  105. res = await storageApi.getWarehouseTrees();
  106. } else {
  107. res = await getTreeByGroup({ type: 2 });
  108. }
  109. this.treeLoading = false;
  110. if (res?.code === '0') {
  111. this.treeList = res.data;
  112. // this.$nextTick(() => {
  113. // // 默认高亮第一级树节点
  114. // if (this.treeList[0]) {
  115. // this.$refs.treeRef.setCurrentKey(this.treeList[0].id);
  116. // this.current = this.treeList[0];
  117. // }
  118. // });
  119. return this.treeList;
  120. }
  121. } catch (error) {
  122. console.log(error);
  123. }
  124. this.treeLoading = false;
  125. },
  126. handleNodeClick(data, node) {
  127. if (data.id == this.currentId) {
  128. this.$refs.treeRef.setCurrentKey(null);
  129. this.currentId = '';
  130. this.current = {};
  131. this.$refs.listRef.reload();
  132. } else {
  133. this.currentId = data.id;
  134. this.current = node;
  135. }
  136. },
  137. openEdit() {
  138. const data = this.$refs.commonTree.getSelectList();
  139. if (data?.id) {
  140. let node = this.$refs.commonTree.getInstance().getNode(data.id);
  141. const urlIdList = [data.id];
  142. while (node.parent?.data?.id) {
  143. urlIdList.unshift(node.parent?.data?.id);
  144. node = node.parent;
  145. }
  146. data.urlIdList = urlIdList.filter((i) => i !== '0');
  147. }
  148. this.$router.push({
  149. path: '/classifyManage/itemInformation/add',
  150. query: {
  151. pageTitle: '新建物品',
  152. selectNode: JSON.stringify(data)
  153. }
  154. });
  155. }
  156. }
  157. };
  158. </script>
  159. <style lang="scss" scoped>
  160. #stockLedger__index {
  161. padding: 6px;
  162. .el-tree_box {
  163. height: 100%;
  164. display: flex;
  165. flex-direction: column;
  166. }
  167. .tabs_box {
  168. display: flex;
  169. align-items: center;
  170. justify-content: center;
  171. box-sizing: border-box;
  172. margin-bottom: 3px;
  173. width: 100%;
  174. > div {
  175. width: 100%;
  176. display: flex;
  177. :deep(.el-radio-button) {
  178. flex: 1;
  179. .el-radio-button__inner {
  180. width: 100%;
  181. }
  182. }
  183. }
  184. }
  185. .sys-organization-list {
  186. height: calc(100vh - 185px);
  187. box-sizing: border-box;
  188. border-width: 1px;
  189. border-style: solid;
  190. overflow: auto;
  191. }
  192. .sys-organization-list :deep(.el-tree-node__content) {
  193. height: 40px;
  194. & > .el-tree-node__expand-icon {
  195. margin-left: 10px;
  196. }
  197. }
  198. }
  199. </style>