You need to sign in or sign up before continuing.
loading.js 6.03 KB
const WXRequest = require('../../utils/wxrequest.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        modalHidden: true,
        userInfoAuth: true,
        isSharePage: false,
        sns: null
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        if (options.code) {
            wx.setStorageSync('publicCode', options.code);
            /*wx.showModal({
              content: options.code,
              showCancel: false
            });*/
        }
        if (options.carShareInfo) {
            wx.setStorageSync('carShareInfo', JSON.parse(decodeURIComponent(options.carShareInfo)));
            wx.setStorageSync('loginUserId', options.loginUserId);
        } else {
            wx.setStorageSync('carShareInfo', null)
        }
        if (options.sns) { // 新e盾找车
            this.setData({
                sns: decodeURIComponent(options.sns)
            })
        } else {
            this.setData({
                sns: null
            })
        }
        if (options.isSharePage) {
            this.setData({
                isSharePage: true
            })
        }

        /* wx.showModal({
               content: String(options.test),
               showCancel: false
             });*/

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function (options) {
        var that = this;

        WXRequest.login().then(() => {
            const userStatus = wx.getStorageSync("userStatus");
            const scene = wx.getStorageSync('scene');
            if (scene == '1007' || scene == '1008' || scene == '1044') { //转发场景

                if (userStatus === 2) { //转发新用户
                    that.setData({
                        modalHidden: false,
                        userInfoAuth: false
                    });
                    return;
                    wx.getSetting({
                        success(res) {
                            console.log(res)
                            if (!res.authSetting['scope.userInfo']) {
                                that.setData({
                                    modalHidden: false,
                                    userInfoAuth: false
                                });
                            } else {
                                wx.switchTab({
                                    url: '../../pages/findCar/findCar'
                                });
                            }
                        }
                    });
                } else if (userStatus === 1) {
                    wx.switchTab({
                        url: '../../pages/findCar/findCar'
                    });

                } else if (userStatus === 0) {
                    wx.setStorageSync('carShareInfo', null);
                    wx.switchTab({
                        url: '../../pages/home/home'
                    });
                }

            } else {

                if (userStatus === 2) {
                    wx.redirectTo({
                        url: '../../pages/login/login'
                    });
                } else {
                    wx.switchTab({
                        url: '../../pages/home/home'
                    });
                    /*wx.redirectTo({
                      url: '../../pages/collectCarDetail/collectCarDetail'
                    });*/
                }
            }
        })




        /*setTimeout(()=>{
          wx.switchTab({
            url: '../../pages/findCar/findCar'
          });
        },5000)*/

        /*console.log(wx.getStorageSync('scene'))
        if(wx.getStorageSync('scene') == '1044'){
          wx.switchTab({
            url: '../../pages/mine/mine'
          });
        }else{
          wx.switchTab({
            url: '../../pages/findCar/findCar'
          });
        }*/
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },
    onGotUserInfo(e) {

        if (e.detail.errMsg === 'getUserInfo:ok') {
            this.setData({
                modalHidden: true,
                userInfoAuth: true
            });
            wx.login({
                success: res => {
                    wx.request({
                        url: `${WXRequest.domain}loginWxUser`,
                        data: {
                            ...e.detail.userInfo,
                            code: res.code
                        },
                        success: function (res) {

                            const data = res.data;
                            if (res.statusCode === 200) {
                                const data = res.data;
                                if (data.returnCode === '0') {
                                    wx.setStorageSync("sessionid", res.header["Set-Cookie"]);
                                    wx.setStorageSync("userStatus", 1);
                                    wx.setStorageSync("userinfo", data.data);
                                    wx.switchTab({
                                        url: '../../pages/findCar/findCar'
                                    });
                                } else {
                                    wx.showModal({
                                        content: data.message,
                                        showCancel: false
                                    });
                                }
                            } else if (res.statusCode === 401) {
                                wx.redirectTo({
                                    url: '../../pages/login/login'
                                });
                            }
                        },
                        fail() {
                            console.log('fail')
                        }
                    });
                }
            });

        }
        wx.setStorageSync('wxUserInfo', e.detail.userInfo)
        console.log(e.detail.userInfo)
        console.log(e.detail.rawData)
    }
})