<template>
	<view class="book-page btPadding" v-if="bookInfo">
		<view class="list-box">
			<list-box class="item-wrapper" v-if="item.show" v-for="(item,key) in list" :key="key" :leftTitle="item.leftTitle" :rightTitle="item.rightTitle?item.rightTitle:''">
				<view class="item-inner" v-html="item.custom" v-if="item.custom"></view>
			</list-box>
		</view>

		<view class="bot-con">
			<view class="title PfScMedium">就诊提醒</view>
			<view class="content" v-html="notice"></view>
		</view>
		<view class="btPadding pagebt"></view>
		
		<view class="fixedBot btPadding">
			<view class="submit">
				<view :class="'btn cancel'+(showCancelBook?' btn1':' btn3')" hover-class="hover" @click="reback">返回</view>
				<view class="btn primary btn1" hover-class="hover" v-if="showCancelBook" @click="cancelBook">取消预约</view>
				<!-- <view class="btn primary btn1" hover-class="hover" v-if="showReBook && !showCancelBook" @click="rebook">重新预约</view> -->
			</view>
		</view>
	</view>
</template>

<script>
	import listBox from '@/components/listBox.vue';
	
	export default {
		data() {
			return {
				statusList:['status_wait', 'status_ing', 'status_out_num', 'status_expire', 'status_down', 'status_expire'],
				statusDescList:['候诊', '就诊中', '过号', '已过期', '已完成', '已取消'],
				status:'',
				queueNum:88,
				bookDate:"2024.01.09 周二  09:30-12:00",
				notice:"",
				list:[
					{'leftTitle':'状态','custom':"",show:true},
					{'leftTitle':'就诊人','rightTitle':'',show:true},
					{'leftTitle':'就诊医院','rightTitle':'',show:true},
					{'leftTitle':'就诊科室','rightTitle':'',show:true},
					{'leftTitle':'医生','rightTitle':'',show:true},
					{'leftTitle':'排队情况','custom':"",show:true},
					{'leftTitle':'就诊时间','custom':"",show:true}
				],
				showCancelBook:false,
				redirect:'/pages/prebook_list/prebook_list',
				bookId:false,
				bookInfo:false,
				showReBook:false,
				cssUrl:this.cssUrl
			}
		},
		onLoad(option) {
			// if(option.index) this.redirect = '/pages/index/index'
			if(option.id) this.bookId = option.id
			
		},
		onShow() {
			if(!this.bookId){
				this.$func.toPage('/pages/index/index')
				return;
			}
			this.getBookDetail()
		},
		components:{
			listBox
		},
		methods: {
			cancelBook(){
				var that = this
				uni.showModal({
					title:'取消预约',
					content:'确认取消预约?',
					success(res) {
						if(!res.confirm) return
						that.$http.req('cancel_appoint', {appoint_id:that.bookId}, 'GET').then(data=>{
							if(data == -1) return
							that.getBookDetail()
							uni.showToast({
								title:"取消预约成功",
								mask:true,
								image:that.cssUrl+'gou.svg',
								times:false,
								success() {
									
								}
							})
						});
					}
				})
			},
			rebook(){
				this.$func.toPage('/pages/index/index')
			},
			reback(){
				this.$func.toPage('/pages/index/index')
			},
			getBookDetail(){
				this.$http.req('get_appoint_detail', {appoint_id:this.bookId}, 'GET').then(data=>{
					if(data == -1) {
						this.bookInfo = false
						return
					}

					var bookInfo = data
					if(bookInfo && bookInfo.length <= 0){
						this.$pop.modelShow('预约信息为空')
						return
					}

					bookInfo = data
					this.bookInfo = bookInfo
					this.status = this.statusList[bookInfo.status]
					if(bookInfo.status==0 || bookInfo.status==2) this.showCancelBook = true
					this.list[0].custom = "<view class='"+this.status+" status'><view class='over status_text'>"+this.statusDescList[bookInfo.status]+"</view></view>"
					this.list[1].rightTitle = bookInfo.visitor_name
					this.list[2].rightTitle = bookInfo.hospital_name
					this.list[3].rightTitle = bookInfo.depart_name
					this.list[4].rightTitle = bookInfo.doctor_name ? bookInfo.doctor_name : '无'
					this.list[5].custom = "<view class='queue-text'>前方<text class='queue-num-txt PfScSemibold'>"+bookInfo.wait_visit_count+"</text>人</view>"
					if(bookInfo.wait_visit_count<=0 || bookInfo.status!=0) this.list[5].show = false
					this.list[6].custom = "<view class='book-date"+(bookInfo.status==0?' wait':' expire')+"'>"+bookInfo.visit_date+' '+bookInfo.week+' '+bookInfo.visit_time+"</view>"
					this.notice = bookInfo.notice
				});
			}
		}
	}
