<template>
	<view class="page-view">
		<top-return :color="'#FFF'" text="活动列表"></top-return>

		<view class="bg-box2"></view>

		<!-- 页面标题内容 -->
		<view class="top-box">
			<view class="flex-baseline">
				<view class="info-title" style="margin-left: 0;">{{dayTime.split('月')[0]}}</view>
				<view class="info-subtitle">月</view>
				<view class="info-title">{{dayTime.split('月')[1]}}</view>
				<view class="info-subtitle">日</view>
				<view class="info-subtitle" style="margin-left: 20rpx;">已完成</view>
				<view class="info-title">{{value}}%</view>
			</view>
			<view class="flex-baseline">
				<view class="data-subtitle" style="margin-left: 0;">当前共</view>
				<view class="data-title">{{swapData.length}}</view>
				<view class="data-subtitle">场活动</view>
			</view>
		</view>

		<view class="card-view">
			<view class="card-item" v-for="(item,index) in swapData" :key="index" @click="navSwapReport(index)">
				<view class="card-title">
					<view class="t-icon t-icon-swapfont"></view>
					<view class="YS-title" style="font-size: 45rpx;">{{item.survey.name||item.vote.name}}</view>
					<view
						:class="[item.survey.progress === 'finish'||item.vote.progress === 'finish'?'t-icon t-icon-yiwancheng1':'t-icon t-icon-jinhangzhong-copy','state-seal']"
						style="width: 55px;height: 55px;margin-left: auto;margin-right: -20rpx;"></view>
				</view>
				<view class="card-info">
					<view class="flex-baseline">
						<view class="info-type">布置老师:</view>
						<view class="YS-title" style="margin-left: 10rpx;">
							{{item.survey.creatorId||item.vote.creatorId}}</view>
						<view class="info-type" style="margin-left: 20rpx;">截至时间:</view>
						<view class="YS-title" style="margin-left: 10rpx;" v-if="item.survey">
							{{$timeStampToTime(item.survey.endTime)}}</view>
						<view class="YS-title" style="margin-left: 10rpx;" v-if="item.vote">
							{{$timeStampToTime(item.vote.endTime)}}</view>
					</view>
					<view class="flex-row" style="margin-top: 20rpx;">
						<u-parse class="YS-title" style="font-size: 30rpx;"
							:content="item.survey.description||item.vote.description" :selectable="true"></u-parse>
					</view>
				</view>
				<!-- 正文 -->
				<view class="content-box">
					<!-- 问卷 -->
					<view class="title-box"
						:style="{backgroundColor: item.survey.progress === 'finish'? '#23b46c': '#FF6D31' }"
						v-if="item.survey">
						<view class="title-text">问卷详情</view>
					</view>
					<view class="flex-row" style="justify-content: space-around;">
						<view class="option-box"
							:style="{backgroundColor: item.survey.progress === 'finish'? '#23b46c': '#FF6D31' }"
							v-for="(option,i) in item.survey.answers[0]" :key="i">
							<view class="content-subtitle">{{option}}</view>
						</view>
					</view>
					<!-- 投票 -->
					<view class="title-box"
						:style="{backgroundColor: item.vote.progress === 'finish'? '#23b46c': '#FF6D31' }"
						v-if="item.vote">
						<view class="title-text">{{item.vote.secret ? '匿名投票':'普通投票'}}</view>
					</view>
					<view class="flex-row" style="justify-content: space-around;">
						<view class="flex-column" style="align-items: center;" v-for="(option,j) in item.vote.options"
							:key="j">
							<u-parse class="title" style="font-size: 30rpx;margin-bottom: 15rpx;"
								:content="option.value"></u-parse>
							<view class="option-box"
								:style="{backgroundColor: item.vote.progress === 'finish'? '#23b46c': '#FF6D31' }">
								<view class="content-subtitle">{{option.code}}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		computed: {
			...mapState('m_children', ['swapData'])
		},
		data() {
			return {
				value: '',
				dayTime: ''
			}
		},
		onLoad(parameter) {
			this.value = parameter.value
			this.dayTime = (new Date()).format('M-d').replace('-', '月')
		},
		methods: {
			fixNum(num) {
				return num.toFixed(2)
			},
			navSwapReport(index) {
				uni.navigateTo({
					url: `/subpkg/datalist/swapReport?index=${index}`
				})
			}
		}
	}
</script>

<style lang="scss">
	@import 'data_pages.scss';
	@import 'top_info.scss';
	.option-box {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 120rpx;
		height: 50rpx;
		border-radius: 10rpx;
		padding: 5rpx;
	}
</style>
