// pagesSquare/pages/PCAuthorization/PCAuthorization.js import { closePage } from "../../../utils/miucms" import http from "./http/http" var miucms = require('../../../utils/miucms') let app = getApp() Page({ /** * 1:触发授权手机号页面, authorizedLog * 2:询问用户是否已有寄托账号, account 选择是创建新账号还是绑定就账号 * 3:直接登录成功 直接首页 | * 4:跳转设置头像名称页面 4:询问用户是否已有寄托账号(废弃),并拉起用户资料授权, account 区别是授权 (已经删除了) * 5:请在PC完善资料 nowAccount 弹出提示电脑完成信息 */ data: { screen_data: {}, top: 0, title: "欢迎来到寄托天下", tab: "", // oldAccount nowAccount authorizedLog account bjurl: "https://app.gter.net/image/miniApp/offer/u34.png", // u34 u55 info: {}, query: '', // 扫码获取到的 参数 oldAccountUsername: "", // 绑定寄托账号的数据 oldAccountPassword: "", // 绑定寄托账号的数据 isaccredit: false, canIUseGetUserProfile: false, phoneNumber: {}, getUserInfoData: {}, getUserInfoState: false, synchronizeState: false, token: "", isbing: 0, // 是否是offer榜小程序的绑定账号 isScanQR: false, // 是否是扫码进来 hintTickState: false, // 下面条款的确定按钮状态 }, /** * 生命周期函数--监听页面加载 */ onLoad: function (query) { let screen_data = app.globalData.screen_data let top = 300 / 750 * screen_data.windowWidth + screen_data.totalTopHeight this.setData({ screen_data, top, query, token: query.token, status: query.status, isbing: query.isbing, // getUserInfoState: app.globalData.getUserInfoData ? true : false }) let that = this miucms.pageStart(app).then(res => { that.init() }) }, init() { // if (JSON.stringify(this.data.query) == "{}") return if (this.data.token) { let tab = "" let status = this.data.status if (status == 1) tab = "authorizedLog" else if (status == 2) tab = "account" else tab = "authorizedLog" this.setData({ tab }) return } let code = "" let that = this wx.login({ success: function (res) { code = res.code http.wxpost('/api/applets/init', { code, options: app.globalData.options, query: that.data.query }).then(res => { if (res.code == 200) { that.setData({ info: res.data, tab: res.data.status == 1 ? 'authorizedLog' : res.data.status == 2 ? 'account' : res.data.status == 4 ? 'account' : '', islogin: app.globalData.user.uid > 0 ? true : false, canIUseGetUserProfile: app.globalData.canIUseGetUserProfile, isScanQR: true, token: res.data.token }) if (res.data.status == 3) { wx.showToast({ // 登录成功 title: '登录成功', icon: "success", duration: 2000, success: () => { console.log('成功'); } }) setTimeout(function () { that.backHome() // 跳转首页 }, 2000) } else if (res.data.status == 2) { that.setData({ getUserInfoState: true, tab: 'account' }) } else if (res.data.status == 4) { that.status = 4 wx.redirectTo({ url: '/pages/setAvatarNickname/setAvatarNickname?token=' + (that.data.token || that.data.info.token), }) } else if (res.data.status == 1) { that.setData({ tab: 'authorizedLog' }) } else if (res.data.status == 5) { that.setData({ tab: 'nowAccount' }) } } }) }, fail: function () { that.init() } }) }, status: null, // 专门第4步的 getPhoneNumber(e) { let that = this let code = "" if (e.detail.errMsg == 'getPhoneNumber:ok') { this.setData({ phoneNumber: e.detail }) wx.login({ success: function (res) { code = res.code http.wxpost('/api/applets/obtainMobile', { token: that.data.info.token || that.data.token, encryptedData: e.detail.encryptedData, iv: e.detail.iv, cloudID: e.detail.cloudID, code }).then(res => { if (res.data.status == 3) { wx.showToast({ // 登录成功 title: '登录成功', icon: "success", duration: 2000 }) app.globalData.setSate = true setTimeout(function () { app.globalData.setSate = true wx.navigateBack({ delta: 1, fail: function () { that.backHome() } }) // that.backHome() // 跳转首页 }, 2000) } else if (res.data.status == 2) { that.setData({ getUserInfoState: true, tab: 'account' }) } else if (res.data.status == 4) { that.status = 4 wx.redirectTo({ url: '/pages/setAvatarNickname/setAvatarNickname?token=' + (that.data.token || that.data.info.token), }) } else if (res.data.status == 1) { that.setData({ tab: 'authorizedLog' }) } else if (res.data.status == 5) { if (!that.data.isScanQR) { wx.showToast({ // 登录成功 title: '登录成功', icon: "success", duration: 2000 }) setTimeout(function () { app.globalData.setSate = true wx.navigateBack({ delta: 1, fail: function () { that.backHome() } }) }, 2000) } else { that.setData({ tab: 'nowAccount' }) } } app.globalData.user = res.data.user }) } }) } }, onShow: function () { if (this.status == 4) { this.setData({ tab: "account" }) } }, account(e) { let tab = e let title = tab == 'nowAccount' ? '账号创建成功' : '绑定已有寄托账号' this.setData({ tab, title, bjurl: 'https://app.gter.net/image/miniApp/offer/u55.png' }) }, backPreviousStep() { this.setData({ tab: 'account', title: '是否已有寄托账号?', bjurl: 'https://app.gter.net/image/miniApp/offer/u34.png' }) }, // 一键创建新账号 createAccount() { let that = this http.wxpost('/api/applets/create', { token: this.data.info.token || this.data.token }).then(res => { if (res.code == 200) { if (res.data.status == 3) { if (!that.data.isScanQR) { wx.showToast({ // 登录成功 title: that.data.isbing == 1 ? '绑定成功' : '登录成功', icon: "success", duration: 2000 }) app.globalData.setSate = true setTimeout(function () { that.backHome() // 跳转首页 }, 2000) } else that.account('nowAccount') } else if (res.data.status == 1) { that.setData({ tab: 'authorizedLog' }) } else if (res.data.status == 2) { that.setData({ getUserInfoState: true, tab: 'account' }) } else if (res.data.status == 4) { that.status = 4 wx.redirectTo({ url: '/pages/setAvatarNickname/setAvatarNickname?token=' + that.data.token, }) } else if (res.data.status == 5) { if (!that.data.isScanQR) { wx.showToast({ // 登录成功 title: '登录成功', icon: "success", duration: 2000 }) setTimeout(function () { app.globalData.setSate = true wx.navigateBack({ delta: 1, fail: function () { that.backHome() } }) // that.backHome() // 跳转首页 }, 2000) } else { that.setData({ tab: 'nowAccount' }) } } if (res.data.user) app.globalData.user = res.data.user } }) }, // 绑定已有账号跳转 bindingAccount() { this.account('oldAccount') }, // 绑定已有账号 提交按钮 bindingAccountSubmitBtn() { if (!this.data.hintTickState) { wx.showToast({ title: '请阅读并勾选同意', icon: 'none' }) return } let that = this http.wxpost('/api/applets/bind', { account: this.data.oldAccountUsername, password: this.data.oldAccountPassword, token: this.data.info.token || this.data.token }).then(res => { if (res.data.status == 3) { wx.showToast({ // 登录成功 title: that.data.isbing == 1 ? '绑定成功' : '登录成功', icon: "success", duration: 2000, success: () => { console.log('成功'); } }) app.globalData.setSate = true setTimeout(function () { // 跳转首页 that.backHome() }, 2000) } else if (res.data.status == 2) { that.setData({ getUserInfoState: true, tab: 'account' }) } else if (res.data.status == 4) { that.status = 4 wx.redirectTo({ url: '/pages/setAvatarNickname/setAvatarNickname?token=' + that.data.token, }) } else if (res.data.status == 1) { that.setData({ tab: 'authorizedLog' }) } else if (res.data.status == 5) { if (!that.data.isScanQR) { wx.showToast({ // 登录成功 title: '登录成功', icon: "success", duration: 2000 }) setTimeout(function () { app.globalData.setSate = true wx.navigateBack({ delta: 1, fail: function () { that.backHome() } }) // that.backHome() // 跳转首页 }, 2000) } else { that.setData({ tab: 'nowAccount' }) } } if (res.data.user) app.globalData.user = res.data.user }) }, // 跳转首页 backHome() { app.globalData.setSate = true wx.redirectTo({ url: '/pages/newIndex/index' }) }, // 跳转详细页面 godetail(e) { let { link } = e.currentTarget.dataset wx.navigateTo({ url: '/pagesSquare/pages/webview/webview?urll=' + link, }) }, bindgetuserinfo(e) { let value = e.currentTarget.dataset.value let that = this; wx.getUserProfile({ lang: "en", desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 success: (res1) => { app.globalData.getUserInfoData = res1 that.setData({ getUserInfoState: true }) let code = "" wx.login({ success: function (res) { code = res.code http.wxpost('/api/applets/synchronize', { encryptedData: res1.encryptedData, iv: res1.iv, userInfo: res1.userInfo, signature: res1.signature, code: code }).then(res => { if (res.data.status == 2) { if (value == "binding") that.account('oldAccount') else that.createAccount() that.setData({ synchronizeState: true }) } else if (res.data.status == 1) { that.setData({ tab: 'authorizedLog' }) } else if (res.data.status == 4) { that.status = 4 wx.redirectTo({ url: '/pages/setAvatarNickname/setAvatarNickname?token=' + that.data.token, }) } else if (res.data.status == 5) { that.setData({ tab: 'nowAccount' }) } }) } }) } }) }, userinf() { this.setData({ isaccredit: true }) }, login() { return new Promise((resolve, reject) => wx.login({ success: resolve, fail: reject })) }, ifjudge() { let that = this if (res.data.status == 3) { wx.showToast({ // 登录成功 title: '登录成功', icon: "success", duration: 2000, success: () => { console.log('成功'); } }) setTimeout(function () { that.backHome() // 跳转首页 }, 2000) app.globalData.setSate = true } else if (res.data.status == 2) { that.setData({ getUserInfoState: true, tab: 'account' }) } else if (res.data.status == 4) { that.setData({ getUserInfoState: false, tab: 'account' }) } else if (res.data.status == 1) { that.setData({ tab: 'authorizedLog' }) } else if (res.data.status == 5) { that.setData({ tab: 'nowAccount' }) } }, // 切换下面 条款的状态 cutHintTickState() { this.data.hintTickState = !this.data.hintTickState this.setData({ hintTickState: this.data.hintTickState }) }, // 弹出 需要 选中条款 popupClause() { wx.showToast({ title: '请阅读并勾选同意', icon: 'none' }) }, // 没有点击同意同款时 点击账号操作 bindTickMask() { wx.showToast({ icon: "none", title: '请同意协议和条款', }) }, })