Blame view

pc-master/src/components/canvasShow/basics/coupon/mixin.js 1.52 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
  import {
    getCoupons,
    getShopCoupons
  } from '../../config/api'
  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: {
      async getData() {
        const _ = this
        if(_.componentContent.selectedCoupon && _.componentContent.selectedCoupon.length > 0){
          let params = {
            page: 1,
            pageSize: 99,
            ids: `${this.componentContent.selectedCoupon}`
          }
          if(this.typeId === 1){
            const response = await getCoupons(params)
            this.successCallback(response.data)
          } else if(this.typeId === 3) {
            params.shopId = this.shopId
            const response = await getShopCoupons(params)
            this.successCallback(response.data)
          }
        } else {
          this.couponsData = []
        }
      },
      successCallback(res) {
        this.couponsData = res.data.list
        if(JSON.stringify(this.componentContent.couponList) !== JSON.stringify(this.couponsData)){
          this.componentContent.couponList = this.couponsData
        }
      }
    }
  }