// pages/my/experience/experience.js const App = getApp() Page({ /** * 页面的初始数据 */ data: { expertId: null, meetId: null, memberId: null, topicId: null, content: null, user: wx.getStorageSync('USER'), isAnonymous: false, checked: false, list: [], picture: '', }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { console.log(options) this.setData({ meetId: options.meetId, expertId: options.expertId, topicId: options.topicId, memberId: options.memberId }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, change(e) { if (e.detail.value.length > 0) { this.setData({ isAnonymous: true }) } else { this.setData({ isAnonymous: false }) } }, submit() { if (!this.data.content) { wx.showToast({ icon: 'none', title: '心得感受不能为空', }) return false } App._post_form('meetevaluation/shareExperience', '', { content: this.data.content, expertId: this.data.expertId, id: this.data.user.id, meetId: this.data.meetId, isAnonymous: this.data.isAnonymous == true ? 1 : 0, memberId: this.data.user.id, picture: this.data.list.join(','), topicId: this.data.topicId }, res => { if (res.code === 0) { wx.showToast({ title: '分享心得成功', }) setTimeout(() =>{ wx.switchTab({ url: '/pages/home/index/index', }) },2000) } }) }, uploadHandle() { if (this.data.list.length == 6) { return false } let _this = this; var tempFile; wx.showActionSheet({ itemList: ['拍照上传', '从相册中选择'], success(res) { if (res.tapIndex === 0) { wx.chooseImage({ count: 1, sizeType: ['original', 'compressed'], sourceType: ['camera'], success(res) { const tempFilePaths = res.tempFilePaths wx.uploadFile({ url: App.apiRoot + 'file/upload', filePath: tempFilePaths[0], name: 'file', success: function (res) { if (res.errMsg === "uploadFile:ok") { wx.showToast({ title: '上传成功', image: '', duration: 1500, mask: false }); let data = JSON.parse(res.data) let imglist = _this.data.list imglist.push(data.data) _this.setData({ list: imglist }) } }, function () { wx.showToast({ title: '上传失败', icon: 'none', image: '', duration: 1500, mask: false, }); } }) } }) } else if (res.tapIndex === 1) { wx.chooseImage({ count: 1, sizeType: ['original', 'compressed'], sourceType: ['album'], success(res) { const tempFilePaths = res.tempFilePaths wx.uploadFile({ url: App.apiRoot + 'file/upload', filePath: tempFilePaths[0], name: 'file', success: function (res) { if (res.errMsg === "uploadFile:ok") { wx.showToast({ title: '上传成功', image: '', duration: 1500, mask: false }); let data = JSON.parse(res.data) let imglist = _this.data.list imglist.push(data.data) _this.setData({ list: imglist }) } }, function () { wx.showToast({ title: '上传失败', icon: 'none', image: '', duration: 1500, mask: false, success: (result) => {}, fail: () => {}, complete: () => {} }); } }) } }) } }, fail(res) {} }) }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })