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.

262 lines
6.0 KiB

5 years ago
// pages/order/comment/index.js
import commonApi from "../../../utils/https/common"
Page({
/**
* 页面的初始数据
*/
data: {
info: null,
imgs: [],
upImgs:[],
checked:false,
rate:0
5 years ago
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
commonApi.user_post("order/query", {
order_id: options.id
}).then(res => {
5 years ago
let list = [];
res.data.order_product_list.map(item => {
5 years ago
item.star = 5;
item.content = "";
if (item.state == 'WAIT_COMMENT') {
5 years ago
list.push(item);
}
})
if (list.length == 0) {
5 years ago
wx.showToast({
title: '该订单没有待评价产品',
icon: 'none'
5 years ago
})
setTimeout(() => {
5 years ago
wx.navigateBack()
}, 1000)
5 years ago
return;
}
res.data.order_product_list = list;
this.setData({
info: res.data
5 years ago
})
})
},
changeStar: function (e) {
5 years ago
wx.showLoading({
title: '加载中'
})
let index = e.currentTarget.dataset.index,
star = e.currentTarget.dataset.star;
5 years ago
let info = this.data.info;
info.order_product_list[index].star = Number(star) + 1;
5 years ago
this.setData({
info: info,
rate:info.order_product_list[index].star
5 years ago
})
wx.hideLoading({})
5 years ago
},
changeContent: function (e) {
let index = e.currentTarget.dataset.index,
info = this.data.info;
5 years ago
info.order_product_list[index].content = e.detail.value;
this.setData({
info: info
5 years ago
})
},
submit: function () {
let info = this.data.info,
flag = true,
ajax = []
info.order_product_list.map(item => {
if (!item.content) {
5 years ago
wx.showToast({
title: '请输入评价内容',
icon: 'none'
5 years ago
})
flag = false;
}
ajax.push(commonApi.user_post("product/product_comment", {
product_id: item.product_id,
content: item.content,
order_id: item.order_id,
integer:this.data.rate,
img_list:this.data.upImgs.join(','),
is_anonymous:this.data.checked?1:0
5 years ago
}))
})
if (!flag) return;
Promise.all(ajax).then(res => {
5 years ago
let flag = false;
res.map(item => {
if (item.code == 1) {
5 years ago
flag = true
}
})
if (flag) {
5 years ago
wx.navigateBack()
}
})
},
//图片上传
// 上传图片
chooseImg: function (e) {
var that = this;
var imgs = this.data.imgs;
if (imgs.length >= 9) {
wx.showToast({
title: '最多上传九张图片哦..',
icon: 'none'
})
return false;
}
wx.chooseImage({
// count: 1, // 默认9
sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
success: function (res) {
// 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
let size = res.tempFiles[0].size
const temp = res.tempFilePaths[0]
if (size > 1024 * 1024 * 20) {
wx.showToast({
title: '图片最大支持20M..',
icon: 'none'
})
return
} else if (temp.substr(temp.length - 4, 4) == '.gif') {
wx.showToast({
title: '图片格式错误',
icon: 'none'
})
return;
}
var tempFilePaths = res.tempFilePaths;
var imgs = that.data.imgs;
console.log(imgs);
wx.showLoading({
title: '上传中',
})
for (let i = 0; i < tempFilePaths.length; i++) {
wx.uploadFile({
url: 'https://test.api.cloud.sz-trip.com/api/pbservice.other/upload', //这里是上传的服务器地址
filePath: tempFilePaths[i],
name: 'file',
header: {
token: wx.getStorageSync('jstrip_token'),
},
success(res) {
wx.hideLoading()
var res = JSON.parse(res.data);
if (res.code!=1) {
wx.showToast({
title: res.msg,
icon: 'none'
})
return
}
let img = res.data.url;
let arr = that.data.upImgs
arr.push(img)
that.setData({
upImgs:arr
})
imgs.push(tempFilePaths[i]);
that.setData({
imgs: imgs
});
}
})
if (that.data,imgs.length+i==8) {
return
}
}
}
});
},
// 删除图片
deleteImg: function (e) {
let imgs = this.data.imgs;
let index = e.currentTarget.dataset.index;
let upimg = this.data.upImgs
imgs.splice(index, 1);
upimg.splice(index,1)
this.setData({
imgs: imgs,
upImgs:upimg
});
},
// 预览图片
previewImg: function (e) {
//获取当前图片的下标
var index = e.currentTarget.dataset.index;
//所有图片
var imgs = this.data.imgs;
wx.previewImage({
//当前显示图片
current: imgs[index],
//所有图片
urls: imgs
})
},
checkboxChange:function(){
this.setData({
checked:!this.data.checked
})
},
5 years ago
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})