<template>
	<view class="index-content-other" :style="transition?{opacity: `1`}:{opacity: `0`}">
		<view class="right-container-title-nav">
			<view class="title-card">
				<view class="card-top">
					<view class="card-top-left">
						50
					</view>
					<view class="card-top-right">
						<image class="right-img" src="/static/index/card/arrow.png" />
					</view>
					<view class="card-spec">
						<view class="line">
						</view>
						<view class="line-gray">
							80
						</view>
					</view>

				</view>
				<view class="card-bottom">
					<image class="bottom-img" src="/static/index/card/help.png" />
					<view class="bottom-font">
						护理
					</view>
				</view>
			</view>
			<view class="title-card">
				<view class="card-top">
					<view class="card-top-left">
						32
					</view>
					<view class="card-top-right">
						<image class="right-img" src="/static/index/card/arrow.png" />
					</view>
					<view class="card-spec">
						<view class="line">
						</view>
						<view class="line-gray">
							60
						</view>
					</view>
			
				</view>
				<view class="card-bottom">
					<image class="bottom-img" src="/static/index/card/doctor.png" />
					<view class="bottom-font">
						医疗
					</view>
				</view>
			</view>
			<view class="title-card">
				<view class="card-top">
					<view class="card-top-left">
						65
					</view>
					<view class="card-top-right">
						<image class="right-img" src="/static/index/card/arrow.png" />
					</view>
					<view class="card-spec">
						<view class="line">
						</view>
						<view class="line-gray">
							70
						</view>
					</view>
			
				</view>
				<view class="card-bottom">
					<image class="bottom-img" src="/static/index/card/work.png" />
					<view class="bottom-font">
						行政
					</view>
				</view>
			</view>
			<view class="title-time">
				<view class="time-title">
					{{ currentTime }}
				</view>
				<view class="time-date">
					{{ fullDate }}
				</view>
				<view class="right-container-tem">
					<image class="right-container-tem-img" src="/static/index/newindex/wendu/0.png" />
					<text class="right-container-tem-text">{{ (uni.getStorageSync('NUall').humidDeviceList && uni.getStorageSync('NUall').humidDeviceList[0])? uni.getStorageSync('NUall').humidDeviceList[0].temperature: '-' }}°C</text>
					<image class="right-container-tem-img" src="/static/index/newindex/wendu/1.png" />
					<text class="right-container-tem-text">{{ (uni.getStorageSync('NUall').humidDeviceList && uni.getStorageSync('NUall').humidDeviceList[0])? uni.getStorageSync('NUall').humidDeviceList[0].humidity: '-' }}%</text>
				</view>
			</view>
		</view>
		<view class="photo-father">
			<view class="juzhong" style="margin-left: -30rpx;">
				<donghua :width="`1300rpx`" :height="`900rpx`" :links="blueArray" :playing="photoplay" :loop="true"
					:interval="120" />
			</view>
			<view class="juzhong" style="z-index: 2;margin-top: 80rpx;">
				<donghua :width="`800rpx`" :height="`500rpx`" :links="bluesmallArray" :playing="photoplay" :loop="true"
					:interval="120" />
			</view>
			<view class="weight-time">
				10:00 - 10:10
				<view class="pao-father">
					<image class="pao-img" :src="`/static/index/newindex/states/pao.png`" />
					<view style="z-index: 1;">
						待执行
					</view>

				</view>
			</view>
			<image class="big-img" :src="`/static/index/newindex/wendu/2.png`" />
			<view style="display: flex;align-items: center;">
				<view class="server-name">
					一级压疮防护
				</view>
			</view>
			<view style="display: flex;align-items: center;margin-top: 20rpx;">
				<image class="down-img" :src="`/static/index/newindex/states/left.png`" />
				<view v-for="(item,index) in downStates" :key="index" class="states-father">
					<image class="icon-img" :src="item.url" />
					<view style="margin-top: 15rpx;margin-left: 10rpx;">
						{{item.name}}
					</view>

				</view>
				<image class="down-img" :src="`/static/index/newindex/states/right.png`" />
			</view>
			<view style="display: flex;margin-top: 40rpx;">
				<view style="width: 240rpx;height: 90rpx;margin-right: 40rpx;">
					<view class="start-button">
						开始服务
					</view>
				</view>
				<view style="width: 240rpx;height: 90rpx;">
					<view class="end-button">
						结束服务
					</view>
				</view>

			</view>
		</view>
		<view class="left-menu">
			<view v-for="(item,index) in leftArray" :key="index" style="margin: 30rpx 0;">
				<view class="left-ball">
					<image class="left-menu-img" :src="item" />
				</view>

			</view>
		</view>
		<view class="right-menu">
			<view class="zhezhao-top" @click="scrollTop -= 115"></view>
			<view class="zhezhao-bottom" @click="scrollTop += 115"></view>
			<image class="top-img" :src="`/static/index/newindex/rightmenu/top.png`"
				@click="scrollTop>0? scrollTop -= 115:scrollTop=0" />
			<scroll-view scroll-y="true" class="right-scroll" :scroll-top="scrollTop" @scroll="onScroll">
				<view style="height: 20rpx;">

				</view>
				<view v-for="(item,index) in rightMenu" style="margin: 20rpx 0;width: 110rpx;margin-left: 20rpx;">
					<view class="white-circle">
						<image class="right-menu-img" :src="item.url" />
						<view class="right-menu-name">
							{{ item.name }}
						</view>
					</view>


				</view>
				<view style="height: 30rpx;">

				</view>
			</scroll-view>
			<image class="top-img" :src="`/static/index/newindex/rightmenu/bottom.png`"
				@click="scrollTop > (55* rightMenu.length) ? scrollTop = (55* rightMenu.length) : scrollTop += 115 " />
		</view>
	</view>
	<view class="index-content-right" :style="transition?{opacity: `1`}:{opacity: `0`}">
		<view class="right-top">
			
		</view>
		<view class="right-bottom">
			<view class="bottom-title">
				<image class="bottom-carmera" src="/static/index/newindex/leftmenu/carmera.png" />
				<view class="blue-button">
					长者标签
				</view>
				
			</view>
			<image class="big-older" src="/static/index/newindex/leftmenu/older.png" />
			<view class="name-weight">
				{{ uni.getStorageSync('NUall').elderInfo?.name }}
			</view>
		</view>
	</view>

</template>

<script setup lang="ts">
	import { ref, onMounted, onBeforeUnmount, computed, nextTick, watch } from 'vue';


	const props = defineProps({
		isShow: {
			type: Boolean,
			required: true,
		},

	});


	const typeNow = ref(-1);
	const photoplay = ref(false)
	const downArray = ref()
	const scrollTop = ref(0);

	function onScroll(e) {
		// e.detail.scrollTop 就是当前滚动距离
		scrollTop.value = e.detail.scrollTop
	}
	// 通用的生成函数
	function genPaths(base, prefix, count, ext = 'png', startIndex = 0, pad = false) {
		return Array.from({ length: count }, (_, i) => {
			const idx = pad
				? String(i + startIndex).padStart(2, '0')
				: i + startIndex
			return `${base}/${prefix}${idx}.${ext}`
		})
	}
	const rightMenu = ref([
		{
			url: "/static/index/newindex/rightmenu/0.png",
			name: '重点追踪'
		},
		{
			url: "/static/index/newindex/rightmenu/1.png",
			name: '转单执行'
		},
		{
			url: "/static/index/newindex/rightmenu/2.png",
			name: '协助执行'
		},
	])
	const downStates = ref([
		{
			url: "/static/index/newindex/states/0.png",
			name: '狂躁'
		},
		{
			url: "/static/index/newindex/states/1.png",
			name: '易怒'
		},
		{
			url: "/static/index/newindex/states/2.png",
			name: '大体重'
		},
		{
			url: "/static/index/newindex/states/3.png",
			name: '四肢'
		},
	])
	const leftArray = ref(genPaths(
		'/static/index/newindex/leftmenu',
		'left',
		5,     // 张数
		'png',
		0,     // 起始索引
		false  // 不补零
	))
	const huliArray = ref(genPaths(
		'/static/index/newindex/huli',
		'care',
		9,     // 张数
		'png',
		0,     // 起始索引
		false  // 不补零
	))
	const base = genPaths(
		'/static/index/newindex/curve',
		'curve_',
		9,
		'png',
		1,
		false
	)
	const blueArray = ref([
		...base,
		...[...base].reverse()   // 先拷贝一份再反转，避免修改原 base
	])
	const basesmall = genPaths(
		'/static/index/newindex/curve',
		'breathe_',
		9,
		'png',
		1,
		false
	)
	const bluesmallArray = ref([
		...basesmall,
		...[...basesmall].reverse()   // 先拷贝一份再反转，避免修改原 base
	])


	// 使用watch监听isShow变化
	const transition = ref(false);


	watch(
		() => props.isShow,
		(newVal, oldVal) => {
			// 当旧值为false，新值为true时延迟0.2秒调用方法
			if (!oldVal && newVal) {
				transition.value = false;
				// console.log("????",transition.value)
				setTimeout(() => {
					transition.value = true;
					// console.log("看看",uni.getStorageSync('NUall'))
				}, 50)
			} else {
				transition.value = false;
			}

		}
	)
	const name = ref("");

	// 定义响应式数据现在时间
	const currentTime = ref('');
	const fullDate = ref('');
	const weekDay = ref('');
	let timerId = null;
	// 更新时间、日期和星期的方法
	const updateTime = () => {
		const now = new Date();

		// 获取当前时间的时分
		const hours = now.getHours().toString().padStart(2, '0');
		const minutes = now.getMinutes().toString().padStart(2, '0');
		currentTime.value = `${hours}:${minutes}`;

		// 获取星期几
		const weekDays = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
		const week = weekDays[now.getDay()];
		weekDay.value = week;
		
		// 获取完整的日期（年/月/日）
		const year = now.getFullYear();
		const month = (now.getMonth() + 1).toString().padStart(2, '0');
		const day = now.getDate().toString().padStart(2, '0');
		fullDate.value = `${year}.${month}.${day} ${weekDay.value}`;
	};
	onMounted(() => {
		name.value = uni.getStorageSync('realname')
		typeNow.value = 0;
		timerId = updateTime();
		// 每秒更新一次时间
		setInterval(updateTime, 1000);
		photoplay.value = true;
	})
	const lanjie = ref(false);
