<template>
	<view class="main">
		<view style="padding: 15px 0;">
			<u-search placeholder="患者姓名" v-model="param.patientName" bgColor="white" :showAction="false" @search="refresh()" @clear="(param.patientName = ''), refresh()"></u-search>
		</view>
		<view class="list">
			<view class="item" v-for="(item, index) in list" :key="index" @click="go('/pages/detection/doctor/list?cardId='+item.cardId+'&patId=' + item.patId+'&patientName='+ item.name)">
				<view class="title omit">
					<text>{{ item.name }}</text>
						<text class="check">({{ item.cardId }})</text>
				</view>
			</view>
			<u-empty v-if="list.length == 0" text="暂无患者"></u-empty>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			list: [],
			param:{
				pageNum:1,
				pageSize:20,
			},
			loadMore: true
		};
	},
	onLoad(e) {
		this.getData();
		uni.$on('bind', (res) => {
			this.getData();
		});
	},
	methods: {
		getData() {
			this.http.request({
				url: '/system/user/deptTree',
				success: (res) => {
					console.log(res);
					this.param.departmentName = res.data.data[0].label
					this.http.request({
						url: '/work/visit/patientCard',
						data: this.param,
						success: (res) => {
							this.loadMore = res.data.pages > this.param.pageNum ? true : false;
							res.data.rows.forEach((item) => {
								this.list.push(item);
							});
						}
					});
				}
			});
		},
		go(url) {
			uni.navigateTo({ url: url });
		},
		//刷新数据
		refresh() {
			this.loadMore = true;
			this.param.pageNum = 1;
			this.list = [];
			this.getData();
		},
		
	},
	//上拉加载
	onReachBottom() {
		if (this.loadMore) {
			this.param.pageNum++;
			this.getData();
		}
	}
};
</script>

<style lang="scss">
.list {
	background-color: white;
	border-radius: 10px;
	.item {
		padding: 16px 12px 16px 12px;
		border-bottom: 1px solid $line;
		overflow: hidden;
		.title {
			font-size: 15px;
			font-weight: bold;
			.check {
				color: #737373;
				font-size: 13px;
				font-weight: normal;
				padding-left: 5px;
			}
		}
		.del {
			color: #f44336;
			float: right;
			margin-top: -20px;
			font-size: 20px;
		}
	}
}
</style>
