shopEvaluate.vue 9.6 KB
<template>
	<view class="page">
		<view class="item" v-for="(item,index) in orderinfo" :key="index">
			<view class="infobox">
				<image :src="item.image" mode="widthFix" class="left"></image>
				<view class="info">
					<view class="word">{{item.goods_name}}</view>
					<view class="score">
						商品评分:
						<view class="num">
							<!-- :data-item="item" :data-index="index" -->
							<view @click="selstar"  :data-id="1"  :data-index="index">
								<image src="../../static/star.png" mode="widthFix" class="star" v-if="item.star>=1"></image>
								<image src="../../static/nostar.png" mode="widthFix" class="star" image v-else>
							</view>
							<view @click="selstar"  :data-id="2"  :data-index="index">
								<image src="../../static/star.png" mode="widthFix" class="star" v-if="item.star>=2"></image>
								<image src="../../static/nostar.png" mode="widthFix" class="star" image v-else>
							</view>
							<view @click="selstar"  :data-id="3"  :data-index="index">
								<image src="../../static/star.png" mode="widthFix" class="star" v-if="item.star>=3"></image>
								<image src="../../static/nostar.png" mode="widthFix" class="star" image v-else>
							</view>
							<view @click="selstar"  :data-id="4"  :data-index="index">
								<image src="../../static/star.png" mode="widthFix" class="star" v-if="item.star>=4"></image>
								<image src="../../static/nostar.png" mode="widthFix" class="star" image v-else>
							</view>
							<view @click="selstar" :data-id="5"  :data-index="index">
								<image src="../../static/star.png" mode="widthFix" class="star" v-if="item.star>=5"></image>
								<image src="../../static/nostar.png" mode="widthFix" class="star" image v-else>
							</view>
						</view>
					</view>
				</view>
			</view>
			<textarea name="" id="" cols="30" rows="10" class="fill" placeholder="请填写评价内容…" @input="entercomment" :data-index="index"></textarea>
			<view class="flexone">
				<view class="imgarr" v-for="(item,indexk) in item.images" :key="indexk" >
					<image :src="item" mode="widthFix" class="imagItem"></image>
					
					<view class="delimg" @click="delimg(index,indexk)">
						<image src="../../static/publishchahao.png" mode=""></image>
					</view>
				</view>
				<view class="imgarr" @click="chooseImage(index)">
					<image src="../../static/add.png" mode="widthFix" class="imagItem"></image>
				</view>
			</view>
		</view>
		<!-- 
		<view class="item">
			<view class="infobox">
				<image src="../../static/cai.png" mode="widthFix" class="left"></image>
				<view class="info">
					<view class="word">商品名称名称名称商品名称名称名称商品名称名称名称名称</view>
					<view class="score">
						商品评分:
						<view class="num">
							<image src="../../static/star.png" mode="widthFix" class="star"></image>
							<image src="../../static/star.png" mode="widthFix" class="star"></image>
							<image src="../../static/star.png" mode="widthFix" class="star"></image>
							<image src="../../static/star.png" mode="widthFix" class="star"></image>
							<image src="../../static/nostar.png" mode="widthFix" class="star" style="margin-right: 0;"></image>
						</view>
					</view>
				</view>
			</view>
			<textarea name="" id="" cols="30" rows="10" class="fill" placeholder="请填写评价内容….."></textarea>
			<view class="imgarr">
				<image src="../../static/add.png" mode="widthFix" class="imagItem"></image>
			</view>
		</view>
		
		 -->
		
		<view class="btnbox">
			<view class="submit" @click="subevalute">发表评价</view>
		</view>


	</view>
</template>

