<template>
	<view class="container safe-area-inset-bottom">
		<MessageNotification />
		<view class="head" @click="toChoose">
			<view class="head_name">{{infoUserList[0].name || '请选择就诊人'}}</view>
			<view class="head_qh">
				切换就诊人
				<text class="iconfont icon-jiantou1"></text>
			</view>
		</view>


		<!-- 空页 -->
		<view class="empty" v-if="infoList.length==0">
			<image src="@/static/empty/orders.png" mode="aspectFit"></image>
			<view class="word">暂无挂号记录~</view>
		</view>


		<!-- 挂号记录  -->
		<view class="list" v-for="(item,index) in infoList" :key="item.id">
			<view class="li_title">
				<text>{{item.created_at}}</text>

				<text class="text"
					v-if="item.status<4">{{item.status==0&&'待支付'||item.status==1&&'待接诊' || item.status==2&&'接诊中' || item.status==3&&'已结束'}}</text>
				<text class="txt" v-if="item.status>=4">{{item.status==4&&'已取消' || item.status==7&&'已拒诊'}}</text>
			</view>
			<view class="info">
				<view class="list_name">
					患者姓名
				</view>
				<text>{{item.patient}}</text>
			</view>
			<view class="info">
				<view class="list_name">
					预约诊所
				</view>
				<text>{{item.store}}</text>
			</view>
			<view class="info">
				<view class="list_name">
					预约科室
				</view>
				<text>{{item.depart}}</text>
			</view>
			<view class="info">
				<view class="list_name">
					预约医生
				</view>
				<text>{{item.doctor}}</text>
			</view>
			<view class="info">
				<view class="list_name">
					预约序号
				</view>
				<text>{{item.order_number}}</text>
			</view>
			<view class="info">
				<view class="list_name">
					挂号金额
				</view>
				<text>{{item.store}}</text>
			</view>
			<!-- 查看详情 -->
			<view class="detail" @click="getInfo(item.id)"><text>查看详情</text></view>
		</view>
		<u-loadmore :status="status" />
		<u-back-top :scroll-top="scrollTop"></u-back-top>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import {
		registeList,
		userList
	} from '../../request/api/api'
	export default {
		data() {
			return {
				status: 'nomore',
				infoList: [],
				infoUserList: [],
				myinfo: [],
				id: "",
				page: 1, // 当前页数
				total: "", // 总条数
				totalPage: "", // 总页数
				pageSize: 20, // 每页条数
				scrollTop: 0
			}
		},
		onLoad() {

		},
		created() {
			this.getInfolist()
		},
		methods: {
			// 切换
			toChoose() {
				uni.navigateTo({
					url: "/subPackages/my/myinfo?id="
				})
			},
			// 详情
			getInfo(id) {
				uni.navigateTo({
					url: "/subPackages/register/register-info?id=" + id + '&type=' + 1
				})
			},
			// 就诊人列表
			getInfolist() {
				userList({
					method: "post",
					data: {
						store_id: uni.getStorageSync('store_id') || 11001,
					}
				}).then((res) => {
					if (res.data.errcode == 0) {
						this.infoUserList = res.data.data.filter((item) => item.is_default == 1)
						// console.log(this.infoUserList, 'info');
						if (this.infoUserList != '') {
							this.id = this.infoUserList[0].id
						}
					}
					this.getInfos()
				})
			},

			// 列表
			getInfos() {
				registeList({
					method: "post",
					data: {
						store_id: uni.getStorageSync('store_id') || 11001,
						patient_id: this.id || '',
						page: this.page
					}
				}).then((res) => {
					// console.log(res, 'info');
					if (res.data.errcode == 0) {
						// this.infoList = (res.data.data.list).reverse()
						this.totalPage = res.data.data.pagination.totalPage
						this.total = res.data.data.pagination.total

						if (this.page > 1) {
							this.infoList = [...this.infoList, ...res.data.data.list]
						} else {
							this.infoList = res.data.data.list
						}
					}
				})
			},
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		// 触底触发
		onReachBottom() {
			if (this.page < this.totalPage) {
				this.page += 1
				uni.showToast({
					title: "加载中",
					duration: 700,
					mask: false,
					icon: 'loading'
				})
				setTimeout(() => {
					this.getInfos();
				}, 700)
			}
		},
		onPullDownRefresh() {
			// console.log("触发了下拉刷新") 
			// if (this.page <= 1) return
			if (this.page <= 1) {
				this.getInfos();
				setTimeout(() => {
					uni.stopPullDownRefresh()
				}, 300)
			}
			// if (this.page <= 1) return
			this.page = 1
			this.infoList = []
			this.getInfos(() => uni.stopPullDownRefresh())

			//重置一下数据
			// this.page = 1
			// //重新发起请求
			// this.getOrder(() => uni.stopPullDownRefresh())
		},
		mounted() {

		},
		onShow() {
			this.getInfolist();
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		width: 750rpx;
		min-height: 100vh;
		max-height: 100%;
		background-color: #F9FAFB;
		padding-top: 32rpx;
		padding-bottom: env(safe-area-inset-bottom);

		.head {
			width: 750rpx;
			height: 80rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 0 42rpx;
			position: -webkit-sticky;
			position: sticky;
			top: var(--window-top);
			z-index: 99;
			margin-bottom: 10rpx;
			background-color: #F9FAFB;
			font-size: 28rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;

			.iconfont {
				font-size: 28rpx;
				margin-left: 10rpx;
			}
		}

		.empty {
			width: 440rpx;
			height: 393rpx;
			margin: 200rpx auto;
			text-align: center;

			image {
				width: 100%;
				height: 100%;
				z-index: 10;
			}

			.word {
				margin-top: 10rpx;
			}
		}


		.list {
			margin: 0rpx auto 30rpx;
			width: 710rpx;
			background: #FFFFFF;
			border-radius: 8rpx;
			padding: 32rpx;

			.detail {
				width: 648rpx;
				display: flex;
				justify-content: flex-end;
				align-items: center;

				text {
					width: 160rpx;
					height: 58rpx;
					line-height: 52rpx;
					text-align: center;
					border-radius: 64rpx;
					border: 1rpx solid #999999;
					font-size: 28rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 500;
					color: #999999;
				}
			}


			.li_title {
				width: 648rpx;
				height: 76rpx;
				line-height: 66rpx;
				font-size: 28rpx;
				margin: 0 auto;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #475569;
				justify-content: space-between;
				border-bottom: 2rpx solid #E2E8F0;
				display: flex;

				.text {
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #4175EE;
				}

				.txt {
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #FC3636;
				}
			}

			.info {
				width: 628rpx;
				display: flex;
				align-items: center;
				margin: 40rpx auto;

				.list_name {
					width: 170rpx;
					line-height: 40rpx;
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #94A3B8;
				}

				text {
					width: 466rpx;
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #1E293B;

					display: -webkit-box;
					-webkit-line-clamp: 1;
					-webkit-box-orient: vertical;
					text-overflow: ellipsis;
					overflow: hidden;
				}
			}
		}

	}
</style>