<template>
	<view class="CheckItemMain">
		<view class="head"></view>
		<view class="userInfo" v-if="List.length>0">
			<view class="title">患者信息</view>
			<view class="row">
			    <view class="label" >姓名：</view>
			    <view class="value" >{{List[0].user_name}}</view>
			</view>
			<view class="row">
			    <view class="label">性别：</view>
			    <view  class="value"><span v-if="List[0].user_sex==1">男</span><span v-if="List[0].user_sex==2">女</span></view>
				 
			</view>
			<view class="row">
			    <view class="label">手机号：</view>
			    <view class="value">{{List[0].user_phone}}</view>
			</view>
			<view class="row">
			    <view class="label">注册号：</view>
			    <view class="value">{{List[0].reg_num}}</view>
			</view>
			<view class="date">
				<view class="datetime">
					<uni-datetime-picker  v-model="SearchInfo.dateRange" type="daterange" @change="dateSelecteFunc" />
				</view>
			</view>
		</view>
		<view v-if="List.length>0" class="list">
			<view class="info" v-for="(item,index) in List">
				<view class="item_title">检查项目：{{item.entrust}}</view>
				<view class="item_info">
					<view>医嘱时间：<span class="item_value">{{item.entrust_date}}</span></view>
					<view>申请科室：<span class="item_value">{{item.reservation_department}}</span></view>
					<view>状态：
						<span v-if="item.list_status==0" class="item_value">待申请</span>
						<span v-if="item.list_status==1" class="item_value">已预约</span>
						<span v-if="item.list_status==2" class="item_value">已登记</span>
						<span v-if="item.list_status==3" class="item_value">已完成</span>
					</view>
					<view v-if="item.list_status==1">预约时段：<span class="item_value">{{item.reservation_date}} {{item.period_begin_time.substring(0,5)}}~{{item.period_end_time.substring(0,5)}}</span></view>
					<view class="button_row" v-if="item.list_status==0">
						<view class="button" @click="ToPlanList(1,item)">预 约</view>
					</view>
					<view class="button_row" v-if="item.list_status==1">
					 	<view class="button red" @click="Cancel(item)">取 消</view>
						<view class="button blue" @click="ToPlanList(2,item)">改 约</view>
					</view>
					
				</view>
			</view>
		</view>
		<view class="nodata" v-else>
			暂无记录
		</view>
	</view>
</template>

<script setup>
	import{ref,onMounted} from "vue"
	import {EntrustGetList,H5_CancelYuYue} from "@/api"
	import {onLoad,onShow} from "@dcloudio/uni-app"
	 
	let SearchInfo=ref({
		dateRange:['2021-05-01','2049-01-01'],
	}) 
	let List=ref([])
	const GetList=()=> {
		  EntrustGetList({searchInfo:SearchInfo.value}).then(res => {
			  console.log(res)
			  if(res.status){
				  List.value=res.data.list
			  } 
		  })	
	}
	const dateSelecteFunc=(e)=>{
		 SearchInfo.value.dateRange=e
		 GetList()
	}
	//跳转预约
	const ToPlanList=(do_type,item)=>{
		let data={
			do_type:do_type,
			appointment_type:2,
			regnum:item.reg_num,
			entrustid:[item.entrust_id],
			episodeid:item.episodeid
		}
		uni.navigateTo({
			url: '/pages/PlanList?data=' + encodeURIComponent(JSON.stringify(data))
		})
	}
	//取消预约
	const Cancel=(item)=>{
		uni.showModal({
			cancelText:"取消",
			confirmText:"确定",
			title: '提示',
			content: '确定取消预约吗？',
			success: function (res) {
				if (res.confirm) {
					H5_CancelYuYue({MainListId:item.id}).then(res => {
								  console.log(res)
								  if(res.status){
									   GetList()
								  } 
					})	
				}  
			}
		});
		
	}
	//获取当前日期 前后各1个月的的日期
	function getDatesAroundCurrentMonth() {
	    var today = new Date();
	
	    // 获取前一个月的日期
	    function getPreviousMonth(date) {
	        return new Date(date.getFullYear(), date.getMonth() - 1, date.getDate());
	    }
	
	    // 获取后一个月的日期
	    function getNextMonth(date) {
	        return new Date(date.getFullYear(), date.getMonth() + 1, date.getDate());
	    }
	
	    // 格式化日期为YYYY-MM-DD形式
	    function formatDate(date) {
	        var year = date.getFullYear();
	        var month = ("0" + (date.getMonth() + 1)).slice(-2); // 月份从0开始，所以需要+1
	        var day = ("0" + date.getDate()).slice(-2);
	        return year + "-" + month + "-" + day;
	    }
	
	    var currentDateFormatted = formatDate(today);
	    var previousMonthDate = formatDate(getPreviousMonth(today));
	    var nextMonthDate = formatDate(getNextMonth(today));
	
	    return {
	        currentDate: currentDateFormatted,
	        previousMonth: previousMonthDate,
	        nextMonth: nextMonthDate
	    };
	}
	onLoad(()=>{
	 
		var dates = getDatesAroundCurrentMonth();
 
		SearchInfo.value.dateRange=[dates.previousMonth,dates.nextMonth]
 
		GetList()
	})
</script>

<style scoped>
	.CheckItemMain{
		height: calc(100vh - 120rpx) ;
		background: radial-gradient(circle at top center, #dcdcdc    30%, #e3e3e3, transparent 2%);
		padding-top: 30rpx;
	}
	.userInfo{
		background-color: #33cdc9;
		margin-left: 20rpx;
		margin-right: 20rpx;
		border-radius: 30rpx;
		padding: 40rpx 40rpx 0rpx 40rpx;
	  border: 1rpx solid #fff;
	}
	.userInfo .row{
		margin-top: 20rpx;
		font-size: 32rpx;
	
		color: #fff;
	}
	.userInfo .value{
		margin-left: 20rpx;
	}
	.userInfo   .label {
	    text-align: right;
 
		width: 30% ;
	
	}
	.row{
		display: flex;
		
	}
	.junfen{
		
	}
	.title{
		font-weight: 700;
		color:#fff;
	}
	.date{
		text-align: center;
		font-size: 30rpx;
		background-color: #fff;
		padding: 20rpx 60rpx;
		border-radius: 30rpx;
		box-shadow: 0rpx 10rpx 10rpx #add2d1;
		color: #333;
		
		/* transform: translateY(40rpx); */
		position: relative;
		top: 50rpx;
		white-space: nowrap;
	}
	.datetime{
	
	}
	.list{
		 padding: 20rpx;
	}
	.info{
		margin-top: 60rpx;
		padding: 20rpx;
		background-color: #fff;
		border-radius: 20rpx;
		margin-bottom: -20rpx;
	}
	.item_title{
		color:#999;
		border-bottom: 1rpx solid #ccc;
		padding: 20rpx;
	}
	.item_info{
		padding: 30rpx 50rpx;
		color: #333;
	}
	.item_info view{
		margin-top: 20rpx;
	}
	.item_value{
		font-weight: 700;
	}
	.button{
		width: 100%;
		height: 60rpx;
		line-height: 60rpx;
		border-radius: 20rpx;
		background-color: #33cdc9;
		text-align: center;
		color: #fff;
		margin-top: 20rpx;
		margin-left: 10px;
		margin-right: 10px;
	}
	.red{
		background-color: coral;
	}
	.blue{
		background-color: #39a6cd;
	}
	.button_row{
		display: flex;
		justify-content: space-between;
	}
	.nodata{
		text-align: center;
		margin-top: 100rpx;
		color: #ccc;
	}
</style>
