const util = require("../../utils/tool"); const App = getApp(); // import common from "/utils/tool.js"; Page({ data: { appAssetsUrl: App.appAssetsUrl, apiRoot: App.apiRoot, isCheck: false, mobile: "", inviteCode: "", // App.apiRoot+'auth/captcha.jpg?t='+ new Date().getTime() captcha: "", imgCode: "", code: "", time: 60, word: "获取验证码", isDjs: false, clear: null, openid: "", meetId: "", expertId: "", memberId: "", disabled: false, }, onLoad: function (options) { // inviteCode console.log(options, options.inviteCode, "inviteCode"); this.setData({ inviteCode: options.inviteCode, openid: options.openid, }); // this.getCaptcha() this.getYzcode(); if (options.meetId != "") { this.setData({ meetId: options.meetId, expertId: options.expertId, memberId: options.memberId, }); } }, getYzcode() { App._get( `auth/base64/captcha`, { openid: this.data.openid, }, (res) => { if (res.code === 0) { this.setData({ captcha: res.data, }); } } ); }, // getPhoneNumber(e) { // if (e.detail.errMsg == 'getPhoneNumber:ok') { // // 用户允许获取手机号 // this.setData({ // code: e.detail.code // }) // this.getKey(e.detail.code); // } // }, // getKey(code) { // let that = this; // App._post_form('auth/getAppletPhone', "application/json", code, res => { // console.log(res, 222222) // if (res.code == 0) { // that.setData({ // telInput: res.msg // }) // } // }, fail => { // console.log(fail); // }) // }, getPhoneNumber(e) { const that = this; if (e.detail.errMsg != "getPhoneNumber:ok") { return; } var params = { encryptedData: e.detail.encryptedData, iv: e.detail.iv, sessionKey: wx.getStorageSync("session_key"), }; App._post_form( "member/decodeUserInfo?encryptedData=" + params.encryptedData + "&iv=" + params.iv + "&sessionKey=" + params.sessionKey, "application/json;charset=UTF-8", params, function (data) { if (data.code == 0) { that.setData({ mobile: data.msg, disabled: true }); } }, function (err) { wx.showToast({ title: "请求失败", icon: "none", duration: 3500, }); return; } ); // wx.checkSession({ // success (res) { // console.log(res, 111) // if(res.errMsg=="checkSession:ok"){ // } // }, // fail () { // // session_key 已经失效,需要重新执行登录流程 // util.alert('微信登录已过期'); // setTimeout(() => { // wx.navigateBack({ // delta: 1 // }); // },2500) // } // }) }, // 获取图形验证码 getCaptcha() { this.setData({ captcha: "", }); if (this.data.captcha === "") { setTimeout(() => { this.setData({ captcha: this.data.apiRoot + "auth/captcha.jpg?openid=" + this.data.openid + "&t=" + new Date().getTime(), }); }, 300); } // console.log('dddddddddddddd') // this.setData({ // captcha: this.data.apiRoot + 'auth/captcha.jpg?openid=' + this.data.openid + '&t=' + new Date().getTime() // }) // console.log(this.data.captcha,'11111111111111') }, // changeCode() { // this.setData({ // captcha: '' // }) // this.getCaptcha() // }, codeDetail(e) { console.log(e); }, change(e) { if (e.detail.value.length > 0) { this.setData({ isCheck: true, }); } else { this.setData({ isCheck: false, }); } }, //倒计时 countDown() { var that = this; if (that.data.time <= 0) { this.setData({ isDjs: false, time: 60, }); clearInterval(that.data.clear); } else { --that.data.time; this.setData({ isDjs: true, time: that.data.time, }); } }, getCode() { let that = this; if (!this.data.mobile) { return util.alert("请先获取手机号"); } if (!this.data.isDjs) { this.setData({ isDjs: true, clear: setInterval(that.countDown, 1000), }); App._get( "auth/sendCode", { mobile: this.data.mobile, }, (res) => { if (res.code === 0) { wx.showToast({ title: "发送成功", }); } } ); // this.data.clear = setInterval(this.countDown, 1000); } // this.setData({ // word: this.data.time // }) // this.data.word = this.data.time console.log("dffddf"); console.log(this.data.isDjs); }, toPrivacy() { wx.navigateTo({ url: "/pages/privacy/privacy", }); }, reg() { if (!this.data.mobile) { return util.alert("请获取手机号"); } if (!this.data.imgCode) { return util.alert("请输入图形验证码"); } if (!this.data.code && !this.data.disabled) { return util.alert("请输入短信证码"); } if (!this.data.isCheck) { return util.alert("请勾选隐私协议"); } let userInfo = wx.getStorageSync("userInfo"); let form = { captcha: this.data.imgCode, inviteCode: this.data.inviteCode, memberPhoto: userInfo.avatarUrl, mobile: this.data.mobile, name: userInfo.nickName, openid: wx.getStorageSync("openid"), shortMessageCode: this.data.code, }; App._post_form( "auth/appletsRegistered", "application/json;charset=UTF-8", form, (res) => { if (res.code === 0) { wx.setStorageSync("USER", res.memberinfo); console.log(this.data.meetId, 11111111) if (this.data.meetId != "") { wx.reLaunch({ url: `/meet/meet/addmeet?meetId=${this.data.meetId}&expertId=${this.data.expertId}&memberId=${this.data.memberId}`, }); } else { wx.reLaunch({ url: "/pages/home/index/index?login=1", }); } } } ); }, onUnload: function () { clearInterval(this.data.clear); console.log("卸载"); }, });