index.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <div class="ele-body">
  3. <el-card shadow="never" v-loading="loading">
  4. <ele-split-layout
  5. width="266px"
  6. allow-collapse
  7. :right-style="{ overflow: 'hidden' }"
  8. >
  9. <div>
  10. <!-- 操作按钮 -->
  11. <ele-toolbar class="ele-toolbar-actions">
  12. <div style="margin: 5px 0">
  13. <el-input size="small" suffix-icon="el-icon-search" placeholder="请输入功能名称" v-model="filterText"> </el-input>
  14. </div>
  15. </ele-toolbar>
  16. <div class="ele-border-lighter sys-organization-list">
  17. <el-tree
  18. ref="tree"
  19. :data="data"
  20. highlight-current
  21. node-key="id"
  22. :props="{ label: 'name' }"
  23. :expand-on-click-node="false"
  24. :default-expand-all="true"
  25. @node-click="onNodeClick"
  26. />
  27. </div>
  28. </div>
  29. <template v-slot:content>
  30. <code-list
  31. v-if="current"
  32. :organization-list="data"
  33. :organization-id="current.id"
  34. />
  35. </template>
  36. </ele-split-layout>
  37. </el-card>
  38. </div>
  39. </template>
  40. <script>
  41. import CodeList from './components/code-list.vue';
  42. import {
  43. listOrganizations,
  44. removeOrganization
  45. } from '@/api/system/organization';
  46. export default {
  47. name: 'codeManagement',
  48. components: { CodeList },
  49. data() {
  50. return {
  51. // 加载状态
  52. loading: true,
  53. // 列表数据
  54. data: [],
  55. // 选中数据
  56. current: null,
  57. // 是否显示表单弹窗
  58. showEdit: false,
  59. // 编辑回显数据
  60. editData: null,
  61. // 上级id
  62. parentId: null,
  63. filterText:''
  64. };
  65. },
  66. created() {
  67. this.query();
  68. },
  69. methods: {
  70. /* 查询 */
  71. query() {
  72. this.loading = true;
  73. listOrganizations()
  74. .then((list) => {
  75. this.loading = false;
  76. this.data = this.$util.toTreeData({
  77. data: list,
  78. idField: 'id',
  79. parentIdField: 'parentId'
  80. });
  81. this.$nextTick(() => {
  82. this.onNodeClick(this.data[0]);
  83. });
  84. })
  85. .catch((e) => {
  86. this.loading = false;
  87. this.$message.error(e.message);
  88. });
  89. },
  90. /* 选择数据 */
  91. onNodeClick(row) {
  92. if (row) {
  93. this.current = row;
  94. this.parentId = row.id;
  95. this.$refs.tree.setCurrentKey(row.id);
  96. } else {
  97. this.current = null;
  98. this.parentId = null;
  99. }
  100. },
  101. /* 显示编辑 */
  102. openEdit(item) {
  103. this.editData = item;
  104. this.showEdit = true;
  105. },
  106. /* 删除 */
  107. remove() {
  108. this.$confirm('确定要删除选中的机构吗?', '提示', {
  109. type: 'warning'
  110. })
  111. .then(() => {
  112. const loading = this.$loading({ lock: true });
  113. removeOrganization([this.current.id])
  114. .then((msg) => {
  115. loading.close();
  116. this.$message.success(msg);
  117. this.query();
  118. })
  119. .catch((e) => {
  120. loading.close();
  121. this.$message.error(e.message);
  122. });
  123. })
  124. .catch(() => {});
  125. }
  126. }
  127. };
  128. </script>
  129. <style lang="scss" scoped>
  130. .sys-organization-list {
  131. height: calc(100vh - 264px);
  132. box-sizing: border-box;
  133. border-width: 1px;
  134. border-style: solid;
  135. overflow: auto;
  136. }
  137. .sys-organization-list :deep(.el-tree-node__content) {
  138. height: 40px;
  139. & > .el-tree-node__expand-icon {
  140. margin-left: 10px;
  141. }
  142. }
  143. </style>