<template>
	<view class="app">
		<view class="" v-if="list.length>0">
			<view class="item" v-for="item in list" @tap="godetail(item.id)">
				<view class="text">
					就诊医院：
					{{item.hospitalAgencyName?item.hospitalAgencyName:''}}
				</view>
				<view class="text">
					就诊科室：
					{{item.departmentName?item.departmentName:''}}
				</view>
				<view class="text">
					就诊时间：
					{{item.visitDate?item.visitDate:''}}
				</view>
			</view>
		</view>
		<u-empty v-else text="暂无" mode="list" icon-size="220"></u-empty>
	</view>
</template>

<script>
	import {
		getHealthRecordList
	} from '@/api/healthRecords/index.js'
	import {
		parseTime
	} from '@/api/time.js'
	export default {
		data() {
			return {
				query: {
					pageNum: 1,
					pageSize: 10,
					residentId: uni.getStorageSync('patientId')
				},
				list: [],
				total: 0,
			}
		},
		onLoad() {
			this.info();
		},
		methods: {
			info() {
				getHealthRecordList(this.query).then(res => {
					this.list = [...this.list, ...res.rows]
					this.list.forEach(e => {
						e.visitDate ? e.visitDate = parseTime(e.visitDate, '{y}-{m}-{d} {h}:{i}:{s}') : ''
					})
					this.total = res.total
				})
			},
			godetail(id) {
				uni.navigateTo({
					url: `/pages/healthRecordDetail/healthRecordDetail?id=${id}`
				})
			},
		},
		onReachBottom() { //下滑加载
			if (this.list.length >= this.total) {} else {
				this.query.pageNum++;
				this.info();
			}
		},
		onPullDownRefresh() { //下拉刷新
			this.list = []
			this.query.pageNum = 1;
			this.info();
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
	}
</script>

<style lang="scss">
	page {
		background-color: #F4F5F7;
	}

	::v-deep .u-empty {
		margin-top: 100rpx !important;
	}

	.app {
		.item {
			background-color: #fff;
			width: 95%;
			margin: 20rpx auto;
			border-radius: 10rpx;
			padding: 0 30rpx;

			.text {
				line-height: 70rpx;
			}
		}
	}
</style>
