198 lines
3.7 KiB
JavaScript
198 lines
3.7 KiB
JavaScript
// pages/signup/code.js
|
|
import _ from '../../commons/js/commons'
|
|
const timer = require('../../commons/js/lib/wxTimer');
|
|
var wxTimer = null
|
|
const app = getApp()
|
|
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
navBar: {
|
|
title: '客户签到',
|
|
txtColor: '#fff',
|
|
bgColor: '#1a1c26',
|
|
isShowBg: true,
|
|
showHomeIcon: true
|
|
},
|
|
qrcode_img: '',
|
|
qrcode_count_time: 3000,
|
|
wxTimerList: {},
|
|
wxTimer: null,
|
|
nowTime: "",
|
|
item: {},
|
|
info: "",
|
|
fail_img: ''
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad(options) {
|
|
let that = this
|
|
wx.getScreenBrightness({
|
|
success: (res) => {
|
|
that.setData({
|
|
ori_screen_bright: res.value
|
|
})
|
|
}
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow() {
|
|
this.getappSignConf()
|
|
},
|
|
|
|
onHide() {
|
|
if (wxTimer) {
|
|
wxTimer.stop();
|
|
wxTimer = null
|
|
}
|
|
this.setData({
|
|
wxTimerList: {},
|
|
wxTimer: null,
|
|
})
|
|
this.resetScreenBright()
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload() {
|
|
if (wxTimer) {
|
|
wxTimer.stop();
|
|
wxTimer = null
|
|
}
|
|
this.setData({
|
|
wxTimerList: {},
|
|
wxTimer: null,
|
|
})
|
|
this.resetScreenBright()
|
|
},
|
|
|
|
/**
|
|
* 接口请求小程序码
|
|
*/
|
|
getappSignConf() {
|
|
this.getUserLocation().then(() => {
|
|
if (this.loading) return
|
|
wx.showLoading({
|
|
title: '重新生成中...',
|
|
mask: true
|
|
})
|
|
if (wxTimer) {
|
|
wxTimer.stop();
|
|
wxTimer = null
|
|
}
|
|
this.setData({
|
|
wxTimerList: {},
|
|
wxTimer: null,
|
|
loading: true
|
|
})
|
|
const params = {
|
|
lat: this.data.lat,
|
|
lng: this.data.lng
|
|
}
|
|
/////接口方法
|
|
_.apiQuery.getappSignConf(params).then(res => {
|
|
|
|
if (res.data.type == 'fail') {
|
|
this.setData({
|
|
fail_img: res.data.fail_img
|
|
})
|
|
wx.showToast({
|
|
title: res.data.msg,
|
|
icon: 'none',
|
|
duration: 2000,
|
|
})
|
|
} else {
|
|
this.setData({
|
|
qrcode_img: res.data.qcode,
|
|
qrcode_count_time: parseInt(res.data.qrcode_count_time),
|
|
loading: false,
|
|
info: res.data
|
|
}, () => {
|
|
wx.hideLoading()
|
|
this.getTimes(this.data.qrcode_count_time).then(() => {
|
|
this.getappSignConf()
|
|
})
|
|
this.setScreenBright()
|
|
})
|
|
}
|
|
})
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 设置亮度
|
|
*/
|
|
setScreenBright() {
|
|
wx.setScreenBrightness({
|
|
value: 1
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 恢复亮度
|
|
*/
|
|
resetScreenBright() {
|
|
wx.setScreenBrightness({
|
|
value: this.data.ori_screen_bright
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 生成倒计时
|
|
*/
|
|
getTimes(seconds) {
|
|
let that = this
|
|
return new Promise(function (resolve, reject) {
|
|
wxTimer = new timer({
|
|
name: 'wxTimer',
|
|
leftTime: seconds,
|
|
complete: function () {
|
|
setTimeout(() => {
|
|
that.setData({
|
|
// 'submitFlag': false,
|
|
wxTimerList: {}
|
|
})
|
|
resolve()
|
|
}, 1000);
|
|
},
|
|
})
|
|
wxTimer.start(that);
|
|
})
|
|
},
|
|
|
|
//推送链接
|
|
pushLink(e) {
|
|
if (e.currentTarget.dataset.url) {
|
|
_.$router.openUrlScheme(e.currentTarget.dataset.url)
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 授权地理位置
|
|
*/
|
|
getUserLocation() {
|
|
let that = this
|
|
return new Promise(function (resolve, reject) {
|
|
_.userManager.getUserLocation().then(location => {
|
|
that.setData({
|
|
lat: location.lat,
|
|
lng: location.lng
|
|
}, () => {
|
|
resolve()
|
|
})
|
|
}).catch(res => {
|
|
reject(res)
|
|
})
|
|
})
|
|
},
|
|
|
|
}) |