|
|
|
@ -6,93 +6,220 @@ Page({ |
|
|
|
* 页面的初始数据 |
|
|
|
*/ |
|
|
|
data: { |
|
|
|
info:null |
|
|
|
info: null, |
|
|
|
imgs: [], |
|
|
|
upImgs:[], |
|
|
|
checked:false, |
|
|
|
rate:0 |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* 生命周期函数--监听页面加载 |
|
|
|
*/ |
|
|
|
onLoad: function (options) { |
|
|
|
commonApi.user_post("order/query",{ |
|
|
|
order_id:options.id |
|
|
|
}).then(res=>{ |
|
|
|
commonApi.user_post("order/query", { |
|
|
|
order_id: options.id |
|
|
|
}).then(res => { |
|
|
|
let list = []; |
|
|
|
res.data.order_product_list.map(item=>{ |
|
|
|
res.data.order_product_list.map(item => { |
|
|
|
item.star = 5; |
|
|
|
item.content = ""; |
|
|
|
if(item.state=='WAIT_COMMENT'){ |
|
|
|
if (item.state == 'WAIT_COMMENT') { |
|
|
|
list.push(item); |
|
|
|
} |
|
|
|
}) |
|
|
|
if(list.length==0){ |
|
|
|
if (list.length == 0) { |
|
|
|
wx.showToast({ |
|
|
|
title: '该订单没有待评价产品', |
|
|
|
icon:'none' |
|
|
|
icon: 'none' |
|
|
|
}) |
|
|
|
setTimeout(()=>{ |
|
|
|
setTimeout(() => { |
|
|
|
wx.navigateBack() |
|
|
|
},1000) |
|
|
|
}, 1000) |
|
|
|
return; |
|
|
|
} |
|
|
|
res.data.order_product_list = list; |
|
|
|
this.setData({ |
|
|
|
info:res.data |
|
|
|
info: res.data |
|
|
|
}) |
|
|
|
}) |
|
|
|
}, |
|
|
|
changeStar:function(e){ |
|
|
|
changeStar: function (e) { |
|
|
|
console.log(e) |
|
|
|
wx.showLoading({ |
|
|
|
title: '加载中' |
|
|
|
}) |
|
|
|
let index = e.currentTarget.dataset.index,star = e.currentTarget.dataset.star; |
|
|
|
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; |
|
|
|
info.order_product_list[index].star = Number(star) + 1; |
|
|
|
this.setData({ |
|
|
|
info:info |
|
|
|
}) |
|
|
|
wx.hideLoading({ |
|
|
|
info: info, |
|
|
|
rate:info.order_product_list[index].star |
|
|
|
}) |
|
|
|
console.log(info); |
|
|
|
wx.hideLoading({}) |
|
|
|
}, |
|
|
|
changeContent:function(e){ |
|
|
|
changeContent: function (e) { |
|
|
|
console.log(e) |
|
|
|
let index = e.currentTarget.dataset.index,info = this.data.info; |
|
|
|
let index = e.currentTarget.dataset.index, |
|
|
|
info = this.data.info; |
|
|
|
info.order_product_list[index].content = e.detail.value; |
|
|
|
this.setData({ |
|
|
|
info:info |
|
|
|
info: info |
|
|
|
}) |
|
|
|
}, |
|
|
|
submit:function(){ |
|
|
|
let info = this.data.info,flag = true,ajax=[] |
|
|
|
info.order_product_list.map(item=>{ |
|
|
|
if(!item.content) { |
|
|
|
submit: function () { |
|
|
|
let info = this.data.info, |
|
|
|
flag = true, |
|
|
|
ajax = [] |
|
|
|
info.order_product_list.map(item => { |
|
|
|
if (!item.content) { |
|
|
|
wx.showToast({ |
|
|
|
title: '请输入评价内容', |
|
|
|
icon:'none' |
|
|
|
icon: 'none' |
|
|
|
}) |
|
|
|
flag = false; |
|
|
|
} |
|
|
|
ajax.push(commonApi.user_post("product/product_comment",{ |
|
|
|
product_id:item.product_id, |
|
|
|
content:item.content, |
|
|
|
order_id:this.data.id |
|
|
|
console.log(item); |
|
|
|
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 |
|
|
|
})) |
|
|
|
}) |
|
|
|
if(!flag) return; |
|
|
|
Promise.all(ajax).then(res=>{ |
|
|
|
if (!flag) return; |
|
|
|
Promise.all(ajax).then(res => { |
|
|
|
console.log(res) |
|
|
|
let flag = false; |
|
|
|
res.map(item=>{ |
|
|
|
if(item.code==1){ |
|
|
|
res.map(item => { |
|
|
|
if (item.code == 1) { |
|
|
|
flag = true |
|
|
|
} |
|
|
|
}) |
|
|
|
if(flag){ |
|
|
|
if (flag) { |
|
|
|
wx.navigateBack() |
|
|
|
} |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
//图片上传
|
|
|
|
// 上传图片
|
|
|
|
chooseImg: function (e) { |
|
|
|
console.log(e); |
|
|
|
var that = this; |
|
|
|
var imgs = this.data.imgs; |
|
|
|
if (imgs.length >= 8) { |
|
|
|
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; |
|
|
|
wx.uploadFile({ |
|
|
|
url: 'https://test.api.cloud.sz-trip.com/api/pbservice.other/upload', //这里是上传的服务器地址
|
|
|
|
filePath: tempFilePaths[0], |
|
|
|
name: 'file', |
|
|
|
header: { |
|
|
|
token: wx.getStorageSync('jstrip_token'), |
|
|
|
}, |
|
|
|
success(res) { |
|
|
|
|
|
|
|
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 |
|
|
|
}) |
|
|
|
console.log(that.data.upImgs); |
|
|
|
for (var i = 0; i < tempFilePaths.length; i++) { |
|
|
|
if (imgs.length >= 9) { |
|
|
|
that.setData({ |
|
|
|
imgs: imgs |
|
|
|
}); |
|
|
|
return false; |
|
|
|
} else { |
|
|
|
imgs.push(tempFilePaths[i]); |
|
|
|
} |
|
|
|
} |
|
|
|
// console.log(imgs);
|
|
|
|
that.setData({ |
|
|
|
imgs: imgs |
|
|
|
}); |
|
|
|
console.log(that.data.imgs); |
|
|
|
const data = res.data |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
}); |
|
|
|
}, |
|
|
|
// 删除图片
|
|
|
|
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 |
|
|
|
}) |
|
|
|
console.log(this.data.checked); |
|
|
|
}, |
|
|
|
/** |
|
|
|
* 生命周期函数--监听页面初次渲染完成 |
|
|
|
*/ |
|
|
|
|