<script>
	import app from "../../App.vue";
	export default {
		data() {
			return {
				order_detail_id:'',
				orderinfo:'',
				data:[]
			};
		},
		onLoad(options) {
			console.log(344834838)
			this.order_detail_id=options.order_detail_id;
			console.log(this.order_detail_id)
			this.getordercomment();
		},
		methods: {
			// 获取订单详情
			getordercomment(){
				let that = this;
				var url = 'order/comments';
				
				var params = {
					order_detail_id:that.order_detail_id
				}
				console.log(params)
				app.post(url, params, "post").then((res) => {
					console.log(res);
					
					that.orderinfo=res.data.data.order_info;
					that.orderinfo.forEach(function(value,index,array){
						value.star=0;
						value.images=[];
						
						
					})
					that.orderinfo=that.orderinfo;
					that.orderinfo.forEach(function(value,index,array){
						let obj={};
						obj.goods_id=value.goods_id;
						obj.images=[];
						obj.content='';
						obj.star=0;
						that.data.push(obj)
					})
					that.data=that.data;
				
				}).catch((err) => {
					console.log(err)
				})
			},
			// 选择星星
			selstar(e){
				let that=this;
				console.log(e)
				let id=e.currentTarget.dataset.id;
				let index=e.currentTarget.dataset.index;
				that.orderinfo[index].star=id;
				that.$forceUpdate();
				that.orderinfo=that.orderinfo;
				that.data[index].star=id;
				that.data=that.data;
			},
			chooseImage(index){
				console.log(index)
			   let that = this; 
			   let indexone=index
			  console.log('99999',index)
			   uni.chooseImage({
			     count: 9,
			     sizeType: ['original', 'compressed'],
			     success: function (res) {
					 console.log(res)
			       console.log(res.tempFilePaths);
				   console.log(res.tempFilePaths[0]);
				        res.tempFilePaths.forEach(function(value,index,array){
				              app.upload('image', value, "post").then((res) => {
				                console.log('上传文件', res);
				                let url = app.globalData.imgurl+res.url;
								
				    //             newimage.push(url);
								// console.log(newimage)
								that.data[indexone].images.push(url);
								that.data=that.data;
								console.log('273734734743',indexone)
								that.orderinfo[indexone].images.push(url);
								that.orderin=that.orderinfo;
								console.log(that.orderinfo)
								that.$forceUpdate();
								console.log(that.orderinfo[indexone].images)
				              }).catch((err) => {
				                console.log(err)
				              })
				            })	
			     },
			     fail: function (res) { }
			   })
			 },
			 // 删除图片
			 delimg(index,indexk){
				 let that=this;
				 console.log(index,indexk);
				 that.orderinfo[index].images.splice(indexk,1);
				 that.orderinfo=that.orderinfo;
				 that.data[index].images.splice(indexk,1)
				 that.$forceUpdate();
			 },
			 // 写评论
			 entercomment(e){
				 console.log(e.detail.value);
				 let index=e.currentTarget.dataset.index;
				 console.log(index)
				 this.data[index].content=e.detail.value;
				 
				 // that.data[index].content=e.detail.value
			 },
			// 提交评论
			subevalute(){
				let that = this;
				console.log(that.data);
				var result = true;
				that.data.forEach(function(value,index,array){
					console.log(value)
					if(value.star==0){
						console.log(value.star,3489834894389)
						uni.showToast({
							title:"请选择商品评分",
							icon:'none'
						})
						result = false;
						return false;
							
					}else if(value.content==''){
						uni.showToast({
							title:"请输入商品评论",
							icon:'none'
						})
						result = false;
						return false;
					}else{
						result = true;
						return false;
					}
				})
				if(result){
					that.data.forEach(function(value,index,array){
						console.log(value.images)
						
							value.images=value.images.join(",")
						
						
					})
					
					var url = 'order/submit_comments';
					var params = {
						data:JSON.stringify(that.data),
						order_detail_id:that.order_detail_id
					}
					console.log(params)
					app.post(url, params, "post").then((res) => {
						console.log(res);
						uni.showToast({
							title:"评论成功",
							icon:'none'
						})
						setTimeout(function(){
							uni.navigateBack({
								checked:true
							})
						},1500)
					
					}).catch((err) => {
						console.log(err)
					})
				}
				
				
				
				
			}
		}
	};
</script>

<style>
	.item {
		padding: 32rpx;
		border-bottom: 16rpx solid #F7F7F7;
		box-sizing: border-box;
		background: #fff;
		margin-bottom: 16rpx;
		overflow: hidden;
	}

	.infobox {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.left {
		width: 140rpx;
	}

	.info {
		width: 530rpx;
	}

	.word {
		font-size: 30rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: rgba(61, 69, 76, 1);
		line-height: 40rpx;
	}

	.score {
		margin-top: 22rpx;
		display: flex;
		align-items: center;
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: rgba(61, 68, 76, 1);
	}

	.num {
		display: flex;
		align-items: center;
	}

	.star {
		width: 32rpx;
		margin-right: 24rpx;
	}

	.fill {
		width: 686rpx;
		height: 192rpx;
		padding: 24rpx;
		box-sizing: border-box;
		background: rgba(247, 247, 247, 1);
		border-radius: 16rpx;
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: rgba(189, 196, 206, 1);
		line-height: 42rpx;
		margin-top: 66rpx;
	}

	.imgarr {
		padding: 32rpx 0;
		box-sizing: border-box;
		position: relative;
	}
	.delimg{
		width:40rpx;
		height:40rpx;
		font-size: 0;
		position: absolute;
		right:-10rpx;
		top:0rpx;
		
	}

	.imagItem {
		width: 160rpx;
		margin-right: 16rpx;
	}

	.btnbox {
		padding: 14rpx 32rpx;
		box-sizing: border-box;
		background: #fff;
	}

	.submit {
		width: 686rpx;
		height: 88rpx;
		background: rgba(194, 148, 69, 1);
		border-radius: 16rpx;
		font-size: 28rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: rgba(255, 255, 255, 1);
		display: flex;
		align-items: center;
		justify-content: center;
	}
</style>