You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
2.3 KiB
JavaScript
102 lines
2.3 KiB
JavaScript
// pages/verify/verify.js
|
|
const app = getApp()
|
|
Component({
|
|
options: {
|
|
addGlobalClass: true,
|
|
},
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
userInfo: {},
|
|
hasUserInfo: false,
|
|
canIUse: wx.canIUse('button.open-type.getUserInfo'),
|
|
hospital: '',
|
|
name: '',
|
|
phone: ''
|
|
},
|
|
lifetimes:{
|
|
attached: function(){
|
|
if (app.globalData.userInfo) {
|
|
this.setData({
|
|
userInfo: app.globalData.userInfo,
|
|
hasUserInfo: true
|
|
})
|
|
}else if (this.data.canIUse) {
|
|
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
|
|
// 所以此处加入 callback 以防止这种情况
|
|
app.userInfoReadyCallback = res => {
|
|
this.setData({
|
|
userInfo: res.userInfo,
|
|
hasUserInfo: true
|
|
})
|
|
}
|
|
} else {
|
|
// 在没有 open-type=getUserInfo 版本的兼容处理
|
|
wx.getUserInfo({
|
|
success: res => {
|
|
app.globalData.userInfo = res.userInfo
|
|
this.setData({
|
|
userInfo: res.userInfo,
|
|
hasUserInfo: true
|
|
})
|
|
}
|
|
})
|
|
}
|
|
}
|
|
},
|
|
methods: {
|
|
signIn(e){
|
|
let formData=e.detail.value;
|
|
let userInfo=this.data.userInfo;
|
|
let that=this;
|
|
// 验证数据
|
|
if(!formData.hospital){
|
|
wx.showToast({
|
|
title: '医院名称必填',
|
|
icon: 'error',
|
|
})
|
|
return;
|
|
}
|
|
if(!formData.name){
|
|
wx.showToast({
|
|
title: '姓名必填',
|
|
icon: 'error',
|
|
})
|
|
return;
|
|
}
|
|
if(!formData.phone){
|
|
wx.showToast({
|
|
title: '手机号必填',
|
|
icon: 'error',
|
|
})
|
|
return;
|
|
}
|
|
app.utils.util.request({
|
|
url: '/signIn',
|
|
data: {
|
|
nickName: userInfo.nickName,
|
|
avatar: userInfo.avatarUrl,
|
|
gender: userInfo.gender,
|
|
phone: formData.phone,
|
|
hospital: formData.hospital,
|
|
name: formData.name
|
|
},
|
|
success: function(res) {
|
|
app.globalData.status = 0
|
|
that.triggerEvent("reflush")
|
|
}
|
|
})
|
|
},
|
|
getUserInfo(e) {
|
|
if (e.detail.userInfo) {
|
|
//用户按了允许授权按钮
|
|
app.globalData.userInfo = e.detail.userInfo
|
|
this.setData({
|
|
userInfo: e.detail.userInfo,
|
|
hasUserInfo: true
|
|
})
|
|
}
|
|
}
|
|
}
|
|
}) |