index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <template>
  2. <div class="ele-body">
  3. <el-card shadow="never" v-loading="loading">
  4. <!-- 数据表格 -->
  5. <ele-pro-table
  6. ref="table"
  7. row-key="id"
  8. :columns="columns"
  9. :datasource="datasource"
  10. :default-expand-all="false"
  11. :need-page="false"
  12. cache-key="systemMenuTable"
  13. @done=""
  14. >
  15. <!-- 表头工具栏 -->
  16. <template v-slot:toolbar>
  17. <el-button
  18. size="small"
  19. type="primary"
  20. icon="el-icon-plus"
  21. class="ele-btn-icon"
  22. @click="openEdit()"
  23. >
  24. 添加
  25. </el-button>
  26. <el-button class="ele-btn-icon" size="small" @click="expandAll">
  27. 展开全部
  28. </el-button>
  29. <el-button class="ele-btn-icon" size="small" @click="foldAll">
  30. 折叠全部
  31. </el-button>
  32. <el-button type="primary" size="mini" icon="el-icon-upload2" plain @click="uploadFile">导入</el-button>
  33. </template>
  34. <!-- 标题列 -->
  35. <template v-slot:name="{ row }">
  36. <i :class="row.icon"></i> {{ row.name }}
  37. </template>
  38. <!-- 类型列 -->
  39. <template v-slot:type="{ row }">
  40. <el-tag
  41. type="primary"
  42. size="mini"
  43. :disable-transitions="true"
  44. v-if="row.type == 1"
  45. >
  46. 菜单
  47. </el-tag>
  48. <el-tag
  49. type="warning"
  50. size="mini"
  51. :disable-transitions="true"
  52. v-if="row.type == 2"
  53. >
  54. 按钮
  55. </el-tag>
  56. </template>
  57. <template v-slot:status="{ row }">
  58. <el-tag
  59. type="danger"
  60. :disable-transitions="true"
  61. v-if="row.status == 0"
  62. >
  63. 关闭
  64. </el-tag>
  65. <el-tag
  66. type="primary"
  67. :disable-transitions="true"
  68. v-if="row.status == 1"
  69. >
  70. 开启
  71. </el-tag>
  72. </template>
  73. <!-- 操作列 -->
  74. <template v-slot:action="{ row }">
  75. <el-link
  76. type="primary"
  77. :underline="false"
  78. icon="el-icon-edit"
  79. @click="openEdit(row)"
  80. >
  81. 修改
  82. </el-link>
  83. <el-popconfirm
  84. class="ele-action"
  85. title="确定要删除吗?"
  86. @confirm="remove(row)"
  87. v-if="row.id != 99999"
  88. >
  89. <template v-slot:reference>
  90. <el-link type="danger" :underline="false" icon="el-icon-delete">
  91. 删除
  92. </el-link>
  93. </template>
  94. </el-popconfirm>
  95. </template>
  96. </ele-pro-table>
  97. </el-card>
  98. <!-- 编辑弹窗 -->
  99. <org-edit
  100. :visible.sync="showEdit"
  101. :data="editData"
  102. :parent-id="parentId"
  103. :organization-list="data"
  104. @done="reload"
  105. />
  106. <importDialog :defModule="moudleName" ref="importDialogRef" @success="reload" />
  107. </div>
  108. </template>
  109. <script>
  110. import OrgEdit from './components/org-edit.vue';
  111. import importDialog from "@/components/upload/import-dialog.vue";
  112. import {
  113. listOrganizations,
  114. removeOrganization
  115. } from '@/api/system/organization';
  116. export default {
  117. name: 'SystemOrganization',
  118. components: {OrgEdit, importDialog},
  119. data() {
  120. return {
  121. //模块名称
  122. moudleName : "mainGroup",
  123. // 加载状态
  124. loading: false,
  125. // 列表数据
  126. data: [],
  127. // 选中数据
  128. current: null,
  129. // 是否显示表单弹窗
  130. showEdit: false,
  131. // 编辑回显数据
  132. editData: null,
  133. // 上级id
  134. parentId: null
  135. };
  136. },
  137. computed: {
  138. // 表格列配置
  139. columns() {
  140. return [
  141. {
  142. columnKey: 'index',
  143. type: 'index',
  144. width: 45,
  145. align: 'center',
  146. showOverflowTooltip: true,
  147. fixed: 'left'
  148. },
  149. {
  150. prop: 'name',
  151. label: '部门名称',
  152. showOverflowTooltip: true,
  153. minWidth: 110,
  154. slot: 'name'
  155. },
  156. {
  157. prop: '',
  158. label: '负责人',
  159. showOverflowTooltip: true,
  160. align: 'center',
  161. formatter: (_row) => {
  162. return _row.manager.map(item => item.name).join(',')
  163. },
  164. minWidth: 110,
  165. },
  166. {
  167. prop: 'sort',
  168. label: '排序',
  169. showOverflowTooltip: true,
  170. align: 'center',
  171. width: 60
  172. },
  173. {
  174. prop: 'status',
  175. label: '状态',
  176. showOverflowTooltip: true,
  177. align: 'center',
  178. width: 80,
  179. slot: 'status'
  180. },
  181. {
  182. prop: 'createTime',
  183. label: '创建时间',
  184. showOverflowTooltip: true,
  185. align: 'center',
  186. minWidth: 110,
  187. formatter: (_row, _column, cellValue) => {
  188. return this.$util.toDateString(cellValue);
  189. }
  190. },
  191. {
  192. columnKey: 'action',
  193. label: '操作',
  194. width: 190,
  195. align: 'center',
  196. resizable: false,
  197. slot: 'action',
  198. showOverflowTooltip: true
  199. }
  200. ]
  201. },
  202. },
  203. created() {
  204. //this.query();
  205. },
  206. methods: {
  207. /* 查询 */
  208. async datasource() {
  209. const data = await listOrganizations()
  210. this.data = this.$util.toTreeData({
  211. data: data,
  212. idField: 'id',
  213. parentIdField: 'parentId'
  214. });
  215. return this.data
  216. },
  217. /* 刷新表格 */
  218. reload(where) {
  219. this.$refs.table.reload();
  220. },
  221. /* 选择数据 */
  222. onNodeClick(row) {
  223. if (row) {
  224. this.current = row;
  225. this.parentId = row.id;
  226. this.$refs.tree.setCurrentKey(row.id);
  227. } else {
  228. this.current = null;
  229. this.parentId = null;
  230. }
  231. },
  232. /* 展开全部 */
  233. expandAll() {
  234. this.$refs.table.toggleRowExpansionAll(true);
  235. },
  236. /* 折叠全部 */
  237. foldAll() {
  238. this.$refs.table.toggleRowExpansionAll(false);
  239. },
  240. /* 显示编辑 */
  241. openEdit(item) {
  242. this.editData = item;
  243. this.showEdit = true;
  244. },
  245. /* 删除 */
  246. remove(row) {
  247. this.$confirm('确定要删除选中的机构吗?', '提示', {
  248. type: 'warning'
  249. }).then(() => {
  250. const loading = this.$loading({lock: true});
  251. removeOrganization([row.id])
  252. .then((msg) => {
  253. loading.close();
  254. this.$message.success(msg);
  255. this.reload();
  256. })
  257. .catch((e) => {
  258. loading.close();
  259. // this.$message.error(e.message);
  260. });
  261. })
  262. .catch(() => {
  263. });
  264. },
  265. uploadFile () {
  266. this.$refs.importDialogRef.open();
  267. }
  268. }
  269. };
  270. </script>
  271. <style lang="scss" scoped>
  272. .sys-organization-list {
  273. height: calc(100vh - 264px);
  274. box-sizing: border-box;
  275. border-width: 1px;
  276. border-style: solid;
  277. overflow: auto;
  278. }
  279. .sys-organization-list :deep(.el-tree-node__content) {
  280. height: 30px;
  281. & > .el-tree-node__expand-icon {
  282. margin-left: 10px;
  283. }
  284. }
  285. </style>