<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" scroll-y :show-scrollbar="false"  v-if="list.length>0" @scrolltolower="loadMore">
			<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>
		<scroll-view class="scroll-view-pk" scroll-y :show-scrollbar="false" v-if="list.length==0">
			<list-empty></list-empty>
		</scroll-view>

	</view>
</template>

<script>
	import {
		voteList
	} from '@/api/api.js'
	import ListEmpty from '@/components/ListEmpty.vue';
	export default {
		data() {
			return {
				queryParams: {
					pageNum: 1,
					pageSize: 10,
					momentId: '',
					optionCode:undefined
				},
				total:0,
				activeIndex: 0,
				voteOptions: [],
				list:[]
			}
		},
		components:{
			ListEmpty
		},
		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() {
				uni.showLoading({
					title:'加载中...'
				})
				voteList(this.queryParams).then(res => {
					this.list = [...this.list,...res.rows];
					this.total = res.total;
				}).finally(()=>{
					uni.hideLoading()
				})
			},
			handleChange(item,index){
				this.activeIndex = index
				this.queryParams.optionCode = item.code;
				this.queryParams.pageNum = 1;
				this.list = []
				this.getList()
			},
			loadMore() {
				if(this.list.length < this.total){
					this.queryParams.pageNum += 1;
					this.getList()
				}
			},
		}
	}
</script>

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

	.pk-detail-page {
		background-color: white;
		.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>
