<template>
	<view class="content">
		<view class="order-item">
			<view class="masterWorker flex" v-if="reportDeatil.processor_user">
				<image class="imgUser" src="../../../static/error/missing-face.png" mode="scaleToFill"></image>
				<view class="padding-l-30">
					<view class="masterName">
						{{reportDeatil.processor_user.staff_name}}
					</view>
					<view class="masterTime margin-t-20">
						完成时间：{{reportDeatil.processor_time}}
					</view>
				</view>
			</view>
			<view class="flex_item zhil" v-for="(item,index) in rateValue">
				<view>{{item.text}}：</view>
				<view>
					<uni-rate text="1" size="20" margin="10" :value="item.value" @change="rateChange($event,index)">
					</uni-rate>
				</view>
			</view>
		</view>
		<view @click.stop="submit" class="base-buttom">
			提交并结束报修
		</view>
	</view>
</template>

<script>
	import {
		question_score,
	} from '@/api/user.js';
	export default {
		data() {
			return {
				rateValue: [{
					text: '响应速度',
					value: 0,
				}, {
					text: '技术评分',
					value: 0,
				}, {
					text: '服务态度',
					value: 0,
				}],
			};
		},
		props: {
			reportDeatil: {
				type: Object,
				default: function() {
					return {

					}
				}
			},
		},
		methods: {
			// 评分
			rateChange(val, index) {
				console.log(val, index);
				this.rateValue[index].value = val.value
			},
			//提交评论
			submit(e) {
				let obj = this;
				if (this.rateValue[0].value == 0 || this.rateValue[1].value == 0 || this.rateValue[2].value == 0) {
					uni.showModal({
						title: '错误',
						content: '最低评分为一颗星，请重新选择',
						showCancel: false,
					});
					return
				}
				uni.showLoading({
					title: '提交中',
					mask: true
				});
				question_score({
						id: this.reportDeatil.id,
						response_score: this.rateValue[0].value, //响应频分
						skill_score: this.rateValue[1].value, //技术评分
						attitude_score: this.rateValue[2].value, //服务评分
					})
					.then(e => {
						uni.hideLoading();
						uni.showModal({
							title: '提示',
							content: e.msg,
							showCancel: false,
							success: res => {
								uni.navigateBack()
							},
						});
					})
					.catch(e => {
						uni.showToast({
							title: e.msg,
							icon: 'error'
						});
						uni.hideLoading()
					});
			},
			// 页面跳转
			navto(e) {
				uni.navigateTo({
					url: e
				});
			}
		}
	};
</script>

<style lang="scss">
	.content {
		padding: 0 $page-row-spacing;
	}

	.order-item {
		display: flex;
		flex-direction: column;
		padding: 30rpx 0;
		border-radius: 20rpx;
		background: #fff;
		margin-top: 20rpx;

		.masterWorker {
			padding: 0 30rpx;
			border-bottom: 1px solid $page-color-light;
			padding-bottom: 30rpx;
			justify-content: flex-start;

			.masterTime {
				font-size: 22rpx;
				color: $font-color-light;
			}

			.masterName {
				color: $font-color-base;
				font-size: 28rpx;
				font-weight: bold;
			}

			.imgUser {
				width: 120rpx;
				height: 120rpx;
				border-radius: 100rpx;
			}
		}

		.flex_item {
			margin: 0 30rpx;
			color: $font-color-base;
			font-size: $font-base;
		}
	}

	.zhil {
		font-size: 28rpx !important;
		padding: 15rpx 15rpx;
	}

	.submit-box {
		bottom: 0;
		left: 0;
		width: 750rpx;
	}

	.submit-btn {
		margin-top: 10px;
		display: inline-block;
		width: 670rpx;
		height: 96rpx;
		line-height: 96rpx;
		text-align: center;
		background-color: #1BCC26 !important;
		opacity: 1;
		border-radius: 32rpx;
		border-width: 8rpx;
		border-color: rgba(255, 255, 255, 1);
		box-shadow: 0rpx 8rpx 12rpx rgba(0, 0, 0, 0.16);
		border-radius: 56rpx;
		font-size: 39rpx;
		font-weight: bold;
		color: rgba(255, 255, 255, 1);
	}

	.address-box {
		padding: 15rpx 40rpx;
		margin-bottom: 10px;
	}
</style>
