<template>
	<view>
		<view class="search">
			<u-search placeholder="搜索患者" v-model="param.patientName" bgColor="white" :showAction="false" @search="refresh()" @clear="(param.patientName = ''), refresh()"></u-search>
		</view>
		<view class="listv">
			<view class="item" v-for="(item, index) in list" :key="index" @click="detail(item)">
				<view class="title omit">
					<text class="icon" v-if="item.top === 1">&#xe61f;</text>
					<text>{{ item.templateName }}</text>
				</view>
				<view class="desc">
					<text>{{ item.patientName }}</text>
					<text>{{ item.createTime }}</text>
					<text class="del" @click.stop="del(item, index)">删除</text>
					<text class="edit" @click.stop="go('/pages/follow/doctor/add?id=' + item.id + ' &patientName=' + item.patientName)">编辑</text>
					<text class="icon state" :style="{ color: item.state == 0 ? '#b5b5b5' : '#4CAF50' }" v-if="param.type == 1">&#xe830;{{ item.state == 0 ? '待回访' : '已回访' }}</text>
					<text class="icon state" :style="{ color: item.state == 0 ? '#b5b5b5' : '#4CAF50' }" v-else>&#xe830;{{ item.state == 0 ? '消息未读' : '已读' }}</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 class="mfooter">
			<button class="btn" @click="go('/pages/follow/doctor/add?type=' + param.type)">
				<text class="icon">&#xe8d5;</text>
				<text>新增</text>
			</button>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			list: [],
			param: { pageNum: 1, pageSize: 10, orderByColumn: 'k.id', isAsc: 'desc' },
			loadMore: true
		};
	},
	onLoad(e) {
		this.param.type = e.type || 0;
		this.getData();
		uni.$on('record', (res) => {
			this.refresh();
		});
		setTimeout(() => {
			uni.setNavigationBarTitle({ title: this.param.type == 0 ? '复诊提醒' : '随访记录' });
		}, 300);
	},
	methods: {
		getData() {
			this.http.request({
				url: '/work/record/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);
					});
				}
			});
		},
		del(item, index) {
			uni.showModal({
				title: '提示',
				content: '确定删除该内容?',
				success: (res) => {
					if (res.confirm) {
						this.http.request({
							url: '/work/record/remove/' + item.id,
							success: (res) => {
								uni.showToast({ title: '删除成功' });
								this.list.splice(index, 1);
							}
						});
					}
				}
			});
		},
		detail(item) {
			if (this.param.type == 1) {
				uni.navigateTo({ url: '/pages/follow/detail?id=' + item.id });
			}
		},
		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"></style>
