index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. <template>
  2. <div class="app-container">
  3. <el-form
  4. :model="queryParams"
  5. ref="queryForm"
  6. size="small"
  7. :inline="true"
  8. v-show="showSearch"
  9. label-width="68px"
  10. >
  11. <el-form-item label="岗位编码" prop="postCode">
  12. <el-input
  13. v-model="queryParams.postCode"
  14. placeholder="请输入岗位编码"
  15. clearable
  16. @keyup.enter.native="handleQuery"
  17. />
  18. </el-form-item>
  19. <el-form-item label="岗位名称" prop="postName">
  20. <el-input
  21. v-model="queryParams.postName"
  22. placeholder="请输入岗位名称"
  23. clearable
  24. @keyup.enter.native="handleQuery"
  25. />
  26. </el-form-item>
  27. <el-form-item label="状态" prop="status">
  28. <el-select
  29. v-model="queryParams.status"
  30. placeholder="岗位状态"
  31. clearable
  32. >
  33. <el-option
  34. v-for="dict in dict.type.sys_normal_disable"
  35. :key="dict.value"
  36. :label="dict.label"
  37. :value="dict.value"
  38. />
  39. </el-select>
  40. </el-form-item>
  41. <el-form-item>
  42. <el-button
  43. type="primary"
  44. icon="el-icon-search"
  45. size="mini"
  46. @click="handleQuery"
  47. >搜索</el-button
  48. >
  49. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
  50. >重置</el-button
  51. >
  52. </el-form-item>
  53. </el-form>
  54. <el-row :gutter="10" class="mb8">
  55. <el-col :span="1.5">
  56. <el-button
  57. type="primary"
  58. plain
  59. icon="el-icon-plus"
  60. size="mini"
  61. @click="handleAdd"
  62. v-hasPermi="['system:post:add']"
  63. >新增</el-button
  64. >
  65. </el-col>
  66. <el-col :span="1.5">
  67. <el-button
  68. type="success"
  69. plain
  70. icon="el-icon-edit"
  71. size="mini"
  72. :disabled="single"
  73. @click="handleUpdate"
  74. v-hasPermi="['system:post:edit']"
  75. >修改</el-button
  76. >
  77. </el-col>
  78. <el-col :span="1.5">
  79. <el-button
  80. type="danger"
  81. plain
  82. icon="el-icon-delete"
  83. size="mini"
  84. :disabled="multiple"
  85. @click="handleDelete"
  86. v-hasPermi="['system:post:remove']"
  87. >删除</el-button
  88. >
  89. </el-col>
  90. <el-col :span="1.5">
  91. <el-button
  92. v-if="selection.length == 0"
  93. type="warning"
  94. plain
  95. icon="el-icon-download"
  96. size="mini"
  97. @click="handleExport"
  98. v-hasPermi="['system:post:export']"
  99. >导出</el-button
  100. >
  101. <ExcelDownLoad
  102. v-else
  103. :headerList="headerList"
  104. :fieldList="selection"
  105. :excelTitle="excelTitle"
  106. ></ExcelDownLoad>
  107. </el-col>
  108. <right-toolbar
  109. :showSearch.sync="showSearch"
  110. @queryTable="getList"
  111. ></right-toolbar>
  112. </el-row>
  113. <el-table
  114. v-loading="loading"
  115. ref="tableRef"
  116. :data="postList"
  117. @selection-change="handleSelectionChange"
  118. >
  119. <el-table-column type="selection" width="55" align="center" />
  120. <!-- <el-table-column label="岗位编号" align="center" prop="postId" /> -->
  121. <el-table-column label="岗位编码" align="center" prop="postCode" />
  122. <el-table-column label="岗位名称" align="center" prop="postName" />
  123. <el-table-column label="岗位排序" align="center" prop="postSort" />
  124. <el-table-column label="状态" align="center" prop="status">
  125. <template slot-scope="scope">
  126. <dict-tag
  127. :options="dict.type.sys_normal_disable"
  128. :value="scope.row.status"
  129. />
  130. </template>
  131. </el-table-column>
  132. <el-table-column
  133. label="创建时间"
  134. align="center"
  135. prop="createTime"
  136. width="180"
  137. >
  138. <template slot-scope="scope">
  139. <span>{{ parseTime(scope.row.createTime) }}</span>
  140. </template>
  141. </el-table-column>
  142. <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  143. <template slot-scope="scope">
  144. <el-button
  145. size="mini"
  146. type="text"
  147. icon="el-icon-edit"
  148. @click="handleUpdate(scope.row)"
  149. v-hasPermi="['system:post:edit']"
  150. >修改</el-button>
  151. <el-button
  152. size="mini"
  153. type="text"
  154. icon="el-icon-delete"
  155. @click="handleDelete(scope.row)"
  156. v-hasPermi="['system:post:remove']"
  157. >删除</el-button>
  158. </template>
  159. </el-table-column> -->
  160. <el-table-column
  161. label="操作"
  162. align="center"
  163. class-name="small-padding fixed-width"
  164. >
  165. <template slot-scope="scope">
  166. <el-dropdown>
  167. <el-button type="warning" plain size="small">
  168. 处理<i class="el-icon-arrow-down el-icon--right"></i>
  169. </el-button>
  170. <el-dropdown-menu slot="dropdown">
  171. <el-dropdown-item>
  172. <el-button
  173. size="mini"
  174. type="text"
  175. icon="el-icon-edit"
  176. @click="handleUpdate(scope.row)"
  177. v-hasPermi="['system:post:edit']"
  178. >修改
  179. </el-button>
  180. </el-dropdown-item>
  181. <el-dropdown-item>
  182. <el-button
  183. v-if="scope.row.parentId != 0"
  184. size="mini"
  185. type="text"
  186. icon="el-icon-delete"
  187. @click="handleDelete(scope.row)"
  188. v-hasPermi="['system:post:remove']"
  189. >删除
  190. </el-button>
  191. </el-dropdown-item>
  192. </el-dropdown-menu>
  193. </el-dropdown>
  194. </template>
  195. </el-table-column>
  196. </el-table>
  197. <pagination
  198. v-show="total > 0"
  199. :total="total"
  200. :page.sync="queryParams.pageNum"
  201. :limit.sync="queryParams.pageSize"
  202. @pagination="getList"
  203. />
  204. <!-- 添加或修改岗位对话框 -->
  205. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  206. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  207. <el-form-item label="岗位名称" prop="postName">
  208. <el-input v-model="form.postName" placeholder="请输入岗位名称" />
  209. </el-form-item>
  210. <el-form-item label="岗位编码" prop="postCode">
  211. <el-input v-model="form.postCode" placeholder="请输入编码名称" />
  212. </el-form-item>
  213. <el-form-item label="岗位顺序" prop="postSort">
  214. <el-input-number
  215. v-model="form.postSort"
  216. controls-position="right"
  217. :min="0"
  218. />
  219. </el-form-item>
  220. <el-form-item label="岗位状态" prop="status">
  221. <el-radio-group v-model="form.status">
  222. <el-radio
  223. v-for="dict in dict.type.sys_normal_disable"
  224. :key="dict.value"
  225. :label="dict.value"
  226. >{{ dict.label }}</el-radio
  227. >
  228. </el-radio-group>
  229. </el-form-item>
  230. <el-form-item label="备注" prop="remark">
  231. <el-input
  232. v-model="form.remark"
  233. type="textarea"
  234. placeholder="请输入内容"
  235. />
  236. </el-form-item>
  237. </el-form>
  238. <div slot="footer" class="dialog-footer">
  239. <el-button type="primary" @click="submitForm">确 定</el-button>
  240. <el-button @click="cancel">取 消</el-button>
  241. </div>
  242. </el-dialog>
  243. </div>
  244. </template>
  245. <script>
  246. import {
  247. listPost,
  248. getPost,
  249. delPost,
  250. addPost,
  251. updatePost,
  252. } from "@/api/system/post";
  253. import ExcelDownLoad from "@/components/ExcelDownLoad/index.vue";
  254. export default {
  255. name: "Post",
  256. dicts: ["sys_normal_disable"],
  257. components: { ExcelDownLoad },
  258. data() {
  259. return {
  260. // 前端导出数据
  261. headerList: {
  262. 岗位序号: "postId",
  263. 岗位编码: "postCode",
  264. 岗位名称: "postName",
  265. 岗位排序: "postSort",
  266. 状态: "status",
  267. },
  268. excelTitle: "post",
  269. // 遮罩层
  270. loading: true,
  271. // 选中数组
  272. ids: [],
  273. // 选中数组(包含所有数据)
  274. selection: [],
  275. // 非单个禁用
  276. single: true,
  277. // 非多个禁用
  278. multiple: true,
  279. // 显示搜索条件
  280. showSearch: true,
  281. // 总条数
  282. total: 0,
  283. // 岗位表格数据
  284. postList: [],
  285. // 弹出层标题
  286. title: "",
  287. // 是否显示弹出层
  288. open: false,
  289. // 查询参数
  290. queryParams: {
  291. pageNum: 1,
  292. pageSize: 10,
  293. postCode: undefined,
  294. postName: undefined,
  295. status: undefined,
  296. },
  297. // 表单参数
  298. form: {},
  299. // 表单校验
  300. rules: {
  301. postName: [
  302. { required: true, message: "岗位名称不能为空", trigger: "blur" },
  303. ],
  304. postCode: [
  305. { required: true, message: "岗位编码不能为空", trigger: "blur" },
  306. ],
  307. postSort: [
  308. { required: true, message: "岗位顺序不能为空", trigger: "blur" },
  309. ],
  310. },
  311. };
  312. },
  313. created() {
  314. this.getList();
  315. },
  316. methods: {
  317. /** 查询岗位列表 */
  318. getList() {
  319. this.loading = true;
  320. let tempSelection = JSON.parse(JSON.stringify(this.selection));
  321. listPost(this.queryParams).then((response) => {
  322. response.rows = response.rows.filter(
  323. (item) => !tempSelection.find((val) => val.postId == item.postId)
  324. );
  325. // this.postList = [...tempSelection, ...response.rows];
  326. this.postList = response.rows;
  327. this.total = response.total;
  328. this.loading = false;
  329. // if (tempSelection.length) {
  330. // this.$nextTick(() => {
  331. // tempSelection.forEach((item) => {
  332. // this.$refs.tableRef.toggleRowSelection(item);
  333. // });
  334. // });
  335. // }
  336. });
  337. },
  338. // 取消按钮
  339. cancel() {
  340. this.open = false;
  341. this.reset();
  342. },
  343. // 表单重置
  344. reset() {
  345. this.form = {
  346. postId: undefined,
  347. postCode: undefined,
  348. postName: undefined,
  349. postSort: 0,
  350. status: "0",
  351. remark: undefined,
  352. };
  353. this.resetForm("form");
  354. },
  355. /** 搜索按钮操作 */
  356. handleQuery() {
  357. this.queryParams.pageNum = 1;
  358. this.getList();
  359. },
  360. /** 重置按钮操作 */
  361. resetQuery() {
  362. this.resetForm("queryForm");
  363. this.handleQuery();
  364. },
  365. // 多选框选中数据
  366. handleSelectionChange(selection) {
  367. this.ids = selection.map((item) => item.postId);
  368. this.selection = selection;
  369. this.single = selection.length != 1;
  370. this.multiple = !selection.length;
  371. },
  372. /** 新增按钮操作 */
  373. handleAdd() {
  374. this.reset();
  375. this.open = true;
  376. this.title = "添加岗位";
  377. },
  378. /** 修改按钮操作 */
  379. handleUpdate(row) {
  380. this.reset();
  381. const postId = row.postId || this.ids;
  382. getPost(postId).then((response) => {
  383. this.form = response.data;
  384. this.open = true;
  385. this.title = "修改岗位";
  386. });
  387. },
  388. /** 提交按钮 */
  389. submitForm: function () {
  390. this.$refs["form"].validate((valid) => {
  391. if (valid) {
  392. if (this.form.postId != undefined) {
  393. updatePost(this.form).then((response) => {
  394. this.$modal.msgSuccess("修改成功");
  395. this.open = false;
  396. this.getList();
  397. });
  398. } else {
  399. addPost(this.form).then((response) => {
  400. this.$modal.msgSuccess("新增成功");
  401. this.open = false;
  402. this.getList();
  403. });
  404. }
  405. }
  406. });
  407. },
  408. /** 删除按钮操作 */
  409. handleDelete(row) {
  410. const postIds = row.postId || this.ids;
  411. this.$modal
  412. .confirm('是否确认删除岗位编号为"' + postIds + '"的数据项?')
  413. .then(function () {
  414. return delPost(postIds);
  415. })
  416. .then(() => {
  417. this.getList();
  418. this.$modal.msgSuccess("删除成功");
  419. })
  420. .catch(() => {});
  421. },
  422. /** 导出按钮操作 */
  423. handleExport() {
  424. this.download(
  425. "system/post/export",
  426. {
  427. ...this.queryParams,
  428. },
  429. `post_${new Date().getTime()}.xlsx`
  430. );
  431. },
  432. },
  433. };
  434. </script>