<template>
	<view class="pageBgImg">
		<topNavbar title="评价"></topNavbar>
		<evaluateItem :info="schoolInfo" key="1"/>
		<evaluateItem :info="coachInfo" key="2"/>

		<view class="btnBox">
			<view class="btnBg" @click="submintFn" :class="{active: btnActive}">提交</view>
		</view>
	</view>
</template>

<script>
	import evaluateItem from './comp/evaluateItem'
	import { getStudentinfo, addSchoolComment,addCoachComment } from '@/config/api.js'
	export default {
		components: {
			evaluateItem
		},
		data() {
			return {
				checked: false,
				info: {},
				schoolInfo: {},
				coachInfo: {},
				subject: ''
			}
		},
		onLoad(options) {
			this.subject = options.subject
			
			this.getStudentinfoFn()
		},
		computed: {
			btnActive() {
				let {schoolInfo, coachInfo} = this
				let num1 = schoolInfo.schoolLevel + schoolInfo.qualityLevel + schoolInfo.teachLevel + schoolInfo.serviceLevel
				let num2 = coachInfo.qualityLevel + coachInfo.teachLevel + coachInfo.serviceLevel
				if(num1&&num2) {
					return true
				}else {
					return false
				}
				
			}
		},
		methods: {
			initFrom() {
				this.schoolInfo = {
					tit: '您对驾校满意吗？',
					school: 1,
					"schoolId": 8750,
					"schoolName": "",
					"stars": 0,
					"studentId": '',
					"studentIdcard": "",
					"studentPhone": "",
					"serviceLevel": 0,
					"schoolLevel": 0,
					"qualityLevel": 0,
					"teachLevel": 0,
					"subject": 0,
					"description": "",
					"images": "",
					"videoUrl": "",
					"anonymity": 2,
					"userId": 0,
					imgArr: []
				}
				this.coachInfo = {
					tit: '您对教练满意吗？',
					"schoolId": 8750,
					"stars": 0,
					"studentId": '',
					"studentIdcard": "",
					"studentPhone": "",
					"schoolInfo": 0,
					"schoolLevel": 0,
					"qualityLevel": 0,
					"serviceLevel": 0,
					"teachLevel": 0,
					"subject": 0,
					"description": "",
					"images": "",
					"videoUrl": "",
					"anonymity": 2,
					"userId": 0,
					coachName: '',
					imgArr: []
				}
				this.coachInfo.subject = this.schoolInfo.subject = this.subject
				this.coachInfo.userId = this.schoolInfo.userId = this.$store.state.user.vuex_loginInfo.userId
				this.coachInfo.studentPhone = this.vuex_userInfo.studentPhone
				
				this.coachInfo.schoolId = this.schoolInfo.schoolId = this.info.schoolId
				this.coachInfo.schoolName = this.schoolInfo.schoolName = this.info.schoolName
				this.coachInfo.coachName = this.info.coachName
				this.coachInfo.coachId = this.info.coachId
			},
			// 获取用户驾校信息
			async getStudentinfoFn() {
				const {data: res} = await getStudentinfo({id: this.$store.state.user.vuex_loginInfo.userId})
				this.info = res
				this.initFrom()
			},
			async submintFn() {
				if(this.coachInfo.imgArr.length) {
					this.coachInfo.images = this.coachInfo.imgArr.join(',')
				}
				if(this.schoolInfo.imgArr.length) {
					this.schoolInfo.images = this.schoolInfo.imgArr.join(',')
				}
				const res = await addSchoolComment(this.schoolInfo)
				const res2 = await addCoachComment(this.coachInfo)
				this.initFrom()
				this.$u.toast('评价成功')
				setTimeout(()=>{
					this.$goPage('/pages/mineEntry/myEvaluate/myEvaluate')
				},1500)
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import '../../../common/css/textareaBg.scss';

	.btnBox {
		padding-bottom: 76rpx;
	}

	.btnBg {
		margin: 90rpx auto 0 auto;
		width: 396rpx;
		opacity: 0.5;
		&.active {
			opacity: 1;
		}
	}

	.textareaBg {
		margin-top: 22rpx;
	}

	.card {
		padding: 28rpx;

		.top_row {
			display: flex;
			align-items: center;
			padding-bottom: 24rpx;
			border-bottom: 2rpx solid #E8E9EC;
			justify-content: space-between;

			.tit {
				font-weight: 600;
				color: #333333;
				font-size: 32rpx;
			}


		}

		.user_row {
			width: 100%;
			height: 100rpx;
			display: flex;
			align-items: center;

			.avatar {
				width: 60rpx;
				height: 60rpx;
				border-radius: 50%;
				overflow: hidden;
			}

			.name {
				font-size: 28rpx;
				font-weight: 500;
				padding-left: 26rpx;
			}
		}

		.star_row {
			padding: 14rpx 0;
			display: flex;
			align-items: center;

			.lab {
				font-size: 28rpx;
				font-weight: 500;
				padding-right: 32rpx;
			}

			.star {}
		}
	}
</style>