Blame view

ceres-uniapp-master/components/canvasShow/basics/coupon/mixin.js 2.72 KB
3f535f30   杨鑫   '初始'
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
  import api from '../../config/api'
  import NET from '../../../../utils/request'
  import { funMixin } from '../../config/mixin'
  
  export const commonMixin = {
    name: 'textComponent',
    mixins: [funMixin],
    data () {
      return {
        couponsData: []
      }
    },
    props: {
      terminal: {
        type: Number,
        default: 4
      },
      typeId: {
        type: Number,
        default: 1
      },
      shopId: {
        type: Number,
        default: 0
      },
      componentContent: {
        type: Object
      }
    },
    watch: {
      'componentContent': {
        handler(newVal, oldVal) {
          this.getData()
        },
        deep: true
      }
    },
    created() {
      this.getData()
    },
    methods: {
      getData() {
        const _ = this
        if(_.componentContent.selectedCoupon && _.componentContent.selectedCoupon.length > 0){
          let _url = ''
          if(_.typeId === 1){
            _url =`${api.getCoupons}?page=1&pageSize=99&ids=${_.componentContent.selectedCoupon}`
          } else if(_.typeId === 3) {
            _url =`${api.getShopCoupons}?page=1&pageSize=99&shopId=${_.shopId}&ids=${_.componentContent.selectedCoupon}`
          }
          const params = {
            method: 'GET',
            url: _url,
          }
          this.sendReq(params, (res) => {
            _.couponsData = res.data.list
            if(_.typeId === 1){
              _.couponsData.forEach(item=>{
                item.couponName = item.activityName
                item.effectiveStart = item.activityStartTime
                item.effectiveEnd = item.activityEndTime
              })
            }
            if(JSON.stringify(_.componentContent.couponList) !== JSON.stringify(_.couponsData)){
              _.componentContent.couponList = _.couponsData
            }
          })
        } else {
          _.couponsData = []
        }
      },
      // 领取优惠券
      receiveCoupon(item) {
        const res = uni.getStorageSync('storage_key');
        const token = res.token
        if (token) {
          var paramsData = {}
          if(this.typeId === 1){
            paramsData.couponId = item.couponId
          } else if(this.typeId === 3) {
            paramsData.shopCouponId = item.shopCouponId
            paramsData.shopId = this.shopId
          }
          NET.request(api.takeCoupon, paramsData, 'POST').then(res => {
            this.getData()
            uni.showToast({
              title:'领取成功',
              icon:"success"
            })
          }).catch(res => {
            if(res.data.code !== '200'){
              uni.showToast({
                title:res.data.message,
                icon:"none"
              })
            }
          })
        } else {
          uni.showToast({
            title:'请先登录',
            icon:"none"
          })
          uni.navigateTo({
            url:'/pages_category_page2/userModule/login'
          })
        }
      }
    }
  }