blank.js 2.08 KB
import { commonApi, ssoApi } from '~/api/api'
Page({
  // 体验卡中转站---解决H5端跳转小程序swichTab无法传参问题
  onLoad(options) {
      console.log(options)
    if(options.scene){
        this.getOptions(options.scene)
    }else{
        wx.$storage.set('bindInfo', options.freecard)
        const index = 1-wx.$util.judgeMerchantForXubao()
        wx.$router.reLaunch(`/pages/tab/shopMall/index?tabIndex=${index}`)
    }
  },
  getOptions(scene){
    console.log(scene,'scene')
  if(!scene)  return wx.$api.showToast('二维码错误');
  const qrcodeQuery = decodeURIComponent(scene);
  const id = qrcodeQuery.split("=").pop();
  commonApi
    .getQrcodeParams({
      id,
    })
    .then((res) => {
      if(res.code=='0'){
        let optionByApi = {}
        console.log(res.data, 'resdata')
        let arr = res.data.scene.split('&')
        arr.forEach(item=> {
            let newArr = item.split('=')
            optionByApi[newArr[0]] = newArr[1]
        })
          if(!optionByApi.openId)  return wx.$api.showToast('暂未登录');
              ssoApi.loginByOpenId({openId: optionByApi.openId}).then(({
                  code,
                  data,
                  message
              }) => {
                  if(code=='0'){
                      wx.clearStorageSync()
                      wx.$util.setUserInfo(data)
                      wx.$util.setSessionId(data.sessionId)
                      wx.$storage.set('srcm_shopmall_merchant_id', optionByApi.merchantId)
                      wx.setStorageSync('showServicesMerchantId', optionByApi.merchantId);
                      let { pageType, tabIndex, merchantId } = optionByApi
                      let path = `/pages/tab/shopMall/index?tabIndex=${tabIndex}&merchantId=${merchantId}&pageType=${pageType}`
                      wx.reLaunch({
                          url: path,
                        });
                  }else{
                      wx.$api.showToast(message || '系统异常')
                  }
              })
      }else{
          wx.$api.showToast(res.message || '系统异常')
      }
    });
  },
})