</script>

<style lang="scss" scoped>

.book-page{
	height: 100vh;
	width: 100%;
	background: #F6F6F6;
	overflow-y: auto;
	box-sizing: border-box;
	.list-box,.bot-con{
		width: calc(100% - 34rpx);
		height: auto;
		margin: 17rpx auto 0;
		overflow: hidden;
		border-radius: 0 0 8rpx 8rpx;
	}
	
	.list-box{
		.item-wrapper{
			.item-inner /deep/{
				 .status{
					display: flex;
					justify-content: flex-end;
					.status_text{
						display: flex;
						border-radius: 6rpx;
						font-size: 22rpx;
						height: 32rpx;
						line-height: 32rpx;
						padding:  0 10rpx;
						box-sizing: border-box;
						min-width: 90rpx;
						display: block;
						text-align: center;
					}
					&.status_wait {
						.status_text{
							background: #F8FFF7;
							border: 1rpx solid #5BD07A;
							color: #58CA7F;
						}
					}
					&.status_out_num{
						.status_text{
							background: #FFFAF7;
							border: 1rpx solid #FE6710;
							color: #FE6710;
						}
					}
					&.status_down{
						.status_text{
							background: #FCFCFC;
							border: 1rpx solid #AEB0B8;
							color: #B6B8BF;
						}
					}
					&.status_expire{
						.status_text{
							background: #FCFCFC;
							border: 1rpx solid #AEB0B8;
							color: #B6B8BF;
						}
					}
					&.status_ing{
						.status_text{
							border: 1rpx solid #5FA1CB;
							background: #F7FCFF;
							color: #5FA1CB;
						}
					}
				}
				
				.queue-text{
					height: 40rpx;
					font-size: 28rpx;
					color: #242833;
					line-height: 40rpx;
					.queue-num-txt{
						height: 48rpx;
						font-weight: 600;
						font-size: 48rpx;
						color: #39D067;
						line-height: 48rpx;
						margin: 0 8rpx;
					}
				}
				.book-date{
					height: 45rpx;
					font-size: 32rpx;
					line-height: 45rpx;
					&.wait{
						color: #39D067;
					}
					&.expire{
						color: #FD7B13;
					}
				}
			}
		}
	}
	.bot-con{
		background: #FFFFFF;
		margin-top: 15rpx;
		padding: 40rpx 27rpx;
		box-sizing: border-box;
		overflow: hidden;
		min-height: 430rpx;
		.title{
			height: 44rpx;
			font-size: 32rpx;
			color: #000000;
			line-height: 44rpx;
			letter-spacing: 2rpx;
		}
		.content{
			margin-top: 16rpx;
			font-size: 32rpx;
			color: #666666;
			line-height: 46rpx;
			padding-bottom: 124rpx;
		}
	}
	.pagebt{
		opacity: 0;
	}
	.fixedBot{
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 124rpx;
		background: #FFFFFF;
		box-shadow: 0rpx -2rpx 6rpx 0rpx rgba(181,181,181,0.13);
		backdrop-filter: blur(20rpx);
		display: flex;
		.submit{
			width: 100%;
			display: flex;
			justify-content: center;
			align-items: center;
			column-gap: 50rpx;
		}
	}
	
	// <view class="fixedBot btPadding">
	// 	<view class="submit">
	// 		<view class="btn cancel">返回</view>
	// 		<view class="btn primary">取消预约</view>
	// 	</view>
	// </view>
}
</style>
