const extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {} const Http = require("../../utils/HttpBasics"); const imgurl = require("../../utils/imgurl"); const config = require("../../config/config"); let app = getApp(); Page({ /** * 页面的初始数据 */ data: {}, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { let that = this; /** * 根据接收到的参数的值,判断跳转到哪个页面 */ if (options && options.type) { app.globalData.type = options.type; } 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) //// 大屏-二维码-start 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' } else if (this.data.newArr[0] == 't') { // 普通二维码 options.type = this.data.newArr[1]; app.globalData.type = options.type; if(options.type == 'cd') { options.couponChannelId = this.data.newArr[2]; } else if (options.type == 'bd') { options.bt = this.data.newArr[2]; options.id = this.data.newArr[3]; } else if (options.type == 'gm') { options.id = this.data.newArr[2]; } else if (options.type == 'sd') { options.couponChannelId = this.data.newArr[2]; } else if (options.type == 'td') { // 专题活动页 options.id = this.data.newArr[2]; } } } wx.showToast({ title: '加载中', icon: "loading", duration: 2000 }) wx.setStorageSync('options', JSON.stringify(options)) wx.setStorageSync('imgurl', imgurl) app.getLocation(); if (options.couponChannelId || options.orderId || options.id) { that.userLogin(options); } else { that.userLogin() } }, checkuserstatus(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; } //来自大屏的跳转拼团券详情 else 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; } else if (options && options.couponChannelId) { // 转赠判断 if (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{ // 跳转普通券/消费卡/限时秒杀/砍价详情 wx.redirectTo({ url: `/pages/coupon/detail/index?couponChannelId=${options.couponChannelId}`, }) } } // 拼团详情页(只有通过扫码进入才可能进入拼团详情页面,只有这一个入口) else if (options && options.couponChannelId && app.globalData.type == 'sd') { wx.redirectTo({ url: `/pages/spellGroup/mySpellGroup/index?couponChannelId=${options.couponChannelId}`, }) } // 游戏页面 else if (options && options.id && app.globalData.type == 'gm') { that.getGameOne(app.globalData.token, options.id) } // 宣传页详情 else if (options && options.bt && options.id && app.globalData.type == 'bd') { if (options.bt == '2') { // 自由图文 wx.redirectTo({ url: `/pages/freeBannerDetail/index?id=${options.id}`, }) } else { // 标准格式 wx.redirectTo({ url: `/pages/bannerdetail/index?id=${options.id}`, }) } } // 专题 else if (options && options.id && app.globalData.type == 'td'){ wx.redirectTo({ url: `/pages/topicDetail/index?id=${options.id}` }); } // 参与砍价 else if (options && options.orderId) { 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 == 'jf') { wx.redirectTo({ url: '/pages/integralmall/index' }); } // 首页 else if (app.globalData.type == 'in') { wx.switchTab({ url: '/pages/main/index' }); } // 停车 else if (app.globalData.type == 'pc') { // 停车 wx.switchTab({ url: '/pages/passCar/passCar' }); } // 我的券包 else if (app.globalData.type == 'mc') { // 我的券包 wx.redirectTo({ url: '/pages/couponorder/index/index' }); } // 我的订单 else if (app.globalData.type == 'mo') { // 我的订单 wx.redirectTo({ url: '/pages/order/index/index?id=all' }); } // 我的卡包 else if (app.globalData.type == 'ca') { // 我的卡包 wx.redirectTo({ url: '/pages/cardorder/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 if (app.globalData.type == 'bl') { // 砍价专场 wx.redirectTo({ url: '/pages/bargain/bargain' }); } // 我的砍价 else if (app.globalData.type == 'mb') { // 我的砍价 wx.redirectTo({ url: '/pages/bargain/bargain?from=myhtml' }); } // 拼团专场 else if (app.globalData.type == 'sl') { // 拼团专场 wx.redirectTo({ url: '/pages/spellGroup/spellGroup' }); } // 我的拼团 else if (app.globalData.type == 'ms') { // 我的拼团 wx.redirectTo({ url: '/pages/spellGroup/spellGroup?from=myhtml' }); } // 消费卡 else if (app.globalData.type == 'dc') { // 消费卡 wx.redirectTo({ url: '/pages/discountCardList/discountCardList' }); } // 门店 else if (app.globalData.type == 'ml') { // 门店 wx.switchTab({ url: '/pages/index/searchbar/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) { 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 || options.id)) { that.checkuserstatus(options); } else { that.checkuserstatus(); } }) .catch(err => { wx.showModal({ title: '提示', showCancel: false, content: '登录失败,请重新尝试', success: function (res) { if (res.cancel) { //点击取消,默认隐藏弹框 } else { //点击确定 wx.reLaunch({ url: '/pages/index/index', }) } } }) }); } }); }, getGameOne: function (token, id) { let _this = this; Http.get({ url: config.api.getOneGame, data: { token: token, id: id } }).then(res => { wx.redirectTo({ url: '/pages/game/index?url=' + res.data.url + "&id=" + res.data.id + "&gameId=" + res.data.gameId, }) }) .catch(err => { wx.showModal({ title: '提示', content: err.message, showCancel: false, success:function(res){ // 如果游戏下架或者找不到,重启首页 if (res.confirm){ wx.reLaunch({ url: '/pages/index/index', }) } } }) this.alphaClick(); }) }, })