index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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-button
  14. size="small"
  15. type="primary"
  16. icon="el-icon-plus"
  17. class="ele-btn-icon"
  18. @click="openEdit()"
  19. >
  20. 添加
  21. </el-button>
  22. <el-button
  23. size="small"
  24. type="warning"
  25. icon="el-icon-edit"
  26. class="ele-btn-icon"
  27. :disabled="!current"
  28. @click="openEdit(current)"
  29. >
  30. 修改
  31. </el-button>
  32. <el-button
  33. size="small"
  34. type="danger"
  35. icon="el-icon-delete"
  36. class="ele-btn-icon"
  37. :disabled="!current"
  38. @click="remove"
  39. >
  40. 删除
  41. </el-button>
  42. </div>
  43. </ele-toolbar>
  44. <div class="ele-border-lighter sys-organization-list">
  45. <el-tree
  46. ref="tree"
  47. :data="data"
  48. highlight-current
  49. node-key="id"
  50. :props="{ label: 'name' }"
  51. :expand-on-click-node="false"
  52. :default-expand-all="true"
  53. @node-click="onNodeClick"
  54. />
  55. </div>
  56. </div>
  57. <template v-slot:content>
  58. <org-user-list
  59. v-if="current"
  60. :organization-list="data"
  61. :organization-id="current.id"
  62. />
  63. </template>
  64. </ele-split-layout>
  65. </el-card>
  66. <!-- 编辑弹窗 -->
  67. <org-edit
  68. :visible.sync="showEdit"
  69. :data="editData"
  70. :parent-id="parentId"
  71. :organization-list="data"
  72. @done="query"
  73. />
  74. </div>
  75. </template>
  76. <script>
  77. import OrgUserList from './components/org-user-list.vue';
  78. import OrgEdit from './components/org-edit.vue';
  79. import {
  80. listOrganizations,
  81. removeOrganization
  82. } from '@/api/system/organization';
  83. export default {
  84. name: 'SystemOrganization',
  85. components: { OrgUserList, OrgEdit },
  86. data() {
  87. return {
  88. // 加载状态
  89. loading: true,
  90. // 列表数据
  91. data: [],
  92. // 选中数据
  93. current: null,
  94. // 是否显示表单弹窗
  95. showEdit: false,
  96. // 编辑回显数据
  97. editData: null,
  98. // 上级id
  99. parentId: null
  100. };
  101. },
  102. created() {
  103. this.query();
  104. },
  105. methods: {
  106. /* 查询 */
  107. query() {
  108. this.loading = true;
  109. listOrganizations()
  110. .then((list) => {
  111. this.loading = false;
  112. this.data = this.$util.toTreeData({
  113. data: list,
  114. idField: 'id',
  115. parentIdField: 'parentId'
  116. });
  117. this.$nextTick(() => {
  118. this.onNodeClick(this.data[0]);
  119. });
  120. })
  121. .catch((e) => {
  122. this.loading = false;
  123. // this.$message.error(e.message);
  124. });
  125. },
  126. /* 选择数据 */
  127. onNodeClick(row) {
  128. if (row) {
  129. this.current = row;
  130. this.parentId = row.id;
  131. this.$refs.tree.setCurrentKey(row.id);
  132. } else {
  133. this.current = null;
  134. this.parentId = null;
  135. }
  136. },
  137. /* 显示编辑 */
  138. openEdit(item) {
  139. this.editData = item;
  140. this.showEdit = true;
  141. },
  142. /* 删除 */
  143. remove() {
  144. this.$confirm('确定要删除选中的机构吗?', '提示', {
  145. type: 'warning'
  146. })
  147. .then(() => {
  148. const loading = this.$loading({ lock: true });
  149. removeOrganization([this.current.id])
  150. .then((msg) => {
  151. loading.close();
  152. this.$message.success(msg);
  153. this.query();
  154. })
  155. .catch((e) => {
  156. loading.close();
  157. // this.$message.error(e.message);
  158. });
  159. })
  160. .catch(() => {});
  161. }
  162. }
  163. };
  164. </script>
  165. <style lang="scss" scoped>
  166. .sys-organization-list {
  167. height: calc(100vh - 264px);
  168. box-sizing: border-box;
  169. border-width: 1px;
  170. border-style: solid;
  171. overflow: auto;
  172. }
  173. .sys-organization-list :deep(.el-tree-node__content) {
  174. height: 40px;
  175. & > .el-tree-node__expand-icon {
  176. margin-left: 10px;
  177. }
  178. }
  179. </style>