Files
lcb/pages/signup/index.js
T
2024-06-03 20:01:49 +08:00

188 lines
3.9 KiB
JavaScript

// pages/signup/index.js
import _ from '../../commons/js/commons'
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
navBar: {
title: '签到',
txtColor: '#fff',
bgColor: '#1a1c26',
isShowBg: true,
showHomeIcon: false
},
list: [],
userinfo: {},
has_mobile: false,
lat: 0,
lng: 0,
qkey: '',
info: '',
show_sign: false,
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
var obj = wx.getEnterOptionsSync()
if (obj.query.key) {
this.setData({
qkey: obj.query.key
})
}
this.getappUserConf({
'key': this.data.qkey
})
this.isBindMobile()
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
getappUserConf(params) {
_.apiQuery.getappUserConf(params).then(res => {
if (res.data.type === 'fail') {
let arr = [];
for (const key in res.data) {
arr.push(`${key}=${res.data[key]}`)
}
let string = '?' + arr.join('&')
wx.navigateTo({
url: '/pages/signup/status' + string,
})
} else {
this.setData({
info: res.data,
show_sign: true
})
}
})
},
/**
* 是否绑定用户手机号
*/
isBindMobile() {
let that = this
_.apiQuery.asyncLogin().then(res => {
_.apiQuery.getappUserTel().then(res => {
var isBinMobile = false
if (res.data.mobile) {
isBinMobile = true
}
that.setData({
has_mobile: true
})
})
})
},
//授权手机号码
getPhoneNumber(e) {
if (e.detail.errMsg && e.detail.errMsg.indexOf('ok') > -1) {
let that = this;
_.apiQuery.authUserPhone(e).then(res => {
_.apiQuery.getappUserTel().then(res => {
if (res.data.mobile) {
that.setData({
has_mobile: true
})
this.bindsignup()
} else {
that.setData({
has_mobile: false
})
wx.showToast({
title: '授权手机号失败', //提示的内容
duration: 2000, //持续的时间
icon: 'none', //图标有success、error、loading、none四种
})
}
})
})
} else {
app.printErrorClient('failGetPhoneNumber', ['用户拒绝授权手机号码:' + JSON.stringify(e)])
}
},
/**
* 授权地理位置
*/
getUserLocation() {
let that = this
return new Promise(function (resolve, reject) {
if (app.getStorageByKey('u_lat') && app.getStorageByKey('u_lng')) {
that.setData({
lat: app.getStorageByKey('u_lat'),
lng: app.getStorageByKey('u_lng')
}, () => {
resolve()
})
} else {
//u_lat u_lng
_.userManager.getUserLocation().then(location => {
console.log(location)
that.setData({
lat: location.lat,
lng: location.lng
}, () => {
resolve()
})
}).catch(res => {
reject(res)
})
}
})
},
/**
* 签到
*/
bindsignup() {
this.getUserLocation().then(() => {
let params = {
'key': this.data.qkey,
'lng': this.data.lng.toFixed(11),
'lat': this.data.lat.toFixed(11)
}
_.apiQuery.postAppSign(params).then(res => {
let arr = [];
for (const key in res.data) {
arr.push(`${key}=${res.data[key]}`)
}
let string = '?' + arr.join('&')
wx.navigateTo({
url: '/pages/signup/status' + string,
})
})
})
}
})