index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <div class="app-container" style="overflow-y: auto;">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true">
  4. <el-form-item label="科室名称" prop="deptName">
  5. <el-input v-model="queryParams.deptName" placeholder="请输入科室名称" clearable @keyup.enter.native="handleQuery"/>
  6. </el-form-item>
  7. <el-form-item label="科室状态" prop="status">
  8. <el-select v-model="queryParams.status" placeholder="科室状态" clearable class="se">
  9. <el-option v-for="dict in dict.type.sys_normal_disable" :key="dict.value" :label="dict.label" :value="dict.value" />
  10. </el-select>
  11. </el-form-item>
  12. <el-form-item>
  13. <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
  14. <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
  15. <el-button type="info" icon="el-icon-sort" @click="toggleExpandAll">展开/折叠</el-button>
  16. </el-form-item>
  17. </el-form>
  18. <el-table v-if="refreshTable" :data="deptList" row-key="deptId" :default-expand-all="isExpandAll" :tree-props="{ children: 'children', hasChildren: 'hasChildren' }">
  19. <el-table-column prop="deptName" label="科室名称"/>
  20. <el-table-column prop="orderNum" label="科室排序" align="center" width="200"/>
  21. <el-table-column prop="status" label="科室状态" align="center" width="100">
  22. <template slot-scope="scope">
  23. <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status" />
  24. </template>
  25. </el-table-column>
  26. <el-table-column label="操作" align="center" width="220">
  27. <template slot-scope="scope">
  28. <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:dept:edit']">修改</el-button>
  29. <el-button size="mini" type="text" icon="el-icon-plus" @click="handleAdd(scope.row)" v-hasPermi="['system:dept:add']" v-if="scope.row.ancestors.length < 3">新增</el-button>
  30. <el-button v-if="scope.row.parentId != 0" size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['system:dept:remove']">删除</el-button>
  31. </template>
  32. </el-table-column>
  33. <template slot="empty">
  34. <el-empty></el-empty>
  35. </template>
  36. </el-table>
  37. </div>
  38. </template>
  39. <script>
  40. import { listDept, getDept, delDept, addDept, updateDept, listDeptExcludeChild } from '@/api/system/dept';
  41. import Treeselect from '@riophae/vue-treeselect';
  42. import '@riophae/vue-treeselect/dist/vue-treeselect.css';
  43. import edit from './edit';
  44. export default {
  45. name: 'Dept',
  46. dicts: ['sys_normal_disable'],
  47. components: { Treeselect },
  48. data() {
  49. return {
  50. // 表格树数据
  51. deptList: [],
  52. // 科室树选项
  53. deptOptions: [],
  54. // 弹出层标题
  55. title: '',
  56. // 是否显示弹出层
  57. open: false,
  58. // 是否展开,默认全部展开
  59. isExpandAll: true,
  60. // 重新渲染表格状态
  61. refreshTable: true,
  62. // 查询参数
  63. queryParams: {
  64. deptName: undefined,
  65. status: undefined
  66. }
  67. };
  68. },
  69. created() {
  70. this.getList();
  71. },
  72. methods: {
  73. /** 查询科室列表 */
  74. getList() {
  75. listDept(this.queryParams).then((response) => {
  76. response.data.forEach((item) => {
  77. if (item.ancestors) {
  78. item.ancestors = item.ancestors.split(',');
  79. } else {
  80. item.ancestors = [];
  81. }
  82. });
  83. this.deptList = this.handleTree(response.data, 'deptId');
  84. });
  85. },
  86. /** 转换科室数据结构 */
  87. normalizer(node) {
  88. if (node.children && !node.children.length) {
  89. delete node.children;
  90. }
  91. return {
  92. id: node.deptId,
  93. label: node.deptName,
  94. children: node.children
  95. };
  96. },
  97. // 取消按钮
  98. cancel() {
  99. this.open = false;
  100. this.reset();
  101. },
  102. // 表单重置
  103. reset() {
  104. this.form = {
  105. deptId: undefined,
  106. parentId: undefined,
  107. deptName: undefined,
  108. orderNum: undefined,
  109. leader: undefined,
  110. phone: undefined,
  111. email: undefined,
  112. status: '0'
  113. };
  114. this.resetForm('form');
  115. },
  116. /** 搜索按钮操作 */
  117. handleQuery() {
  118. this.getList();
  119. },
  120. /** 重置按钮操作 */
  121. resetQuery() {
  122. this.resetForm('queryForm');
  123. this.handleQuery();
  124. },
  125. /** 新增按钮操作 */
  126. handleAdd(row) {
  127. this.iframe({ obj: edit, param: { parentId: row.deptId, ancestors: row.ancestors }, title: '新增科室', width: '55%', height: '78%' });
  128. },
  129. /** 展开/折叠操作 */
  130. toggleExpandAll() {
  131. this.refreshTable = false;
  132. this.isExpandAll = !this.isExpandAll;
  133. this.$nextTick(() => {
  134. this.refreshTable = true;
  135. });
  136. },
  137. /** 修改按钮操作 */
  138. handleUpdate(row) {
  139. this.iframe({ obj: edit, param: { id: row.deptId }, title: '编辑科室', width: '55%', height: '78%' });
  140. },
  141. /** 删除按钮操作 */
  142. handleDelete(row) {
  143. this.$modal
  144. .confirm('是否确认删除名称为"' + row.deptName + '"的数据项?')
  145. .then(function () {
  146. return delDept(row.deptId);
  147. })
  148. .then(() => {
  149. this.getList();
  150. this.$modal.msgSuccess('删除成功');
  151. })
  152. .catch(() => {});
  153. }
  154. }
  155. };
  156. </script>