You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.8 KiB

  1. <template>
  2. <view class="coupon-list">
  3. <CouponItem
  4. v-for="(item,index) in couponData"
  5. :key="index"
  6. :couponData="item"
  7. @coupon-received="handleCouponReceived"
  8. @update-coupon="updateCouponData"
  9. @show-rule="showRulePopup"
  10. />
  11. <!-- 优惠券详细规则弹窗组件 -->
  12. <CouponRulePopup ref="couponRulePopup" />
  13. </view>
  14. </template>
  15. <script>
  16. import {
  17. getCouponList,
  18. } from "@/api/system/user"
  19. import CouponRulePopup from '@/components/CouponRulePopup/index.vue'
  20. import CouponItem from '@/components/CouponItem/index.vue'
  21. export default {
  22. components: {
  23. CouponRulePopup,
  24. CouponItem
  25. },
  26. data() {
  27. return {
  28. couponData: []
  29. }
  30. },
  31. onLoad() {
  32. // this.openIdStr = this.$globalData.openIdStr;
  33. this.getCouponListAuth()
  34. },
  35. methods: {
  36. getCouponListAuth() {
  37. getCouponList().then(res => {
  38. if (res.code == 200) {
  39. this.couponData = res.data
  40. console.log("this.couponData", this.couponData)
  41. } else {
  42. this.$modal.showToast('获取优惠券失败')
  43. }
  44. })
  45. },
  46. // 显示优惠券规则弹窗
  47. showRulePopup(item) {
  48. this.$refs.couponRulePopup.open(item || {});
  49. },
  50. // 处理优惠券领取成功事件
  51. handleCouponReceived(couponData) {
  52. console.log('优惠券领取成功:', couponData);
  53. // 可以在这里处理一些额外的逻辑,比如刷新列表等
  54. },
  55. // 更新优惠券数据
  56. updateCouponData(updatedCoupon) {
  57. // 找到对应的优惠券并更新数据
  58. const couponIndex = this.couponData.findIndex(item => item.id === updatedCoupon.id);
  59. if (couponIndex !== -1) {
  60. // 使用Vue.set或者$set来确保响应式更新
  61. this.$set(this.couponData, couponIndex, updatedCoupon);
  62. }
  63. }
  64. }
  65. }
  66. </script>
  67. <style lang="scss">
  68. .coupon-list {
  69. // 优惠券列表容器样式
  70. }
  71. </style>