<template>
	<view class="container-main">
		<view class="type-tree">
			<view class="tree-item" v-for="(item, index) in treeList" :key="index"
				:class="currenIndex == index ? 'activeTree' : ''" @click="clickTree(index)">
				{{ item.name }}
			</view>
		</view>
		<view class="data-rows">
			<u-sticky>
				<view class="header-search">
					<u-icon name="search" size="35" color="#9DA2AB"></u-icon>
					<u-input v-model="keyword" placeholder="请输入关键字"
						:custom-style="{ marginLeft: '20rpx', fontSize: '30rpx' }" :height="40" :clearable="false" />
					<view class="search-submit" @click="searchData()">搜索</view>
				</view>
			</u-sticky>
			<scroll-view scroll-y class="scrollView" @scrolltolower="onreachBottom">
				<view class="list-item"  @click="getInfo()">
					<view class="item-data">
						<view class="data-title">23</view>
						<view class="data-subtitle">2</view>
					</view>

					<view class="item-icon">
						<u-icon name="arrow-right" size="35" color="#DCE3EC"></u-icon>
					</view>
				</view>
				<u-loadmore :status="status" :load-text="loadText" />
			</scroll-view>
		</view>
	</view>
</template>

<script>

	export default {
		data() {
			return {
				keyword: "",
				status: "nomore",
				loadText: {
					loading: "努力加载中",
					nomore: "已经到底了~",
				},
				list: [],
				total: 0,
				queryParams: {
					type: 1,
					pageNum: 1,
					pageSize: 10,
				},
				currenIndex: null,
				treeList: [{
						name: "老年人防骗教育",
						litiletype: 1,
					},
					{
						name: "消费警示",
						litiletype: 2,
					},
					{
						name: "政策法规",
						litiletype: 3,
					},
					{
						name: "突发事件",
						litiletype: 4,
					},
					{
						name: "食品新闻",
						litiletype: 5,
					},
					{
						name: "不良企业处置公告",
						litiletype: 6,
					},
					{
						name: "网络大集",
						litiletype: 7,
					},
				],
			};
		},
		onLoad() {
			//初始化
			this.clickTree(0);
		},
		methods: {
			//详情
			getInfo(item) {
				uni.navigateTo({
					url: `/sub-public/oldman-teach/info`,
				});
			},
			//关键字搜索
			searchData() {
				this.reset();
				this.queryParams.litiletype = this.treeList[this.currenIndex].litiletype;
				this.queryParams.title = this.keyword;
				this.getList();
			},

			// 触底加载
			onreachBottom() {
				if (this.queryParams.pageNum < this.total) {
					// if (this.status == "loading") return;
					this.queryParams.pageNum = this.queryParams.pageNum + 1;
					this.getList()
				}
			},
			// 左侧分类
			clickTree(index) {
				if (this.currenIndex == index) return;
				this.keyword = "";
				this.reset();
				this.queryParams.litiletype = this.treeList[index].litiletype;
				this.getList();
				this.currenIndex = index;
			},

			// 获取城市/县区列表
			getList() {
				this.status = "loading";
					this.list = []
					this.total =  1;
					this.status = "nomore";
			},
			// 重置
			reset() {
				this.list = [];
				this.total = 0;
				this.queryParams = {
					type: 1,
					pageNum: 1,
					pageSize: 10,
				};
			},
			clickCell(item) {
				uni.navigateTo({
					url: item.path,
				});
			},
		},
	};
</script>
<style lang="scss" scoped>
	.container-main {
		height: 100%;
		display: flex;
		align-items: center;

		&>view {
			height: 100%;
		}

		.type-tree {
			background: #f5f7fa;

			.tree-item {
				width: 180rpx;
				box-sizing: border-box;
				padding: 20rpx;
				font-size: 28rpx;
				font-weight: 400;
				color: #34373b;
			}

			.activeTree {
				background: #fff;
				color: #3976f1;
			}
		}

		.data-rows {
			box-sizing: border-box;
			padding: 20rpx;
			width: calc(100vw - 180rpx);
			background: #fff;

			.header-search {
				box-sizing: border-box;
				padding: 20rpx;
				border-radius: 16rpx;
				border: 1px solid #dce3ec;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.search-submit {
					font-size: 32rpx;
					font-weight: 500;
					color: #3976f1;
				}
			}

			.scrollView {
				height: 94.5%;

				.list-item {
					display: flex;
					align-items: center;
					justify-content: space-between;
					min-height: 160rpx;
					border-bottom: 1px solid #dce3ec;
					box-sizing: border-box;
					padding: 20rpx 0;

					.item-data {
						width: 92%;
						box-sizing: border-box;

						.data-title {
							width: 100%;
							font-size: 34rpx;
							font-weight: normal;
							color: #34373b;
							text-overflow: ellipsis;
							overflow: hidden;
							word-break: break-all;
							white-space: nowrap;
						}

						.data-subtitle {
							width: 500rpx;
							margin-top: 20rpx;
							font-size: 32rpx;
							font-weight: 400;
							color: #b0b4bb;
							text-overflow: ellipsis;
							overflow: hidden;
							word-break: break-all;
							white-space: nowrap;
						}
					}

					.item-icon {
						width: 8%;
					}
				}
			}
		}
	}
</style>