|
- 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;
- wx.showToast({
- title: '加载中',
- icon: "loading",
- duration: 2000
- })
- console.log(options);
- console.log("----------------------------------options---------------------------------------")
- 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) {
- that.userLogin(options.couponChannelId, options.couponId, options.orderId);
- } else {
- that.userLogin()
- }
- },
- /**
- * 用户登录
- */
- userLogin: function(couponChannelId, couponId, orderId) {
- 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(orderId){
- wx.redirectTo({
- url: '/pages/bargain/bargainDatail/bargainDatail?orderId='+orderId,
- })
- }else{
- wx.switchTab({
- url: '/pages/login/index',
- })
- }
- })
- .catch(err => {
- wx.showToast({
- title: err.message,
- icon: "none"
- })
- });
- }
- });
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function() {
-
- },
-
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function() {
-
- },
-
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function() {
-
- },
-
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function() {
-
- },
-
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function() {
-
- },
-
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function() {
-
- },
-
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function() {
-
- }
- })
|