<template>
	<view class="ques-content">
		<view class="ques-content-tit" v-show="openCommentStatus!=1">问答题</view>
		<view v-for="(item,index) in quesList" :key="index">
			<view class="ques-title">
				<text>{{index + 1}}.</text>
				<view class="ques-type" v-show="item.type == 1 || item.type == 2">
					{{item.type == 1 ? '单选' : item.type == 2 ? '多选' : ''}}
				</view>
				<text>{{item.title}}</text>
			</view>
			<view :class="isAnswer(item,option.name) ?'ques-option ques-option-active':'ques-option'"
				v-for="(option,idx) in item.questionOption" :key="idx" @click="handleAnswer(item,option)">
				<view>
					{{numberToLetter(idx)}}.
				</view>
				<view>{{option.name}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: ['quesList','openCommentStatus'],
		data() {
			return {
				
			}
		},
		computed: {
			isAnswer() {
				return (item, name) => {
					if (item.type == 1) {
						return item.answer == name
					} else if (item.type == 2) {
						const array = item.answer.split(',')
						return array.some(i => i == name)
					} else {
						return false
					}
				}
			}
		},
		methods: {
			numberToLetter(num) {
				// 将数字转换为字母的 ASCII 码
				let letterCode = num + 65;
				// 将 ASCII 码转换为大写字母
				let letter = String.fromCharCode(letterCode);
				return letter;
			},
			handleAnswer(item, option) {
				const param = {
					item,
					option
				}
				this.$emit("handleAnswer", param)
			}
		}
	}
</script>

<style lang="scss" scoped>
	@mixin u-flex($flexD, $alignI, $justifyC) {
		display: flex;
		flex-direction: $flexD;
		align-items: $alignI;
		justify-content: $justifyC;
	}

	.ques-content {
		background-color: #fff;
		padding: 24rpx 32rpx 116rpx 32rpx;
		box-sizing: border-box;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 28rpx;
		color: #222222;
	}

	.ques-content-tit {
		font-family: PingFang SC, PingFang SC;
		font-weight: 600;
		font-size: 36rpx;
		color: #222222;
	}

	.ques-title {
		margin: 48rpx 0 34rpx 0;
		font-weight: 500;
		font-size: 32rpx;
		white-space: normal;
	}

	.ques-type {
		flex-shrink: 0;
		min-width: 72rpx;
		min-height: 40rpx;
		padding: 0 12rpx;
		margin: 0 12rpx;
		box-sizing: border-box;
		background: #FF5C03;
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		line-height: 40rpx;
		text-align: center;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 24rpx;
		color: #FFFFFF;
		display: inline-block;
	}

	.ques-option {
		min-height: 88rpx;
		padding: 24rpx 32rpx;
		box-sizing: border-box;
		margin-bottom: 24rpx;
		background: #F5F7FA;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		display: flex;
		align-items: center;

		&-active {
			color: #FF5C03 !important;
			background: #FCF0E7 !important;
		}
	}
</style>