</script>

<style scoped lang="less">
	.index-content-right{
		width: 19.5vw;
		margin-left: 2vw;
		height: 100%;
		transition: opacity 1s ease;
		.right-top{
			margin-top: 8vh;
			width: 100%;
			height: 50vh;
			background-color: #fff;
			border-radius: 4vh;
		}
		.right-bottom{
			margin-top: 2vh;
			width: 100%;
			height: 38vh;
			background-color: #fff;
			border-radius: 3vh;
			padding-top: 1vh;
			display: flex;
			flex-direction: column;
			align-items: center;
			
			.bottom-title{
				
				width: 100%;
				padding: 0 8%;
				display: flex;
				justify-content: space-between;
				.bottom-carmera{
					width: 3vw;
					height: 3vw;
				}
			}
			.big-older{
				margin-top: 0.5vw;
				width: 10vw;
				height: 10vw;
				border: 1rpx solid #DCDCDC;
				border-radius: 50%;
			}
		}
	}
	.index-content-other {
		width: 65vw;
		height: 100%;
		transition: opacity 1s ease;
		position: relative;

		.abs-time {
			position: absolute;
			right: 20rpx;
			top: 150rpx;
			// width: 300rpx;

			.big-time {
				font-size: 90rpx;
				font-weight: 600;
				width: 100%;
				justify-content: center;
				// padding: 0 40rpx;
			}
		}
	}

	.right-container-title-nav {
		margin-top: 100rpx;
		display: flex;
		height: 20vh;
		position: relative;
		font-size: 28rpx;
	}

	.date {
		display: flex;
		justify-content: space-around;
		margin-top: 0.8vw;
	}

	.right-container-tem {
		display: flex;
		margin-top: 0.8vw;

		.right-container-tem-text {
			font-size: 30rpx;
			margin-right: 20rpx;
		}


		.right-container-tem-img {
			width: 38rpx;
			height: 38rpx;
		}
	}

	.photo-father {
		width: 100%;
		height: 1100rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		position: relative;
		margin-top: 0rpx;
	}

	.juzhong {
		position: absolute;
		top: 0%;
		left: 50%;
		transform: translate(-50%, -20%);
		// 禁止动画阻挡逻辑
		z-index: -1;
	}

	.weight-time {
		font-weight: 800;
		font-size: 70rpx;
		margin-bottom: 0rpx;
		position: relative;
		margin-left: -50rpx;
	}

	.big-img {
		width: 800rpx;
		height: 550rpx;
	}

	.server-name {
		font-size: 35rpx;
		margin-right: 10rpx;
		font-weight: 600;
	}

	.server-bgc {
		width: 160rpx;
		height: 50rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		position: relative;

	}

	.bgc-img {
		width: 100%;
		height: 100%;
		position: absolute;
		top: 0;
		left: 0;
	}

	.bgc-font {
		color: #fff;
		z-index: 1;
	}

	.down-img {
		width: 35rpx;
		height: 35rpx;
	}

	.states-father {
		display: flex;
		margin: 0 20rpx;
	}

	.icon-img {
		width: 55rpx;
		height: 55rpx;
	}

	.start-button {
		width: 100%;
		height: 100%;
		background: linear-gradient(to bottom, #009DEF, #0076FF);
		display: flex;
		justify-content: center;
		align-items: center;
		border-radius: 40rpx;
		color: #fff;
		font-size: 30rpx;

	}

	.end-button {
		width: 100%;
		height: 100%;
		background: linear-gradient(to bottom, #FFFFFF, #C8D0D9);
		display: flex;
		justify-content: center;
		align-items: center;
		border-radius: 40rpx;
		font-size: 30rpx;
	}

	.pao-father {
		position: absolute;
		top: 20rpx;
		right: -110rpx;
		font-size: 22rpx;
		width: 100rpx;
		height: 50rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		color: #FFFFFF;

		.pao-img {
			position: absolute;
			top: 0;
			left: 0;
			width: 100%;
			height: 100%;

		}
	}

	.left-menu {
		position: absolute;
		top: 55%;
		left: 100rpx;
		transform: translateY(-50%);
	}

	.zoom {
		transform: scale(1.2);
		transform-origin: bottom left;
		transition: transform 1s ease;
	}

	.left-ball {

		width: 80rpx;
		height: 80rpx;
		border-radius: 50%;
		display: flex;
		justify-content: center;
		align-items: center;

		background-color: #fff;

		.left-menu-img {
			width: 40rpx;
			height: 40rpx;
		}
	}

	.right-menu {
		position: absolute;
		top: 60%;
		right: 80rpx;
		transform: translateY(-50%);
		display: flex;
		flex-direction: column;
		align-items: center;
		width: 140rpx;

		.top-img {
			width: 140rpx;
			height: 110rpx;
			padding: 0 50rpx;
		}

		.right-scroll {
			width: 100%;
			height: 650rpx;
		}

		.white-circle {
			height: 170rpx;
			border-radius: 60rpx;
			background-color: #fff;
			display: flex;
			justify-content: center;
			align-items: center;
			flex-direction: column;
			text-align: center;
			font-size: 25rpx;
			width: 100rpx;

			.right-menu-img {
				width: 50rpx;
				height: 50rpx;
			}

			.right-menu-name {
				width: 50rpx;
			}
		}
	}

	.zhezhao-top {
		position: absolute;
		top: 105rpx;
		left: 0%;
		width: 120%;
		height: 120rpx;
		background: linear-gradient(to bottom,
				rgba(239, 240, 244, 1) 0%,
				/* #eff0f4 全不透明 */
				rgba(239, 240, 244, 0) 100%
				/* #eff0f4 完全透明 */
			);
		z-index: 4;
	}

	.zhezhao-bottom {
		position: absolute;
		bottom: 105rpx;
		left: 0%;
		width: 120%;
		height: 120rpx;
		background: linear-gradient(to top,
				rgba(239, 240, 244, 1) 0%,
				/* #eff0f4 全不透明 */
				rgba(239, 240, 244, 0) 100%
				/* #eff0f4 完全透明 */
			);
		z-index: 4;
	}

	.zhezhao-left {
		position: absolute;
		top: 0rpx;
		left: 0%;
		height: 100%;
		width: 120rpx;
		background: linear-gradient(to right,
				rgba(239, 240, 244, 1) 0%,
				/* #eff0f4 全不透明 */
				rgba(239, 240, 244, 0) 100%
				/* #eff0f4 完全透明 */
			);
		z-index: 4;
	}

	.zhezhao-right {
		position: absolute;
		top: 0rpx;
		right: 0%;
		height: 100%;
		width: 120rpx;
		background: linear-gradient(to left,
				rgba(239, 240, 244, 1) 0%,
				/* #eff0f4 全不透明 */
				rgba(239, 240, 244, 0) 100%
				/* #eff0f4 完全透明 */
			);
		z-index: 4;
	}

	.title-card {
		width: 10vw;
		height: 9vw;
		border-radius: 2vw;
		background-color: #FFFFFF;
		padding: 1.6vw;
		position: relative;
		margin-right: 1.5vw;
		
		.card-bottom{
			position: absolute;
			left: 0;
			bottom: 0;
			width: 100%;
			height: 3vw;
			display: flex;
			.bottom-img{
				width: 1.6vw;
				height: 1.6vw;
				margin-left: 1.8vw;
			}
			.bottom-font{
				color: #555555;
				font-size: 1.4vw;
				margin-left: 0.5vw;
			}
		}

		.card-top {
			width: 100%;
			display: flex;
			justify-content: space-between;
			position: relative;

			.card-top-left {
				font-size: 1.8vw;
				font-weight: 600;
			}

			.card-top-right {
				width: 2vw;
				height: 2vw;
				border-radius: 50%;
				background-color: #F1F2F3;
				display: flex;
				justify-content: center;
				align-items: center;

				.right-img {
					width: 0.8vw;
					height: 0.8vw;
				}
			}

			.card-spec {
				position: absolute;
				top: 1.1vw;
				left: 1.6vw;
				width: 1.5vw;
				height: 2vw;
				// background-color: #0076FF;

				.line {
					position: absolute;
					inset: 0;
					background: linear-gradient(to bottom right,
							transparent calc(50% - 1px),
							#d5d5d5 50%,
							transparent calc(50% + 1px))
				}

				.line-gray {
					position: absolute;
					right: -1.1vw;
					bottom: -0.6vw;
					color: #888888;
					font-size: 1.3vw;
				}
			}
		}
	}
	.title-time{
		position: absolute;
		right: 0;
		top: 0;
		width: 15vw;
		height: 9.5vw;
		border-radius: 2vw;
		background-color: #fff;
		display: flex;
		flex-direction: column;
		align-items: center;
		.time-title{
			font-weight: 600;
			font-size: 3vw;
			margin-top: 0.4vw;
		}
		.time-date{
			margin-top: 0.2vw;
			font-size: 1.3vw;
			color: #222222;
		}
	}
	.blue-button{
		margin-top: 0.5vw;
		width: 7vw;
		height: 2.5vw;
		background: linear-gradient(to bottom, #009DEF, #0076FF);
		display: flex;
		justify-content: center;
		align-items: center;
		border-radius: 40rpx;
		color: #fff;
		font-size: 28rpx;
	}
	.name-weight{
		font-size: 2vw;
		font-weight: 600;
		margin: 0.2vw 0;
	}
</style>