<template>
	<view>
		<view class="t-box">
			<view class="leftscr">
				<view class="left-menu-father">
					<scroll-view scroll-y="true" scroll-with-animation class="left-menu-scroll" :scroll-top="leftscrolltop"
						 :lower-threshold="400">
						<view class="card" v-for="(v,i) in plsbuy" :key="i" :class="i==lefttarget?'act':''"
							@click="clickLeftMenu(i,v)">
							<view class="rad" v-if="v.izPackage=='Y'">包</view>
							 
							<view class="cont">
								<view class="conle">
									<image :src="serverUrl + v.previewFileSmall" mode="aspectFill" />
								</view>
								<view class="ritcon">
									<view class="rq"  >
										<text>{{v.directiveName}}</text> 
									</view>
									<view class="rq">
										执行人:{{v.employeeName}}
									</view>
									<view class="rq">
										开始时间:{{v.startTime.slice(0,16)}}
									</view>
									 <view class="rq">
									 	结束时间:{{v.endTime.slice(0,16)}}
									 </view>
									 <view class="rq">
									 	状态:{{v.izStart=="N"?"未开始":(v.izFinish=="Y"?'已结束':'进行中')}}
									 </view>
								</view>
							</view>
						</view>
						<view style="height:2vw;width: 90%;display: flex;align-items: center;justify-content: center;">
							<u-loadmore :status="status" :loadText="{nomore:'暂无更多数据'}" v-if="plsbuy.length>4" />
						</view>
					</scroll-view>
				</view>
			</view>
			<view class="rightscr">
				<scroll-view scroll-y="true" class="itembox" scroll-with-animation enable-back-to-top @scroll="scroll" :scroll-top="middletarget">
					<view class="box">
						<view class="fler" v-for="(v,index) in cardarr" :key="index">
							<view class="carditem guodu" >
								<view class="zding" v-if="v.zhiDingId">
									<image src="/static/index/procurement/zd.png" mode="aspectFill"></image>
								</view>
								<view class="speitem guodu" >
									<image :src="serverUrl + v.previewFileSmall" mode="aspectFill">
									</image>
								</view>
								<view class="msitem guodu" >
									<view>
										<view>指令名称：{{v.directiveName}}</view>
									</view>
									<view>
										<text  style="white-space: nowrap;"> 执行人: </text>
										<view>{{v.employeeName}}</view>
									</view>
									<view>
										<text  style="white-space: nowrap;"> 开始时间: </text>
										<view>{{v.startTime.slice(0,16)}}</view>
									</view>
									<view>
										<text  style="white-space: nowrap;"> 结束时间: </text>
										<view>{{v.endTime.slice(0,16)}}</view>
									</view>
								</view>
								<view class="fubtn" >
									<view class="ld">开始服务</view> 
									<view class="ld">结束服务</view>
									<view class="bd">录像</view>
									<view class="bd">拍照</view>
								</view>
							</view>
						</view>
					</view>
				</scroll-view>
			</view>
		</view>
	</view>
</template>
<script setup lang="ts">
	import { ref, onMounted, reactive, onBeforeUnmount, computed, nextTick, defineComponent } from 'vue';
	import { onShow, onLoad, onHide, onPageScroll } from "@dcloudio/uni-app"
	import {queryCareList,queryCareInfoList} from './api/api.js'
	const serverUrl = ref(uni.getStorageSync('serverUrl') + '/sys/common/static/')
	const form = reactive({
		pageNo: 1,
		pageSize: 10,
		employeeId:uni.getStorageSync('userInfo').employessId, 
		nuId:uni.getStorageSync('nuId')
	})
	const plsbuy = ref([])
	onMounted(() => {
		form.pageNo=1;
		plsbuy.value = [];
		firstgetqueryCgdList();
	})
	const status = ref('loadmore')
	const plsbuytolower = () => {
		if (status.value == 'loading' || status.value == 'nomore') { return }
		status.value = 'loading';
		form.pageNo++;
		firstgetqueryCgdList();
	}
	const firstgetqueryCgdList = () => {
		queryCareList(form).then(res => {
			console.log(res)
			plsbuy.value.push(...res.result.records);
			status.value = res.result.total == plsbuy.value.length ? 'nomore' : 'loadmore';
			if(form.pageNo==1){
				clickLeftMenu(0,plsbuy.value[0])
			}
		})
	}
	const lefttarget = ref(0);
	const middletarget = ref(0);
	const leftscrolltop = ref(0);
	const cardarr = ref([])
	const clickLeftMenu = (index : any, item : object) => {
		console.log(item)
		if (lefttarget.value != index) {
			middletarget.value = sctop.value;
			nextTick(()=>{
				middletarget.value = 0;
			})
		}
		let num = Math.ceil((index + 1))
		leftscrolltop.value = (num - 2) * 186;
		lefttarget.value = index;
		queryCareInfoList({ mainId: item.id }).then(res => {
			console.log(res)
			cardarr.value = res.result
		})
		if (item.izRead == 'N') {
				transReads(item, index)
			}
		}
	const sctop = ref(0)
	const scroll = (e)=>{
		sctop.value = e.detail.scrollTop
	}
	const addMaterial = ref([])
	const transReads = (v, i) => {
		transRead({ id: v.id })
		v.izRead = 'Y'
	}
	const tharrlist = ref([])
	const thlist = () => {
		thdList(form).then(res => {
			tharrlist.value=res.result.records;
		})
	}
</script>

