<template>
	<view class="page">
		<scroll-view v-if="list.length>0" scroll-y style="height: 100%; width: 100%" @scrolltolower="reachBottom">
			<view>
				<view class="order" v-for="i in list" :key="i.id">
					<view class="title">
						<view class="title__name">
							<text>咨询时间： </text>
							<text>{{ i.created_at ? $moment(i.created_at).format('YYYY年MM月DD日 HH:mm') : '' }}</text>
						</view>
					</view>
					<view class="info" @click.stop.native="$u.route({
                              url: '/package_sub/pages/ServeOrderDetail/ServeOrderDetail',
                              params: {
                                id: i.id,
                              }
                            })">
						<view class="info__item info__flex100">
							<text>咨询医院</text>
							<text>{{ i.serve_hospital?i.serve_hospital.name:"" }}</text>
						</view>
						<view class="info__item info__flex100">
							<text>咨询科室</text>
							<text>{{ i.serve_hospital_department ? i.serve_hospital_department.name : '' }}</text>
						</view>
						<view class="info__item">
							<text>咨询人</text>
							<text>{{ i.name ? i.name : '' }}</text>
						</view>
						<view class="info__item">
							<text>咨询类型</text>
							<text>{{ i.type ? i.type : '' }}</text>
						</view>
					</view>
				</view>

				<u-loadmore :status="loadStatus" bgColor="#f2f2f2"></u-loadmore>
			</view>
		</scroll-view>
		<view v-else style="height: 100%;" class="d-flex ai-center jc-center">
			<u-empty mode="list"></u-empty>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loadStatus: 'loadmore',
				list: [],
				last_page: 0,
				select: {
					page: 1,
					page_size: 20,
				},
			};
		},
		computed: {},
		methods: {
			reachBottom() {
				if (this.select.page > this.last_page) {
					this.loadStatus = 'nomore'
					return
				}
				this.loadStatus = 'loading'
				this.select.page++
				this.getOrder()
			},
			async getOrder() {
				try {
					const res = await this.$u.api.serveHospitalOrder(this.select);
					this.last_page = res.last_page
					this.loadStatus = this.select.page >= this.last_page ? 'nomore' : 'loadmore'
					this.list.push(...res.data)
				} catch (err) {
					console.error(err);
					this.loadStatus = 'loadmore'
				}
			},
		},
		onLoad(option) {
			this.getOrder()
		},
	}
</script>

<style lang="scss">
	.page {
		padding-top: 24rpx;
		height: 100vh;
		padding-bottom: calc(20rpx);
		padding-bottom: calc(constant(safe-area-inset-bottom) + 20rpx);
		padding-bottom: calc(env(safe-area-inset-bottom) + 20rpx);
		background-color: #f5efee;
	}
	::v-deep .u-load-more-wrap {
		background-color: #f5efee !important;
		.u-line-1 {
			background-color: #f5efee !important;
		}
	}
	.order {
		border-radius: 10rpx;
		filter: drop-shadow(0 0 10rpx rgba(211, 211, 214, 0.3));
		background-color: #ffffff;
		margin: 0 25rpx 24rpx;

		.title {
			display: flex;
			align-items: center;
			padding: 32rpx 39rpx 32rpx 45rpx;
			position: relative;

			&__name {
				font-size: 26rpx;
				color: #333333;
				font-weight: bold;
			}

			&__status {
				font-size: 26rpx;
				color: #c20d12;
				font-weight: 500;
				margin-left: auto;
			}

			&::after {
				content: "";
				height: 2rpx;
				background: #999999;
				opacity: 0.302;

				position: absolute;
				bottom: 0;
				left: 39rpx;
				right: 39rpx;
			}
		}
		.info {
			display: flex;
			flex-wrap: wrap;
			padding: 32rpx 45rpx 16rpx 45rpx;

			&__item {
				flex-basis: 50%;
				color: #333;
				font-size: 26rpx;
				font-weight: 500;
				display: flex;
				margin-bottom: 16rpx;
				&>text {
					display: block;
				}

				&>text:nth-child(1) {
					color: #999;
					padding-right: 20rpx;
					flex: 0;
					word-break: keep-all;
				}

				&>text:nth-child(2) {}
			}
			&__flex100{
				flex-basis: 100%;
			}
		}
	}
</style>