<template>
	<view class="content">
		<!-- 首页展示图 -->
		<image src="../../static/img/top-bg.jpg" mode="widthFix" style="width: 750rpx;"></image>
		<!-- 轮播 -->
		<view class="carousel-section">
			<swiper class="carousel" :autoplay="true" :interval="3000" :duration="1000" indicator-dots indicator-color="rgba(255,255,255,0.5)" indicator-active-color="#fff">
				<swiper-item v-for="item in carouselList" :key="item.id" >
					<image :src="baseURL + item.image" @click="navTo(item.h5_url)"></image>
				</swiper-item>
			</swiper>
		</view>
		<!-- 间隔 -->
		<view class="" style="height: 55rpx;background-color: #fff;"></view>
		<!-- 爱心榜 -->
		<view class="love">
			<view class="love-wrap">
				<view class="" style="height: 46rpx;"></view>
				<view class="love-top">
					爱心榜
				</view>
				<view class="tab-tit flex">
					<view class="tit">
						捐赠时间
					</view>
					<view class="tit" style="width: 30%;">
						捐献者/单位
					</view>
					<view class="tit" style="width: 20%;">
						捐赠金额
					</view>
					<view class="tit">
						捐赠意向
					</view>
				</view>
				<view class="tab-tit flex tab-val" v-for="item in showLove">
					<view class="tit clamp">
						{{item.paytime | getTime}}
					</view>
					<view class="tit clamp" style="width: 30%;">
						{{item.name}}
					</view>
					<view class="tit clamp" style="width: 20%;">
						{{item.amount*1}}
					</view>
					<view class="tit clamp">
						{{item.order_name}}
					</view>
				</view>
				<view class="lookmore" @click="navTo('/pages/index/loveList')">
					查看更多
					<image src="../../static/icon/lm.png" mode="widthFix"></image>
				</view>
			</view>
			
		</view>
		
		<!-- 分类 -->
		<view class="cate-section flex">
			<view class="cate-item flex" @click="navTo('/pages/index/aixin')">
				<view class="img-wrapper flex">
					<image src="../../static/icon/icon1.png" mode="" class="img1"></image>
				</view>
				<view class="item-title">爱心捐款</view>
			</view>
			<!-- <view class="cate-item flex" @click="navTo('/pages/form/applicationForm')">
				<view class="img-wrapper flex">
					<image src="../../static/icon/icon2.png" mode="" class="img1"></image>
				</view>
				<view class="item-title">遗体器官捐献</view>
			</view> -->
			<view class="cate-item flex" @click="navTo('/pages/index/ytjz')">
				<view class="img-wrapper flex">
					<image src="../../static/icon/icon2.png" mode="" class="img1"></image>
				</view>
				<view class="item-title">遗体器官捐献</view>
			</view>
			<view class="cate-item flex" @click="navTo('/pages/applic/appliSystem')">
				<view class="img-wrapper flex">
					<image src="../../static/icon/icon3.png" mode="" class="img1"></image>
				</view>
				<view class="item-title">造血干细胞捐献</view>
			</view>
			<view class="cate-item flex" @click="navTo('/pages/fu/axjz')">
				<view class="img-wrapper flex">
					<image src="../../static/icon/icon4.png" mode="" class="img1"></image>
				</view>
				<view class="item-title">爱心捐赠</view>
			</view>
			<view class="cate-item flex" @click="navTo('/pages/train/index')">
				<view class="img-wrapper flex">
					<image src="../../static/icon/icon5.png" mode="" class="img1"></image>
				</view>
				<view class="item-title">救护培训</view>
			</view>
		</view>
		<!-- 加入红十字 -->
		<view class="join-red">
			<image src="../../static/img/join-banner.png" mode="widthFix" @click="navTo('/pages/index/joinus')"></image>
		</view>
		
		<!-- 就在身边 -->
		<view class="jzsb-wrap">
			<!-- 附近救护员 -->
			<view class="wrap-tit">
				救在身边
				<view class="tit-bg"></view>
			</view>
			<!-- <view class="fjjhy-wrap" @click="navTo('/pages/applic/location')">
				<image src="../../static/img/jzsb-bg.png" mode=""></image>
			</view> -->
			<!-- 救护站 and Aed -->
			<view class="jhz-aed-wrap flex">
				<!-- 救护站 -->
				<view class="jhz-wrap" @click="navTo('/pages/applic/aid')">
					<image src="../../static/img/jhz-bg.png" mode=""></image>
				</view>
				<!-- aed -->
				<view class="aed-wrap" @click="navTo('/pages/applic/aed')">
					<image src="../../static/img/aed-bg.png" mode=""></image>
				</view>
			</view>
		</view>
		<!-- 少儿基金 -->
		<view class="join-red">
			<image src="../../static/img/sejj.png" mode="widthFix" @click="navTo('/pages/index/transfer')"></image>
		</view>
		<!-- 红会科普 -->
		<!-- <view class="kp-wrap" v-if="(science.length != 0) && loaded">
			<view class="wrap-tit">
				红会科普
				<view class="tit-bg"></view>
			</view>
			<view class="readmore" @click="navTo('/pages/applic/science')">
				更多<image src="../../static/icon/next.png" mode="widthFix"></image>
			</view>
			<scroll-view scroll-x="true" class="kp-scroll flex">
				<view class="kp-item" v-for="sitem in science" @click="navTo('/pages/applic/info?id=' + sitem.id)">
					<view class="kp-item-img">
						<image src="../../static/img/002.png" mode="heightFix" ></image>
					</view>
					<view class="kp-item-tit clamp">
						{{sitem.title}}
					</view>
				</view>
			</scroll-view>
		</view> -->
	</view>
