// pages/d-task/d-task.js const app = getApp(); var myRequest = require("../../utils/api.js"); Page({ /** * 页面的初始数据 */ data: { fileList: [], taskData: { id: '', name: '', time: '', content: '', handname: '', }, requestData: { id: '', feedbackText: '', file: '', status: '', }, taskId: '', updateFile: [], feedbackText: '', filePath: '' }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData({ 'taskData.id': options.taskId, 'taskData.name': options.name, 'taskData.time': options.time, 'taskData.content': options.content, 'taskData.handname': options.handname, }) }, getContent(e) { this.setData({ feedbackText: e.detail.value }) }, feedback(e) { var state = e.currentTarget.dataset.state; var token = wx.getStorageSync("token"); var that = this; var parem = {}; parem.id = that.data.taskData.id; parem.state = state; if (that.data.filePath != '') { parem.feedbackImg = that.data.filePath } if (that.data.feedbackText) { parem.feedbackText = that.data.feedbackText } myRequest.myRequest('task/feedback', parem, 'post',{ 'content-type': 'multipart/form-data', 'token': ''+token+'' }).then(function(res){ console.log(res) }).catch(function(res){ console.log(res); }) }, handleAdd(e) { var that = this; const { fileList } = this.data; const { files } = e.detail; var imgArr = []; // for(var i=0; i < files.length; i++){ // imgArr.push(files[i].url); // } this.setData({ fileList: [...fileList, ...files], }); var filePath = this.data.filePath; if (filePath != '') { filePath = filePath + ',' } for (let i = 0; i < files.length; i++) { myRequest.updateImg({file:files[i].url}).then(function(res){ that.setData({ filePath: filePath + res }) }).catch(function(res){ console.log(res); }) } }, handleRemove(e) { const { index } = e.detail; const { fileList } = this.data; fileList.splice(index, 1); this.setData({ fileList, }); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })