<template>
	<view class="content">
		<!-- 轮播 -->
		<view class="carousel-section">
			<swiper class="carousel" :autoplay="true" :interval="3000" :duration="1000">
				<swiper-item v-for="item in carouselList" :key="item.id">
					<image :src="baseURL + item.image"></image>
				</swiper-item>
			</swiper>
		</view>
		<!-- 分类 -->
		<view class="cate-section flex">
			<view class="cate-item flex" @click="navTo('/pages/applic/love')">
				<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="tocontribution">
				<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="toapplic">
				<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>
		<!-- 加入红十字 -->
		<view class="join-red">
			<image src="../../static/img/join-banner.png" mode="" @click="navTo('/pages/cart/cart')"></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="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,
	} 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: 10,
				loaded: false
			};
		},
		onShow() {
			saveUrl();
			if (!this.hasLogin) {
				// 登录拦截
				// interceptor();
				uni.showModal({
					title: '登录',
					content: '您未登录，是否马上登陆?',
					success: e => {
						if (e.confirm) {
							interceptor();
						}
					},
					fail: e => {
						console.log(e);
					}
				});
			} else {
			}
		},
		onLoad() {
			this.getPkList()
			this.loadIndex()
			saveUrl();
		},
		computed: {
			...mapState('user', ['userInfo', 'hasLogin']),
			...mapState('info',['kpCid']),
			...mapState(['baseURL']),
		},
		methods: {
			...mapMutations('user', ['setUserInfo']),
			loadIndex() {
				let obj = this;
				loadIndexs({}).then(({
					data
				}) => {
					console.log(data, 'index')
					//轮播图
					this.carouselList = data.banner
				});
			},
			loadData() {
				let obj = this;
				
				userinfo({}).then(({
					data
				}) => {
					obj.setUserInfo(data);
				});
			},
			// 处理跳转
			navTo(url) {
				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;

			.carousel {
				width: 750rpx;
				height: 547rpx;
				margin: 0 auto;
				overflow: hidden;
				.carousel-item {
					width: 100%;
					height: 100%;
					padding-left: 30rpx;
					padding-right: 30rpx;
					overflow: hidden;
				}
				image {
					width: 100%;
					height: 547rpx;
				}
			}
		}

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

			.cate-item {
				width: 25%;
				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: 24rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #333333;
				}
			}
		}

	}
	.join-red {
		width: 750rpx;
		height: 279rpx;
		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;
		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;
		}
	}
</style>
