import Dialog from '@vant/weapp/dialog/dialog'; const util = require('../../../../utils/util.js'); const api = require('../../../../config/api.js'); const user = require('../../../../utils/user.js'); const app = getApp(); Page({ /** * 页面的初始数据 */ data: { loginCode: '', detail: '', userName: '', avatarUrl: '', codeShow: false, code: '', }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData({ userName: app.globalData.recommend.userName, avatarUrl: app.globalData.recommend.avatarUrl }) }, getPhoneNumber(e) { console.log(e); this.setData({ detail: e.detail }) this.getDenPhone(); }, getDenPhone() { util.request(api.GetDenPhone, { code: this.data.loginCode, encryptedData: this.data.detail.encryptedData, errMsg: this.data.detail.errMsg, iv: this.data.detail.iv }, "POST") .then((res) => { if (res.errno == 0) { let isNew = res.data.isNew; if (isNew) { app.globalData.recommend.phone = res.data.phone; app.globalData.recommend.unionId = res.data.unionId; app.globalData.recommend.openId = res.data.openId; app.globalData.recommend.sessionKey = res.data.sessionKey; wx.navigateTo({ url: '../register/register', }) } else { // 不是新人,则跳转到首页 Dialog.alert({ title: '引荐失败', message: '您已是鲸致商城用户,当前引荐人计划只面向新用户,敬请期待', }).then(() => { // on close wx.switchTab({ url: '/pages/index/index', }); }); } } else { util.showErrorToast(res.errmsg); this.getLoginCode(); } }); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, getLoginCode() { let that = this; user.login().then(res => { that.setData({ loginCode: res.code }) }) }, /** * 生命周期函数--监听页面显示 */ onShow: function () { this.getLoginCode(); }, showDialog() { this.setData({ codeShow: true }) }, onClickHide() { this.setData({ codeShow: false }) }, codeInput(e) { this.setData({ code: e.detail.value }) }, confirm() { if (this.data.code == '') { wx.showToast({ title: '请输入邀请码', icon: 'none', duration: 2000 }) } else { util.request(api.RefBcodeInfo, { bcode: this.data.code, }, "GET") .then((res) => { if (res.errno == 0) { app.globalData.recommend = { bCode: res.data.refereeCode, userName: res.data.refereeName, avatarUrl: res.data.refereeAvatar }; app.globalData.rId = res.data.refereeId; this.setData({ userName: res.data.refereeName, avatarUrl: res.data.refereeAvatar, codeShow: false }) } else { util.showErrorToast(res.errmsg); } }); } }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })