index.vue 9.5 KB

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