<template>
	<view class="content">
		<u-sticky bgColor="#fff">
			<u-tabs :list="list" keyName="title" @click="changeTab"></u-tabs>
		</u-sticky>
		<u-list @scrolltolower="scrolltolower">
			<u-list-item v-for="(item, index) in pageList" :key="index">
				<view class="healthStationModel" @click="gotoDetail(item.id)">
					<view class="healthStationImg">
						<image class="init_image" :src="item.cover" mode=""></image>
					</view>
					<view class="healthStationInfo">
						<view class="healthStationInfoName">
							{{item.title}}
						</view>
						<view class="healthStationInfoTime">
							{{item.created_at}}
						</view>
					</view>
				</view>
			</u-list-item>
		</u-list>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pageList: [],
				list: [],
				pageNum: 1,
				pageSize: 10,
				tabId: null
			}
		},
		onShow() {
			this.pageList = [];
			this.getTabList()
		},
		methods: {
			scrolltolower() {
				console.log('+10')
				this.pageNum += 1;
				this.getPageList(this.tabId)
			},
			changeTab(item) {
				console.log('item', item);
				this.pageNum = 1;
				this.tabId = item.id
				this.pageList = [];
				this.getPageList(item.id)
			},
			//获取分类列表
			getTabList(e) {
				this.$request('/get-cate-list', 'GET', {}).then(res => {
					console.log(res.data)
					this.list = res.data.list;
					this.tabId = res.data.list[0].id;
					this.getPageList(res.data.list[0].id);
				}).catch(err => {
					uni.showToast({

						icon: 'error',

						title: '' + err.message

					})
				})
			},
			//获取分类文章列表
			getPageList(id) {
				this.$request('/article-list', 'GET', {
					cat_id: id,
					page: this.pageNum,
					limit: this.pageSize
				}).then(res => {
					console.log(res.data)
					this.pageList = [...this.pageList, ...res.data.list];
				}).catch(err => {
					uni.showToast({

						icon: 'error',

						title: '' + err.message

					})
				})
			},
			gotoDetail(id) {
				uni.navigateTo({
					url: '/pageSub-index/pages/healthStationDetail/healthStationDetail?id=' + id
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		width: 100vw;
		background: #F8F8F8;
	}

	.healthStationModel {
		height: 160rpx;
		width: calc(100% - 120rpx);
		background-color: #FFFFFF;
		border-radius: 20rpx;
		margin: 20rpx 30rpx;
		padding: 20rpx 30rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;

		.healthStationImg {
			height: 160rpx;
			width: 230rpx;
			margin-right: 20rpx;
			border-radius: 10rpx;
			overflow: hidden;


		}

		.healthStationInfo {
			flex: 1;
			height: 160rpx;
		}

		.healthStationInfoName {
			width: 100%;
			height: 120rpx;
			font-size: 30rpx;
			color: #333333;
			line-height: 40rpx;
			font-weight: 600;
			display: -webkit-box;
			-webkit-box-orient: vertical;
			-webkit-line-clamp: 2;
			overflow: hidden;
			text-overflow: ellipsis;
		}

		.healthStationInfoTime {
			width: 100%;
			height: 40rpx;
			font-size: 24rpx;
			color: #666666;
			line-height: 40rpx;
		}
	}
</style>