index.vue 10 KB

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