import {getOpenCouponParams} from '../server/api'
const app = getApp();
const globalData = app.globalData;
Component({
  options: {
    styleIsolation: 'isolated'
  },
  properties: {
    couponItem: {
      type: Object,
      value: {}
    }
  },
  data: {},
  methods: {
    async bindGoCouponDetail(e) { // 跳转到券详情
      const info = e.currentTarget.dataset.info
      console.log('点击某张券', info)

      const data = {
        loc_name: wx._hwjShareData.loc_name,
        token: wx._hwjShareData.token,
        openid: wx._hwjShareData.openid,
        stock_list: [{
          stock_id: info.stock_id,
          coupon_code: info.coupon_code
        }],
        requestId:globalData.appOrderNo
      }

      const res = await getOpenCouponParams(data)
      console.log('打开券详情页参数', res)
      if (res && res.card_list) {
        res.card_list.forEach((v) => {
          v.cardId = v.card_id
          v.openCardParams = v.open_params
          delete v.card_id
          delete v.open_params
        })
        wx.openCard({
          cardList: res.card_list,
          complete: res => {
            console.log('openCard callback => ', res)
          }
        })
      }
    },
    sendCouponCallback(e) { // 商家券领券回调
      this.triggerEvent('sendCouponCallback', e.detail)
    }
  }
})
