coupon_center.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <template>
  2. <view class="dt-page">
  3. <template v-if="emptyType==0">
  4. <view class="voucher-list">
  5. <view v-for="(item, idx) in dataList" :key="idx" class="voucher">
  6. <DtCoupon :dataDetail="item"
  7. @visible="onVisible($event,idx)" @receive="onRecieve" @use="onUse" />
  8. </view>
  9. </view>
  10. <FootToolbar bgColor="#fff">
  11. <view slot="main" class="btn-voucher-wrap">
  12. <button @tap="tapToMineCoupon" class="dt-btn-submit btn-voucher">查看我的优惠券</button>
  13. </view>
  14. </FootToolbar>
  15. </template>
  16. <DtEmpty :type="emptyType" :tips="errMsg"/>
  17. </view>
  18. </template>
  19. <script>
  20. import DtCoupon from '../comps/dt_coupon.vue'
  21. import FootToolbar from '../comps/foot_toolbar.vue'
  22. import DtEmpty from '../comps/dt_empty.vue'
  23. export default {
  24. components:{
  25. DtCoupon,
  26. FootToolbar,
  27. DtEmpty
  28. },
  29. data () {
  30. return {
  31. sourceList:[],
  32. dataList: [
  33. // {
  34. // isReceive:1,
  35. // voucher_type:1,
  36. // status:1,
  37. // },{
  38. // isReceive:0,
  39. // voucher_type:2,
  40. // status:1,
  41. // },{
  42. // isReceive:1,
  43. // voucher_type:1,
  44. // status:2,
  45. // }
  46. ],
  47. memberId:''
  48. }
  49. },
  50. methods:{
  51. //查看详情
  52. onVisible(ev, idx) {
  53. let dataList = this.dataList.slice(0)
  54. dataList[idx].isShowDetail = !dataList[idx].isShowDetail
  55. this.$set(this, 'dataList', dataList)
  56. },
  57. // 领取优惠券
  58. async onRecieve(item){
  59. console.log('get Voucher',item)
  60. let resp = await this.$api.couponExchange({
  61. memberId: this.memberId,
  62. couponId: item.id
  63. })
  64. if(resp.result){
  65. this.$dialog.success('领取成功')
  66. this.queryDataList()
  67. }else{
  68. this.$dialog.error('领取失败')
  69. }
  70. },
  71. onUse(){
  72. uni.navigateBack({ delta: 1 })
  73. },
  74. tapToMineCoupon(){
  75. uni.navigateTo({
  76. url:'/pagesM/pages/coupon_list'
  77. })
  78. },
  79. async queryDataList(){
  80. let resp = await this.$api.getCouponByStoreId({
  81. _isShowLoading:true,
  82. memberId:this.memberId
  83. })
  84. let list = resp || []
  85. list = list.slice(0,3)
  86. if(this.isLogin){
  87. list = list.filter((item)=>{
  88. return !item.isReceive
  89. })
  90. }else{// 未登录全部显示未领取
  91. list.map((item)=>{
  92. item.isReceive = false
  93. return item
  94. })
  95. }
  96. if(list.length>0){
  97. this.emptyType = 0
  98. }else{
  99. this.emptyType = 1
  100. this.errMsg = '已领取全部优惠券'
  101. }
  102. this.dataList.length = 0
  103. this.dataList = this.dataList.concat(list)
  104. },
  105. onLoadPage(){
  106. wx.hideShareMenu();
  107. this.isLogin = this.$auth.isAuth
  108. this.memberId = this.$auth.getMemberId()
  109. this.queryDataList()
  110. }
  111. },
  112. }
  113. </script>
  114. <style lang="scss" scoped>
  115. .dt-page{
  116. min-height:100vh;
  117. background-color:#f2f2f2;
  118. .voucher-list {
  119. position: relative;
  120. display: flex;
  121. flex-direction: column;
  122. border-radius: 10upx;
  123. padding-top:30upx;
  124. margin:0 30upx;
  125. .voucher{
  126. margin-bottom:30upx;
  127. }
  128. }
  129. .btn-voucher-wrap{
  130. display:flex;
  131. justify-content: center;
  132. align-items: center;
  133. width:100vw;
  134. height:110upx;
  135. background-color:#fff;
  136. .btn-voucher{
  137. width:690upx;
  138. height:80upx;
  139. line-height:80upx;
  140. color:#fff;
  141. background-color:$dt-color-primary;
  142. font-size: 30upx;
  143. }
  144. }
  145. }
  146. </style>