145 lines
2.7 KiB
JavaScript
145 lines
2.7 KiB
JavaScript
// pages/scan/entrance.js
|
|
|
|
const gateService = require("../../services/gate")
|
|
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
// 传入参数
|
|
gateId: "",
|
|
|
|
// 接口返回数据
|
|
gateDetail: "",
|
|
|
|
// UI显示用
|
|
gateName: "未知",
|
|
open: false, // 大门是否开始
|
|
|
|
currentTime: "",
|
|
|
|
// 是否已经完成开门
|
|
finishOpen: false,
|
|
// 用户是否有权限进入
|
|
isForbidden: false,
|
|
forbiddenMsg: "",
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad(options) {
|
|
console.log("entrance -> options", typeof (options), options)
|
|
let scene = options.scene ? decodeURIComponent(options.scene) : undefined // %3B == ; %26 == &
|
|
console.log("scene", options.scene, scene)
|
|
if (!scene || scene.indexOf(';') == -1) {
|
|
wx.showModal({
|
|
title: '出错啦',
|
|
content: '参数不正确' + JSON.stringify(options),
|
|
showCancel: false,
|
|
complete: (res) => {
|
|
wx.navigateBack()
|
|
}
|
|
})
|
|
return
|
|
}
|
|
|
|
let gateId = scene.split(';')[1]
|
|
this.setData({
|
|
gateId: gateId,
|
|
});
|
|
|
|
this.loadPageData()
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh() {
|
|
this.loadPageData()
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage() {
|
|
|
|
},
|
|
|
|
|
|
loadPageData() {
|
|
let gateId = this.data.gateId;
|
|
(async () => {
|
|
let gateDetail = await gateService.getGateDetail(gateId)
|
|
console.log("gateDetail", gateDetail)
|
|
this.setData({
|
|
gateDetail: JSON.stringify(gateDetail),
|
|
gateName: gateDetail.name,
|
|
open: gateDetail.open,
|
|
currentTime: new Date(Date.now() + 8 * 3600 * 1000).toISOString().replace('T', ' ').substring(0, 19)
|
|
});
|
|
})();
|
|
},
|
|
|
|
enterGate: function () {
|
|
(async () => {
|
|
let enterGate = await gateService.enterGate(this.data.gateId, "IN")
|
|
console.log("enterGate", enterGate)
|
|
if (enterGate === true) {
|
|
// 开门成功
|
|
this.setData({
|
|
finishOpen: true,
|
|
isForbidden: false,
|
|
})
|
|
} else {
|
|
// 无权进入大门
|
|
this.setData({
|
|
finishOpen: true,
|
|
isForbidden: true,
|
|
forbiddenMsg: "开门失败",
|
|
})
|
|
}
|
|
})();
|
|
},
|
|
|
|
navigateBack: function () {
|
|
wx.navigateBack()
|
|
}
|
|
}) |