import { get, post } from '../../utils/http'; Page({ /** * 页面的初始数据 */ data: { maxlength: 500, number: 0, value: "", imgs: [], // imgs: [ // { // type: "image", // url: "https://img1.baidu.com/it/u=202543353,3627416815&fm=26&fmt=auto" // }, // { // type: "image", // url: "https://img0.baidu.com/it/u=745609344,230882238&fm=26&fmt=auto" // }, // { // type: "image", // url: "https://img0.baidu.com/it/u=286636366,3227707112&fm=26&fmt=auto" // }, // { // type: "image", // url: "https://img1.baidu.com/it/u=2450865760,444795162&fm=26&fmt=auto" // }, // { // type: "image", // url: "https://img0.baidu.com/it/u=4226275504,4103997964&fm=26&fmt=auto" // }, // { // type: "image", // url: "https://img0.baidu.com/it/u=2247422843,411257408&fm=26&fmt=auto" // }, // ], raterList: [ { text: '整体满意度', num: 1 }, { text: '效果认可度', num: 2 }, { text: '价格接受度', num: 3 }, { text: '类别满意度', num: 4 }, { text: '安全认可度', num: 5 }, ], raterStatus: { 1: '差', 2: '较差', 3: '一般', 4: '满意', 5: '非常好', }, edit: "false" }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { console.log(options) if(options.orderId) { this.setData({ orderId: options.orderId, cover: options.cover, name: options.name, edit: options.edit || "false" }) if(options.edit == "true") { this.getfeedbackInfo(options.orderId) } } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, /** * 监听文本域 */ bindTextAreaInput(e) { this.setData({ number: e.detail.cursor, value: e.detail.value }) }, /** * 预览图片和视频 */ previewMedia(e) { let arr = this.data.imgs let current = e.currentTarget.dataset.index wx.previewMedia({ sources: arr, current }) }, /** * 删除列表项 */ onDeleteItem(e) { let imgs = this.data.imgs; imgs.splice(e.currentTarget.dataset.index, 1); this.setData({ imgs }) console.log(imgs) }, /** * 选择图片 */ chooseImage() { let that = this; let imgs = this.data.imgs; let count = 9 - this.data.imgs.length wx.chooseImage({ count, sizeType: ['original', 'compressed'], sourceType: ['album', 'camera'], success (res) { wx.showLoading({ title: '正在上传图片', mask: true }); const tempFiles = res.tempFiles tempFiles.forEach((item) => { that.upload(item.path).then((data) => { imgs.push({ type: 'image', url: data.data.url, }) that.setData({ imgs }) wx.hideLoading() }); }) } }) }, /** * 选择视频 */ chooseVideo(){ let that = this; let imgs = this.data.imgs; wx.chooseMedia({ count: 1, mediaType: ['video'], sourceType: ['album', 'camera'], maxDuration: 30, camera: 'back', success(res) { wx.showLoading({ title: '正在上传视频', mask: true }); const tempFiles = res.tempFiles that.upload(tempFiles[0].thumbTempFilePath).then((data) => { if(imgs.length > 0 && imgs[0].type == 'video') { that.setData({ ['imgs[' + 0 + '].thumb']: data.data.url }) } else { imgs.unshift({ type: 'video', thumb: data.data.url, url: '' }) that.setData({ imgs }) } // that.setData({ imgs }) wx.hideLoading() }); that.upload(tempFiles[0].tempFilePath).then((data) => { if(imgs.length > 0 && imgs[0].type == 'video') { that.setData({ ['imgs[' + 0 + '].url']: data.data.url }) } else { imgs.unshift({ type: 'video', thumb: '', url: data.data.url }) that.setData({ imgs }) } // imgs.unshift({ // type: 'video', // thumb: tempFiles[0].thumbTempFilePath, // url: data.data.url // }) // that.setData({ imgs }) wx.hideLoading() }); } }) }, /** * 选择星星 */ onChange(e) { let index = e.currentTarget.dataset.index let value = e.detail.value this.setData({ ['raterList[' + index + '].num']: value }) }, /** * 提交反馈 */ onSubmit() { // api/feedback/add let { orderId,value,raterList,edit } = this.data; console.log(this.data.imgs) console.log(edit) if(edit == "true") { this.editFeedbackUpdate() } else { post('api/feedback/add',{ order_id: orderId, content: value, media_list: JSON.stringify(this.data.imgs), score_whole: raterList[0].num, score_effect: raterList[1].num, score_price: raterList[2].num, score_kind: raterList[3].num, score_safe: raterList[4].num, },(res) => { console.log(res) wx.showToast({ title: res.msg, icon: 'none' }) setTimeout(() => { wx.navigateBack() }, 1500); }) } }, /** * 上传视频/图片 */ upload(filePath) { let that = this; // 上传类型/业务类型:avatar头像,order订单反馈,check检查表反馈 return new Promise((resolve,reject) => { let { imgs } = this.data; wx.uploadFile({ url: 'https://store.test-api.ijolijoli.com/api/upload', header: { token: wx.getStorageSync('token') || '', }, filePath, name: 'file', formData: { 'type': 'order' }, success(res) { console.log(res) if(res.statusCode == 200 && res.data) { let data = JSON.parse(res.data); if(data.code == 200 && data.data) { resolve(data) } else { wx.showToast({ title: '上传失败', icon: 'none' }) } } else { wx.showToast({ title: '上传失败', icon: 'none' }) } }, fail(err) { wx.showToast({ title: '上传失败', icon: 'none' }) } }) }) }, /** * 获取订单反馈详情 * api/feedback/info */ getfeedbackInfo(id) { get('api/feedback/info',{ id },(res) => { this.setData({ value: res.data.content, imgs: JSON.parse(res.data.media_list), raterList: [] }) }) }, /** * 编辑反馈记录 * api/feedback/update */ editFeedbackUpdate() { let { orderId,value,imgs } = this.data; post('api/feedback/update',{ id: orderId, content: value, media_list: JSON.stringify(imgs) },(res) => { wx.showToast({ title: res.msg, icon: 'none' }) setTimeout(() => { wx.navigateBack() }, 1500); console.log(res) }) } })