index.vue 9.7 KB

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