index.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="98px">
  4. <el-form-item label="票务规则名称" prop="ticketRules">
  5. <el-input
  6. v-model="queryParams.ticketRules"
  7. placeholder="请输入票务规则名称"
  8. clearable
  9. @keyup.enter.native="handleQuery"
  10. />
  11. </el-form-item>
  12. <el-form-item>
  13. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  14. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  15. </el-form-item>
  16. </el-form>
  17. <el-row :gutter="10" class="mb8">
  18. <el-col :span="1.5">
  19. <el-button
  20. type="primary"
  21. plain
  22. icon="el-icon-plus"
  23. size="mini"
  24. @click="handleAdd"
  25. >新增
  26. </el-button>
  27. </el-col>
  28. <el-col :span="1.5">
  29. <el-button
  30. type="success"
  31. plain
  32. icon="el-icon-edit"
  33. size="mini"
  34. :disabled="single"
  35. @click="handleUpdate"
  36. >修改
  37. </el-button>
  38. </el-col>
  39. <el-col :span="1.5">
  40. <el-button
  41. type="danger"
  42. plain
  43. icon="el-icon-delete"
  44. size="mini"
  45. :disabled="multiple"
  46. @click="handleDelete"
  47. >删除
  48. </el-button>
  49. </el-col>
  50. <el-col :span="1.5">
  51. <el-button
  52. type="warning"
  53. plain
  54. icon="el-icon-download"
  55. size="mini"
  56. @click="handleExport"
  57. >导出
  58. </el-button>
  59. </el-col>
  60. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  61. </el-row>
  62. <el-table v-loading="loading" :data="rulesList" @selection-change="handleSelectionChange">
  63. <el-table-column type="selection" width="55" align="center"/>
  64. <el-table-column label="序号" align="center" type="index"/>
  65. <el-table-column label="票务规则名称" align="center" prop="ticketRules"/>
  66. <el-table-column label="票种名称" align="center" prop="ticketName"/>
  67. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  68. <template slot-scope="scope">
  69. <el-button
  70. size="mini"
  71. type="text"
  72. icon="el-icon-edit"
  73. @click="handleUpdate(scope.row)"
  74. >修改
  75. </el-button>
  76. <el-button
  77. size="mini"
  78. type="text"
  79. icon="el-icon-delete"
  80. @click="handleDelete(scope.row)"
  81. >删除
  82. </el-button>
  83. </template>
  84. </el-table-column>
  85. </el-table>
  86. <pagination
  87. v-show="total>0"
  88. :total="total"
  89. :page.sync="queryParams.pageNum"
  90. :limit.sync="queryParams.pageSize"
  91. @pagination="getList"
  92. />
  93. <!-- 添加或修改票种规则对话框 -->
  94. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  95. <el-form ref="form" :model="form" :rules="rules" label-width="120px">
  96. <el-form-item label="票务规则名称" prop="ticketRules">
  97. <el-input v-model="form.ticketRules" placeholder="请输入票务规则名称"/>
  98. </el-form-item>
  99. <el-form-item label="票种名称" prop="ticketList">
  100. <el-select v-model="form.ticketList" multiple placeholder="请选择票种名称" style="width:340px"
  101. @change="onChange"
  102. >
  103. <el-option
  104. v-for="item in ticketList"
  105. :key="item.index"
  106. :label="item.ticketName"
  107. :value="item.id"
  108. ></el-option>
  109. </el-select>
  110. </el-form-item>
  111. </el-form>
  112. <div slot="footer" class="dialog-footer">
  113. <el-button type="primary" @click="submitForm">确 定</el-button>
  114. <el-button @click="cancel">取 消</el-button>
  115. </div>
  116. </el-dialog>
  117. </div>
  118. </template>
  119. <script>
  120. import {listRules, getRules, delRules, addRules, updateRules} from "@/api/system/ticketRules";
  121. import {ticketAllList} from "@/api/system/ticket";
  122. export default {
  123. name: "Rules",
  124. data() {
  125. return {
  126. // 遮罩层
  127. loading: true,
  128. // 选中数组
  129. ids: [],
  130. // 非单个禁用
  131. single: true,
  132. // 非多个禁用
  133. multiple: true,
  134. // 显示搜索条件
  135. showSearch: true,
  136. // 总条数
  137. total: 0,
  138. // 票种规则表格数据
  139. rulesList: [],
  140. // 票种数据
  141. ticketList: [],
  142. // 票种存储数据
  143. tickets: [],
  144. // 弹出层标题
  145. title: "",
  146. // 是否显示弹出层
  147. open: false,
  148. // 查询参数
  149. queryParams: {
  150. pageNum: 1,
  151. pageSize: 10,
  152. ticketRules: null
  153. },
  154. // 表单参数
  155. form: {},
  156. // 表单校验
  157. rules: {
  158. ticketRules: [
  159. { required: true, message: "票务规则名称不能为空", trigger: "blur" },
  160. ],
  161. ticketList: [
  162. { required: true, message: "票种名称不能为空", trigger: "blur" },
  163. ],
  164. }
  165. };
  166. },
  167. created() {
  168. this.getList();
  169. this.getTicketList();
  170. },
  171. methods: {
  172. onChange(e) {
  173. this.form.tickets = this.ticketList.filter((item) =>
  174. e.includes(item.id)
  175. )
  176. },
  177. /** 查询票种全部列表 */
  178. getTicketList() {
  179. this.loading = true;
  180. ticketAllList().then(response => {
  181. this.ticketList = response.data;
  182. this.loading = false;
  183. });
  184. },
  185. /** 查询票种规则列表 */
  186. getList() {
  187. this.loading = true;
  188. listRules(this.queryParams).then(response => {
  189. this.rulesList = response.rows;
  190. this.total = response.total;
  191. this.loading = false;
  192. });
  193. },
  194. // 取消按钮
  195. cancel() {
  196. this.open = false;
  197. this.reset();
  198. },
  199. // 表单重置
  200. reset() {
  201. this.form = {
  202. id: null,
  203. ticketRules: null
  204. };
  205. this.resetForm("form");
  206. },
  207. /** 搜索按钮操作 */
  208. handleQuery() {
  209. this.queryParams.pageNum = 1;
  210. this.getList();
  211. },
  212. /** 重置按钮操作 */
  213. resetQuery() {
  214. this.resetForm("queryForm");
  215. this.handleQuery();
  216. },
  217. // 多选框选中数据
  218. handleSelectionChange(selection) {
  219. this.ids = selection.map(item => item.id)
  220. this.single = selection.length !== 1
  221. this.multiple = !selection.length
  222. },
  223. /** 新增按钮操作 */
  224. handleAdd() {
  225. this.reset();
  226. this.open = true;
  227. this.title = "添加票种规则";
  228. },
  229. /** 修改按钮操作 */
  230. handleUpdate(row) {
  231. this.reset();
  232. const id = row.id || this.ids
  233. getRules(id).then(response => {
  234. this.form = response.data;
  235. this.open = true;
  236. this.title = "修改票种规则";
  237. });
  238. },
  239. /** 提交按钮 */
  240. submitForm() {
  241. this.$refs["form"].validate(valid => {
  242. if (valid) {
  243. if (this.form.id != null) {
  244. updateRules(this.form).then(response => {
  245. this.$modal.msgSuccess("修改成功");
  246. this.open = false;
  247. this.getList();
  248. });
  249. } else {
  250. addRules(this.form).then(response => {
  251. this.$modal.msgSuccess("新增成功");
  252. this.open = false;
  253. this.getList();
  254. });
  255. }
  256. }
  257. });
  258. },
  259. /** 删除按钮操作 */
  260. handleDelete(row) {
  261. const ids = row.id || this.ids;
  262. this.$modal.confirm('是否确认删除票种规则编号为"' + ids + '"的数据项?').then(function () {
  263. return delRules(ids);
  264. }).then(() => {
  265. this.getList();
  266. this.$modal.msgSuccess("删除成功");
  267. }).catch(() => {
  268. });
  269. },
  270. /** 导出按钮操作 */
  271. handleExport() {
  272. this.download('system/rules/export', {
  273. ...this.queryParams
  274. }, `rules_${new Date().getTime()}.xlsx`)
  275. }
  276. }
  277. };
  278. </script>