|
|
|
|
import constant from "../../utils/constant"
|
|
|
|
|
import orderAPI from '../../api/orderApi/orderApi'
|
|
|
|
|
import userApi from "../../api/userApi/userApi"
|
|
|
|
|
import {dateChange,formatDate} from "../../utils/util"
|
|
|
|
|
const app = getApp()
|
|
|
|
|
Page({
|
|
|
|
|
data: {
|
|
|
|
|
user:{}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onLoad:function () {
|
|
|
|
|
// TODO 报备历史获取 by userinfo
|
|
|
|
|
// 会设置this.data.role = 2 | 6 | 10 => 门卫 | 老师 | 管理
|
|
|
|
|
let clearTime = wx.getStorageSync(constant.CLEAR_TIME);
|
|
|
|
|
// 判断clearTime是否存在
|
|
|
|
|
let cleartimeNew = dateChange(7)
|
|
|
|
|
if (clearTime) {
|
|
|
|
|
if (formatDate() > clearTime) {
|
|
|
|
|
// 已过期,清除缓存
|
|
|
|
|
wx.clearStorageSync();
|
|
|
|
|
// 清除后执行更新数据及新的过期时间
|
|
|
|
|
wx.setStorageSync(constant.CLEAR_TIME, cleartimeNew);
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
wx.setStorageSync(constant.CLEAR_TIME, cleartimeNew);
|
|
|
|
|
}
|
|
|
|
|
let wechatID = wx.getStorageSync(constant.WECHATID)
|
|
|
|
|
if(wechatID&&wechatID!=null){
|
|
|
|
|
|
|
|
|
|
let userinfo = wx.getStorageSync(constant.USER_INFO)
|
|
|
|
|
if(!userinfo){
|
|
|
|
|
this.getuser(wechatID)
|
|
|
|
|
this.setData({user:userinfo})
|
|
|
|
|
}else{
|
|
|
|
|
this.setData({user:userinfo})
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
app.userInfoReadyCallback = (wcID:string) => {
|
|
|
|
|
if (wcID != '') {
|
|
|
|
|
this.getuser(wcID)
|
|
|
|
|
wx.setStorageSync(constant.WECHATID, wcID);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getuser(wechatID:string){
|
|
|
|
|
let that = this
|
|
|
|
|
userApi.getCurrentUser(wechatID).then(res=>{
|
|
|
|
|
let userInfo = JSON.parse(res.data.return_val)
|
|
|
|
|
wx.setStorageSync(constant.USER_INFO,userInfo)
|
|
|
|
|
that.setData({user:userInfo})
|
|
|
|
|
}).catch(err=>{
|
|
|
|
|
wx.showModal({
|
|
|
|
|
title:"获取信息错误",
|
|
|
|
|
content:JSON.stringify(err),
|
|
|
|
|
showCancel:false
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
async onScanValid() {
|
|
|
|
|
wx.showLoading({ title: '扫描场所码开始~' });
|
|
|
|
|
let that = this
|
|
|
|
|
wx.scanCode({
|
|
|
|
|
success(qrCode) {
|
|
|
|
|
//TODO get orderInfo by qrID
|
|
|
|
|
const qr_code = qrCode.result;
|
|
|
|
|
orderAPI.scanLocationCode({VenueCode:qr_code}).then(res=>{
|
|
|
|
|
let val = JSON.parse(res.data.return_val)
|
|
|
|
|
that.setData({user:val})
|
|
|
|
|
wx.setStorageSync(constant.USER_INFO,val)
|
|
|
|
|
wx.hideLoading()
|
|
|
|
|
if(res&&res.data.success){
|
|
|
|
|
wx.showToast({title:"场所码扫描成功~",icon:"success"})
|
|
|
|
|
}else{
|
|
|
|
|
let message = res.data.message
|
|
|
|
|
wx.showModal({
|
|
|
|
|
title:"扫描场所码失败",
|
|
|
|
|
content:message,icon:'error',
|
|
|
|
|
showCancel:false})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
fail:err=>{
|
|
|
|
|
wx.hideLoading()
|
|
|
|
|
if(err.errMsg&&err.errMsg.indexOf('cancel')<0){
|
|
|
|
|
wx.showToast({title:JSON.stringify(err),icon:"error"})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
uploadHealthCard(){
|
|
|
|
|
let that = this
|
|
|
|
|
wx.showLoading({ title: '健康码上传中' });
|
|
|
|
|
this.chooseBase64Image().then(suc=>{
|
|
|
|
|
orderAPI.uploadHealthCode({ImageBase64:suc.base64File,ext:'.'+suc.imgType}).then(res=>{
|
|
|
|
|
let val = JSON.parse(res.data.return_val)
|
|
|
|
|
that.setData({user:val})
|
|
|
|
|
wx.setStorageSync(constant.USER_INFO,val)
|
|
|
|
|
wx.hideLoading()
|
|
|
|
|
if(res&&res.data.success){
|
|
|
|
|
wx.showToast({title:"健康码上传成功~",icon:"success"})
|
|
|
|
|
}else{
|
|
|
|
|
let message=res.data.message
|
|
|
|
|
wx.showModal({
|
|
|
|
|
title:"健康码上传错误",
|
|
|
|
|
content:message,
|
|
|
|
|
showCancel:false})
|
|
|
|
|
}
|
|
|
|
|
}).catch(err=>{
|
|
|
|
|
wx.hideLoading()
|
|
|
|
|
wx.showModal({
|
|
|
|
|
title:"健康码上传错误",
|
|
|
|
|
content:"uploadHealthCode==="+JSON.stringify(err),
|
|
|
|
|
showCancel:false})
|
|
|
|
|
})
|
|
|
|
|
}).catch(err=>{
|
|
|
|
|
wx.hideLoading()
|
|
|
|
|
if(err&&err!=""){
|
|
|
|
|
wx.showModal({
|
|
|
|
|
title:"健康码上传错误",
|
|
|
|
|
content:"chooseBase64Image==="+JSON.stringify(err),
|
|
|
|
|
showCancel:false})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
uploadTravelCard(){
|
|
|
|
|
let that = this
|
|
|
|
|
wx.showLoading({ title: '行程码上传中' });
|
|
|
|
|
this.chooseBase64Image().then(suc=>{
|
|
|
|
|
orderAPI.uploadTripCode({ImageBase64:suc.base64File,ext:'.'+suc.imgType}).then(res=>{
|
|
|
|
|
let val = JSON.parse(res.data.return_val)
|
|
|
|
|
that.setData({user:val})
|
|
|
|
|
wx.setStorageSync(constant.USER_INFO,val)
|
|
|
|
|
wx.hideLoading()
|
|
|
|
|
if(res&&res.data&&res.data.success){
|
|
|
|
|
wx.showToast({title:"行程码上传成功~",icon:"success"})
|
|
|
|
|
}else{
|
|
|
|
|
let message=res.data.message
|
|
|
|
|
wx.showModal({
|
|
|
|
|
title:"行程码上传错误",
|
|
|
|
|
content:message,
|
|
|
|
|
showCancel:false})
|
|
|
|
|
}
|
|
|
|
|
}).catch(err=>{
|
|
|
|
|
wx.hideLoading()
|
|
|
|
|
wx.showModal({
|
|
|
|
|
title:"行程码上传错误",
|
|
|
|
|
content:"uploadTripCode==="+JSON.stringify(err),
|
|
|
|
|
showCancel:false})
|
|
|
|
|
})
|
|
|
|
|
}).catch(err=>{
|
|
|
|
|
wx.hideLoading()
|
|
|
|
|
if(err&&err!=""){
|
|
|
|
|
wx.showModal({
|
|
|
|
|
title:"行程码上传错误",
|
|
|
|
|
content:"chooseBase64Image==="+JSON.stringify(err),
|
|
|
|
|
showCancel:false})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
chooseBase64Image() {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
wx.chooseImage({
|
|
|
|
|
sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
|
|
|
|
|
count:1,
|
|
|
|
|
sourceType: ['album'], // 可以指定来源是相册还是相机,默认二者都有
|
|
|
|
|
success: (res)=> {
|
|
|
|
|
let tempFile = res.tempFiles[0];
|
|
|
|
|
this.getImageBase64_readFile(tempFile.path).then(suc=>{
|
|
|
|
|
resolve(suc)
|
|
|
|
|
}).catch(err=>{
|
|
|
|
|
reject(err)
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
fail: (err) => {
|
|
|
|
|
if(err.errMsg&&err.errMsg.indexOf('cancel')<0){
|
|
|
|
|
reject(err)
|
|
|
|
|
}
|
|
|
|
|
reject("")
|
|
|
|
|
}
|
|
|
|
|
},);
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
async getImageBase64_readFile(tempFilePath:string) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
wx.getImageInfo({
|
|
|
|
|
src:tempFilePath,
|
|
|
|
|
success:(imageInfo)=>{
|
|
|
|
|
var imgType = imageInfo.type
|
|
|
|
|
wx.compressImage({
|
|
|
|
|
src: tempFilePath, // 图片路径
|
|
|
|
|
quality: 1, // 压缩质量
|
|
|
|
|
compressedWidth:200,
|
|
|
|
|
success:file_path=>{
|
|
|
|
|
wx.getFileSystemManager().readFile({
|
|
|
|
|
filePath: file_path.tempFilePath, //选择图片返回的相对路径
|
|
|
|
|
encoding: "base64", //这个是很重要的
|
|
|
|
|
success: res => { //成功的回调
|
|
|
|
|
//返回base64格式
|
|
|
|
|
var base64Str = '' + res.data
|
|
|
|
|
let result:{base64File:string,imgType:string} ={base64File:base64Str,imgType:imgType}
|
|
|
|
|
resolve(result)
|
|
|
|
|
},
|
|
|
|
|
fail: err => {
|
|
|
|
|
reject(err)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
|
|
*/
|
|
|
|
|
onReady() {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面显示
|
|
|
|
|
*/
|
|
|
|
|
onShow() {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
|
|
*/
|
|
|
|
|
onHide() {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面卸载
|
|
|
|
|
*/
|
|
|
|
|
onUnload() {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
|
|
*/
|
|
|
|
|
onPullDownRefresh() {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
|
|
*/
|
|
|
|
|
onReachBottom() {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 用户点击右上角分享
|
|
|
|
|
*/
|
|
|
|
|
onShareAppMessage() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
})
|