index.vue 9.9 KB

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