<template>
	<view class="questionNaire">
		<view class="Title">{{dataObj.Title}}</view>
		<view class="Title_Second" style="text-indent:0" v-html="dataObj.Description">

		</view>

		<view>
			<view class="QuestionTitle">课程安排与设计</view>
			<view class="QuestionInner" v-for="(item,index) in dataObj.CourseArrangementList" :key="index">
				{{item.Title}}
				<view style="margin:20rpx 0 30rpx 0;">
					<van-rate v-model="item.ScoreNum" :size="25" @change="onChange(item)" color="#ffd21e" void-icon="star" void-color="#ddd" />
				</view>
			</view>
			<view class="QuestionTitle">教师授课情形</view>
			<view class="QuestionInner" v-for="(item,index) in dataObj.TeachersSituationList" :key="index">
				{{item.Title}}
				<view style="margin:20rpx 0 30rpx 0;">
					<van-rate v-model="item.ScoreNum" :size="25" @change="onChange(item)" color="#ffd21e" void-icon="star" void-color="#ddd" />
				</view>
			</view>
			<view class="QuestionTitle">助教老师</view>
			<view class="QuestionInner" v-for="(item,index) in dataObj.TeachingAssistantList" :key="index">
				{{item.Title}}
				<view style="margin:20rpx 0 30rpx 0;">
					<van-rate v-model="item.ScoreNum" :size="25" @change="onChange(item)" color="#ffd21e" void-icon="star" void-color="#ddd" />
				</view>
			</view>
			<view class="QuestionTitle">学习环境</view>
			<view class="QuestionInner" v-for="(item,index) in dataObj.LearningEnvironmentList" :key="index">
				{{item.Title}}
				<view style="margin:20rpx 0 30rpx 0;">
					<van-rate v-model="item.ScoreNum" :size="25" @change="onChange(item)" color="#ffd21e" void-icon="star" void-color="#ddd" />
				</view>
			</view>
			<view class="QuestionTitle">意见与建议</view>
			<view class="QuestionInner" v-for="(item,index) in dataObj.OpinionandsuggestionList" :key="index">
				<view style="margin-top:20rpx;">
					<textarea type="text" v-model="item.TextContent" class="input textarea" placeholder="请填写建议" placeholder-style="textarea-placeholder"
					 :maxlength="300" />
					</view>
			</view>

		</view>
		<view style="margin-top:30rpx;" class="btnDiv">
			<button style="width:100%;height:88rpx;color:#FFF;background: #4C50E7 !important;" @click="saveQuestion">提交</button>
		</view>
		<van-toast id="van-toast" />
	</view>
</template>
<script>
	import {
		ref,
		reactive,
		toRefs,
		toRef,
		getCurrentInstance,
		watch,
		computed,
		onMounted,
		provide,
		inject
	} from "vue";
	import {
		querySurveyInfo,
		saveGuestSurvey
	} from "../../api/activity";
	export default {
		components: {},
		onLoad(options) {
			if (options) {
				if(options.ActivitySurveyId)
				{
				   this.msg.ActivitySurveyId = options.ActivitySurveyId;
				}
				if(options.ActivitySurveyGuestId)
				{
				   this.msg.ActivitySurveyGuestId = options.ActivitySurveyGuestId;
				}
			}
			this.GetSurveyInfo();
		},
		setup(props) {
			let Toast = inject("$toast");
			let {
				proxy
			} = getCurrentInstance();
			let data = reactive({
				msg: {
				  ActivitySurveyId:0,
				  ActivitySurveyGuestId:0,
				},
				loading:false,
				count: 5,
				dataObj: {}
			})
			let methods = {
				validte(){
					let flag=false;
					this.dataObj.CourseArrangementList.forEach(x=>{
						if(x.ScoreNum==0) flag=true;
					})
					if(flag) return false;
					this.dataObj.TeachersSituationList.forEach(x=>{
						if(x.ScoreNum==0) flag=true;
					})
					if(flag) return false;
					this.dataObj.TeachingAssistantList.forEach(x=>{
						if(x.ScoreNum==0) flag=true;
					})
					if(flag) return false;
					this.dataObj.LearningEnvironmentList.forEach(x=>{
						if(x.ScoreNum==0) flag=true;
					})
					if(flag) return false;
					return true;
				},
				async GetSurveyInfo() {
					let res = await querySurveyInfo(data.msg);
					if (res) {
						//this.loading = false;
						this.dataObj = res.data;
						console.log(this.dataObj)
					}
				},
				//打星星改变
				onChange(item) {
					item.ScoreNum = item.ScoreNum.detail;
				},
				//保存数据
				saveQuestion(){
					if(this.loading) return;
					this.loading=true
					if(!this.validte()){
						uni.showToast({
						  title: "请完成打分项目",
						  icon: "none",
						});
						this.loading=false
						return;
					}
					var UserInfo = uni.getStorageSync('userInfo');
					this.dataObj.StudentId = UserInfo.Id;
					this.dataObj.UserType=2;
					this.dataObj.ActivitySurveyId=this.msg.ActivitySurveyId;
					this.dataObj.ActivitySurveyGuestId=this.msg.ActivitySurveyGuestId;
					let res = saveGuestSurvey(this.dataObj).then(res => {
						if (res.resultCode == 1) {
							Toast.success('提交成功');
							setTimeout(()=>{
								
								uni.switchTab({
									url:"/pages/index/index"
								})
							},1000)
						}else{
							Toast.fail('提交失败，请重试');
						}
						this.loading=false
					});
				}
			}
			onMounted(() => {})
			let that = methods;
			return {
				...toRefs(data),
				...methods,
			};
		}
	}
</script>

<style scoped>
	.btnDiv /deep/ .van-button--normal {
		width: 100%;
	}
	.textarea{
		border: 1px solid #d1d1d1;
		width: 93%;
		padding: 20rpx;
	}
	.questionNaire {
		min-height: 100vh;
		background: #F5F5F5;
		padding: 32rpx;
		box-sizing: border-box;
	}

	.Title {
		font-size: 34rpx;
		font-weight: bold;
		text-align: center;
		font-weight: bold;
	}

	.Title_Second {
		font-size: 28rpx;
		margin-top: 20rpx;
		text-indent: 60rpx;
	}

	.QuestionTitle {
		font-size: 30rpx;
		color: #000000;
		margin: 40rpx 0;
		font-weight: bold;
	}

	.QuestionInner {
		font-size: 28rpx;
		color: #000000;
		margin-bottom: 20rpx;
	}
</style>
