index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <div class="app-container coupon-list">
  3. <el-form v-show="showSearch" :model="queryParams" ref="queryForm" :inline="true" size="small">
  4. <el-form-item label="券名称">
  5. <el-input
  6. v-model="queryParams.title"
  7. placeholder="请输入券名称"
  8. clearable
  9. @keyup.enter.native="queryParams.pageNum = 1;getList()"
  10. />
  11. </el-form-item>
  12. <el-form-item label="使用场景">
  13. <el-select v-model="queryParams.type" placeholder="请选择券状态" clearable @change="queryParams.pageNum = 1;getList()">
  14. <el-option label="全部" value="" />
  15. <el-option label="盲票购买" :value="1" />
  16. <el-option label="门店消费" :value="2" />
  17. </el-select>
  18. </el-form-item>
  19. <el-form-item label="状态">
  20. <el-select v-model="queryParams.status" placeholder="请选择券状态" clearable @change="queryParams.pageNum = 1;getList()">
  21. <el-option label="全部" value="" />
  22. <el-option label="待上架" value="init" />
  23. <el-option label="已上架" value="on" />
  24. <el-option label="已下架" value="off" />
  25. </el-select>
  26. </el-form-item>
  27. <el-form-item>
  28. <el-button type="primary" icon="el-icon-search" @click="queryParams.pageNum = 1;getList()">搜索</el-button>
  29. <el-button icon="el-icon-refresh" @click="getList(true)">重置</el-button>
  30. </el-form-item>
  31. </el-form>
  32. <el-row :gutter="10" class="mb8">
  33. <el-col :span="10">
  34. <el-button
  35. type="primary"
  36. icon="el-icon-plus"
  37. size="mini"
  38. @click="$router.push('/coupon/add')"
  39. v-hasPermi="['business:coupon:add']"
  40. >生成优惠券</el-button>
  41. </el-col>
  42. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  43. </el-row>
  44. <el-table v-loading="loading" :data="tableData">
  45. <el-table-column label="券ID" prop="couponId" width="80" />
  46. <el-table-column label="券名称" prop="title" />
  47. <el-table-column label="券金额" prop="discount">
  48. <template slot-scope="{row}">
  49. ¥{{$numberFormat(row.discount)}}
  50. </template>
  51. </el-table-column>
  52. <el-table-column label="使用场景" prop="type">
  53. <template slot-scope="{row}">
  54. {{ JSON.parse(row.type).desc }}
  55. </template>
  56. </el-table-column>
  57. <el-table-column label="已领取数量" prop="distributeQty" />
  58. <el-table-column label="有效期限(天)" prop="dueDays">
  59. <template slot-scope="{row}">
  60. 领取后{{ row.dueDays }}天内有效
  61. </template>
  62. </el-table-column>
  63. <el-table-column label="状态" prop="status">
  64. <template slot-scope="{row}">
  65. <el-tag :type="JSON.parse(row.status).value === 'on' ? 'success' : 'info'">{{ JSON.parse(row.status).desc }}</el-tag>
  66. </template>
  67. </el-table-column>
  68. <el-table-column fixed="right" align="right" label="操作" width="150">
  69. <template slot-scope="{row}">
  70. <el-button v-hasPermi="['business:coupon:query']" type="text" @click="$router.push('/coupon/view?id=' + row.couponId)">查看</el-button>
  71. <el-button v-if="JSON.parse(row.status).value === 'init'" v-hasPermi="['business:coupon:edit']" type="text" @click="$router.push('/coupon/edit?id=' + row.couponId)">编辑</el-button>
  72. <el-button v-if="JSON.parse(row.status).value === 'off' || JSON.parse(row.status).value === 'init'" v-hasPermi="['business:coupon:on']" type="text" @click="setStatus(row, 'on')">上架</el-button>
  73. <el-button v-if="JSON.parse(row.status).value === 'on'" v-hasPermi="['business:coupon:off']" type="text" @click="setStatus(row, 'off')">下架</el-button>
  74. <el-button v-if="JSON.parse(row.status).value === 'init'" v-hasPermi="['business:coupon:remove']" class="del" type="text" @click="del(row)">删除</el-button>
  75. </template>
  76. </el-table-column>
  77. </el-table>
  78. <pagination :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList()" />
  79. </div>
  80. </template>
  81. <script>
  82. import { getCouponList, delCoupon, setCouponStatus } from '@/api/business/coupon'
  83. import { accDiv } from '@/utils/util'
  84. export default {
  85. name: 'CouponList',
  86. data() {
  87. return {
  88. loading: false,
  89. showSearch: true,
  90. tableData: [],
  91. queryParams: {},
  92. total: 0
  93. }
  94. },
  95. created() {
  96. this.getList(true)
  97. },
  98. methods: {
  99. getList(reset) {
  100. if (this.loading) {
  101. return
  102. }
  103. this.loading = true
  104. if (reset) {
  105. this.queryParams = { pageNum: 1, pageSize: 20 }
  106. }
  107. getCouponList('pageNum='+this.queryParams.pageNum + '&pageSize='+this.queryParams.pageSize+'&', this.queryParams).then(res => {
  108. this.loading = false
  109. if (res.code === 0) {
  110. this.tableData = res.rows
  111. this.total = res.total
  112. }
  113. }).catch(() => {
  114. this.loading = false
  115. })
  116. },
  117. setStatus(item, status) {
  118. this.$confirm(`确认${status === 'on' ? '上架' : '下架'}券 “${item.title}” 吗?`, `${status === 'on' ? '上架' : '下架'}券`, {
  119. confirmButtonText: '确定',
  120. cancelButtonText: '取消',
  121. type: 'warning'
  122. }).then(() => {
  123. setCouponStatus({
  124. couponId: item.couponId,
  125. status
  126. }).then(res => {
  127. if (res.code === 0) {
  128. this.$message.success('操作已完成!')
  129. this.getList()
  130. }
  131. })
  132. })
  133. },
  134. del(item) {
  135. this.$confirm(`确认删除券 “${item.title}” 吗?`, '删除券', {
  136. confirmButtonText: '确定',
  137. cancelButtonText: '取消',
  138. type: 'warning'
  139. }).then(() => {
  140. delCoupon(item.couponId).then(res => {
  141. if (res.code === 0) {
  142. this.$message.success('操作已完成!')
  143. this.getList()
  144. }
  145. })
  146. })
  147. }
  148. }
  149. }
  150. </script>