index.vue 9.8 KB

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