

// subPackage/page/pages/paymentStatus/paymentStatus.js
const app = getApp()
const wxService = require('../../../../utils/wxService')
const utils = require('../../../../utils/util')

wxService.page({

  /**
   * 页面的初始数据
   */
  data: {
    amount: 0,
    status: 'S',
    isSubscribe: false
  },

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

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    const { amount, status } = this.options
    console.log('this.options', status)
    this.setData({
      amount,
      status
    }, () => {
      // 当前用户是否关注公众号
      this.getMemberSubscribe()
      this.loginUpdateStroage() //登录更新plus缓存
    })

    // 动态设置title
    wx.setNavigationBarTitle({
      title: status == 'S' ? '支付成功' : '支付失败'
    })
  },
  loginUpdateStroage() {
    const code = wx.getStorageSync('_loginCode')
    const wechatInfo = wx.getStorageSync('_wechatInfo')
    wxService.login().then((res) => {
      wxService.post(`/member/minaLogin`, {
        code:res.code,
        wechatInfo,
        brandId: app.globalData.brandId,
      })
    })
  },
  toPlus() {
    wxService.post(`/merchant/modelPage/mainSetting/page?brandId=${app.globalData.brandId}&isMain=3&type=2`).then(res => {
      const { result, data } = res.data
      if (result == 0) {
        wxService.router(`/subPackage/page/pages/subPage/subPage?pageId=${data.page.pageId}`)
      }
    })
  },
  getMemberSubscribe() {
    const baseUserInfo = wx.getStorageSync('_baseUserInfo')
    const { openid } = baseUserInfo.member
    wxService.post(`/member/subscribe?openid=${openid}`).then(res => {
      const { result, data } = res.data
      if (result == 0) {
        // 0 未关注 1 已关注
        this.setData({
          isSubscribe: data == 0 ? false : true
        })
      }
    })
  },
  goPayAgain() {
    console.log('goPayAgain')
  },
  goOrder() {
    wxService.router(`/pages/order/order`)
  },
  goClassificationPage() {
    wxService.router(`/pages/category/category`)
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})