<template>
	<view class="container">
		<!-- 返回按钮 -->
		<back text="详情列表"></back>

		<view style="margin: 20rpx;">
			<u-skeleton :rows="detailList.length" :rowsHeight="height" :loading="loading">
			</u-skeleton>
		</view>

		<view class="detail-box" v-if="!loading">
			<view class="detail-item" v-for="(item,index) in detailList" :key="index" @click="navSingleData(item)">
				<view class="flex" style="width: 100%;height: 90rpx;">
					<view class="flex" style="margin: -30rpx 0 0 10rpx;">
						<view class="index"
							:style="{backgroundColor: item.survey.progress === 'finish'||item.vote.progress === 'finish'? '#23b46c': '#f9c752' }">
						</view>
						<view class="name">{{item.survey.name||item.vote.name}}</view>
					</view>

					<view class="t-icon t-icon-yiwancheng1"
						v-if="item.survey.progress === 'finish'||item.vote.progress === 'finish'"
						style="margin-left: auto; width: 90rpx; height: 90rpx;"></view>
					<view class="t-icon t-icon-jinhangzhong-copy"
						v-if="item.survey.progress === 'going'||item.vote.progress === 'going'"
						style="margin-left: auto; width: 90rpx; height: 90rpx;"></view>
				</view>
				<!-- 正文 -->
				<view class="content-box">
					<view style="display:flex;flex-direction: column;padding: 0 30rpx;">
						<rich-text class="subtitle-info" style="margin-bottom: 15rpx;"
							:nodes="item.survey.description||item.vote.description">
						</rich-text>
						<view class="flex">
							<view class="subtitle">布置老师:</view>
							<view class="subtitle-info" style="margin-left: 10rpx;">
								{{item.survey.creatorId||item.vote.creatorId}}
							</view>
							<view class="subtitle" style="margin-left: 20rpx;">截止时间:</view>
							<view class="subtitle-info" style="margin-left: 10rpx;" v-if="item.survey">
								{{$timestampToTime(item.survey.endTime)}}
							</view>
							<view class="subtitle-info" style="margin-left: 10rpx;" v-if="item.vote">
								{{$timestampToTime(item.vote.endTime)}}
							</view>
						</view>
					</view>
					<!-- 内容 -->
					<view class="content-detail-box">
						<!-- 问卷 -->
						<view class="title-box"
							:style="{backgroundColor: item.survey.progress === 'finish'? '#23b46c': '#f9c752' }"
							v-if="item.survey">
							<view class="content-subtitle">问卷详情</view>
						</view>
						<view class="flex" style="justify-content: space-around;">
							<view class="option-box"
								:style="{backgroundColor: item.survey.progress === 'finish'? '#23b46c': '#f9c752' }"
								v-for="(option,i) in item.survey.answers[0]" :key="i">
								<view class="content-subtitle" style="font-size: 30rpx;">{{option}}</view>
							</view>
						</view>
						
						<!-- 投票 -->
						<view class="title-box"
							:style="{backgroundColor: item.vote.progress === 'finish'? '#23b46c': '#f9c752' }"
							v-if="item.vote">
							<view class="content-subtitle">{{item.vote.secret ? '匿名投票':'普通投票'}}</view>
						</view>
						<view class="flex" style="justify-content: space-around;">
							<view class="flex-colum" v-for="(option,j) in item.vote.options" :key="j">
								<rich-text class="subtitle-info" style="margin-bottom: 15rpx;" :nodes="option.value">
								</rich-text>
								<view class="option-box"
									:style="{backgroundColor: item.vote.progress === 'finish'? '#23b46c': '#f9c752' }">
									<view class="content-subtitle" style="font-size: 30rpx;">{{option.code}}</view>
								</view>
							</view>
						</view>


					</view>
				</view>

			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		computed: {
			...mapState('m_children', ['detailList'])
		},
		data() {
			return {
				//骨架页配置
				loading: true,
				height: ['200px', '200px', '200px', '200px', '200px', '200px', '200px', '200px', '200px', '200px'],
			};
		},
		onLoad(options) {
			uni.$u.sleep(1500).then(() => {
				this.loading = false
			})
		},
		methods: {
			...mapMutations('m_children', ['updateDetail']),
			//导航到详情页面
			navSingleData(item){
				this.updateDetail(item)
				uni.navigateTo({
					url: `/subpkg/detail/activity`
				})
			},

		}
	}
</script>

<style lang="scss">
	@import '@/subpkg/common/detaillistpage.scss';
	.flex-colum{
		display: flex;
		flex-direction: column;
		align-items: center;
	}
</style>
