|
- 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) {
- let that = this;
- 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];
- }
- }
- console.log(options.couponChannelId)
- wx.showToast({
- title: '加载中',
- icon: "loading",
- duration: 2000
- })
- wx.setStorageSync('options', JSON.stringify(options))
- wx.setStorageSync('imgurl', imgurl)
- app.getLocation();
- if (options.couponChannelId || options.orderId) {
- that.userLogin(options);
- // if (options.cuserId){
- // /**
- // * 转赠判断
- // */
- // // that.userLogin(options.couponChannelId, null, options.cuserId, options.coverImg, options.userName, options.avatarUrl, options.couponOrderId, options.updateDate);
- // that.userLogin(options.couponChannelId, null, options.cuserId, options.coverImg, options.userName, options.avatarUrl, options.couponOrderId, options.updateDate);
- // } else if (options.orderGroupId){
- // // 来自于拼团
- // that.userLogin(options.couponChannelId, null, options.orderGroupId);
- // }else{
- // that.userLogin(options.couponChannelId, options.orderId);
- // }
- } else {
- that.userLogin()
- }
- },
- checkuerstatus(options) {
- let that = this;
- Http.post({
- url: config.api.checkUserStatus,
- data: {}
- })
- .then(res => {
- if (options&&options.couponChannelId && !options.cuserId) {
- 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) {
- wx.redirectTo({
- url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${options.orderId}&from='${"discount"}`,
- })
- }else{
- wx.switchTab({
- url: '/pages/main/index'
- });
- }
- })
- .catch(err => {
- if (err.code == 11004) {
- // 用户昵称未授权
- if (couponChannelId && !cuserId) {
- wx.redirectTo({
- url: `/pages/getuserinfo/index?couponChannelId=${couponChannelId}`
- });
- } else if (couponChannelId && cuserId){
- /**
- * 转赠判断
- */
- wx.redirectTo({
- url: `/pages/getuserinfo/index?couponChannelId=${couponChannelId}&cuserId=${cuserId}&coverImg=${coverImg}&userName=${userName}&avatarUrl=${avatarUrl}&couponOrderId=${couponOrderId}&updateDate=${updateDate}`
- });
- } else if (orderId) {
- wx.redirectTo({
- url: `/pages/getuserinfo/index?orderId=${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;
- 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',
- })
- }
- }
- })
- });
- }
- });
- },
- })
|