index.vue 11 KB

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