<template>
	<view>
		<view class="tab">
			<u-tabs :list="tab" @click="click"></u-tabs>
		</view>
		<view class="list">
			<view class="message-bubble-received" v-for="(item, index) in list" :key="index" @click="go('/pages/follow/detail?id=' + item.id + '&deptName=' + item.deptName + '&doctorName=' + item.doctorName)">
				<view class="title">{{ item.templateName }}</view>
				<view class="desc">尊敬的患者，为了更好的改善服务，我们向你发起了一个回访并且希望您认真填写。</view>
				<view class="desc">{{ item.createTime }}</view>
				<button class="btn" :style="{ backgroundColor: item.state == 0 ? '#4581fb' : '#4CAF50' }">
					<text class="icon" v-if="item.state == 0">&#xe749;</text>
					<text class="icon" v-else>&#xe6c6;</text>
					<text>{{ item.state == 0 ? '去填写' : '已填写' }}</text>
				</button>
			</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, type: 1 },
			loadMore: true
		};
	},
	onLoad(e) {
		this.getData();
		uni.$on('follow', (res) => {
			this.refresh();
		});
	},
	methods: {
		click(e) {
			this.current = e.index;
			this.param.state = e.state;
			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;
	.message-bubble-received {
		.title {
			font-size: 16px;
			font-weight: bold;
		}
		.desc {
			font-size: 13px;
			padding-top: 10px;
			color: $font-c;
		}
		.btn {
			.icon {
				padding-right: 3px;
			}
		}
	}
}
</style>
