const extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {} 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; /** * 根据接收到的值,判断跳转到哪个页面 */ if(options&&options.type){ app.globalData.type = options.type; console.log(app.globalData.type) } // app.globalData.type = 'pc'; if (decodeURIComponent(options.scene) == "undefined") { that.setData({ scene: 0 }); } else { that.setData({ scene: decodeURIComponent(options.scene) }); that.setData({ newArr: this.data.scene.split(':') }) console.log(this.data.newArr) if (this.data.newArr[0]=='JC'){ /** * 来自大屏跳转券详情 */ options.couponChannelId = this.data.newArr[1]; }else if (this.data.newArr[0] == 'JG'){ /** * 来自大屏跳转拼团详情 */ options.couponChannelId = this.data.newArr[1]; options.path='daping' } } wx.showToast({ title: '加载中', icon: "loading", duration: 2000 }) wx.setStorageSync('options', JSON.stringify(options)) wx.setStorageSync('imgurl', imgurl) app.getLocation(); if (options.couponChannelId || options.orderId) { console.log(options,33333333333) that.userLogin(options); } else { that.userLogin() } }, checkuerstatus(options) { let that = this; Http.get({ url: config.api.checkUserStatus, data: {} }) .then(res => { if (options && options.orderGroupId) { wx.redirectTo({ url: `/pages/joinFrDpell/index?couponId=${options.couponId}&orderGroupId=${options.orderGroupId}&couponChannelId=${options.couponChannelId}&orderId=${options.orderId}&avatarUrl=${options.avatarUrl}&nickName=${options.nickName}` }) return; } /** * 来自大屏的跳转拼团券详情 */ if (options && options.couponChannelId && options.path== 'daping'){ /** * 主要是为了拿couponId */ Http.get({ url: config.api.couponDetail, data: { couponChannelId: options.couponChannelId } }).then(res => { let data = res.data; wx.redirectTo({ url: `/pages/spellGroup/mySpellGroup/index?couponChannelId=${options.couponChannelId}&couponId=${data.couponId}` }) }); return; } if (options && options.couponChannelId && !options.cuserId &&app.globalData.type == 'cd') { wx.redirectTo({ url: `/pages/coupon/detail/index?couponChannelId=${options.couponChannelId}`, }) } else if (options &&options.couponChannelId && options.cuserId){ /** * 转赠判断 */ wx.redirectTo({ url: `/pages/coupon/detail/index?couponChannelId=${options.couponChannelId}&cuserId=${options.cuserId}&coverImg=${options.coverImg}&userName=${options.userName}&avatarUrl=${options.avatarUrl}&couponOrderId=${options.couponOrderId}&updateDate=${options.updateDate}`, }) } else if (options&&options.orderId&&app.globalData.type=='bg') { wx.redirectTo({ url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${options.orderId}&from='${"discount"}`, }) } else if (app.globalData.type == 'uc'){ wx.switchTab({ url: '/pages/user/index' }); } else if (app.globalData.type == 'pc') { wx.switchTab({ url: '/pages/passCar/passCar' }); } else if (app.globalData.type == 'co') { wx.redirectTo({ url: '/pages/couponorder/index/index' }); } else if (app.globalData.type == 'or') { wx.redirectTo({ url: '/pages/couponorder/index/index' }); } else if (app.globalData.type == 'sc') { wx.redirectTo({ url: '/pages/specialcourtesy/specialcourtesy' }); }else if (app.globalData.type == 'rb') { wx.redirectTo({ url: '/pages/rushToBuy/index' }); }else{ wx.switchTab({ url: '/pages/main/index' }); } }) .catch(err => { if (err.code == 11004) { // 用户昵称未授权 if (options && options.orderGroupId) { wx.redirectTo({ url: `/pages/getuserinfo/index?couponId=${options.couponId}&orderGroupId=${options.orderGroupId}&couponChannelId=${options.couponChannelId}&orderId=${options.orderId}&avatarUrl=${options.avatarUrl}&nickName=${options.nickName}` }) return; } if (options && options.couponChannelId && !options.cuserId) { wx.redirectTo({ url: `/pages/getuserinfo/index?couponChannelId=${options.couponChannelId}` }); } else if (options &&options.couponChannelId && options.cuserId){ /** * 转赠判断 */ wx.redirectTo({ url: `/pages/getuserinfo/index?couponChannelId=${options.couponChannelId}&cuserId=${options.cuserId}&coverImg=${options.coverImg}&userName=${options.userName}&avatarUrl=${options.avatarUrl}&couponOrderId=${options.couponOrderId}&updateDate=${options.updateDate}` }); } else if (options && options.orderId) { wx.redirectTo({ url: `/pages/getuserinfo/index?orderId=${options.orderId}&from='${"discount"}` }); } else { wx.redirectTo({ url: `/pages/getuserinfo/index` }); } } }); }, /** * 用户登录 */ userLogin: function (options) { console.log(1111,options,2222222222) 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; app.globalData.openId = res.data.openId; // 初始化websocket if (extConfig.attr.ifHaveWebSocket == 1) { app.initSocket(); // 回调发送给自己的消息 app.globalData.socketReceiver = function (e) { let msgList = that.data.msgList msgList.push(e) that.setData({ msgList: msgList }) } } if (res.data && res.data.score) { if (res.data.score != 0){ app.globalData.score=res.data.score; } } Http.setToken(res.data.token); if (options&&(options.couponChannelId || options.orderId)){ that.checkuerstatus(options); }else{ that.checkuerstatus(); } }) .catch(err => { wx.showModal({ title: '提示', showCancel: false, content: '登录失败,请重新尝试', success:function(res){ if (res.cancel) { //点击取消,默认隐藏弹框 } else { //点击确定 wx.reLaunch({ url: '/pages/index/index', }) } } }) }); } }); }, })