index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
  4. <el-form-item label="部门名称" prop="deptName">
  5. <el-input
  6. v-model="queryParams.deptName"
  7. placeholder="请输入部门名称"
  8. clearable
  9. size="small"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item label="状态" prop="status">
  14. <el-select v-model="queryParams.status" placeholder="部门状态" clearable size="small">
  15. <el-option
  16. v-for="dict in dict.type.sys_normal_disable"
  17. :key="dict.value"
  18. :label="dict.label"
  19. :value="dict.value"
  20. />
  21. </el-select>
  22. </el-form-item>
  23. <el-form-item>
  24. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  25. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  26. </el-form-item>
  27. </el-form>
  28. <el-row :gutter="10" class="mb8">
  29. <el-col :span="1.5">
  30. <el-button
  31. type="primary"
  32. plain
  33. icon="el-icon-plus"
  34. size="mini"
  35. @click="handleAdd"
  36. v-hasPermi="['system:dept:add']"
  37. >新增</el-button>
  38. </el-col>
  39. <el-col :span="1.5">
  40. <el-button
  41. type="info"
  42. plain
  43. icon="el-icon-sort"
  44. size="mini"
  45. @click="toggleExpandAll"
  46. >展开/折叠</el-button>
  47. </el-col>
  48. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  49. </el-row>
  50. <el-table
  51. v-if="refreshTable"
  52. v-loading="loading"
  53. :data="deptList"
  54. row-key="deptId"
  55. :default-expand-all="isExpandAll"
  56. :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
  57. >
  58. <el-table-column prop="deptName" label="部门名称" width="260"></el-table-column>
  59. <el-table-column prop="orderNum" label="排序" width="200"></el-table-column>
  60. <el-table-column prop="status" label="状态" width="100">
  61. <template slot-scope="scope">
  62. <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status"/>
  63. </template>
  64. </el-table-column>
  65. <el-table-column label="创建时间" align="center" prop="createTime" width="200">
  66. <template slot-scope="scope">
  67. <span>{{ parseTime(scope.row.createTime) }}</span>
  68. </template>
  69. </el-table-column>
  70. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  71. <template slot-scope="scope">
  72. <el-button
  73. size="mini"
  74. type="text"
  75. icon="el-icon-edit"
  76. @click="handleUpdate(scope.row)"
  77. v-hasPermi="['system:dept:edit']"
  78. >修改</el-button>
  79. <el-button
  80. size="mini"
  81. type="text"
  82. icon="el-icon-plus"
  83. @click="handleAdd(scope.row)"
  84. v-hasPermi="['system:dept:add']"
  85. >新增</el-button>
  86. <el-button
  87. v-if="scope.row.parentId != 0"
  88. size="mini"
  89. type="text"
  90. icon="el-icon-delete"
  91. @click="handleDelete(scope.row)"
  92. v-hasPermi="['system:dept:remove']"
  93. >删除</el-button>
  94. </template>
  95. </el-table-column>
  96. </el-table>
  97. <!-- 添加或修改部门对话框 -->
  98. <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
  99. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  100. <el-row>
  101. <el-col :span="24" v-if="form.parentId !== 0">
  102. <el-form-item label="上级部门" prop="parentId">
  103. <treeselect v-model="form.parentId" :options="deptOptions" :normalizer="normalizer" placeholder="选择上级部门" />
  104. </el-form-item>
  105. </el-col>
  106. <el-col :span="12">
  107. <el-form-item label="部门名称" prop="deptName">
  108. <el-input v-model="form.deptName" placeholder="请输入部门名称" />
  109. </el-form-item>
  110. </el-col>
  111. <el-col :span="12">
  112. <el-form-item label="显示排序" prop="orderNum">
  113. <el-input-number v-model="form.orderNum" controls-position="right" :min="0" />
  114. </el-form-item>
  115. </el-col>
  116. <el-col :span="12">
  117. <el-form-item label="负责人" prop="leader">
  118. <el-input v-model="form.leader" placeholder="请输入负责人" maxlength="20" />
  119. </el-form-item>
  120. </el-col>
  121. <el-col :span="12">
  122. <el-form-item label="联系电话" prop="phone">
  123. <el-input v-model="form.phone" placeholder="请输入联系电话" maxlength="11" />
  124. </el-form-item>
  125. </el-col>
  126. <el-col :span="12">
  127. <el-form-item label="邮箱" prop="email">
  128. <el-input v-model="form.email" placeholder="请输入邮箱" maxlength="50" />
  129. </el-form-item>
  130. </el-col>
  131. <el-col :span="12">
  132. <el-form-item label="部门状态">
  133. <el-radio-group v-model="form.status">
  134. <el-radio
  135. v-for="dict in dict.type.sys_normal_disable"
  136. :key="dict.value"
  137. :label="dict.value"
  138. >{{dict.label}}</el-radio>
  139. </el-radio-group>
  140. </el-form-item>
  141. </el-col>
  142. </el-row>
  143. </el-form>
  144. <div slot="footer" class="dialog-footer">
  145. <el-button type="primary" @click="submitForm">确 定</el-button>
  146. <el-button @click="cancel">取 消</el-button>
  147. </div>
  148. </el-dialog>
  149. </div>
  150. </template>
  151. <script>
  152. import { listDept, getDept, delDept, addDept, updateDept, listDeptExcludeChild } from "@/api/system/dept";
  153. import Treeselect from "@riophae/vue-treeselect";
  154. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  155. export default {
  156. name: "Dept",
  157. dicts: ['sys_normal_disable'],
  158. components: { Treeselect },
  159. data() {
  160. return {
  161. // 遮罩层
  162. loading: true,
  163. // 显示搜索条件
  164. showSearch: true,
  165. // 表格树数据
  166. deptList: [],
  167. // 部门树选项
  168. deptOptions: [],
  169. // 弹出层标题
  170. title: "",
  171. // 是否显示弹出层
  172. open: false,
  173. // 是否展开,默认全部展开
  174. isExpandAll: true,
  175. // 重新渲染表格状态
  176. refreshTable: true,
  177. // 查询参数
  178. queryParams: {
  179. deptName: undefined,
  180. status: undefined
  181. },
  182. // 表单参数
  183. form: {},
  184. // 表单校验
  185. rules: {
  186. parentId: [
  187. { required: true, message: "上级部门不能为空", trigger: "blur" }
  188. ],
  189. deptName: [
  190. { required: true, message: "部门名称不能为空", trigger: "blur" }
  191. ],
  192. orderNum: [
  193. { required: true, message: "显示排序不能为空", trigger: "blur" }
  194. ],
  195. email: [
  196. {
  197. type: "email",
  198. message: "'请输入正确的邮箱地址",
  199. trigger: ["blur", "change"]
  200. }
  201. ],
  202. phone: [
  203. {
  204. pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
  205. message: "请输入正确的手机号码",
  206. trigger: "blur"
  207. }
  208. ]
  209. }
  210. };
  211. },
  212. created() {
  213. this.getList();
  214. },
  215. methods: {
  216. /** 查询部门列表 */
  217. getList() {
  218. this.loading = true;
  219. listDept(this.queryParams).then(response => {
  220. this.deptList = this.handleTree(response.data, "deptId");
  221. this.loading = false;
  222. });
  223. },
  224. /** 转换部门数据结构 */
  225. normalizer(node) {
  226. if (node.children && !node.children.length) {
  227. delete node.children;
  228. }
  229. return {
  230. id: node.deptId,
  231. label: node.deptName,
  232. children: node.children
  233. };
  234. },
  235. // 取消按钮
  236. cancel() {
  237. this.open = false;
  238. this.reset();
  239. },
  240. // 表单重置
  241. reset() {
  242. this.form = {
  243. deptId: undefined,
  244. parentId: undefined,
  245. deptName: undefined,
  246. orderNum: undefined,
  247. leader: undefined,
  248. phone: undefined,
  249. email: undefined,
  250. status: "0"
  251. };
  252. this.resetForm("form");
  253. },
  254. /** 搜索按钮操作 */
  255. handleQuery() {
  256. this.getList();
  257. },
  258. /** 重置按钮操作 */
  259. resetQuery() {
  260. this.resetForm("queryForm");
  261. this.handleQuery();
  262. },
  263. /** 新增按钮操作 */
  264. handleAdd(row) {
  265. this.reset();
  266. if (row != undefined) {
  267. this.form.parentId = row.deptId;
  268. }
  269. this.open = true;
  270. this.title = "添加部门";
  271. listDept().then(response => {
  272. this.deptOptions = this.handleTree(response.data, "deptId");
  273. });
  274. },
  275. /** 展开/折叠操作 */
  276. toggleExpandAll() {
  277. this.refreshTable = false;
  278. this.isExpandAll = !this.isExpandAll;
  279. this.$nextTick(() => {
  280. this.refreshTable = true;
  281. });
  282. },
  283. /** 修改按钮操作 */
  284. handleUpdate(row) {
  285. this.reset();
  286. getDept(row.deptId).then(response => {
  287. this.form = response.data;
  288. this.open = true;
  289. this.title = "修改部门";
  290. });
  291. listDeptExcludeChild(row.deptId).then(response => {
  292. this.deptOptions = this.handleTree(response.data, "deptId");
  293. });
  294. },
  295. /** 提交按钮 */
  296. submitForm: function() {
  297. this.$refs["form"].validate(valid => {
  298. if (valid) {
  299. if (this.form.deptId != undefined) {
  300. updateDept(this.form).then(response => {
  301. this.$modal.msgSuccess("修改成功");
  302. this.open = false;
  303. this.getList();
  304. });
  305. } else {
  306. addDept(this.form).then(response => {
  307. this.$modal.msgSuccess("新增成功");
  308. this.open = false;
  309. this.getList();
  310. });
  311. }
  312. }
  313. });
  314. },
  315. /** 删除按钮操作 */
  316. handleDelete(row) {
  317. this.$modal.confirm('是否确认删除名称为"' + row.deptName + '"的数据项?').then(function() {
  318. return delDept(row.deptId);
  319. }).then(() => {
  320. this.getList();
  321. this.$modal.msgSuccess("删除成功");
  322. }).catch(() => {});
  323. }
  324. }
  325. };
  326. </script>