// pages/confirmOrder/confirmOrder.js
const wxService = require('../../utils/wxService')

wxService.page({
  /**
   * 页面的初始数据
   */
  data: {
    addressInfo: '',
    showSelectCoupon: false,
    skuIds: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let skuIds = []
    skuIds.push(this.options.specId)
    // 计算优惠价
    if(skuIds){this.calPreferentialPrice(skuIds)}
  },
  calPreferentialPrice(skuIds) {
    wx.showLoading({
      title: '加载中'
    })
    wxService.post(`/sale/trade/buyer/preview`,skuIds).then(res => {
      if (res) {
        const { result, data } = res.data
        if (result == 0) {
          wx.hideLoading()
          console.log('data', data)
        }
      }
    })
  },
  //获取微信地址
  chooseWxAddress() {
    wx.chooseAddress({
      success: (res) => {
        console.log(res)
        this.setData({
          addressInfo: res
        })
      },
      fail: function (err) {
        console.log(err)
      }
    })
  },

  //选择优惠券
  selectCoupon() {
    this.setData({
      showSelectCoupon: true
    })
  }


})