<template>
	<view class="main">
		<view class="top">
			<view class="nameBox">
				<view class="name">{{ param.patientName }}</view>
				<text class="icon arrow" style="margin-left: 10px">&#xeb73;</text>
				<view class="change" @click="go('/pages/visit/doctor/selectUser')">切换就诊人</view>
			</view>
			<view style="display: flex; text-align: center; margin: 5px; padding: 13px; font-size: 13px" @click="calendar = true">
				<input placeholder="点击选择时间" :disabled="true" v-model="startTime" type="select" />
				<view>至</view>
				<input placeholder="点击选择时间" :disabled="true" v-model="endTime" type="select" />
			</view>
		</view>

		<view class="tab">
			<u-tabs :list="tab" :current="current" keyName="label" @click="click"></u-tabs>
		</view>
		<view class="content">
			<view class="list">
				<view class="item" v-for="(item, index) in list" @click="go(`/pages/visit/doctor/detail?cardId=${param.cardId}&patientName=${param.patientName}&id=${item.id}`)">
					<view class="title omit">{{ item.department }}</view>
					<view class="time">{{ item.admissionTime }}</view>
				</view>
			</view>
			<u-empty v-if="list.length == 0"></u-empty>
		</view>
		<u-calendar :show="calendar" monthNum="120" mode="range" :maxDate="util.getDate()" minDate="2020-01-01" @confirm="confirm" @close="close()" :closeOnClickOverlay="true"></u-calendar>
	</view>
</template>

<script>
export default {
	data() {
		return {
			userList: [],
			current: 0,
			time: null,
			tab: [{ label: '就诊记录' }],
			startTime: null,
			endTime: null,
			list: [],
			param: {},
			calendar: false,
			user: {}
		};
	},
	onLoad(e) {
		this.param.patId = e.patId;
		this.param.patientName = e.patientName;
		this.getData();
	},
	methods: {
		groupChange(n) {
			uni.showModal({
				title: '提示',
				content: '确定切换就诊人',
				success: (res) => {
					if (res.confirm) {
						this.http.request({
							url: '/app/user/bind/change/' + n.id,
							success: (res) => {
								this.param.patientName = n.patientName;
								this.closePopup();
								this.refresh();
							}
						});
					}
				}
			});
		},
		confirm(e) {
			this.calendar = false;
			this.param.startTime = e[0].replace(/-/g, '');
			this.param.endTime = e[e.length - 1].replace(/-/g, '');
			this.startTime = e[0];
			this.endTime = e[e.length - 1];
			this.refresh();
		},
		close() {
			this.calendar = false;
		},
		getData() {
			this.http.request({
				url: '/work/visit/list',
				data: this.param,
				success: (res) => {
					this.list = res.data.data;
				}
			});
		},
		click(e) {
			this.current = e.index;
			this.param.type = e.dictValue;
			this.refresh();
		},
		selectTime(e) {
			console.log(e);
		},
		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">
.top {
	padding: 15px;
	background-color: white;
	border-radius: 8px;

	.nameBox {
		display: flex;
		align-items: center;

		.name {
			font-weight: bold;
			font-size: 16px;
		}

		.change {
			color: royalblue;
			margin-left: 20px;
		}
	}

	.cardNum {
		padding-top: 10px;
		font-size: 14px;
	}
}

.content {
	padding: 15px;
	background-color: white;
	border-radius: 8px;

	.list {
		.item {
			overflow: hidden;
			padding: 13px 0;
			border-bottom: 1px solid $line;
			margin-bottom: 10px;
			&:last-child {
				border: 0px;
			}
			.title {
				font-size: 18px;
				font-weight: bold;
			}

			.time {
				font-size: 14px;
				padding-top: 15px;
				color: $font-c;
			}
		}
	}
}

.userChangeTitle {
	display: flex;
	justify-content: center;
	align-items: center;
	height: 48px;
	font-weight: bold;
}

.userChangeItem {
	width: 100%;

	.userChangeItemName {
		padding: 5px 10px;
	}

	.userChangeCartNo {
		padding: 5px 10px;
	}
}
</style>
