<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" @click="start(v)" v-if="v.izStart=='N'">开始服务</view> 
									<view class="ld"  v-if="v.izStart=='Y'&& v.izFinish=='N'" @click="end(v)">结束服务</view>
									<view class="bd"  v-if="(v.izStart=='Y'&& v.izFinish=='N')||v.manuallyMp4Path!=null" @click="ysptp(v,i,2)">录像</view>
									<view class="bd" v-if="(v.izStart=='Y'&& v.izFinish=='N')|| v.manuallyPicPath!=null"  @click="ysptp(v,i,1)" >拍照</view>
									<view class="bd"  v-if="(v.izStart=='Y'&& v.izFinish=='Y')&&v.tplinkPath!=null" @click="ysptp(v,i,3)">Tplink</view>
								</view>
							</view>
							
						</view>
					</view>
				</scroll-view>
			</view>
		</view>
		
		
		
		<!-- 照片墙 -->
		<view class="mengban" v-if="topbuttontarget>0" @click="topbuttontarget=0"></view>
		<view class="photowall" v-show="topbuttontarget>0" :style="donghuaopo?{opacity:1}:{opacity:0}">
			<view class="photowall-title">
				<view class="photowall-name">
					{{ topbuttontarget==1?`照片`:`录像` }}
				</view>
			</view>
			<scroll-view scroll-y="true" class="photowall-other" scroll-with-animation enable-flex v-if="topbuttontarget>0">
				<view class="photowall-other" >
				<view class="photowall-other-one" v-for="(item,index) in ilanarr" :key="index"
					@click="previewImage(item,index,ilanarr)">
					<view  v-if="topbuttontarget==1"  style="width: 100%;height: 70%;border-radius: 30rpx;position: relative;">
						<image style="width: 100%;height: 100%;border-radius: 30rpx;"
							:src="item?serverUrl + item:'/static/ceshiyaoshan.png'" mode="aspectFill"
							:lazy-load="true"/>
						<view @click.stop="open=1;del(item,index)"
						style="width: 1.6vw;
						height: 1.6vw;
						z-index: 20;
						position: absolute;
						right: -1vw;
						top: -0.7vw;
						background: red;
						display: flex;
						justify-content: center;
						border-radius: 50%;
						align-items: center;"
						 v-if="topbuttontarget>0&&(listobj.izStart=='Y'&& listobj.izFinish=='N')">
							<image src="/static/index/warehouse/procurement/x.png" mode="aspectFill" 
							style="width: 1.4vw;
						height: 1.4vw;"></image>
						</view>
					</view>
					<view  v-if="topbuttontarget==2" style="width: 100%;height: 70%;border-radius: 30rpx ;position: relative;" @click="clik(serverUrl + item)">
						<video style="width: 100%;height: 100%;border-radius: 30rpx;"  :id="'myVideo'+index" 
						:src="servervideoUrl+item"
						  mode="aspectFill"  ></video>
						<view @click.stop="ilanarr.splice(index,1)"
						 v-if="topbuttontarget>0&&(listobj.izStart=='Y'&& listobj.izFinish=='N')"
						style="width: 1.6vw;
						height: 1.6vw;
						z-index: 20;
						position: absolute;
						right: -1vw;
						top: -0.7vw;
						background: red;
						display: flex;
						justify-content: center;
						border-radius: 50%;
						align-items: center;">
							<image src="/static/index/warehouse/procurement/x.png" mode="aspectFill" 
							style="width: 1.4vw;
						height: 1.4vw;"></image>
						</view>
					</view>
					<!-- <view style="margin-top: 20rpx;">
						<text style="color: #888888;">
							上传时间:
						</text>
						<text style="margin-left: 15rpx;">
							{{item.createTime.replace(/-/g, '.')}}
						</text>
					</view>
					<view style="margin-top: 10rpx;">
						<text style="color: #888888;letter-spacing: 8.9rpx;">
							上传人:
						</text>
						<text>
							{{item.createBy}}
						</text>
					</view> -->
				</view>
				<view class="photowall-other-one" v-if="topbuttontarget>0&&(listobj.izStart=='Y'&& listobj.izFinish=='N')">
					<view style="width: 100%;height: 71%;display: flex;flex-direction: column;
						justify-content: center;align-items: center;position: absolute;top:0vw;left: 0;
						background-color:#fafdff ;border: 1rpx solid #78B1EB;border-radius: 30rpx;" @click="uplod(1)">
						<image style="width: 70rpx;height: 70rpx;margin-bottom: 5rpx;"
							src="/static/index/warehouse/procurement/picking/addphoto.png" />
						<view style="color: #78B1EB;">
							点击上传{{topbuttontarget==1?'图片':'录像'}}
						</view>
					</view>
				</view>
				<!-- <view class="noarray" v-if="!ilanarr.length">
					<image class="noarray-img" src="/static/index/warehouse/procurement/picking/noarray.png"
						mode="aspectFill" />
					<view class="noarray-font">
						暂无照片
					</view>
				</view> -->
			</view>
			</scroll-view>
			<view style="position: absolute;right: 2vw;bottom: 0.8vw;height: 4vw;" v-if="topbuttontarget>0&&(listobj.izStart=='Y'&& listobj.izFinish=='N')">
				<button type="primary" style="width: 9vw; position: absolute;right: 0vw;bottom: 0.vw;" @click="submit" >确定</button>
			</view>
		</view>
		<tanchuang :show="open==1" font="是否删除此图片" @back="open = 0" @right="del1()"> </tanchuang>
		<view class="mengban" style="background: #fff;width:100vw;right:0;left: 0vw;top:-5vw;height: 110vh;" v-if="status=='nomore'&&plsbuy.length==0">
			<defaultr cont="暂无数据" style="z-index: 999;margin: auto;top: 0;left:35vw;bottom: 0;right: 0;"></defaultr>
		</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 {queryOrderList,queryOrderInfoList,startOrder,endOrder,editSubPicPath,editSubMp4} from './api/api.js'
	const serverUrl = ref(uni.getStorageSync('serverUrl') + '/sys/common/static/')
	const servervideoUrl = ref(uni.getStorageSync('serverUrl') + '/sys/commonVideo/staticVideo/')
	const form = reactive({
		pageNo: 1,
		pageSize: 10,
		employeeId:uni.getStorageSync('userInfo').employessId, 
		nuId:uni.getStorageSync('nuId')
	})
	const open = ref(0)
	const clik = (e)=>{
		console.log(e)
	}
	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 = () => {
		queryOrderList(form).then(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) => {
		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;
		queryOrderInfoList({ mainId: item.id }).then(res => {
			cardarr.value = res.result
		})
		}
	const sctop = ref(0)
	const scroll = (e)=>{
		sctop.value = e.detail.scrollTop
	}
	const start = (v) =>{
		startOrder({id:v.id}).then(res=>{
			if(res.success){
				v.izStart = "Y";
				plsbuy.value[lefttarget.value].izStart = 'Y';
				clickLeftMenu(lefttarget.value,plsbuy.value[lefttarget.value])
			}else{
				
				
			}
		})
	}
	const end = (v)=>{
		endOrder({id:v.id}).then(res=>{
			if(res.success){
				v.izStart = "N";
				v.izFinish = "Y";
				plsbuy.value[lefttarget.value].izFinish = 'Y';
				clickLeftMenu(lefttarget.value,plsbuy.value[lefttarget.value])
			}else{
				
			}
		})
	}
	const donghuaopo = ref(false);
	const topbuttontarget = ref(0);
	const ilanarr = ref([]);
	const listobj = ref({})
	const ysptp = (v,i,r) =>{
		// v.manuallyPicPath
		if(r == 1&&v.manuallyPicPath){
			ilanarr.value = v.manuallyPicPath.split(",");
			ilanarr.value = ilanarr.value.filter(item => item !== '');
		}else if(r == 2&&v.manuallyMp4Path){
			ilanarr.value = v.manuallyMp4Path.split(",");
			ilanarr.value = ilanarr.value.filter(item => item !== '');
		}else if(r == 3&&v.tplinkPath){
			ilanarr.value = v.tplinkPath.split(",");
			ilanarr.value = ilanarr.value.filter(item => item !== '');
		}
		else{
			ilanarr.value = [];
		}
		
		listobj.value = v;
		topbuttontarget.value = r;
		donghuaopo.value = true;
	}
	const uplod = (v) => {
		if(topbuttontarget.value==1){
			uni.chooseImage({
				count: 1, //默认9
				sizeType: ['compressed'], //可以指定是原图还是压缩图，默认二者都有
				sourceType: ['camera'], //从相册选择
				success: (e) => {
					let ar = JSON.stringify(e.tempFilePaths)
					uni.compressImage({
						src: JSON.parse(ar)[0],
						quality: 60,
						success: res => {
							sxdupld(res.tempFilePath)
							// v.picPatharr.push(res.tempFilePath);
							// console.log(v.picPatharr)
						}
					})
				}
			});
		}else{
			uni.chooseVideo({
				sourceType: ['camera' ],
				success: (e)=> {
					uni.compressVideo({
						src: e.tempFilePath,
						quality: 60,
						success: res => {
							sxdupld(res.tempFilePath)
							// v.picPatharr.push(res.tempFilePath);
							// console.log(v.picPatharr)
						}
					})
					// sxdupld(res.tempFilePath )
				}
			});
		}
		
	}
	const sxdupld = (e) => {
		let now = new Date();
		let year = now.getFullYear();
		let month = now.getMonth() + 1;
		uni.uploadFile({
			url: uni.getStorageSync('serverUrl') + '/sys/common/upload',
			filePath: e,
			name: 'file',
			fileType:topbuttontarget.value==2?'video':'image',
			formData: {
				biz: year + '/' + month + (topbuttontarget.value==1?'/fwxm/manuallyPicPath':'/fwxm/manuallyMp4Path')
			},
			header: {
				'X-Access-Token': uni.getStorageSync('token')
			},
			success: res => {
				const data = JSON.parse(res.data);
				console.log(data)
				ilanarr.value.push(data.message)
			},
			fail: () => {
				uni.showToast({ title: '上传失败', icon: 'none' })
			}
		})
	}
	const submit = ()=>{
		let sub = "";
		ilanarr.value.forEach(item=>{
			sub+=item+','
		})
		if(topbuttontarget.value == 1){
			editSubPicPath({id:listobj.value.id,manuallyPicPath:sub}).then(res=>{
				if(res.success){
					topbuttontarget.value = 0;
					donghuaopo.value = false;
					clickLeftMenu(lefttarget.value,plsbuy.value[lefttarget.value])
				}
			})
		}else{
			editSubMp4({id:listobj.value.id,manuallyMp4Path:sub}).then(res=>{
				if(res.success){
					topbuttontarget.value = 0;
					donghuaopo.value = false;
					clickLeftMenu(lefttarget.value,plsbuy.value[lefttarget.value])
				}
			})
		}
	}
	const previewImage = (v, i, arr) => {
		if(topbuttontarget.value == 1){
			let u = []
			arr.forEach(e => {
				u.push(serverUrl.value + e)
				console.log(serverUrl.value + e)
			})
			uni.previewImage({
				current: i,
				urls: u,
				showmenu: false,
				longPressActions: {
					itemList: [],
				}
			})
		}
	}
	const videoContext = ref(null)
	const play = (e,i)=>{
		 videoContext.value = uni.createVideoContext('myVideo'+i);
		 videoContext.value.play()
	}
	const pici = ref(0);
	const del = (v,i) =>{
		pici.value = i;
	}
	const del1=()=>{
		ilanarr.value.splice(pici.value,1);
		open.value = 0
	}
</script>

<style scoped lang="less">
	
	.noarray {
		width: 90%;
		height: 100%;
		// background-color: red;
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
	
		.noarray-img {
			margin-top: -200rpx;
			width: 350rpx;
			height: 350rpx;
		}
	
	}
	
	.noarray-font {
		margin-top: -60rpx;
		color: #888888;
		font-size: 25rpx;
	}
	.mengban {
		width: 100vw;
		height: 100vh;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 100;
		background: RGBA(239, 240, 244, 0.55);
	}
	.photowall {
		position: fixed;
		top: 54%;
		left: 50%;
		transform: translate(-50%, -50%);
		width: 80vw;
		height: 83%;
		border-radius: 30rpx;
		background-color: #fff;
		transition: all 0.3s;
		z-index: 999;
		box-shadow: 0 0 10rpx rgba(0, 0, 0, 0.1);
		padding: 0 90rpx;
		.photowall-title {
			margin-top: 50rpx;
			display: flex;
			justify-content: space-between;
			width: 100%;
			margin-bottom: 50rpx;
	
			.photowall-name {
				font-size: 38rpx;
				// font-weight: 600;
			}
	
			.photowall-left {
				color: #888888;
			}
	
			.photowall-right {
				font-size: 30rpx;
				font-weight: 600;
			}
		}
	
		.photowall-other {
			width: 76vw;
			height: 62vh;
			display: flex;
			margin-top: 20rpx;
			flex-wrap: wrap;
			.photowall-other-one {
				width: 22vw;
				height: 430rpx;
				margin-right: 3vw;
				margin-bottom: 0%;
				border-radius: 30rpx;
				display:flex;
				position: relative;
				video{
					width: 100%;
					height: 100%;
				}
			}
		}
	}
	
	.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: 46vw;
			min-height: 13vw;
			margin-bottom: 0.9vw;
			margin-left: 0.5vw;
			.carditem{
				width: 46vw;
				height: 15vw;
				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(92vh);
		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(92vh);
			margin-left: 1vw;
		}
	}

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