index.vue 11 KB

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