// pages/bind-phone/index.js const api = require('../../utils/api.js') Page({ /** * 页面的初始数据 */ data: { phone: '' }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { }, formSubmit: e => { if(!e.detail.value.phone) { wx.showToast({ icon: 'none', title: '手机号不能为空', }) } else { wx.request({ url: api.bindPhoneUrl, method: 'GET', data: { 'id': wx.getStorageSync('we_chat_user_id'), 'phone': e.detail.value.phone }, success: res => { if (res.data.status == 'success') { wx.setStorageSync('pt_student', res.data.data) wx.switchTab({ url: '/pages/index/index', }) } else if (res.data.status == 'fail') { wx.showToast({ icon: 'none', title: res.data.info, }) } } }) } }, getPhoneNumber: function(e) { var that = this; if (e.detail.errMsg == 'getPhoneNumber:ok') { wx.request({ url: api.getPhoneUrl, method: 'POST', data: { 'id': wx.getStorageSync('we_chat_user_id'), 'iv': e.detail.iv, 'encryptedData': e.detail.encryptedData, }, success: res => { if(res.data.status == 'success') { that.setData({ phone: res.data.phone }) } else if(res.data.status == 'fail') { wx.showToast({ title: res.data.info, }) } } }) } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })