<script setup>
	/**
	 * name：
	 * user：yytjsj
	 * date：2024年9月25日 10:25:00
	 */
	import {
		ref
	} from 'vue'
	import {
		$api,
		$response,
		$image
	} from '@/api'
	import {
		onShow
	} from '@dcloudio/uni-app'
	import {
		useStore
	} from '@/store'
	const $store = useStore()
	const dqDate = ref('')
	const doctor_name = ref('')
	const $props = defineProps({

	});

	const mountedAction = () => {
		uni.showLoading({
			title: "加载中",
		});
		console.log($store.getYytjInfo(), '123123')
		doctor_name.value = $store.getYytjInfo().name || ''; //选择体检医生
		// if (dqDate.value) {
		getnmrList(); //  
		// }
	}
	const date_list = ref(false)
	const time_list = ref(false)
	const currentDate = ref(0)
	const currentTime = ref(0)
	const currentXmmcObj = ref(false) //当前选中体检项目对象
	const nmr_list = ref(false) //当前项目列表

	const getnmrList = async () => {
		console.log($store, 'store')
		let obj = {
			"hospital": 1,
			"combo_id": "2053",
			"item_ids": ["2074", "2075"],
			"person_id": 1,
			"group_id": null,
			"integral": 50,
			"save_money": 100,
			"coupon_id": 1
		};
		const response = await $api("BuyInfo", obj);
		$response(response, () => {

			currentDate.value = getToday(); //huo获取今天的日期

			nmr_list.value = response.data.nmr_list || false;
			nmr_list.value[0].rq = currentDate.value
			console.log(nmr_list.value, 'data.nmr_list')
			xmmcClick(nmr_list.value[0]) //默认当前对象
			getTjTimeList()
			uni.hideLoading();
		});
	} 
	const getToday = () => {
		// 获取当前日期  
		var today = new Date();

		// 获取年、月、日  
		var year = today.getFullYear(); // 年  
		var month = (today.getMonth() + 1).toString().padStart(2, '0'); // 月，月份是从0开始的，所以要+1，并使用padStart补零  
		var day = today.getDate().toString().padStart(2, '0'); // 日，使用padStart补零  

		// 拼接日期字符串  
		return year + '-' + month + '-' + day;
	}
	const getTjTimeList = async () => {
		console.log(currentDate.value)
		// 获取 体检号源
		let obj = {
			"hospital": "1",
			"person_id": "1",
			"date": "2024-08-17", //currentDate.value
			"use_type": 1,
			"checkup_type_id": 1,
			"amount": "500"
		};
		const response = await $api("GetDayPlanList", obj);
		$response(response, () => {
			console.log(response, 'response')
			currentXmmcObj.value['sj'] = ''; //每次请求新的时间时间置空
			currentTime.value = ''
			date_list.value = response.data.weeklist;
			time_list.value = response.data.list;

			time_list.value.forEach((item) => {
				console.log(item.date)
				item.newTime = item.time.slice(0, 5);
			})
			date_list.value.forEach((item) => {
				const [year, month, day] = item.date.split('-');
				item.newMonthDate = `${month}/${day}`; //月份日期
				item.newWeek = item.xingqi.replace("星期", "周")
			})
			uni.hideLoading();
		});
	};

	const getCurrentClick = (item, i) => {
		console.log(item, i) //当前日期和星期
		currentDate.value = item.date
		let obj = {}
		getTjTimeList() //带着选中的日期重新选择

	}
	const getCurrentTime = (item) => {
		currentTime.value = item
		currentXmmcObj.value['sj'] = item.newTime
	}
	const xmmcClick = (i) => {
		currentXmmcObj.value = i //对象

	}

	const clickDoctor = () => {
		//选择医生列表
		uni.navigateTo({
			url: `/pages/main/selectDoctor/selectDoctor?date=${'2024-08-01'}`
		})
	}
	
	const comfrimyy=()=>{
		uni.$lu.toast('提交成功')
	}

	const config_ref = ref(null)
	const configRef = (e) => {
		if (!config_ref.value) {
			config_ref.value = e
			mountedAction()
		}
	}

	onShow(() => {
		if (!!config_ref.value) {
			mountedAction()
		}
	})
</script>
<template>
	<view>
		<view v-if="!!$store.config">
			<view :ref="configRef"></view>
		</view>
		<view class="h-38rpx bg-#239EA3 pl-20rpx pr-20rpx    box-border">
			<view style="box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(0,0,0,0.04);"
				class="p-16rpx pb-20rpx pt-30rpx   rounded-15rpx  bg-#fff">
				<view class="">
					---------------------
				</view>
				<view class="">
					<view class="text-30rpx text-#0E0E0E pb-34rpx">
						自选项目
					</view>
					<view class=" text-#8B8B8B text-24rpx">
						<view class="flex  mb-20rpx">
							妇科（化验）-<span class="flex-1 ml-10rpx   text-#0E0E0E line-clamp-1"> 头瘤病毒（乳头瘤病毒（乳头瘤病毒（乳头瘤病毒（乳头瘤病毒（乳头瘤病毒（HPV）
							</span>
						</view>
						<view class="flex  mb-20rpx">
							超声科-<span class="flex-1 ml-10rpx text-#0E0E0E"> 腹部B超 </span>
						</view>
						<view class="flex  mb-20rpx">
							体检医生 -
							<span class="flex-1 ml-10rpx text-#0E0E0E" @click="clickDoctor"> {{doctor_name || '请选择'}}
								<span class="ml-10rpx">&gt;</span>
							</span>
						</view>
					</view>
				</view>

			</view>
			<view style="box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(0,0,0,0.04);"
				class="p-16rpx pb-20rpx pt-30rpx   rounded-15rpx  bg-#fff mt-15rpx">
				<view class="">
					<view class="text-30rpx text-#0E0E0E pb-34rpx font-500">
						{{currentXmmcObj.name || ''}}
					</view>
					<view class="flex" v-if="date_list">
						<view class="w-15% text-center text-18rpx" v-for="(item,index) in date_list" :key="index">
							<view @click="getCurrentClick(item,index)" :class="3==index?'activeTime':''"
								class="rounded-12rpx pt-10rpx pb-10rpx   ml-10rpx mr-10rpx mb-6rpx  ">
								<view> {{item.newMonthDate}} </view>
								<view class="text-26rpx font-500"> {{item.newWeek}} </view>
							</view>
							<view class="ma">
								<text class="bg-#EFEFEF rounded-10rpx h-28rpx pl-10rpx pr-10rpx">余{{item.count }}</text>
							</view>
						</view>
						<!-- <view  class="w-1rpx m-20rpx bg-#E6E9E9 ml-15rpx"   />
						<view class="flex text-#239EA3 text-20rpx">
							更多
						</view> -->
					</view>
					<view class="w-100% h-1rpx bg-#E6E9E9  mt-18rpx" />
					<view class="flex flex-wrap pt-30rpx pb-30rpx">
						<view class="w-20% text-center box-border p-20rpx" v-for="(item,index) in time_list" :key="index"
							@click="getCurrentTime(item)">
							<view class="text-24rpx rounded-12rpx  h-54rpx flex flex-items-center flex-justify-center"
								:class="currentTime.newTime==item.newTime?'activeTime':''">
								{{item.newTime}}
							</view>
						</view>
					</view>
				</view>

			</view>
			<view style="box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(0,0,0,0.04);"
				class=" p-30rpx  pl-10rpx pr-10rpx rounded-15rpx  bg-#fff mt-15rpx text-#101010 text-28rpx">
				<view class="bg-#F7F7F7   pl-20rpx pr-20rpx   pt-23rpx pb-25rpx">
					路雅思
					<view class="bg-#EFEFEF rounded-15rpx p-10rpx pb-15rpx pt-15rpx mt-20rpx" v-if="nmr_list">

						<view v-for="(item,index) in nmr_list" :key="index" @click="xmmcClick(item)"
							:class="currentXmmcObj.name==item.name ?'acitvetc':''"
							class="flex flex-justify-around p-20rpx pl-10rpx pr-10rpx  rounded-15rpx">
							<view class="flex-1 line-clamp-1">
								{{item.name}}
							</view>
							<view>
								{{item.rq}} <span class="ml-5rpx">{{item.sj}}</span>
								<!-- 2024年12月12日 09:00 -->
							</view>
						</view>


					</view>
				</view>

			</view>

			<view class="pb-100rpx">
				<view @click="comfrimyy"
					class="text-#fff text-32rpx rounded-45rpx bg-#239EA3   mt-40rpx    ma w-520rpx h-90rpx flex flex-items-center flex-justify-center">
					确定
				</view>
			</view>
		</view>
	</view>
</template>
<style scoped>
	.activeTime {
		background-color: #239EA3;
		color: #fff;
	}

	.acitvetc {
		background-color: #E0F1F2;
	}
</style>