创建新的小程序,进出码,体温上报功能迁移基本完成
This commit is contained in:
291
weixin-miniprogram/pages/residents/report.js
Normal file
291
weixin-miniprogram/pages/residents/report.js
Normal file
@@ -0,0 +1,291 @@
|
||||
// pages/residents/report.js
|
||||
import utils from '../../utils/util'
|
||||
|
||||
const app = getApp();
|
||||
|
||||
Page({
|
||||
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
isSkipOnShowFunc: false, // 是否跳过 onShow
|
||||
userInfo: null,
|
||||
timeInterval: null,
|
||||
formData: {
|
||||
userId: '',
|
||||
userRealname: '',
|
||||
address: '',
|
||||
time: '',
|
||||
timestamp: '',
|
||||
temperature: 0,
|
||||
},
|
||||
// 是否填报过
|
||||
isFilled: true,
|
||||
filledMsg: "",
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad(options) {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面初次渲染完成
|
||||
*/
|
||||
onReady() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow() {
|
||||
if (this.data.isSkipOnShowFunc) {
|
||||
this.setData({
|
||||
isSkipOnShowFunc: false,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
console.log('onShow')
|
||||
let userInfo = wx.getStorageSync("userInfo")
|
||||
console.log("userInfo", userInfo)
|
||||
this.setData({
|
||||
userInfo: userInfo,
|
||||
"formData.userId": userInfo.id,
|
||||
"formData.userRealname": userInfo.realname,
|
||||
timeInterval: setInterval(this.updateTime, 1000)
|
||||
})
|
||||
console.log("formData", this.data.formData)
|
||||
|
||||
this.updateTime();
|
||||
|
||||
// 获取用户当日是否填报过
|
||||
wx.showLoading({
|
||||
title: '加载中'
|
||||
})
|
||||
var that = this;
|
||||
wx.request({
|
||||
url: `${app.globalData.baseUrl}/access/report/getLatestRecord`,
|
||||
method: "POST",
|
||||
header: {
|
||||
"Content-Type": "application/x-www-form-urlencoded" //用于post
|
||||
},
|
||||
data: {
|
||||
userId: this.data.userInfo.id
|
||||
},
|
||||
success: function (d) {
|
||||
wx.hideLoading()
|
||||
let result = d.data
|
||||
console.log("result", result)
|
||||
if (result.success) {
|
||||
console.log("result.data", result.data);
|
||||
if (result.data == null || new Date(result.data.time) < new Date(new Date().toISOString().substring(0, 10))) {
|
||||
// 如果没有填报记录,或者填报记录不是今天,那么说明没有填报过
|
||||
that.setData({
|
||||
isFilled: false
|
||||
})
|
||||
} else {
|
||||
// 有今日记录,说明已经填报过
|
||||
that.setData({
|
||||
isFilled: true,
|
||||
filledMsg: "您已完成今日体温填报"
|
||||
})
|
||||
}
|
||||
} else {
|
||||
wx.showToast({
|
||||
title: "加载填报信息失败",
|
||||
icon: 'error',
|
||||
duration: 2000
|
||||
})
|
||||
}
|
||||
},
|
||||
fail: function () {
|
||||
wx.hideLoading()
|
||||
wx.showToast({
|
||||
title: "请求失败",
|
||||
icon: 'error',
|
||||
duration: 2000
|
||||
})
|
||||
},
|
||||
complete: function () {
|
||||
wx.hideNavigationBarLoading();
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面隐藏
|
||||
*/
|
||||
onHide() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面卸载
|
||||
*/
|
||||
onUnload() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面相关事件处理函数--监听用户下拉动作
|
||||
*/
|
||||
onPullDownRefresh() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
*/
|
||||
onReachBottom() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 用户点击右上角分享
|
||||
*/
|
||||
onShareAppMessage() {
|
||||
|
||||
},
|
||||
|
||||
|
||||
bindTemperatureChanged(e) {
|
||||
this.setData({
|
||||
"formData.temperature": e.detail.value
|
||||
})
|
||||
|
||||
},
|
||||
|
||||
updateTime() {
|
||||
let timestamp = Date.now()
|
||||
this.setData({
|
||||
"formData.timestamp": timestamp,
|
||||
"formData.time": utils.formatTime(new Date(timestamp))
|
||||
})
|
||||
},
|
||||
chooseLocation: async function () {
|
||||
wx.showLoading({
|
||||
title: '正在获取权限'
|
||||
})
|
||||
await new Promise((resolve) => {
|
||||
wx.getSetting({
|
||||
success(res) {
|
||||
wx.hideLoading()
|
||||
if (!res.authSetting['scope.userLocation']) {
|
||||
wx.authorize({
|
||||
scope: 'scope.userLocationBackground',
|
||||
success() {
|
||||
resolve();
|
||||
}
|
||||
})
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
wx.showLoading({
|
||||
title: '正在定位'
|
||||
})
|
||||
var that = this;
|
||||
this.setData({
|
||||
isSkipOnShowFunc: true, // 关闭位置选择器后,会触发 onShow,这里避免掉
|
||||
})
|
||||
wx.chooseLocation({
|
||||
success: function (res) {
|
||||
console.log("wx.chooseLocation success")
|
||||
that.setData({
|
||||
"formData.address": res.address
|
||||
})
|
||||
},
|
||||
fail: function () {
|
||||
console.log("wx.chooseLocation fail", that.data.formData)
|
||||
if (!that.data.formData.address) {
|
||||
wx.showToast({
|
||||
title: "请获取当前位置",
|
||||
icon: 'error'
|
||||
})
|
||||
}
|
||||
},
|
||||
})
|
||||
wx.hideLoading()
|
||||
},
|
||||
// 体温上报 提交按钮
|
||||
report() {
|
||||
console.log("点击提交", "this.data.formData", this.data.formData)
|
||||
if (!this.data.formData.address) {
|
||||
wx.showToast({
|
||||
title: "请获取当前位置",
|
||||
icon: 'error'
|
||||
})
|
||||
return;
|
||||
}
|
||||
wx.showLoading({
|
||||
title: '加载中'
|
||||
})
|
||||
var that = this;
|
||||
wx.request({
|
||||
url: `${app.globalData.baseUrl}/access/report/submit`,
|
||||
method: "POST",
|
||||
header: {
|
||||
"Content-Type": "application/x-www-form-urlencoded" //用于post
|
||||
},
|
||||
data: {
|
||||
...this.data.formData,
|
||||
},
|
||||
success: function (d) {
|
||||
console.log("begin success")
|
||||
wx.hideLoading()
|
||||
let result = d.data;
|
||||
if (result.success) {
|
||||
// 填报完成
|
||||
that.setData({
|
||||
isFilled: true,
|
||||
filledMsg: "您已完成今日体温填报"
|
||||
})
|
||||
console.log("result.data", result.data);
|
||||
wx.showToast({
|
||||
title: "填报成功",
|
||||
icon: 'success',
|
||||
duration: 2000
|
||||
})
|
||||
} else {
|
||||
wx.showToast({
|
||||
title: result.msg || "出错啦",
|
||||
icon: 'error',
|
||||
duration: 2000
|
||||
})
|
||||
}
|
||||
that.isShow = ''
|
||||
console.log("end success")
|
||||
},
|
||||
fail: function () {
|
||||
console.log("begin fail")
|
||||
wx.hideLoading()
|
||||
wx.showToast({
|
||||
title: "请求失败",
|
||||
icon: 'error',
|
||||
duration: 2000
|
||||
})
|
||||
console.log("end fail")
|
||||
},
|
||||
complete: function () {
|
||||
console.log("begin complete")
|
||||
if (typeof (callback) === "function")
|
||||
callback();
|
||||
wx.hideNavigationBarLoading();
|
||||
console.log("end complete")
|
||||
}
|
||||
})
|
||||
},
|
||||
// 历史填报
|
||||
myreport() {
|
||||
wx.navigateTo({
|
||||
url: "/pages/residents/reportHistory"
|
||||
})
|
||||
}
|
||||
})
|
Reference in New Issue
Block a user