open.js 2.34 KB
import { IMG_URL } from '~/config';
Page({
  /**
   * 页面的初始数据
   */
  data: {
    IMGURL:IMG_URL,
    isOpen: false,
    openingStatus: false
  },

  // 获取门店会员卡信息
  getMemberCardData() {
    const {
      merchantId
    } = wx.p.storage.get('merchant_info')
    let para = {
      merchantId: merchantId
    }

    wx.p.api.equityApi.memberCard(para).then(res => {
      this.setData({
        memberInfo: res
      })
    })
  },

  // 获取用户会员信息
  toCheckMember() {
    wx.p.api.equityApi.checkOpenMember().then(res => {
      if (res.code == 0 && res.data.cardNo) {
        wx.p.storage.set('isVIP', true)
        this.setData({
          openingStatus: false
        })
        if (this.data.pageForm) {
          if (this.data.pageForm == 'oil') {
            wx.p.storage.set('refresh_oil_oage', true)
          }
          wx.navigateBack({
            delta: 1
          })
          return
        }
        wx.switchTab({
          url: '/pages/tab/equity/index',
        });
      }
    })
  },
  // 去购买会员
  async openMemberFn() {
    const authStatus = await wx.p.router.intercept()
    if (authStatus) return
    const { memberInfo } = this.data
    const {
      merchantId
    } = wx.p.storage.get('merchant_info')
    wx.p.wxApi.showLoading()
    let para = {
      equityClassId: memberInfo.equityClassId,
      orderCode: memberInfo.orderCode,
      orderSource: 3,
      merchantId
    }
    wx.p.api.equityApi.buyMemberCard(para).then(res => {
      wx.hideLoading()
      this.handlePay(res)
    })
  },
  // 处理购买参数拉起支付
  handlePay(payData) {
    const { timeStamp, nonceStr, packages, signType, paySign } = payData
    let self = this
    wx.requestPayment({
      timeStamp: timeStamp,
      nonceStr: nonceStr,
      package: packages,
      signType: signType,
      paySign: paySign,
      success() {
        setTimeout(() => {
          self.toCheckMember()
        }, 1500)
        self.setData({
          openingStatus: true
        })
      },
      fail() { }
    })
  },

  onLoad: function (options) {
    this.getMemberCardData()
    this.data.pageForm = options.page
  },
  toLook() {
    wx.navigateTo({
      url: '/packageEquity/pages/agreement/index'
    })
  },
  // toActive() {
  //   wx.navigateTo({
  //     url: '/packageEquity/pages/active/active'
  //   })
  // }
})