<template>
	<view class="detail-page-container pk-detail-page">
		<view class="pk-tab-box" v-if="voteOptions.length>0">
			<view class="tab-item" v-for="(item,index) in voteOptions" @click="handleChange(item,index)">
				<view class="text" :class="{'active':index==activeIndex}">{{item.name}}（{{item.voteCount}}）</view>
			</view>

		</view>
		<scroll-view class="scroll-view-pk" v-if="list.length>0">
			<view class="list-item" v-for="(item,index) in list">
				<image src="/static/images/default-avatar.png" class="avatar"></image>
				<view class="name">{{item.nickName}}</view>
				<view class="datetime">{{item.createTime}}</view>
			</view>
		</scroll-view>

	</view>
</template>

<script>
	import {
		voteList
	} from '@/api/api.js'
	export default {
		data() {
			return {
				queryParams: {
					pageNum: 1,
					pageSize: 10,
					momentId: '',
					optionCode:undefined
				},
				activeIndex: 0,
				voteOptions: [],
				list:[]
			}
		},
		onLoad(options) {
			let {
				momentId,
				index,
				voteOptions
			} = options;
			this.queryParams.momentId = momentId;
			this.activeIndex = index;
			this.voteOptions = JSON.parse(voteOptions)
			this.queryParams.optionCode = this.voteOptions[index].code
			this.getList()
		},
		methods: {
			getList() {
				voteList(this.queryParams).then(res => {
					console.log(res)
					this.list = res.data
				})
			},
			handleChange(item,index){
				this.activeIndex = index
				this.queryParams.optionCode = item.code;
				this.getList()
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import '@/static/styles/common.scss';

	.pk-detail-page {
		.pk-tab-box {
			height: 92rpx;
			display: flex;
			align-items: center;
			border: 1px solid rgba(238, 238, 238, 1);

			.tab-item {
				flex: 1;
				display: flex;
				justify-content: center;
				align-items: flex-end;
				height: 100%;

				.text {
					text-align: center;
					line-height: 76rpx;
					color: #BBBBBB;
					border-bottom: 4rpx solid transparent;
				}

				.active {
					color: #3484FD;
					border-bottom: 4rpx solid #3484FD;
				}
			}
		}

		.scroll-view-pk {
			@include scroll-view-container(calc(100vh - 100rpx));
			padding: 0 34rpx;
			box-sizing: border-box;

			.list-item {
				height: 130rpx;
				border-bottom: 1px solid #eee;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.avatar {
					width: 80rpx;
					height: 80rpx;
					border-radius: 50%;
				}

				.name {
					width: calc(100% - 400rpx);
					color: rgba(16, 16, 16, 1);
					font-size: 28rpx;
				}

				.datetime {
					color: rgba(187, 187, 187, 1);
					font-size: 28rpx;
					width: 290rpx;
					text-align: right;
				}
			}
		}
	}
</style>
