coupon-select.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <div class="product-select">
  3. <el-form :inline="true" :model="formData" class="demo-form-inline">
  4. <el-form-item label="">
  5. <el-input v-model="formData.keyword" maxlength="20" placeholder="请输入优惠券名称"></el-input>
  6. </el-form-item>
  7. <el-form-item>
  8. <el-button type="primary" @click="onSubmit">查询</el-button>
  9. </el-form-item>
  10. </el-form>
  11. <el-table
  12. :data="tableData"
  13. max-height="500"
  14. border
  15. style="width: 100%"
  16. ref="couponTable"
  17. row-key="productId"
  18. @selection-change="handleSelectionChange"
  19. >
  20. <el-table-column
  21. width="40"
  22. type="selection"
  23. :reserve-selection="true"
  24. fixed="left"
  25. >
  26. </el-table-column>
  27. <el-table-column
  28. prop="couponName"
  29. label="优惠券名称"
  30. width="180">
  31. </el-table-column>
  32. <el-table-column
  33. prop="content"
  34. label="内容">
  35. </el-table-column>
  36. <el-table-column
  37. prop="effectiveStart"
  38. label="活动开始时间">
  39. </el-table-column>
  40. <el-table-column
  41. prop="effectiveEnd"
  42. label="活动结束时间">
  43. </el-table-column>
  44. </el-table>
  45. <el-pagination
  46. @size-change="handleSizeChange"
  47. @current-change="handleCurrentChange"
  48. :current-page="currentPage"
  49. :hide-on-single-page="true"
  50. :page-sizes="[10, 20, 50, 100]"
  51. :page-size="pageSize"
  52. layout="total, sizes, prev, pager, next, jumper"
  53. :total="total">
  54. </el-pagination>
  55. </div>
  56. </template>
  57. <script>
  58. import api from '@@/components/canvasShow/config/api'
  59. import {sendReqMixin} from '@@/components/canvasShow/config/mixin'
  60. import Cookies from 'js-cookie'
  61. import { mapGetters } from 'vuex'
  62. export default {
  63. name: 'coupon-select',
  64. mixins: [sendReqMixin],
  65. data () {
  66. return {
  67. tableRadio: '',
  68. formData: {
  69. keyword: ''
  70. },
  71. currentPage: 1,
  72. total: 0,
  73. pageSize: 10,
  74. multipleSelection: [],
  75. tableData: [{
  76. id: 100,
  77. name: '测试'
  78. }]
  79. }
  80. },
  81. mounted () {
  82. this.getTableData()
  83. },
  84. computed: {
  85. ...mapGetters([
  86. 'typeId'
  87. ])
  88. },
  89. methods: {
  90. // 获取优惠券
  91. getTableData () {
  92. var _this = this
  93. let _url = ''
  94. if(this.typeId===1){
  95. _url = `${api.getCoupons}?page=${this.currentPage}&pageSize=${this.pageSize}`
  96. } else if(this.typeId===3){
  97. _url = `${api.getShopCoupons}?page=${this.currentPage}&pageSize=${this.pageSize}&shopId=${Cookies.get('shopID')}`
  98. }
  99. if (this.formData.keyword) {
  100. _url += `&search=${this.formData.keyword}`
  101. }
  102. let params = {
  103. url: _url,
  104. method: 'GET'
  105. }
  106. this.sendReq(params, (res) => {
  107. _this.tableData = res.data.list
  108. if(this.typeId===1){
  109. _this.tableData.map(function(value){
  110. value.couponName = value.activityName
  111. value.effectiveStart = value.activityStartTime
  112. value.effectiveEnd = value.activityEndTime
  113. return value;
  114. });
  115. }
  116. _this.total = res.data.total
  117. })
  118. },
  119. // 搜索
  120. onSubmit () {
  121. this.getTableData()
  122. },
  123. // 每页条数改变
  124. handleSizeChange (val) {
  125. this.pageSize = val
  126. this.getTableData()
  127. },
  128. // 当前页改变
  129. handleCurrentChange (val) {
  130. this.currentPage = val
  131. this.getTableData()
  132. },
  133. // 多选改变
  134. handleSelectionChange (val) {
  135. this.multipleSelection = val
  136. },
  137. // 多选改变
  138. resetTableData (list) {
  139. this.$refs.couponTable.clearSelection();
  140. this.$refs.couponTable.toggleRowSelection(list,true);
  141. }
  142. }
  143. }
  144. </script>
  145. <style lang="scss" scoped>
  146. .product-select{
  147. .el-pagination{
  148. padding: 0px;
  149. margin-top: 30px;
  150. }
  151. .el-table{
  152. .img{
  153. width: 80px;
  154. height: 80px;
  155. }
  156. }
  157. }
  158. </style>