// pages/register/register.js // 到入一个 import api from "../../utils/api" import {encryptedData} from "../../utils/index" Page({ /** * 页面的初始数据 */ data: { formData:{ mobile:'', password:'', appId:'wx7ff137a3f9393c98' }, show:false }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.getPubKey() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, onClickHide() { this.setData({ show: false }); }, getPubKey(){ api.getPubKey().then(res=>{ this.setData({ pubKey:res.data }) }).catch(err=>{ }) }, submitLogin(){ const parm = { wxCode :'', ...this.data.formData, customerId:this.data.customerId } wx.login({ success: (res) => { parm.wxCode = res.code; console.log(parm,'seee'); api.userLoginlog(parm).then((res)=>{ console.log(res); if(res.code == 0){ wx.switchTab({ url: '/pages/index/index', }) wx.setStorageSync('token', res.data.token) } }).catch(err=>{ wx.showToast({ title: res.msg, icon:'none', duration:3000 }) console.log(err); }) }, }) }, getCustomerlist(){ let parm = { phone:encryptedData(this.data.pubKey, this.data.formData.mobile) } api.customerlist(parm).then(res=>{ if(res.code === 0 ){ if(res.data.length>1){ this.setData({ show:true, customerlist:res.data }) }else{ this.setData({ customerId:res.data[0].customerId }) this.submitLogin() } } }).catch(err=>{ }) }, handelClickCustomer(e){ this.setData({ customerId:e.currentTarget.dataset.id, show:false }) this.submitLogin() }, handelBlurMobile(e){ this.setData({ // 获取绑定过的值,付给fromData.mobile 'formData.mobile': e.detail.value }) console.log(this.data.formData) }, handelBlurPassword(e){ this.setData({ // 获取绑定过的值,付给fromData.password 'formData.password': e.detail.value }) console.log(this.data.formData) }, handelClickSubmit(){ let that = this if(!this.data.formData.mobile){ // 微信的轻量级api wx.showToast({ title: '请填写手机号', // 不显示图标 icon:'none', duration:3000 }) return } if(!this.data.formData.password){ wx.showToast({ title: '请输入密码', icon:'none', // 提示时间为3s duration:3000 }) return } // // 轻量级api,在加载时进行显示 // wx.showLoading({ // title: '登录中', // }) //微信的api,获取登录凭证,用户获取凭证 wx.getUserProfile({ desc: '用于获取用户个人信息', success: function (res) { var userInfo = res.userInfo; var avatarUrl = userInfo.avatarUrl; wx.setStorageSync('avatarUrl', avatarUrl) console.log("User's Avatar URL:", avatarUrl); that.getCustomerlist() } }) }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })