const Http = require("../../utils/HttpBasics"); const imgurl = require("../../utils/imgurl"); const config = require("../../config/config"); const QR = require("../../utils/memberqrcode.js"); let app = getApp(); Page({ /** * 页面的初始数据 */ data: { }, /** * 生命周期函数--监听页面加载 */ onLoad: function(options) { console.log(options) let that = this; wx.showToast({ title: '加载中', icon: "loading", duration: 2000 }) wx.setStorageSync('options', JSON.stringify(options)) wx.setStorageSync('imgurl', imgurl) if (decodeURIComponent(options.scene) == "undefined") { that.setData({ scene: 0 }); } else { that.setData({ scene: decodeURIComponent(options.scene) }); } app.getLocation(); if (options.couponChannelId && options.couponId || options.orderId) { if (options.cuserId){ /** * 转赠判断 */ that.userLogin(options.couponChannelId, options.couponId, null, options.cuserId, options.coverImg, options.userName, options.avatarUrl); }else{ that.userLogin(options.couponChannelId, options.couponId, options.orderId); } } else { that.userLogin() } }, checkuerstatus(couponChannelId, couponId, orderId, cuserId, coverImg, userName, avatarUrl) { let that = this; Http.post({ url: config.api.checkUserStatus, data: {} }) .then(res => { if (couponChannelId && couponId && !cuserId) { wx.redirectTo({ url: `/pages/coupon/detail/index?couponChannelId=${couponChannelId}&couponId=${couponId}`, }) } else if (couponChannelId && couponId && cuserId){ /** * 转赠判断 */ wx.redirectTo({ url: `/pages/coupon/detail/index?couponChannelId=${couponChannelId}&couponId=${couponId}&cuserId=${cuserId}&coverImg=${coverImg}&userName=${userName}&avatarUrl=${avatarUrl}`, }) } else if (orderId) { wx.redirectTo({ url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${orderId}&from='${"discount"}`, }) }else{ wx.switchTab({ url: '/pages/login/index' }); } }) .catch(err => { if (err.code == 11004) { // 用户昵称未授权 if (couponChannelId && couponId && !cuserId) { wx.redirectTo({ url: `/pages/getuserinfo/index?couponChannelId=${couponChannelId}&couponId=${couponId}` }); } else if (couponChannelId && couponId && cuserId){ /** * 转赠判断 */ wx.redirectTo({ url: `/pages/getuserinfo/index?couponChannelId=${couponChannelId}&couponId=${couponId}&cuserId=${cuserId}&coverImg=${coverImg}&userName=${userName}&avatarUrl=${avatarUrl}` }); } else if (orderId) { wx.redirectTo({ url: `/pages/getuserinfo/index?orderId=${orderId}&from='${"discount"}` }); } else { wx.redirectTo({ url: `/pages/getuserinfo/index` }); } } }); }, /** * 用户登录 */ userLogin: function (couponChannelId, couponId, orderId, cuserId, coverImg, userName, avatarUrl) { var that = this; // 登录 wx.login({ success: ({ code }) => { wx.getSystemInfo({ success: function(res) { that.setData({ systemInfo: JSON.stringify(res) }) } }) var usrdata = { appId: config.weapp.AppId, code: code, sceneAddress: app.globalData.sceneAddress, scene: that.data.scene, systemInfo: that.data.systemInfo }; if (app.globalData.locationInfo) { usrdata = { appId: config.weapp.AppId, code: code, sceneAddress: app.globalData.sceneAddress, latitude: "" + app.globalData.locationInfo.latitude, longitude: "" + app.globalData.locationInfo.longitude, scene: that.data.scene, systemInfo: that.data.systemInfo }; } Http.post({ url: config.api.login, data: usrdata }) .then(res => { that.setData({ showPages: true }) app.globalData.token = res.data.token; Http.setToken(res.data.token); if (couponChannelId&&couponId || orderId){ that.checkuerstatus(couponChannelId, couponId, orderId, cuserId, coverImg, userName, avatarUrl); }else{ that.checkuerstatus(); } }) .catch(err => { wx.showModal({ title: '提示', showCancel: false, content: '登录失败,请重新尝试', success:function(res){ if (res.cancel) { //点击取消,默认隐藏弹框 } else { //点击确定 wx.reLaunch({ url: '/pages/index/index', }) } } }) }); } }); }, })