fuliqi
2024-01-24 29c1e7eb5ac16e90d8991a86c1c071bc312ec8d9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<!--
/**
* @description 商品详情-优惠券模态框板块
* @author shm
*/
-->
<template>
  <div class="coupon-modal">
    <div class="coupon-list row-between coloum-center mt20 mb20" v-if="couponList.length"
         @click="clickGetBtn">
      <div class="common-txt-color font600 flex1 flex">
        优惠:
        <span class="color_red flex1" v-if="couponList && couponList.length">
          {{ couponList[0].couponName }}
        </span>
      </div>
      <!-- <div class="get-button ml20">领取</div> -->
      <img src="~@/assets/images/goodsDetail/arrows.png" class="common-base-icon ml20" />
    </div>
    <NewModal :visable="modalVis" title="优惠券" @close-modal="CloseModal" class="coupon-modal-content"
              v-if="modalVis">
      <scroll-view scroll-y slot="modal-content" class="modal-content-box">
        <w-coupon type="get" :item="item" v-for="(item, index) in couponList" :key="index"
                  @click-right="reciveCoupon"></w-coupon>
      </scroll-view>
    </NewModal>
  </div>
</template>
 
<script>
import NewModal from '@/components/new-modal/index.vue'
import wCoupon from '@/components/w-coupon/index.vue'
import {
  checkGoodHaveCouponLogin,
  checkGoodHaveCouponUnLogin
} from '@/api/goodsDetail/index.js'
export default {
  name: 'CouponModal',
  components: {
    NewModal,
    wCoupon
  },
  props: {
    visable: {
      type: Boolean,
      default: false
    },
    spuId: {
      type: String,
      default: ''
    },
    list: {
      type: Array,
      default () {
        return []
      }
    }
  },
  created () {
    this.checkIsLogin()
  },
 
  data () {
    return {
      modalVis: this.visable,
      couponList: this.list
    }
  },
  watch: {
    list (newVal) {
      this.couponList = newVal
    }
  },
  methods: {
    // 查看是否登录
    checkIsLogin () {
      if (localStorage.getItem('access_token')) {
        this.getUseCouponByLogin() // 获取商品适用优惠券--已登录
      } else {
        this.getUseCouponUnLogin() // 获取超值优惠券--未登录
      }
    },
    // 点击获取按钮
    clickGetBtn () {
      this.modalVis = !this.modalVis
      if (!this.modalVis) return
      this.checkIsLogin()
    },
    CloseModal () {
      this.modalVis = false
    },
    // 查看此商品可领取的优惠券---已登录
    async getUseCouponByLogin () {
      try {
        const res = await checkGoodHaveCouponLogin({ prodId: this.spuId })
        this.couponList = res.data
        if (this.couponList && this.couponList.length > 0) {
          this.couponList.forEach((item) => {
            item.flag = false
          })
        }
      } catch (e) {
        console.log(e)
        // TODO handle the exception
      }
    },
    // 查看此商品可领取的优惠券---未登录
    async getUseCouponUnLogin () {
      try {
        const res = await checkGoodHaveCouponUnLogin({ shopSpuId: this.shopSpuId })
        this.couponList = res.data
        if (this.couponList && this.couponList.length > 0) {
          this.couponList.forEach((item) => {
            item.flag = false
          })
        }
      } catch (e) {
        console.log(e)
        // TODO handle the exception
      }
    },
    // 点领取 提示下载app
    reciveCoupon () {
      this.$emit('openGuide')
    }
  }
}
</script>
 
<style lang="scss" scoped>
.coupon-modal {
  .coupon-modal-content {
    z-index: 100;
  }
  .modal-content-box {
    max-height: 800px;
    overflow-y: auto;
  }
  .get-button {
    width: 100px;
    height: 50px;
    border-radius: 50px;
    line-height: 50px;
    text-align: center;
    color: #fff;
    background: #eb0f17;
  }
  /deep/.modal-box-open {
    left: 0;
  }
  .common-txt-color {
    color: #333333;
    .color_red {
      font-size: 26px;
      margin-left: 30px;
      font-weight: 400;
      color: #eb0f17;
    }
  }
}
</style>