center.js 880 Bytes
Page({
  data: {
    couponsList: []
  },
  toReciveAll() {
    let para = {
      couponIdList: this.data.ids
    }
    wx.p.api.couponsApi.toReciveCard(para).then(res => {
      if (res) {
        wx.p.router.go('/packageMine/pages/coupon/success/success')
      }
    })
  },
  /**获取礼券 */
  getCoupons() {
    let para = {
      discountTypes: [3]
    }
    let ids = []
    wx.p.api.couponsApi.getHomeCardData(para).then(res => {
      res.list.map(item => {
        if (item.effectiveStartTime) {
          item.effectiveStartTime = new Date(item.effectiveStartTime).format('yyyy.MM.dd')
          item.effectiveEndTime = new Date(item.effectiveEndTime).format('yyyy.MM.dd')
        }
        ids.push(item.id)
        return item
      })
      this.setData({
        couponsList: res.list,
        ids
      })
    })
  },
  onLoad() {
    this.getCoupons()
  }
})