Browse Source

评论支持图片,匿名

master
caichunsheng 4 years ago
parent
commit
e337f1433e
  1. 195
      pages/order/comment/index.js
  2. 17
      pages/order/comment/index.wxml
  3. 72
      pages/order/comment/index.wxss
  4. 3
      pages/user/cartlist/list.wxml

195
pages/order/comment/index.js

@ -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);
},
/**
* 生命周期函数--监听页面初次渲染完成
*/

17
pages/order/comment/index.wxml

@ -1,7 +1,7 @@
<!--pages/order/comment/index.wxml-->
<title title="填写评论"></title>
<view class="product-box" wx:if="{{info}}" wx:for="{{info.order_product_list}}">
<view class="product-top">
<view class="product-top prd">
<image src="{{item.product_img}}" mode="aspectFill"></image>
<view class="product-info">
<view class="product-title">{{item.product_title}}</view>
@ -18,6 +18,21 @@
<!-- <text wx:for="{{5 - item.star}}" class="iconfont icon-xingxing "></text> -->
</view>
<textarea bindinput="changeContent" data-index="{{index}}" placeholder="您对产品还满意吗?您的评价会帮助更多的人哦~"></textarea>
<view class="weui-uploader">
<view class='pics' wx:for="{{imgs}}" wx:for-item="item" wx:key="*this">
<image class='weui-uploader__img' src="{{item}}" data-index="{{index}}" mode="aspectFill" bindtap="previewImg">
<icon type='cancel' class="delete-btn" data-index="{{index}}" catchtap="deleteImg"></icon>
</image>
</view>
<view class="tp_cont {{tj_ycang?'':'hide'}}" bindtap="chooseImg">
<view class="tp_add"><image style="width: 60rpx;" mode="widthFix" src="https://static.ticket.sz-trip.com/uploads/20220811/13f3f3558cb7e627cef42581f8a2555d.png"></image> <view>上传图片</view></view>
</view>
</view>
</view>
<checkbox-group class="checkbox" bindchange="checkboxChange" >
<label >
<checkbox value="是否匿名" checked="{{checked}}"/>是否匿名
</label>
</checkbox-group>
<view style="height:80rpx"></view>
<view class="btn" bindtap="submit">提交</view>

72
pages/order/comment/index.wxss

@ -1,7 +1,11 @@
/* pages/order/comment/index.wxss */
page{
background-color: #FBF8FB;
}
.product-box {
margin: 0 30rpx;
padding: 0 30rpx 10rpx 30rpx;
font-size: 28rpx;
background-color: #fff;
}
.product-top {
display: flex;
@ -56,6 +60,7 @@
.product-box textarea {
display: block;
width: 100%;
height: 210rpx;
}
.btn {
width: 360rpx;
@ -70,4 +75,67 @@
bottom: 40rpx;
left: 50%;
margin-left: -180rpx;
}
}
/* 图片 */
.three{
margin-top: 27rpx;
}
.weui-uploader{
margin: 16rpx 0;
}
.tp_add{
width: 152rpx;
height: 152rpx;
border-radius: 10rpx;
opacity: 1;
border: 2rpx dashed #999999;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
font-size: 22rpx;
color: #BCBCBC;
}
.pics {
float:left;
position:relative;
margin-right:15px;
margin-bottom:15px;
}
.pics image{
width: 152rpx;
height: 152rpx;
}
.delete-btn{
width: 20rpx;
height: 20rpx;
position: absolute;
top: -15rpx;
right: -5rpx;
}
.weui-uploader{
padding: 10rpx 0;
}
.prd{
border-bottom: 1px solid #CCCCCC;
}
.checkbox{
margin: 16rpx 20rpx;
color: #BCBCBC;
}
checkbox .wx-checkbox-input {
width: 30rpx;
height: 30rpx;
border-radius: 50%;
}
checkbox .wx-checkbox-input.wx-checkbox-input-checked {
border-color: #18d6ff;
background-color: #18d6ff;
}
checkbox .wx-checkbox-input.wx-checkbox-input-checked::before {
color:#fff;
}

3
pages/user/cartlist/list.wxml

@ -31,7 +31,8 @@
<view class="fixed-bottom" wx:if="{{list.length>0}}">
<view bindtap="selectAll" class="iconfont{{allChecked?' icon-gou':' icon-quan'}}"></view>
<view class="tip">合计:</view>
<view class="bottom-price">¥{{allPrice/100}}</view>
<view class="bottom-price">¥{{allPrice/100}} </view>
<view style="margin-right: 10rpx; font-size: 29rpx;color: #000;">起</view>
<view style="flex:1">不含运费</view>
<view class="btn" bindtap="order">去下单</view>
</view>

Loading…
Cancel
Save