index.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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. @click="handleExport"
  77. v-hasPermi="['system:post:export']"
  78. >导出</el-button>
  79. </el-col>
  80. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  81. </el-row>
  82. <el-table v-loading="loading" :data="postList" @selection-change="handleSelectionChange">
  83. <el-table-column type="selection" width="55" align="center" />
  84. <el-table-column label="岗位编号" align="center" prop="postId" />
  85. <el-table-column label="岗位编码" align="center" prop="postCode" />
  86. <el-table-column label="岗位名称" align="center" prop="postName" />
  87. <el-table-column label="岗位排序" align="center" prop="postSort" />
  88. <el-table-column label="状态" align="center" prop="status">
  89. <template slot-scope="scope">
  90. <dict-tag :options="statusOptions" :value="scope.row.status"/>
  91. </template>
  92. </el-table-column>
  93. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  94. <template slot-scope="scope">
  95. <span>{{ parseTime(scope.row.createTime) }}</span>
  96. </template>
  97. </el-table-column>
  98. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  99. <template slot-scope="scope">
  100. <el-button
  101. size="mini"
  102. type="text"
  103. icon="el-icon-edit"
  104. @click="handleUpdate(scope.row)"
  105. v-hasPermi="['system:post:edit']"
  106. >修改</el-button>
  107. <el-button
  108. size="mini"
  109. type="text"
  110. icon="el-icon-delete"
  111. @click="handleDelete(scope.row)"
  112. v-hasPermi="['system:post:remove']"
  113. >删除</el-button>
  114. </template>
  115. </el-table-column>
  116. </el-table>
  117. <pagination
  118. v-show="total>0"
  119. :total="total"
  120. :page.sync="queryParams.pageNum"
  121. :limit.sync="queryParams.pageSize"
  122. @pagination="getList"
  123. />
  124. <!-- 添加或修改岗位对话框 -->
  125. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  126. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  127. <el-form-item label="岗位名称" prop="postName">
  128. <el-input v-model="form.postName" placeholder="请输入岗位名称" />
  129. </el-form-item>
  130. <el-form-item label="岗位编码" prop="postCode">
  131. <el-input v-model="form.postCode" placeholder="请输入编码名称" />
  132. </el-form-item>
  133. <el-form-item label="岗位顺序" prop="postSort">
  134. <el-input-number v-model="form.postSort" controls-position="right" :min="0" />
  135. </el-form-item>
  136. <el-form-item label="岗位状态" prop="status">
  137. <el-radio-group v-model="form.status">
  138. <el-radio
  139. v-for="dict in statusOptions"
  140. :key="dict.dictValue"
  141. :label="dict.dictValue"
  142. >{{dict.dictLabel}}</el-radio>
  143. </el-radio-group>
  144. </el-form-item>
  145. <el-form-item label="备注" prop="remark">
  146. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
  147. </el-form-item>
  148. </el-form>
  149. <div slot="footer" class="dialog-footer">
  150. <el-button type="primary" @click="submitForm">确 定</el-button>
  151. <el-button @click="cancel">取 消</el-button>
  152. </div>
  153. </el-dialog>
  154. </div>
  155. </template>
  156. <script>
  157. import { listPost, getPost, delPost, addPost, updatePost } from "@/api/system/post";
  158. export default {
  159. name: "Post",
  160. data() {
  161. return {
  162. // 遮罩层
  163. loading: true,
  164. // 选中数组
  165. ids: [],
  166. // 非单个禁用
  167. single: true,
  168. // 非多个禁用
  169. multiple: true,
  170. // 显示搜索条件
  171. showSearch: true,
  172. // 总条数
  173. total: 0,
  174. // 岗位表格数据
  175. postList: [],
  176. // 弹出层标题
  177. title: "",
  178. // 是否显示弹出层
  179. open: false,
  180. // 状态数据字典
  181. statusOptions: [],
  182. // 查询参数
  183. queryParams: {
  184. pageNum: 1,
  185. pageSize: 10,
  186. postCode: undefined,
  187. postName: undefined,
  188. status: undefined
  189. },
  190. // 表单参数
  191. form: {},
  192. // 表单校验
  193. rules: {
  194. postName: [
  195. { required: true, message: "岗位名称不能为空", trigger: "blur" }
  196. ],
  197. postCode: [
  198. { required: true, message: "岗位编码不能为空", trigger: "blur" }
  199. ],
  200. postSort: [
  201. { required: true, message: "岗位顺序不能为空", trigger: "blur" }
  202. ]
  203. }
  204. };
  205. },
  206. created() {
  207. this.getList();
  208. this.getDicts("sys_normal_disable").then(response => {
  209. this.statusOptions = response.data;
  210. });
  211. },
  212. methods: {
  213. /** 查询岗位列表 */
  214. getList() {
  215. this.loading = true;
  216. listPost(this.queryParams).then(response => {
  217. this.postList = response.rows;
  218. this.total = response.total;
  219. this.loading = false;
  220. });
  221. },
  222. // 取消按钮
  223. cancel() {
  224. this.open = false;
  225. this.reset();
  226. },
  227. // 表单重置
  228. reset() {
  229. this.form = {
  230. postId: undefined,
  231. postCode: undefined,
  232. postName: undefined,
  233. postSort: 0,
  234. status: "0",
  235. remark: undefined
  236. };
  237. this.resetForm("form");
  238. },
  239. /** 搜索按钮操作 */
  240. handleQuery() {
  241. this.queryParams.pageNum = 1;
  242. this.getList();
  243. },
  244. /** 重置按钮操作 */
  245. resetQuery() {
  246. this.resetForm("queryForm");
  247. this.handleQuery();
  248. },
  249. // 多选框选中数据
  250. handleSelectionChange(selection) {
  251. this.ids = selection.map(item => item.postId)
  252. this.single = selection.length!=1
  253. this.multiple = !selection.length
  254. },
  255. /** 新增按钮操作 */
  256. handleAdd() {
  257. this.reset();
  258. this.open = true;
  259. this.title = "添加岗位";
  260. },
  261. /** 修改按钮操作 */
  262. handleUpdate(row) {
  263. this.reset();
  264. const postId = row.postId || this.ids
  265. getPost(postId).then(response => {
  266. this.form = response.data;
  267. this.open = true;
  268. this.title = "修改岗位";
  269. });
  270. },
  271. /** 提交按钮 */
  272. submitForm: function() {
  273. this.$refs["form"].validate(valid => {
  274. if (valid) {
  275. if (this.form.postId != undefined) {
  276. updatePost(this.form).then(response => {
  277. this.msgSuccess("修改成功");
  278. this.open = false;
  279. this.getList();
  280. });
  281. } else {
  282. addPost(this.form).then(response => {
  283. this.msgSuccess("新增成功");
  284. this.open = false;
  285. this.getList();
  286. });
  287. }
  288. }
  289. });
  290. },
  291. /** 删除按钮操作 */
  292. handleDelete(row) {
  293. const postIds = row.postId || this.ids;
  294. this.$confirm('是否确认删除岗位编号为"' + postIds + '"的数据项?', "警告", {
  295. confirmButtonText: "确定",
  296. cancelButtonText: "取消",
  297. type: "warning"
  298. }).then(function() {
  299. return delPost(postIds);
  300. }).then(() => {
  301. this.getList();
  302. this.msgSuccess("删除成功");
  303. }).catch(() => {});
  304. },
  305. /** 导出按钮操作 */
  306. handleExport() {
  307. this.download('system/post/export', {
  308. ...this.queryParams
  309. }, `post_${new Date().getTime()}.xlsx`)
  310. }
  311. }
  312. };
  313. </script>