<template>
	<view>
		<view class="noComment" v-if='comment.scoreAll <= 0 || JSON.stringify(comment) == "{}"'>
			<view class="start">
				<view @click="setScore(index + 1)" :key="index" v-for="(i,index) in 5">
					<image src="../../static/img/star.full.svg" v-if="index + 1 <= commentscore"></image>
					<image src="../../static/img/star.empty.svg" v-else></image>
				</view>
			</view>
			<view class="textview">
				<textarea value="" @input="settext" placeholder="评论(选填)100字以内" placeholder-class="textClass" maxlength="100" />
				</view>
			<view class="btn" @click="sendCom"><view class="bottombtn">确认</view></view>
		</view>
		<view class="noComment" v-if='comment.scoreAll>0'>
			<view class="start">
				评分
				<image src="../../static/img/star.full.svg" v-for="index in comment.scoreAll" mode="" :key="index"></image>
				<image src="../../static/img/star.empty.svg" v-for="index in (5-comment.scoreAll)" mode="" :key="index"></image>
			</view>
			<view class="textview">
				<textarea :value="comment.remarks" disabled  />
			</view>
			
		</view>
	</view>
</template>

<script>
	import {myRate,rate,rateDetail } from '@/api/rate.js';
	import testData from '@/common/textdata.js';
	export default {
		data() {
			return {
				comment:{},
				missionNo:'',
				commenttext:'',
				commentscore:0
			}
		},
		onLoad: function (option) {
			if(option.missionNo){
				this.missionNo = decodeURIComponent(option.missionNo);
			}
		},
		onShow: function() {
			/*获取评价详情*/
			rateDetail(this.missionNo).then(res => {
				this.comment = res.data.data;
			});
		},
		methods: {
			settext:function(e){
				this.commenttext=e.detail.value;
			},
			setScore:function(score){
				this.commentscore = score
			},
			/*提交*/
			sendCom:function(){
				if(!this.commentscore){
					uni.showToast({
						icon:'none',
						title:'请完成评分',
						duration:3000
					})
					return
				}else{
					rate(this.missionNo,this.commentscore,this.commenttext).then(res => {
						uni.showToast({
							icon:'none',
							title:'提交成功',
							duration:3000,
							success: function (res) {
							    uni.navigateBack({
							    	delta: 1
							    })
							}
						})
					}, error => {
						uni.showToast({
							icon:'none',
							title:'操作失败',
							duration:3000
						})
					});
				}
			}
		}
	}
</script>

<style>
	.bottombtn {
		background-color: #1b66ff;
		color: #fff;
		text-align: center;
		border-radius: 10rpx;
		font-family: PingFangSC-Medium;
		font-size: 32rpx;
		height: 90rpx;
		line-height: 90rpx;
	}
	.btn {
		background-color: #fefefe;
		width: 690rpx;
		padding: 30rpx;
		padding-bottom: 80rpx;
		position: fixed;
		bottom: 0;
		left: 0;
	}
	.textview{
		padding: 20rpx;
	}
	textarea{
		font-family: PingFangSC-Regular;
		font-size: 32rpx;
		color: #666;
		
	}
	.textClass{
		font-family: PingFangSC-Regular;
		font-size: 32rpx;
		color: #CCCCCC;
	}
	.start view:first-child{
		margin-left: 20rpx;
	}
	.start image{
		width: 40rpx;
		height: 40rpx;
	}
	.start{
		padding: 20rpx;
		border-bottom: 1rpx solid #f6f6f6;
		font-family: PingFangSC-Regular;
		font-size: 32rpx;
		color: #333333;
		display: flex;
		align-items: center;
		justify-content: flex-start;
	}
page{background-color: #fefefe;}
</style>
