<template>
	<view class="active-list">
		<!-- 活动查询 -->
		<view class="active-list-search">
			<!-- 搜索框 -->
			<view class="search">
				<u-input placeholder="输入活动名称或参赛项目" border='none' v-model="search" @input="searchText">
					<template slot="suffix" style='margin-right:40rpx;'>
						<u-image :showLoading="true" :showError='true' src="/static/icon/search.png" width="40rpx"
							height="32rpx"></u-image>
					</template>
				</u-input>
			</view>
			<view class="tab_nav">
				<view class="navTitle" v-for="(item,index) in items" :key="index">
					<view :class="{'active':isActive === index}" @click="checked(index)">
						{{item.name}}
					</view>
				</view>
			</view>
		</view>

		<view class="List" v-if="isActive==0">
			<view class="ListItem" v-for="(item,index) in List" @click="activeDetail(item.id)">
				<image :src="item.banners?item.cover_img:'http://t9.9026.com/imgs/Kudosbg.png'" style="width: 640rpx;height:420rpx;"></image>
				<view class="kudosicon" @click.stop="kudosActive(item.id,index)">
					<image src="/static/icon/Kudos.png" v-if="item.is_like==0"></image>
					<image src="/static/icon/Kudos(1).png" v-if="item.is_like==1"></image>
				</view>
				<view class="nav">
					<view class="events">
						<text>{{item.title}}</text>
					</view>
					<view class="voteStatus">
						<text v-if="false">未开始</text>
						<text style="color:#FF6503 ;">{{item.vote_name}}</text>
					</view>
				</view>
				<view class="foot">
					<image src="/static/icon/data.png"></image>
					<text>{{item.end_time}} 结束</text>
				</view>
			</view>
		</view>

		<!-- 触底 -->
		<view class="home-bottom">
			<uni-load-more :status="status" color="#CCCCCC" :content-text="contentText"/>
		</view>
	</view>
</template>

<script>
	import util from './../../../utils/util.js'
	export default {
		data() {
			return {
				// 搜索
				search:'',
				//分段器
				items: [{
						name: '热门活动'
					},
					{
						name: '西区活动'
					}, {
						name: '酒店评选'
					},
					{
						name: '旅游推选'
					}
				],
				//激活指定table菜单
				isActive: 0,
				status: 'noMore',
				contentText: {
					contentdown: '查看更多',
					contentrefresh: '加载中',
					contentnomore: '——  已经到底啦  ——'
				},
				// 活动列表
				List:[],
			}
		},
		onLoad() {
			this.getList()
			this.getCategoryList()
			console.log(util,"until")
		},
		methods: {
			// 获取活动列表
			getList(){
				this.$api.active.getActiveList({
					page:1,
					keyword:'',
					category_id:''
				}).then(res=>{
					console.log(res,'活动列表')
					if(res.code==0){
						this.List=res.data.data
					}
				})
			},
			// 获取分类列表
			getCategoryList(){
				this.$api.category.getCategoryList({
					page:1,
					type:1
				}).then(res=>{
					console.log(res,"活动分类列表")
					if(res.code==0){
						// this.items=res.data.data
					}
				})
			},
			// 点赞活动
			kudosActive(id,index){
				let beforeLike=this.List[index].is_like
				this.$api.active.kudos({
					activity_id:id
				}).then(res=>{
					console.log(res,'点赞')
					if(res.code==0){
						if(beforeLike==1){
							this.List[index].is_like=0
						}else{
							this.List[index].is_like=1
						}
					}
				})
			},
			//菜单index切换
			checked(index) {
				this.isActive = index
			},
			// 活动详情页
			activeDetail(id){
				uni.navigateTo({
					url:'/pages/index/active-detail/index?id='+id
				})
			},
			// 搜索防抖
			searchText:util.debounce(function(){
				this.goSearch()
			},1000),
			// 搜索
			goSearch(){
				this.$api.active.getActiveList({
					page:1,
					keyword:this.search,
					category_id:''
				}).then(res=>{
					console.log(res,'搜索活动列表')
					if(res.code==0){
						this.List=res.data.data
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	$pageColor:#F9F9F9;
	$bgColor:#FFFFFF;

	@mixin flexlayout {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.active-list {
		height: 100%;
		background: #F9F9F9;
	}
	
	.home-bottom {
		background-color: #f9f9f9;
		padding-bottom: 84rpx;
	}

	.active-list-search {
		padding: 24rpx 30rpx 32rpx;
		height: 222rpx;
		background-color: #FFFFFF;

		// 搜索
		.search {

			::v-deep .u-input {
				width: 690rpx !important;
				height: 68rpx !important;
				background: #F1F1F1;
				border-radius: 74rpx;
			}

			::v-deep .u-input__content__field-wrapper {
				padding-left: 36rpx;
			}
			::v-deep .u-input__content__field-wrapper__field{
				color:#999999 !important;
				font-size: 28rpx !important;
			}
		}

		//菜单切换
		.tab_nav {
			width: 100%;
			margin-top: 32rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			font-family: PingFang-SC-Heavy, PingFang-SC;
			
		}

		.tab_nav .navTitle {
			width: 150rpx;
			flex: none;
			height: 28rpx;
			font-size: 32rpx;
			color: #666;
			position: relative;
		}
		.active {
			color: #D9A94D;
			font-weight: bold;
			&::after {
				display: inline-block;
				content: '';
				width: 48rpx;
				height: 12rpx;
				background: linear-gradient(90deg, #F3D69F 0%, #D9A94D 100%);
				border-radius: 6px;
				position: absolute;
				bottom:-40rpx;
				left:40rpx;
			}
		}

	}

	.List {
		padding: 0 30rpx;
		box-sizing: border-box;
		padding-top: 20rpx;
		padding-bottom:88rpx ;
		background-color: #F9F9F9;

		.ListItem {
			position: relative;
			margin-bottom: 24rpx;
			width: 100%;
			height: 562rpx;
			background: #F9F9F9;
			box-shadow: 0rpx 12rpx 40rpx 0rpx rgba(220, 222, 229, 0.4);
			border-radius: 24rpx;
			padding: 20rpx 26rpx 26rpx 24rpx;
			.kudosicon {
				width: 48rpx;
				height: 48rpx;
				position: absolute;
				top: 52rpx;
				right: 58rpx;
				border-radius: 50%;
				background: #FFFFFF;
				opacity: 0.84;
				@include flexlayout() image {
					width: 32rpx;
					height: 28rpx;
				}
			}

			.nav {
				display: flex;
				align-items: center;
				justify-content: space-between;

				.events {
					text {
						font-size: 30rpx;
						font-family: PingFang-SC-Bold, PingFang-SC;
						font-weight: bold;
						color: #333333;
					}
				}

				.voteStatus {
					font-size: 30rpx;
					font-family: PingFang-SC-Medium, PingFang-SC;
					font-weight: 500;
					color: #999999;
				}
			}

			.foot {
				margin-top: 10rpx;
				display: flex;
				align-items: center;

				image {
					width: 28rpx;
					height: 28rpx;
					margin-right: 8rpx;
				}

				text {
					font-size: 24rpx;
					font-family: PingFang-SC-Medium, PingFang-SC;
					font-weight: 500;
					color: #999999;
					display: block;
				}
			}

		}
	}
</style>
