|
|
@ -1,6 +1,7 @@ |
|
|
|
// pages/register/register.js
|
|
|
|
// 到入一个
|
|
|
|
import {userLoginlog} from "../../utils/api" |
|
|
|
import api from "../../utils/api" |
|
|
|
import {encryptedData} from "../../utils/index" |
|
|
|
Page({ |
|
|
|
|
|
|
|
/** |
|
|
@ -8,17 +9,18 @@ Page({ |
|
|
|
*/ |
|
|
|
data: { |
|
|
|
formData:{ |
|
|
|
mobile:'', |
|
|
|
password:'', |
|
|
|
mobile:'18500000001', |
|
|
|
password:'Elink8888', |
|
|
|
appId:'wxaf87b420b87e2d79' |
|
|
|
} |
|
|
|
}, |
|
|
|
show:false |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* 生命周期函数--监听页面加载 |
|
|
|
*/ |
|
|
|
onLoad(options) { |
|
|
|
|
|
|
|
this.getPubKey() |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
@ -61,6 +63,77 @@ Page({ |
|
|
|
*/ |
|
|
|
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({ |
|
|
@ -77,6 +150,7 @@ Page({ |
|
|
|
console.log(this.data.formData) |
|
|
|
}, |
|
|
|
handelClickSubmit(){ |
|
|
|
let that = this |
|
|
|
if(!this.data.formData.mobile){ |
|
|
|
// 微信的轻量级api
|
|
|
|
wx.showToast({ |
|
|
@ -96,16 +170,11 @@ Page({ |
|
|
|
}) |
|
|
|
return |
|
|
|
} |
|
|
|
const parm = { |
|
|
|
// wxCode对象的初始化
|
|
|
|
wxCode :'', |
|
|
|
// ...将this.data.formData所有属性,赋值到表单中
|
|
|
|
...this.data.formData |
|
|
|
} |
|
|
|
// 轻量级api,在加载时进行显示
|
|
|
|
wx.showLoading({ |
|
|
|
title: '登录中', |
|
|
|
}) |
|
|
|
|
|
|
|
// // 轻量级api,在加载时进行显示
|
|
|
|
// wx.showLoading({
|
|
|
|
// title: '登录中',
|
|
|
|
// })
|
|
|
|
//微信的api,获取登录凭证,用户获取凭证
|
|
|
|
wx.getUserProfile({ |
|
|
|
desc: '用于获取用户个人信息', |
|
|
@ -114,35 +183,9 @@ Page({ |
|
|
|
var avatarUrl = userInfo.avatarUrl; |
|
|
|
wx.setStorageSync('avatarUrl', avatarUrl) |
|
|
|
console.log("User's Avatar URL:", avatarUrl); |
|
|
|
wx.login({ |
|
|
|
success: (res) => { |
|
|
|
parm.wxCode = res.code |
|
|
|
console.log(parm.wxCode); |
|
|
|
// 调用登录的接口
|
|
|
|
userLoginlog(parm).then((res)=>{ |
|
|
|
console.log(res); |
|
|
|
// 判断登录是否成功
|
|
|
|
if(res.code == 0){ |
|
|
|
// 用于跳转的api,跳转到某某某
|
|
|
|
wx.switchTab({ |
|
|
|
url: '/pages/index/index', |
|
|
|
}) |
|
|
|
//加入本地内存的api
|
|
|
|
wx.setStorageSync('token', res.data.token) |
|
|
|
that.getCustomerlist() |
|
|
|
|
|
|
|
} |
|
|
|
}).catch(err=>{ |
|
|
|
wx.showToast({ |
|
|
|
title: res.msg, |
|
|
|
icon:'none', |
|
|
|
duration:3000 |
|
|
|
}) |
|
|
|
console.log(err); |
|
|
|
}) |
|
|
|
wx.hideLoading() |
|
|
|
}, |
|
|
|
}) |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|