// pages/home/xyc/index.js import FormData from './../../../utils/formdata/index' import Toast from 'tdesign-miniprogram/toast/index'; const app = getApp();//新建页面时 默认引入 const req = app.xzjlReq();//初始化一个的request() 实例 Page({ /** * 页面的初始数据 */ data: { fileList: [],//图片list form:{ content:"", deadline:'', link:'', img:'111' }, cvisible: false, note: '', xyForm:{ }, visible:false,//弹窗 single:true, xzInfo:{}, userInfo:{}, xyNfc:true, xyInfo:{ } }, handleAdd(e){/**添加图片 */ const { fileList } = this.data; const { files } = e.detail; // 方法1:选择完所有图片之后,统一上传,因此选择完就直接展示 this.setData({ fileList: [...fileList, ...files], // 此时设置了 fileList 之后才会展示选择的图片 }); // files.forEach(file => this.uploadFile(file)) wx.chooseImage({ count: 1, // 默认9 sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有 sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有 success: res => { var tempFilePaths = res.tempFilePaths; wx.uploadFile({ url: 'https://xzjl-api.windymuse.cn/api/resource', filePath: tempFilePaths[0], name: 'file', header: { 'Authorization': wx.getStorageSync('token'), 'Content-Type': 'multipart/form-data' }, formData: { type: 'poster' }, success: async res => { console.log(res, '111111'); if (res.statusCode == 200) { res.data = JSON.parse(res.data); console.log(res.data); if (res.data.code == 1) { console.log(res.data.data.url); this.img = this.baseUrl + res.data.data.url; // 图片路径 this.userinfo.avatar = res.data.data.url; // let n = await this.$api.upload({ file: res.data.fullurl }); // console.log(n, '上传后'); } } }, fail(res) { showToast('图片上传失败'); } }); } }); }, handleRemove(e){/**删除图片 */ const { index } = e.detail; const { fileList } = this.data; fileList.splice(index, 1); this.setData({ fileList, }); }, uploadFile(file) {/**执行 */ const FormData = require('./../../../utils/formdata/index.js') let fd = new FormData() fd.append('type','graphic') console.log(file) fd.appendFile(file.name,file.url) console.log('文件上传') req.postRequest('/api/resource',fd.getData()).then((res)=>{ console.log(res) if(res.data.code==200){ console.log('res') } console.log(this.userInfo); }).catch((err)=>{ console.log(err); }) console.log('许愿成功!') }, go2MyYw(){ wx.navigateTo({ url: '/pages/home/xyc/wdyw/wdyw' }) }, go2TaYw(){ wx.navigateTo({ url: '/pages/home/xyc/tdyw/tdyw' }) }, doXzTime(){ this.setData({ cvisible: true }); console.log('执行选择时间') }, handleConfirm(e) { const { value } = e.detail; const format = (val) => { const date = new Date(val); return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`; }; this.setData({ note: format(value) }); }, onClose({ detail }) { console.log(detail.trigger); }, showMultiText() { Toast({ context: this, selector: '#t-toast', message: '投枚银币许个愿吧\n守护精灵将会祝福你的愿望!', dataduration:10 }); }, doXyPop(){/**弹出许愿弹窗 */ console.log('执行力。。。。。') this.setData({visible:true}) }, onVisibleChange(e) { this.setData({ visible: e.detail.visible, }); }, doCancelXy(){/**取消许愿 */ this.setData({ visible: false, }); }, doFinishXy(e){/**许愿 */ console.log('开始执行xxxx') console.log(e.target) console.log(e.target.dataset.fs) this.setData({ visible: false, }); let param = e.target.dataset.fs console.log(e.target.dataset) console.log(e.target.dataset.note) param.deadline = e.target.dataset.note console.log(this.note) //api/user/curt/wish req.postRequest('/api/user/curt/wish',param).then((res)=>{ console.log(res) if(res.data.code==200){ this.setData({userInfo:res.data.data}) if(res.data.data&&res.data.data.loverId&&res.data.data.loverId!=null){ this.setData({single:false}) } } console.log(this.userInfo); }).catch((err)=>{ console.log(err); }) console.log('许愿成功!') }, initXy(){ req.getRequest('/api/user/curt',{}).then((res)=>{ console.log(res) if(res.data.code==200){ this.setData({userInfo:res.data.data}) if(res.data.data&&res.data.data.loverId&&res.data.data.loverId!=null){ this.setData({single:false}) } } console.log(this.userInfo); }).catch((err)=>{ console.log(err); }) this.setData({xyInfo:wx.getStorageSync('nfc')}) }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.initXy() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { this.initXy() }, /** * 生命周期函数--监听页面显示 */ onShow() { console.log('隐藏了') }, /** * 生命周期函数--监听页面隐藏 */ onHide() { console.log('隐藏了') }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })