<template>
	<view class="content">
		<view class="f_banner" v-if="fimages.length">
			<swiper class="swiper" indicator-dots="true" autoplay="true">
				<swiper-item v-for="(image, index) in fimages" :key="index" @click="$tools.NewsPtype(image)">
					<image :src="image.cover_image" mode="aspectFill" />
				</swiper-item>
			</swiper>
		</view>
		<!-- 标签 -->
		<view class="tabbar">
			<scroll-view class="scroll-menu" scroll-x="true" style="white-space: nowrap;">
				<view @click="handleactive(index)" v-for="(name,index) in labelList" :key="index"
					:class="[active==index?'active':'']">
					{{name.name}}
				</view>
			</scroll-view>
		</view>
		<!-- list -->
		<view class="list">
			<view class="newslist" v-for="(item,index) in list" :key="index" @click="handleActive(item,index)">
				<view class="left">
					<view class="title">
						{{item.title}}
					</view>
				</view>
				<view class="right">
					<image :src="item.cover_image" mode="aspectFill"></image>
				</view>
				<view class="time">
					<view class="size14 c999">
						<icon class="iconfont icon-icon-test"></icon>
						{{$t("index.browse")}}{{item.reading}}
					</view>
					<view class="size14 c999">
						<icon class="iconfont icon-icon-test1"></icon>
						{{item.create_time}}
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from "vuex";
	export default {
		data() {
			return {
				page: 1,
				fimages: [],
				lastPage: "",
				labelList: [],
				active: 0,
				list: []
			};
		},
		computed: {
			...mapState([]),
		},
		onLoad() {
			let that = this;
			that.page = 1
			that.handleContentLabel()
		},
		onReachBottom() {
			let that = this
			if (!this.lastPage || this.page >= this.lastPage) {
				uni.showToast({
					title: that.$t("tips.msgNoMoreData"),
					icon: 'none'
				})
				return
			}
			this.page++
			this.handleContentMsg()
		},
		methods: {
			// 资讯信息
			handleContentMsg() {
				let that = this
				that.$model.getContentMsg({
					type: that.active,
					sector_id: 1,
					page: that.page,
				}).then(res => {
					console.log("资讯", res)
					if (res.code != 0) return
					that.list = that.list.concat(res.data.content_data)
				})
			},
			// 标签类别信息
			handleContentLabel() {
				let that = this
				that.$model.getContentLabel({}).then(res => {
					console.log("标签类别信息", res)
					if (res.code != 0) return
					that.labelList = res.data[0].list
					that.fimages = res.data[0].loop_data
					that.handleContentMsg()
				})
			},
			// 切换文章类别
			handleactive(ind) {
				let that = this
				that.active = ind
				that.page = 1
				that.list = []
				that.handleContentMsg()
			},
			detail(ite) {
				this.$tools.NewsPtype(ite)
				// uni.navigateTo({
				// 	url: "/pageTwo/webview/webview?url=" + item.jump_url
				// })
			},
			handleActive(ite, ind) {
				let that = this
				that.$tools.NewsPtype(ite)
				setTimeout(function() {
					that.list[ind].reading++
				}, 2000);
			}
		}
	}
</script>

<style lang="scss">
	// banner
	.f_banner {
		width: 100%;
		height: 400upx;

		/deep/swiper {
			height: 400upx;
		}

		image {
			width: 100%;
			height: 100%;
			background-size: 100%;
		}
	}

	.tabbar {
		height: 50px;
		display: flex;
		font-weight: bold;
		font-size: 16px;
		justify-content: space-between;
		margin: 15px 10px;

		.scroll-menu {
			width: 100%;
			white-space: nowrap;
		}

		view {
			display: inline-block;
			height: 48px;
			line-height: 48px;
			padding: 0 10px;

			text {
				display: block;
				width: 100%;
				text-align: center;
				margin-top: 10px;
			}
		}

		.active {
			color: #fff;
			border-radius: 5px;
			background-color: $btncolor;
		}
	}

	.list {
		width: 100%;
		padding-bottom: 50px;
	}

	.newslist {
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
		padding: 10px 15px;
		border-bottom: 1px solid #f7f7f7;

		.left {
			width: calc(100% - 115px);
			height: 60px;
			display: flex;
			flex-wrap: wrap;
			flex-flow: column;
			justify-content: space-between;

			.title {
				width: 100%;
				font-size: 30rpx;
				overflow: hidden;
				text-overflow: ellipsis;
				display: -webkit-box;
				-webkit-box-orient: vertical;
				-webkit-line-clamp: 2;
				line-height: 30px;
				font-weight: bold;
			}
		}

		.right {
			width: 105px;
			height: 60px;
			border: 1px solid #f7f7f7;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.time {
			width: 100%;
			margin-top: 5px;
			display: flex;
			justify-content: space-between;

			icon {
				width: 20px;
				display: block;
				margin-right: 3px;
				margin-top: -5px;
				float: left;
			}

			.icon-icon-test1 {
				font-size: 16px;
			}

			view {
				color: #666;
				font-size: 14px;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
			}
		}
	}
</style>