index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="岗位编码" prop="postCode">
  5. <el-input
  6. v-model="queryParams.postCode"
  7. placeholder="请输入岗位编码"
  8. clearable
  9. size="small"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item label="岗位名称" prop="postName">
  14. <el-input
  15. v-model="queryParams.postName"
  16. placeholder="请输入岗位名称"
  17. clearable
  18. size="small"
  19. @keyup.enter.native="handleQuery"
  20. />
  21. </el-form-item>
  22. <el-form-item label="状态" prop="status">
  23. <el-select v-model="queryParams.status" placeholder="岗位状态" clearable size="small">
  24. <el-option
  25. v-for="dict in statusOptions"
  26. :key="dict.dictValue"
  27. :label="dict.dictLabel"
  28. :value="dict.dictValue"
  29. />
  30. </el-select>
  31. </el-form-item>
  32. <el-form-item>
  33. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  34. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  35. </el-form-item>
  36. </el-form>
  37. <el-row :gutter="10" class="mb8">
  38. <el-col :span="1.5">
  39. <el-button
  40. type="primary"
  41. plain
  42. icon="el-icon-plus"
  43. size="mini"
  44. @click="handleAdd"
  45. v-hasPermi="['system:post:add']"
  46. >新增</el-button>
  47. </el-col>
  48. <el-col :span="1.5">
  49. <el-button
  50. type="success"
  51. plain
  52. icon="el-icon-edit"
  53. size="mini"
  54. :disabled="single"
  55. @click="handleUpdate"
  56. v-hasPermi="['system:post:edit']"
  57. >修改</el-button>
  58. </el-col>
  59. <el-col :span="1.5">
  60. <el-button
  61. type="danger"
  62. plain
  63. icon="el-icon-delete"
  64. size="mini"
  65. :disabled="multiple"
  66. @click="handleDelete"
  67. v-hasPermi="['system:post:remove']"
  68. >删除</el-button>
  69. </el-col>
  70. <el-col :span="1.5">
  71. <el-button
  72. type="warning"
  73. plain
  74. icon="el-icon-download"
  75. size="mini"
  76. :loading="exportLoading"
  77. @click="handleExport"
  78. v-hasPermi="['system:post:export']"
  79. >导出</el-button>
  80. </el-col>
  81. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  82. </el-row>
  83. <el-table v-loading="loading" :data="postList" @selection-change="handleSelectionChange">
  84. <el-table-column type="selection" width="55" align="center" />
  85. <el-table-column label="岗位编号" align="center" prop="postId" />
  86. <el-table-column label="岗位编码" align="center" prop="postCode" />
  87. <el-table-column label="岗位名称" align="center" prop="postName" />
  88. <el-table-column label="岗位排序" align="center" prop="postSort" />
  89. <el-table-column label="状态" align="center" prop="status">
  90. <template slot-scope="scope">
  91. <dict-tag :options="statusOptions" :value="scope.row.status"/>
  92. </template>
  93. </el-table-column>
  94. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  95. <template slot-scope="scope">
  96. <span>{{ parseTime(scope.row.createTime) }}</span>
  97. </template>
  98. </el-table-column>
  99. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  100. <template slot-scope="scope">
  101. <el-button
  102. size="mini"
  103. type="text"
  104. icon="el-icon-edit"
  105. @click="handleUpdate(scope.row)"
  106. v-hasPermi="['system:post:edit']"
  107. >修改</el-button>
  108. <el-button
  109. size="mini"
  110. type="text"
  111. icon="el-icon-delete"
  112. @click="handleDelete(scope.row)"
  113. v-hasPermi="['system:post:remove']"
  114. >删除</el-button>
  115. </template>
  116. </el-table-column>
  117. </el-table>
  118. <pagination
  119. v-show="total>0"
  120. :total="total"
  121. :page.sync="queryParams.pageNum"
  122. :limit.sync="queryParams.pageSize"
  123. @pagination="getList"
  124. />
  125. <!-- 添加或修改岗位对话框 -->
  126. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  127. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  128. <el-form-item label="岗位名称" prop="postName">
  129. <el-input v-model="form.postName" placeholder="请输入岗位名称" />
  130. </el-form-item>
  131. <el-form-item label="岗位编码" prop="postCode">
  132. <el-input v-model="form.postCode" placeholder="请输入编码名称" />
  133. </el-form-item>
  134. <el-form-item label="岗位顺序" prop="postSort">
  135. <el-input-number v-model="form.postSort" controls-position="right" :min="0" />
  136. </el-form-item>
  137. <el-form-item label="岗位状态" prop="status">
  138. <el-radio-group v-model="form.status">
  139. <el-radio
  140. v-for="dict in statusOptions"
  141. :key="dict.dictValue"
  142. :label="dict.dictValue"
  143. >{{dict.dictLabel}}</el-radio>
  144. </el-radio-group>
  145. </el-form-item>
  146. <el-form-item label="备注" prop="remark">
  147. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
  148. </el-form-item>
  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 { listPost, getPost, delPost, addPost, updatePost, exportPost } from "@/api/system/post";
  159. export default {
  160. name: "Post",
  161. data() {
  162. return {
  163. // 遮罩层
  164. loading: true,
  165. // 导出遮罩层
  166. exportLoading: false,
  167. // 选中数组
  168. ids: [],
  169. // 非单个禁用
  170. single: true,
  171. // 非多个禁用
  172. multiple: true,
  173. // 显示搜索条件
  174. showSearch: true,
  175. // 总条数
  176. total: 0,
  177. // 岗位表格数据
  178. postList: [],
  179. // 弹出层标题
  180. title: "",
  181. // 是否显示弹出层
  182. open: false,
  183. // 状态数据字典
  184. statusOptions: [],
  185. // 查询参数
  186. queryParams: {
  187. pageNum: 1,
  188. pageSize: 10,
  189. postCode: undefined,
  190. postName: undefined,
  191. status: undefined
  192. },
  193. // 表单参数
  194. form: {},
  195. // 表单校验
  196. rules: {
  197. postName: [
  198. { required: true, message: "岗位名称不能为空", trigger: "blur" }
  199. ],
  200. postCode: [
  201. { required: true, message: "岗位编码不能为空", trigger: "blur" }
  202. ],
  203. postSort: [
  204. { required: true, message: "岗位顺序不能为空", trigger: "blur" }
  205. ]
  206. }
  207. };
  208. },
  209. created() {
  210. this.getList();
  211. this.getDicts("sys_normal_disable").then(response => {
  212. this.statusOptions = response.data;
  213. });
  214. },
  215. methods: {
  216. /** 查询岗位列表 */
  217. getList() {
  218. this.loading = true;
  219. listPost(this.queryParams).then(response => {
  220. this.postList = response.rows;
  221. this.total = response.total;
  222. this.loading = false;
  223. });
  224. },
  225. // 取消按钮
  226. cancel() {
  227. this.open = false;
  228. this.reset();
  229. },
  230. // 表单重置
  231. reset() {
  232. this.form = {
  233. postId: undefined,
  234. postCode: undefined,
  235. postName: undefined,
  236. postSort: 0,
  237. status: "0",
  238. remark: undefined
  239. };
  240. this.resetForm("form");
  241. },
  242. /** 搜索按钮操作 */
  243. handleQuery() {
  244. this.queryParams.pageNum = 1;
  245. this.getList();
  246. },
  247. /** 重置按钮操作 */
  248. resetQuery() {
  249. this.resetForm("queryForm");
  250. this.handleQuery();
  251. },
  252. // 多选框选中数据
  253. handleSelectionChange(selection) {
  254. this.ids = selection.map(item => item.postId)
  255. this.single = selection.length!=1
  256. this.multiple = !selection.length
  257. },
  258. /** 新增按钮操作 */
  259. handleAdd() {
  260. this.reset();
  261. this.open = true;
  262. this.title = "添加岗位";
  263. },
  264. /** 修改按钮操作 */
  265. handleUpdate(row) {
  266. this.reset();
  267. const postId = row.postId || this.ids
  268. getPost(postId).then(response => {
  269. this.form = response.data;
  270. this.open = true;
  271. this.title = "修改岗位";
  272. });
  273. },
  274. /** 提交按钮 */
  275. submitForm: function() {
  276. this.$refs["form"].validate(valid => {
  277. if (valid) {
  278. if (this.form.postId != undefined) {
  279. updatePost(this.form).then(response => {
  280. this.msgSuccess("修改成功");
  281. this.open = false;
  282. this.getList();
  283. });
  284. } else {
  285. addPost(this.form).then(response => {
  286. this.msgSuccess("新增成功");
  287. this.open = false;
  288. this.getList();
  289. });
  290. }
  291. }
  292. });
  293. },
  294. /** 删除按钮操作 */
  295. handleDelete(row) {
  296. const postIds = row.postId || this.ids;
  297. this.$confirm('是否确认删除岗位编号为"' + postIds + '"的数据项?', "警告", {
  298. confirmButtonText: "确定",
  299. cancelButtonText: "取消",
  300. type: "warning"
  301. }).then(function() {
  302. return delPost(postIds);
  303. }).then(() => {
  304. this.getList();
  305. this.msgSuccess("删除成功");
  306. }).catch(() => {});
  307. },
  308. /** 导出按钮操作 */
  309. handleExport() {
  310. const queryParams = this.queryParams;
  311. this.$confirm('是否确认导出所有岗位数据项?', "警告", {
  312. confirmButtonText: "确定",
  313. cancelButtonText: "取消",
  314. type: "warning"
  315. }).then(() => {
  316. this.exportLoading = true;
  317. return exportPost(queryParams);
  318. }).then(response => {
  319. this.download(response.msg);
  320. this.exportLoading = false;
  321. }).catch(() => {});
  322. }
  323. }
  324. };
  325. </script>