<template>
	<view class="msilde">
		<view class="top">
			<u-search placeholder="搜索标题" bgColor="white" :showAction="false"></u-search>
		</view>
		<view class="left">
			<view class="item" :class="{ active: index == current }" v-for="(item, index) in type_list" :key="index" @click="selected(item, index)">{{ item.dictLabel }}</view>
		</view>
		<view class="right">
			<view class="list">
				<view class="u_item" v-for="(item, index) in list" :key="index" @click="go('/pages/knowledge/detail?id=' + item.id)">
					<view class="con">
						<view class="name">{{ item.name }}</view>
						<view class="labels omit">{{ item.labels }}</view>
						<view class="labels">{{ item.columnName }}</view>
					</view>
				</view>
			</view>
			<view class="loading" v-if="loadMore"><u-loadmore :status="loadMore ? 'loading' : 'nomore'" /></view>
			<u-empty v-if="!loadMore && list.length == 0"></u-empty>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			type_list: [],
			current: 0,
			list: [],
			param: { pageNum: 1, pageSize: 10 },
			loadMore: true
		};
	},
	onLoad(e) {
		this.getType();
		this.getData();
	},
	methods: {
		getData() {
			this.http.request({
				url: '/app/knowledge/list',
				data: this.param,
				loading: 'false',
				success: (res) => {
					this.loadMore = res.data.pages > this.param.pageNum ? true : false;
					res.data.rows.forEach((item) => {
						item.createTime = uni.$u.timeFrom(Date.parse(item.createTime));
						this.list.push(item);
					});
				}
			});
		},
		getType() {
			this.http.request({
				url: '/app/common/type/knowledge_type',
				success: (res) => {
					this.type_list = res.data.data;
					this.type_list.unshift({ dictLabel: '全部类型', dictValue: '' });
				}
			});
		},
		//刷新数据
		refresh() {
			this.loadMore = true;
			this.param.pageNum = 1;
			this.list = [];
			this.getData();
		},
		go(url) {
			uni.navigateTo({ url: url });
		}
	},
	//下拉刷新
	onPullDownRefresh() {
		setTimeout(() => {
			this.refresh();
			uni.stopPullDownRefresh();
		}, 1000);
	},
	//上拉加载
	onReachBottom() {
		if (this.loadMore) {
			this.param.pageNum++;
			this.getData();
		}
	}
};
</script>

<style lang="scss"></style>
