<template>
	<view>
		<view class="tab">
			<u-tabs :list="tab" @click="click"></u-tabs>
		</view>
		<view class="list">
			<view class="item" v-for="(item, index) in list" :key="index" @click="go('/pages/follow/detail?id=' + item.id)">
				<view class="title omit">
					<text class="icon" v-if="item.top === 1">&#xe61f;</text>
					<text>{{ item.templateName }}</text>
				</view>
				<view class="desc">
					<text>{{ item.state == 0 ? '待回访' : '已回访' }}</text>
					<text>{{ item.createTime }}</text>
				</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 {
			tab: [
				{ name: '全部', state: '' },
				{ name: '待回访', state: 0 },
				{ name: '已回访', state: 1 }
			],
			list: [],
			param: { pageNum: 1, pageSize: 10 },
			loadMore: true
		};
	},
	onLoad(e) {
		this.getData();
	},
	methods: {
		click(e) {
			this.current = e.index;
			this.param.type = e.dictValue;
			this.refresh();
		},
		getData() {
			this.http.request({
				url: '/app/follow/list',
				data: this.param,
				loading: 'false',
				success: (res) => {
					this.loadMore = res.data.pages > this.param.pageNum ? true : false;
					this.list.push(...res.data.rows);
				}
			});
		},
		go(url) {
			uni.navigateTo({ url: url });
		},
		//刷新数据
		refresh() {
			this.loadMore = true;
			this.param.pageNum = 1;
			this.list = [];
			this.getData();
		}
	},
	//下拉刷新
	onPullDownRefresh() {
		setTimeout(() => {
			this.refresh();
			uni.stopPullDownRefresh();
		}, 1000);
	},
	//上拉加载
	onReachBottom() {
		if (this.loadMore) {
			this.param.pageNum++;
			this.getData();
		}
	}
};
</script>

<style lang="scss">
.list {
	padding: 10px 12px;
	.item {
		border-radius: 5px;
		padding: 13px 12px 13px 12px;
		margin-bottom: 10px;
		overflow: hidden;
		box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
		background-color: white;
		.title {
			font-size: 15px;
			font-weight: bold;
			.icon {
				color: orangered;
				padding-right: 3px;
			}
		}
		.desc {
			font-size: 14px;
			padding-top: 10px;
			text {
				padding-right: 30px;
			}
		}
	}
}
</style>
