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.
183 lines
3.7 KiB
183 lines
3.7 KiB
// pages/suggestion/suggestion.js |
|
const $api = require('../../utils/api').API; |
|
const FormData = require('../../utils/FormData') |
|
Page({ |
|
|
|
/** |
|
* 页面的初始数据 |
|
*/ |
|
data: { |
|
myData:{ |
|
contact:'', |
|
contactDetail:'', |
|
suggestion:'', |
|
attachment:[] |
|
}, |
|
files: [], |
|
filesUrl:'' |
|
}, |
|
|
|
/** |
|
* 生命周期函数--监听页面加载 |
|
*/ |
|
onLoad: function (options) { |
|
this.setData({ |
|
selectFile:this.selectFile.bind(this), |
|
uplaodFile:this.uplaodFile.bind(this) |
|
}) |
|
}, |
|
|
|
/** |
|
* 生命周期函数--监听页面初次渲染完成 |
|
*/ |
|
onReady: function () { |
|
|
|
}, |
|
|
|
/** |
|
* 生命周期函数--监听页面显示 |
|
*/ |
|
onShow: function () { |
|
|
|
}, |
|
|
|
/** |
|
* 生命周期函数--监听页面隐藏 |
|
*/ |
|
onHide: function () { |
|
|
|
}, |
|
|
|
/** |
|
* 生命周期函数--监听页面卸载 |
|
*/ |
|
onUnload: function () { |
|
|
|
}, |
|
|
|
/** |
|
* 页面相关事件处理函数--监听用户下拉动作 |
|
*/ |
|
onPullDownRefresh: function () { |
|
|
|
}, |
|
|
|
/** |
|
* 页面上拉触底事件的处理函数 |
|
*/ |
|
onReachBottom: function () { |
|
|
|
}, |
|
|
|
/** |
|
* 用户点击右上角分享 |
|
*/ |
|
onShareAppMessage: function () { |
|
|
|
}, |
|
contact(e){ |
|
this.setData({ |
|
'myData.contact': e.detail.value |
|
}) |
|
}, |
|
contactDetail(e){ |
|
this.setData({ |
|
'myData.contactDetail': e.detail.value |
|
}) |
|
}, |
|
suggestion(e){ |
|
this.setData({ |
|
'myData.suggestion': e.detail.value |
|
}) |
|
}, |
|
submit(){ |
|
this.data.myData.attachment=this.data.myData.attachment.join(',') |
|
$api.feedback(this.data.myData).then(res=>{ |
|
if(res.msg=='ok'){ |
|
wx.showToast({ |
|
title: '成功', |
|
icon: 'success', |
|
duration: 2000 |
|
}) |
|
this.setData({ |
|
myData:{ |
|
contact:'', |
|
contactDetail:'', |
|
suggestion:'', |
|
attachment:[] |
|
}, |
|
}) |
|
} |
|
}) |
|
console.log(this.data.myData) |
|
}, |
|
|
|
|
|
//------------------附件上传开始------------------------ |
|
// selectFile(files) { |
|
// uploadArr = []; |
|
// uploadIndex = 0; |
|
// for(var i=0;i<files.tempFilePaths.length;i++){ |
|
// uploadArr.push(files.tempFilePaths[i]) |
|
// } |
|
// console.log(uploadArr,'9999999') |
|
// // uploadArr = files.tempFilePaths |
|
// // 返回false可以阻止某次文件上传 |
|
// }, |
|
// 缓存文件 |
|
uplaodFile(files) { |
|
console.log('upload files', files); |
|
var that = this; |
|
// 文件上传的函数,返回一个promise |
|
return new Promise((resolve, reject) => { |
|
const tempFilePaths = files.tempFilePaths; |
|
that.setData( |
|
{ |
|
filesUrl: tempFilePaths |
|
} |
|
) |
|
var object = {}; |
|
object['urls'] = tempFilePaths; |
|
resolve(object); |
|
}) |
|
}, |
|
deleteFile(e){ |
|
this.data.myData.attachment.splice(e.detail.index,1); |
|
}, |
|
selectFile(files) { |
|
console.log('files', files) |
|
// 返回false可以阻止某次文件上传 |
|
}, |
|
uploadError(e) { |
|
console.log('upload error', e.detail) |
|
}, |
|
uploadSuccess(e) { |
|
|
|
const _this=this; |
|
let token = wx.getStorageSync('access_token') |
|
let Authorization =token?`Bearer ${token}`:'Basic YXBwOmFwcA==' |
|
let formData = new FormData(); |
|
formData.appendFile("file", e.detail.urls[0]); |
|
let data = formData.getData(); |
|
wx.request({ |
|
url: 'http://192.168.24.3:9002/file', |
|
header: { |
|
'content-type': data.contentType, |
|
'Authorization': Authorization, |
|
}, |
|
method: "POST", |
|
data: data.buffer, |
|
success(res) { |
|
// console.log(res) |
|
_this.data.myData.attachment.push(res.data.data.path) |
|
}, |
|
fail(err) { |
|
//请求失败 |
|
console.log(err) |
|
} |
|
}); |
|
// $api.uploadImg(formData).then(res=>{ |
|
// console.log(res) |
|
// }) |
|
} |
|
}) |