</template>

<script>
	import {
		loadIndexs,
		loveList
	} from '@/api/index.js';
	import { getArticList} from '@/api/index.js';
	import {
		saveUrl,
		interceptor
	} from '@/utils/loginUtils.js';
	import {
		mapState,
		mapMutations
	} from 'vuex';
	import {
		userinfo
	} from '@/api/user.js';
	import uniPopup from '@/components/uni-popup/uni-popup.vue';
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	export default {
		components: {
			uniPopup,
			uniLoadMore
		},
		data() {
			return {
				carouselList: [], //轮播
				science: [], //文章列表
				page: 1,
				limit: 20,
				loaded: false,
				loveList: [],
				loadingType: 'more',
				timer: ''
			};
		},
		filters: {
			getTime(val) {
				let date = new Date(val * 1000);
				let Y = date.getFullYear();
				let M = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1;
				let D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
				return Y + '/' + M + '/' + D;
			},
		},
		onShow() {
			saveUrl();
			if (!this.hasLogin) {
				// 登录拦截
				// interceptor();
				uni.showModal({
					title: '登录',
					content: '您未登录，是否马上登陆?',
					success: e => {
						if (e.confirm) {
							interceptor();
						}
					},
					fail: e => {
						console.log(e);
					}
				});
			} else {
			}
			if(this.timer) {
				clearTimeout(this.timer)
			}
			this.getLoveList()
		},
		onLoad() {
			// this.getPkList()
			this.loadIndex()
			saveUrl();
		},
		computed: {
			...mapState('user', ['userInfo', 'hasLogin']),
			...mapState('info',['kpCid']),
			...mapState(['baseURL']),
			showLove() {
				return this.loveList.slice(0, 5);
			}
		},
		methods: {
			...mapMutations('user', ['setUserInfo']),
			gundong() {
				let obj = this;
				obj.timer = setTimeout(() => {
					obj.loveList.push(obj.loveList.shift());
					// console.log(obj.moreJxList)
					obj.gundong();
				}, 2000);
			},
			//获取红会爱心榜 
			getLoveList() {
				let obj = this
				loveList({
					page:obj.page,
					limit: obj.limit
				}).then(res => {
					obj.loveList = res.data.data
					if(obj.loveList.length > 5) {
						obj.gundong();
					}
					
				})
			},
			loadIndex() {
				let obj = this;
				loadIndexs({}).then(({
					data
				}) => {
					console.log(data, 'index')
					//轮播图
					this.carouselList = data.banner
					console.log(this.carouselList,'this.carouselList++++++++')
				});
			},
			loadData() {
				let obj = this;
				
				userinfo({}).then(({
					data
				}) => {
					obj.setUserInfo(data);
				});
			},
			// 处理跳转
			navTo(url) {
				if(url.indexOf('http') != -1) {
					window.location.href = url
				}else {
					uni.navigateTo({
						url:url,
						fail() {
							uni.switchTab({
								url:url
							})
						}
					});
				}
				
			},
			// 获取科普文章列表
			getPkList() {
				let obj = this
				getArticList({
					page: obj.page,
					limit: obj.limit,
					ifyid: obj.kpCid
				}).then(res => {
					obj.loaded = true
					console.log(res,'获取科普文章列表')
					obj.science = res.data.list
				})
			}
		}
	};
</script>

