index.vue 5.0 KB

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