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/health-card/healthcard.ts Page({ /** * 页面的初始数据 */ data: { count:2, files:[], images:[], uploadImg:"", base64File:"", showUpload:true, user:{}, 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) } }); }) }, 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(query?:any){ let res = await services.API.materialUpload.getIORecordsList.request({userID:query.userID,type:"health",count:this.data.count}); // console.log(res); if(res&&res.data){ let records = res.data if(records.length{ 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}) } }, previewImg(e) { console.log(e.currentTarget.dataset); console.log(this.data.fileUrls); let urls = []; urls.push(e.currentTarget.dataset.src) wx.previewImage({ urls: urls, // 需要预览的图片http链接列表 }); }, 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() { } })