You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
212 lines
5.0 KiB
212 lines
5.0 KiB
|
4 years ago
|
import constant from "../../utils/constant"
|
||
|
|
import { IORecords, User } from '../../services/baseClass'
|
||
|
|
import services from "../../services/index"
|
||
|
|
import { BASE_URL } from '../../utils/util';
|
||
|
|
const recordType = {
|
||
|
|
GREEN: '绿码',
|
||
|
|
YELLOW: "黄码",
|
||
|
|
RED:'红码'
|
||
|
|
}
|
||
|
|
// pages/travel-card/travelcard.ts
|
||
|
|
Page({
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 页面的初始数据
|
||
|
|
*/
|
||
|
|
data: {
|
||
|
|
files:[],
|
||
|
|
images:[],
|
||
|
|
uploadImg:"",
|
||
|
|
base64File:"",
|
||
|
|
showUpload:true,
|
||
|
|
user:{},
|
||
|
|
count:2,
|
||
|
|
nomore:false,
|
||
|
|
recordType
|
||
|
|
},
|
||
|
|
clearImg(e) {
|
||
|
|
this.setData({
|
||
|
|
uploadImg: "",
|
||
|
|
base64File: "",
|
||
|
|
showUpload: true
|
||
|
|
})
|
||
|
|
},
|
||
|
|
chooseBase64Image() {
|
||
|
|
const that = this;
|
||
|
|
wx.showLoading({ title: '图片上传中' });
|
||
|
|
return new Promise((resolve, reject) => {
|
||
|
|
wx.chooseImage({
|
||
|
|
sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
|
||
|
|
count:1,
|
||
|
|
sourceType: ['album'], // 可以指定来源是相册还是相机,默认二者都有
|
||
|
|
success: (res)=> {
|
||
|
|
let tempFilePath = res.tempFilePaths[0];
|
||
|
|
let tempFile = res.tempFiles[0];
|
||
|
|
console.log(res);
|
||
|
|
console.log(tempFile);
|
||
|
|
|
||
|
|
// 返回选定照片的本地文件路径,tempFilePath可以作为img标签的src属性显示图片
|
||
|
|
that.setData({
|
||
|
|
uploadImg: tempFilePath,
|
||
|
|
});
|
||
|
|
wx.getImageInfo({
|
||
|
|
src:tempFilePath,
|
||
|
|
success:(imageInfo)=>{
|
||
|
|
var imgType = imageInfo.type
|
||
|
|
wx.getFileSystemManager().readFile({
|
||
|
|
filePath: tempFilePath, //选择图片返回的相对路径
|
||
|
|
encoding: "base64", //这个是很重要的
|
||
|
|
success: res => { //成功的回调
|
||
|
|
//返回base64格式
|
||
|
|
var base64Str = 'data:image/' + imgType + ';base64,' + res.data
|
||
|
|
|
||
|
|
console.log(base64Str)
|
||
|
|
this.setData({base64File:base64Str,showUpload:false})
|
||
|
|
resolve(base64Str)
|
||
|
|
wx.hideLoading();
|
||
|
|
},
|
||
|
|
fail: err => {
|
||
|
|
console.log(err)
|
||
|
|
reject(err)
|
||
|
|
}
|
||
|
|
})
|
||
|
|
}
|
||
|
|
})
|
||
|
|
},
|
||
|
|
fail: (err) => {
|
||
|
|
console.log(err)
|
||
|
|
}
|
||
|
|
});
|
||
|
|
})
|
||
|
|
},
|
||
|
|
previewImg(e) {
|
||
|
|
let urls = [];
|
||
|
|
urls.push(e.currentTarget.dataset.src)
|
||
|
|
wx.previewImage({
|
||
|
|
urls: urls, // 需要预览的图片http链接列表
|
||
|
|
});
|
||
|
|
},
|
||
|
|
async loadMore() {
|
||
|
|
if(this.data.nomore){
|
||
|
|
wx.showToast({title:"已经到头了~"})
|
||
|
|
|
||
|
|
}else{
|
||
|
|
let count = this.data.count+2;
|
||
|
|
this.setData({count:count});
|
||
|
|
//console.log(this.data)
|
||
|
|
this.getCards(this.data.user)
|
||
|
|
}
|
||
|
|
},
|
||
|
|
async getCards(user:any){
|
||
|
|
|
||
|
|
let res = await services.API.materialUpload.getIORecordsList.request({userID:user.userID,type:"travel",count:this.data.count});
|
||
|
|
|
||
|
|
//console.log(res);
|
||
|
|
if(res&&res.data){
|
||
|
|
let records = res.data
|
||
|
|
if(records.length<this.data.count){
|
||
|
|
this.setData({nomore:true})
|
||
|
|
}
|
||
|
|
records.map((record)=>{
|
||
|
|
let imagePath = record.imagePath
|
||
|
|
if(imagePath){
|
||
|
|
let url = BASE_URL + "/api/image/get"+imagePath;
|
||
|
|
let tempMap = this.data.images;
|
||
|
|
tempMap.push(url);
|
||
|
|
this.setData({images:tempMap})
|
||
|
|
}
|
||
|
|
})
|
||
|
|
this.setData({files:res.data})
|
||
|
|
|
||
|
|
}
|
||
|
|
},
|
||
|
|
onSubmit:async function({ detail }: { detail: any}) {
|
||
|
|
// TODO gen order
|
||
|
|
if(!this.data.teacherID){
|
||
|
|
wx.showToast({
|
||
|
|
title: '提交失败,缺少用户信息',
|
||
|
|
icon: 'none'
|
||
|
|
});
|
||
|
|
}
|
||
|
|
const submitRecord: IORecords = {
|
||
|
|
...detail.value,
|
||
|
|
ioType:this.data.ioTypesArray.indexOf(this.data.ioType),
|
||
|
|
teacherID:this.data.teacherID,
|
||
|
|
commitTime: this.data.applyDate + ' ' + this.data.applyTime+":00",
|
||
|
|
}
|
||
|
|
let res = await services.API.iORecords.addIORecord.request(submitRecord);
|
||
|
|
console.log(res);
|
||
|
|
|
||
|
|
if(res&&res.data){
|
||
|
|
|
||
|
|
let reportid = res.data;
|
||
|
|
wx.setStorageSync("myReport/myReport", reportid)
|
||
|
|
}
|
||
|
|
},
|
||
|
|
/**
|
||
|
|
* 生命周期函数--监听页面加载
|
||
|
|
*/
|
||
|
|
onLoad() {
|
||
|
|
// wx.removeStorageSync(constant.USER_INFO);
|
||
|
|
let user = wx.getStorageSync(constant.USER_INFO);
|
||
|
|
if(!user){
|
||
|
|
wx.navigateTo({url:"../../index/index"})
|
||
|
|
}
|
||
|
|
this.getCards(user);
|
||
|
|
this.setData({
|
||
|
|
...this.data,
|
||
|
|
...(user as User)
|
||
|
|
})
|
||
|
|
},
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 生命周期函数--监听页面初次渲染完成
|
||
|
|
*/
|
||
|
|
onReady() {
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 生命周期函数--监听页面显示
|
||
|
|
*/
|
||
|
|
onShow() {
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 生命周期函数--监听页面隐藏
|
||
|
|
*/
|
||
|
|
onHide() {
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 生命周期函数--监听页面卸载
|
||
|
|
*/
|
||
|
|
onUnload() {
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
||
|
|
*/
|
||
|
|
onPullDownRefresh() {
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 页面上拉触底事件的处理函数
|
||
|
|
*/
|
||
|
|
onReachBottom() {
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 用户点击右上角分享
|
||
|
|
*/
|
||
|
|
onShareAppMessage() {
|
||
|
|
|
||
|
|
}
|
||
|
|
})
|