index.vue 11 KB

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