<template>
	<view class="main">
		<view class="indexswiper" style="margin-top: 10rpx;">
			<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" style="height: 250rpx;">
				<swiper-item v-for="(item,index) in configInfo" :key="index">
					<view class="swiper-item">
						<image :src="item.image" mode="widthFix"></image>
					</view>
				</swiper-item>
			</swiper>
		</view>
		<view class="tltleStyle">
			推荐文章
		</view>
		<u-card :show-head="false" :show-foot="false" margin="0" :border="false">
			<view class="" slot="body" v-for="(item,index) in list" :key="index" @click="bookinfo(item.id,item.title)">
				<view class="u-border-bottom padding-bottom-sm">
					<view class="u-body-item u-flex u-col-between u-p-t-0 justify-between">
						<view class="u-body-item-title u-line-2">{{item.title}}</view>
						<u-image :src="imghost+item.banner_url" width="120" height="120" style="margin-left: 12rpx;"></u-image>
					</view>
					<u-tag :text="item.type==1?'健康科普':item.type==2?'疫苗科普':'常见问题'" size="mini" shape="circle" mode="dark" type="info" />
				</view>
			</view>
		</u-card>
		<view class="margin-tb padding-tb-xs">
			<u-loadmore :status="nomore" :icon-type="flower" />
		</view>
		<u-no-network></u-no-network>
	</view>
</template>

<script>
	var user = require('../../common/user.js');
	export default {
		onLoad(options) {
			this.imghost = this.$imgHost
			this.pageindex = 1
			this.list = []
			this.getbook()
		},
		onShow() {
			this.ismaxbook = true
			this.getconfigLsit()
		},
		mounted() {

		},
		data() {
			return {
				list: [],
				configInfo: {},
				pageindex: 1,
				imghost: "",
				ismaxbook: true
			}
		},
		onReachBottom() {
			this.getbook()
		},
		methods: {
			getbook: async function() {
				if (this.ismaxbook) {
					let res = await this.$request.post("/api/v1/article/articleList", {
						page: this.pageindex
					}, false)
					let status = user.islogin(res)
					if (status) {
						if (this.pageindex > res.data.last_page) {
							uni.showToast({
								title: "没有更多了",
								icon: "none"
							})
							this.ismaxbook = false
							return false
						} else {
							this.list = this.list.concat(res.data.data)
							this.pageindex++
						}
					}
				}
			},
			bookinfo(id, title) {
				uni.navigateTo({
					url: "../common_tools/collection/collection_details?id=" + id + "&title=" + title
				})
			},
			getconfigLsit: async function() {
				let res = await this.$request.post("/api/v1/common/icons", {
					type: 2
				}, false)
				if (res.status == 200) {
					this.configInfo = res.data
				}
			}
		}
	};
</script>

<style scoped lang="scss">
	.main {
		padding-top: 10rpx;
		padding-left: 20rpx;
		padding-right: 20rpx;
	}

	.tltleStyle {
		padding: 30rpx 30rpx 15rpx 15rpx;
		font-weight: bold;
		font-size: 40rpx;
		background-color: #fff;
	}

	.u-card-wrap {
		background-color: $u-bg-color;
		padding: 1px;
	}

	.u-body-item {
		font-size: 32rpx;
		color: #333;
		padding: 20rpx 10rpx;
	}

	.u-body-item image {
		width: 120rpx;
		flex: 0 0 120rpx;
		height: 120rpx;
		border-radius: 8rpx;
		margin-left: 12rpx;
	}
</style>