<style scoped lang="less">
	.left-menu-father {
		width: 33vw;
		height: 90vh;
		.act {
			border: 2px solid #0385FA !important;
			background: rgba(255, 255, 255, 1) !important;
		}
		.left-menu-scroll {
			height: 100%;
			height: 90vh;
			.card {
				width: 31vw;
				height: 13.6vw;
				background: rgba(255, 255, 255, 0.6);
				border-radius: 1.6vw;
				padding: 1vw 1.4vw;
				border: 2px solid rgba(255, 255, 255, 0.01);
				margin-bottom: 0.8vw;
				position: relative;
			
				.rad {
					width: 2.5vw;
					height: 2.5vw;
					border-radius: 0.5vw;
					position: absolute;
					right: 1.3vw;
					top: 1.5vw;
					background: #0385FA;
					color: #fff;
					display: flex;
					justify-content: center;
					align-items: center;
					font-size: 1.6vw;
					font-weight: bold;
				}
			
				.cont {
					width: 100%;
					height: 10vw;
					display: flex;
					justify-content: space-between;
			
					.ritcon {
						width: 19vw;
						height: 100%;
						flex-direction: column;
						justify-content: space-around;
						flex: 1;
						.rq {
							font-weight: 400;
							font-size: 1.3vw;
							color: #888888;
							margin-bottom:0.5vw;
							white-space: nowrap;
							text {
								font-size: 1.8vw;
								font-weight: bolder;
								color: rgba(85, 85, 85, 1);
							}
						}
					}
			
					.conle {
						width: 10vw;
						height: 100%;
						display: flex;
						flex-direction: column;
						align-items: center;
			
						image {
							width: 9.3vw;
							height: 9.3vw;
							margin-top: 1vw;
						}
			
						view {
							font-weight: bold;
							font-size: 1.4vw;
							color: #555555;
							margin-top: 1vw;
						}
					}
				}
			
				.hli {
					width: 100%;
					height: 2vw;
					display: flex;
					justify-content: space-between;
					align-items: center;
			
					.rig {
						width: 3.7vw;
						height: 1.6vw;
						position: relative;
						display: flex;
						justify-content: center;
						align-items: center;
			
						image {
							position: absolute;
							width: 100%;
							height: 100%;
							top: 0;
							left: 0;
							z-index: 1;
						}
			
						text {
							position: relative;
							z-index: 2;
							font-weight: 400;
							font-size: 1vw;
							color: #FFFFFF;
						}
					}
			
					.lig {
						font-weight: 400;
						font-size: 1.2vw;
						color: #666666;
						display: flex;
						justify-content: center;
						align-items: center;
			
						image {
							width: 1.7vw;
							height: 1.7vw;
							margin-right: 0.4vw;
						}
					}
				}
			
			}
		}
	}
	.fubtn{
		width: 8vw;
		height: 100%;
		position: absolute;
		top:0;
		left: 35vw;
		display: flex;
		justify-content: space-around;
		flex-direction: column;
		align-items: center;
		view{
			width: 8vw;
			height: 3vw;
			border-radius: 0.4vw;
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 1.5vw;
			font-weight: bold;
		}
		.ld{
			background: #0385FA;
			color: #fff;
			border: 1px solid #0385FA;
		}
		.bd{
			background: #fff;
			color: #0385FA;
			border: 1px solid #0385FA;
		}
	}
	
	.msitem {
		width: 18.5vw;
		height: 100%;
		position: absolute;
		top:0;
		left: 15vw;
		>view {
			margin-top: 0vw;
	
			&:nth-child(2),&:nth-child(3),&:nth-child(4)  {
				display: flex;
				margin-top: 0.7vw;
				view{
					font-size: 1.4vw;
					color: #888888;
					text-overflow: ellipsis;
					overflow: hidden;
					white-space: nowrap;
				}
	
				text {
					font-weight: 400;
					font-size: 1.3vw;
					color: #777777;
					margin-top: 0.25vw;
				}
			}
	
			&:nth-child(1) {
				margin-top: 1.7vw;
				view{
					width: 100%;
					font-weight: bold;
					font-size: 1.6vw;
					color: #222222;
					height: 3vw;
					padding-top: 1vw;
					text-overflow: ellipsis;
					overflow: hidden;
					white-space: nowrap;
				}
			}
		}
	}
	.zding{
		width: 4.6vw;
		height: 4.6vw;
		position: absolute;
		left: 0;
		top: 0;
		z-index: 11;
		image{
			width: 100%;
			height: 100%;
		}
	}
	.speitem {
		width: 14vw;
		height: 100%;
		display: inline-flex;
		flex-direction: column;
		position: absolute;
		top:0;
		left: 0;
	
		>image {
			width: 12vw;
			height: 12vw;
			margin: 1vw auto 0.25vw;
		}
	}
	
	
	
	.itembox{
		width: 100%;
		height: calc(100vh - 10vw);
		padding:1vw 0.5vw 1vw;
		background: #fff;
		.box{
			width: 100%;
			display: flex;
			flex-wrap: wrap;
		}
		.fler{
			width: 44vw;
			height: 13vw;
			margin-bottom: 0.9vw;
			margin-left: 0.5vw;
			.carditem{
				width: 46vw;
				height: 16vw;
				background: rgba(245, 246, 248, 1);
				border-radius: 1.1vw;
				position: relative;
				overflow: hidden;
				margin: 1vw 0 0vw 1vw;
			}
		}
	}       
	
.t-box {
		width: 85vw;
		height: calc(90vh);
		display: flex;
		justify-content: space-between;
		margin-top: 5vh;

		.rightscr {
			width: 50vw;
			height: 100%;
			background: #fff;
			border-radius: 1.6vw;
			overflow: hidden;
		}

		.leftscr {
			width: 33.4vw;
			height: calc(90vh);
			margin-left: 1vw;
		}
	}

	.guodu {
		transition: .4s;
		-webkit-transform-style: preserve-3d;
		-webkit-overflow-scrolling: touch;
	}
</style>