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.
283 lines
6.4 KiB
283 lines
6.4 KiB
// pages/order/comment/index.js
|
|
import commonApi from "../../../utils/https/common"
|
|
import util from "../../../utils/util"
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
info: null,
|
|
imgs: [],
|
|
upImgs:[],
|
|
checked:false,
|
|
rate:0,
|
|
tjList: [], //推荐商品列表
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
commonApi.user_post("order/query", {
|
|
order_id: options.id
|
|
}).then(res => {
|
|
let list = [];
|
|
res.data.order_product_list.map(item => {
|
|
item.star = 5;
|
|
item.content = "";
|
|
if (item.state == 'WAIT_COMMENT') {
|
|
list.push(item);
|
|
}
|
|
})
|
|
if (list.length == 0) {
|
|
wx.showToast({
|
|
title: '该订单没有待评价产品',
|
|
icon: 'none'
|
|
})
|
|
setTimeout(() => {
|
|
wx.navigateBack()
|
|
}, 1000)
|
|
return;
|
|
}
|
|
res.data.order_product_list = list;
|
|
this.setData({
|
|
info: res.data
|
|
})
|
|
})
|
|
commonApi._post("search/product_recommend", {
|
|
offset: 0,
|
|
limit: 6,
|
|
rand: true,
|
|
type: 'post'
|
|
}).then(res => {
|
|
try {
|
|
this.setData({
|
|
tjList: res.data.list
|
|
})
|
|
} catch (error) {
|
|
console.log(error);
|
|
}
|
|
})
|
|
},
|
|
gotoDetail:function(e){
|
|
let item = e.currentTarget.dataset.item;
|
|
util.gotoDetail(item)
|
|
},
|
|
changeStar: function (e) {
|
|
wx.showLoading({
|
|
title: '加载中'
|
|
})
|
|
let index = e.currentTarget.dataset.index,
|
|
star = e.currentTarget.dataset.star;
|
|
let info = this.data.info;
|
|
info.order_product_list[index].star = Number(star) + 1;
|
|
this.setData({
|
|
info: info,
|
|
rate:info.order_product_list[index].star
|
|
})
|
|
wx.hideLoading({})
|
|
},
|
|
changeContent: function (e) {
|
|
let index = e.currentTarget.dataset.index,
|
|
info = this.data.info;
|
|
info.order_product_list[index].content = e.detail.value;
|
|
this.setData({
|
|
info: info
|
|
})
|
|
},
|
|
submit: function () {
|
|
let info = this.data.info,
|
|
flag = true,
|
|
ajax = []
|
|
info.order_product_list.map(item => {
|
|
if (!item.content) {
|
|
wx.showToast({
|
|
title: '请输入评价内容',
|
|
icon: 'none'
|
|
})
|
|
flag = false;
|
|
}
|
|
ajax.push(commonApi.user_post("product/product_comment", {
|
|
product_id: item.product_id,
|
|
content: item.content,
|
|
order_id: item.order_id,
|
|
rate:this.data.rate,
|
|
img_list:this.data.upImgs.join(','),
|
|
is_anonymous:this.data.checked?1:0,
|
|
sku_id:item.sku_id
|
|
}))
|
|
})
|
|
if (!flag) return;
|
|
Promise.all(ajax).then(res => {
|
|
let flag = false;
|
|
res.map(item => {
|
|
if (item.code == 1) {
|
|
flag = true
|
|
}
|
|
})
|
|
if (flag) {
|
|
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
|
|
})
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage: function () {
|
|
|
|
}
|
|
})
|