<style lang="scss">
	a {
		text-decoration: none;
		color: #5f5f5f;
	}

	.content {
		background-color: #ffabab;
	}

	.content {
		background-color: #f8f8f8;
		height: 100%;

		/* 头部 轮播图 */
		.carousel-section {
			// padding-top: 10px;
			overflow: hidden;
			background-color: #fff;
			padding-top: 30rpx;
			.carousel {
				width: 694rpx;
				height: 466rpx;
				margin: 0 auto;
				overflow: hidden;
				.carousel-item {
					width: 100%;
					height: 100%;
					padding-left: 30rpx;
					padding-right: 30rpx;
					overflow: hidden;
				}
				image {
					width: 100%;
					height: 466rpx;
					border-radius: 20rpx;
				}
			}
		}

		// 分类
		.cate-section {
			justify-content: space-around;
			background-color: #fff;
			padding: 46rpx 0 30rpx;

			.cate-item {
				width:20%;
				flex-shrink: 0;
				flex-direction: column;
				text-align: center;
				align-items: center;
				justify-content: center;

				.img-wrapper {
					width: 100rpx;
					height: 120rpx;
					border-radius: 14rpx;
					position: relative;
					image {
						position: absolute;
						left: 50%;
						top: 50%;
						transform: translate(-50%, -50%);
					}
					.img1 {
						width: 120rpx;
						height: 120rpx;
					}
				}
				.item-title {
					margin-top: 15rpx;
					font-size: 20rpx;
					font-weight: 500;
					color: #333333;
				}
			}
		}

	}
	.join-red {
		width: 750rpx;
		// height: 279rpx;
		padding: 20rpx 0;
		background-color: #fff;
		margin: 20rpx 0;
		display: flex;
		align-items: center;
		justify-content: center;
		image {
			
			width: 710rpx;
			// height: 203rpx;
		}
	}
	.jzsb-wrap {
		width: 750rpx;
		// height: 812rpx;
		background-color: #fff;
		margin: 20rpx 0 0;
		padding-bottom: 30rpx;
		image {
			width: 100%;
			height: 100%;
		}
		.fjjhy-wrap {
			width: 694rpx;
			height: 417rpx;
			margin: 0 auto 20rpx;
			border-radius: 20rpx;
		}
		.jhz-aed-wrap {
			width: 694rpx;
			height: 210rpx;
			margin: 20rpx auto;
			justify-content: space-between;
			.jhz-wrap {
				width: 334rpx;
				height: 208rpx;
				border-radius: 28rpx;
			}
			.aed-wrap {
				width: 334rpx;
				height: 208rpx;
				border-radius: 28rpx;
			}
		}
	}
	.kp-wrap {
		width: 750rpx;
		height: 353rpx;
		background-color: #fff;
		margin: 20rpx auto;
		position: relative;
		.kp-scroll {
			height: 200rpx;
			width: 750rpx;
			// background-color: red;
			// justify-content: ;
			padding-left: 23rpx;
			white-space: nowrap;
			.kp-item {
				display: inline-block;
				width: 286rpx;
				height: 200rpx;
				background: #FFFFFF;
				border: 1px solid #F5F5F5;
				box-shadow: 0px 0px 20rpx 0px rgba(50, 50, 52, 0.06);
				border-radius: 15rpx;
				margin-right:15rpx;
				.kp-item-img {
					height: 155rpx;
					margin-bottom: 5rpx;
					image {
						display: block;
						margin: auto;
						height: 155rpx;
						max-width: 286rpx;
					}
				}
				.kp-item-tit {
					width: 246rpx;
					height: 33rpx;
					background: #a1a1a1;
					border-radius: 17rpx;
					color: #fff;
					margin: auto;
					position: relative;
					font-size: 24rpx;
					font-weight: 500;
					color: #FEFEFE;
					line-height: 33rpx;
					padding-left: 23rpx;
					&::before {
						content: '';
						width: 4rpx;
						height: 4rpx;
						background: #F3392C;
						border-radius: 50%;
						position: absolute;
						top: 0;
						bottom: 0;
						left: 12rpx;
						margin: auto;
					}
				}
			}
		}
	}
	.wrap-tit {
		display: inline-block;
		line-height: 115rpx;
		font-size: 40rpx;
		font-weight:600;
		color: #666666;
		padding-left: 24rpx;
		position: relative;
		.tit-bg {
			width: 160rpx;
			height: 22rpx;
			background: linear-gradient(-330deg, #FFE88B, #FFBA00);
			opacity: 0.4;
			position: absolute;
			bottom: 40rpx;
			margin: auto;
		}
		
	}
	.readmore {
		width: 150rpx;
		padding-right: 27rpx;
		font-size: 28rpx;
		font-weight: 500;
		color: #999999;
		position: absolute;
		text-align: right;
		top: 0;
		right: 0;
		line-height: 110rpx;
		image {
			width: 35rpx;
			vertical-align: text-bottom;
		}
	}
	.love {
		background: #FFFFFF;
	}
	.love-wrap {
		margin: auto;
		width: 694rpx;
		// height: 309px;
		
		box-shadow: 0px 0px 10px 0px rgba(0,0,0,0.1000);
		border-radius: 30rpx;
		position: relative;
		text-align: center;
		.love-top {
			width: 185rpx;
			line-height: 55rpx;
			background: #FF4C4C;
			border-radius: 28rpx;
			font-size: 30rpx;
			font-weight: bold;
			color: #FFFFFF;
			text-align: center;
			position: absolute;
			top: -25rpx;
			left: 0;
			right: 0;
			margin: auto;
		}
		.tab-tit {
			line-height: 65rpx;
			border-bottom: 1px solid #F2F2F2;
			.tit {
				width: 25%;
				font-size: 20rpx;
				font-weight: bold;
				color: #FF4C4C;
			}
		}
		.tab-val {
			.tit {
				color: #101010;
			}
		}
	}
	.lookmore {
		padding: 10rpx 0;
		font-size: 24rpx;
		font-weight: 500;
		color: #090909;
		image {
			display: inline-block;
			margin-left: 10rpx;
			width: 18rpx;
			
		}
	}
</style>
