<template>
	<!-- <u-navbar title="分拣" placeholder border=true :autoBack="true" leftIconSize='35'></u-navbar> -->
	<u-navbar
	title="扫描" 
	placeholder
	:autoBack="true" 
	leftIconSize='35'
	bgColor='#ffffff00'
	leftIconColor='#ffffff'
	titleStyle='color:#ffffff'
	></u-navbar>
	<image mode="widthFix" class="bgimg" src="/pagesHome/static/bgby.png"></image>
	<view class="headtop">
		<view>
			<input placeholder="请输入订单号" />
		</view>
	</view>
	<view class="mabxtop">
		<view>
			<view>
				<view>{{(detauser?.trayCode)||details.trayCode}}</view>
				<view>托盘码</view>
			</view>
			<view>
				<view>{{(detauser?.trayNum)||0}}</view>
				<view>托盘件数</view>
			</view>
		</view>
		<view>
			<view>
				<view>{{(detauser?.name)||'暂无数据'}}</view>
				<view>名称</view>
			</view>
			<view>
				<view>{{(detauser?.orderTotalNum)||0}}</view>
				<view>总件数</view>
			</view>
		</view>
		<view>
			<view>
				<view>{{(detauser?.trayTypeName)||details.trayCodevalue}}</view>
				<view>打托方式</view>
			</view>
		</view>
	</view>
	<!-- <view class="hedtopt">
		<view class="typto">
			<view>托盘码：汇通龙泉001</view>
			<view>托盘件数：19件</view>
		</view>
		<view class="typto">
			<view>名称：名称啊231</view>
			<view>总件数：20件</view>
		</view>
		<view class="typto">
			<view>打托方式：码板打托</view>
		</view>
	</view> -->
	
	<scroll-view class="scvmabx" scroll-y="true">
		<view class="maxboxs">
			<view class="items chuanhuo" @click="godetaillist(item)" v-for="item in datelist">
				<view class="tophd" @click.stop.prevent>
					<image src="/pagesHome/static/topicons.png"></image>
					<view>订单号：</view>
					<view>{{item.dataCode}}</view>
					<image @click="removeitem(item)" src="/pagesHome/static/removeitem.png"></image>
				</view>
				<view class="numbxvie">
					<view>
						<view class="zhon">{{item.orderTotalNum}}</view>
						<view>总数</view>
					</view>
					<view>
						<view class="yish">{{item.scanNum}}</view>
						<view>已扫</view>
					</view>
					<view>
						<view class="weish">{{item.orderTotalNum - item.scanNum }}</view>
						<view>未扫</view>
					</view>
				</view>
			</view>
		</view>
	</scroll-view>
	<saomiao2></saomiao2>
	<tips ref="tip"></tips>
</template>

<script lang="ts" setup>
	import {
		warehouseTrayTypedeleteOrderCode,
		warehouseTrayTypeorderScanOrderPackageCode,
		warehouseTrayTypeorderScanTrayCode
	} from '@/api/user.js'
	import {
		onLoad,
		onShow,
		onHide,
		onUnload
	} from '@dcloudio/uni-app'
	import utils from '@/utils/utils.js'
	import { reactive, ref, toRefs } from "vue";
	let details=reactive({
		trayCode:'',
		trayType:'',
		scancode:'',
		datelist:[],
		detauser:null as any,
		trayCodevalue:'',
	})
	let tip=ref(null)
	onLoad((op)=>{
		details.trayCode=op.trayCode
		details.trayType=op.trayType
		// setTimeout(()=>{
		// 	details.scancode='23081202742-1'
		// 	scandata()
		// },3000)
		// setTimeout(()=>{
			
		// 	details.scancode='23080206190-1'
		// 	scandata()
		// },6000)
		let trayCodeTypearr=uni.getStorageSync('trayCodeType')
		if(trayCodeTypearr){
			trayCodeTypearr.map(item=>{
				if(item.dictKey==details.trayType){
					details.trayCodevalue=item.dictValue
				}
			})
		}
		
	})
	onShow(()=>{
		uni.$on('scancodedate', function(code) {
			if (code) {
				console.log(code);
				details.scancode=code
				scandata()
			}
		})
		initlist()
	})
	onHide(()=>{
		uni.$off('scancodedate')
	})
	async function godetaillist(item){
		uni.navigateTo({
			url:'/pagesHome/pages/OrderSortingDetailList/OrderSortingDetailList?orderCode='
			+item.dataCode+'&trayCode='
			+details.trayCode
		})
	}
	function removeitem(item){
		tip.value.setdetails({
			title:'提示',
			content:'确认删除该订单与托盘码的绑定？',
			confirmTxt:'确认',
			isshow:true,
			isshowcancel:true,
			success:async ()=>{
				let data={
					trayCode:details.trayCode,
					orderCode:item.dataCode,
				}
				let res=await warehouseTrayTypedeleteOrderCode(data)
				if(res.code==200){
					uni.showToast({
						title:'删除绑定成功',
						icon:'none'
					})
					initlist()
				}else {
					uni.showToast({
						title:res.msg,
						icon:'none'
					})
				}
				tip.value.setisshow(false)
			},
			cancel:()=>{
				tip.value.setisshow(false)
			},
			close:()=>{
				tip.value.setisshow(false)
			}
		})
	}
	async function initlist(){
		let data={
			trayCode:details.trayCode
		}
		let res=await warehouseTrayTypeorderScanTrayCode(data)
		console.log(res.data,'resresresres');
		if(res.code==200){
			if(res.data.isHasData==1){
				details.datelist=res.data.data.list
				details.detauser=res.data.data
			}
		}else {
			uni.showToast({
				title:res.msg,
				icon:'none'
			})
		}
	}
	async function scandata(){
		let data={
			trayType:details.trayType,
			trayCode:details.trayCode,
			orderPackageCode:details.scancode,
		}
		let response=await warehouseTrayTypeorderScanOrderPackageCode(data)
		console.log(response);
		initlist()
		uni.showToast({
			title:response.msg,
			icon:'none'
		})
	}
	function initpage(){
		
	}
	const { datelist,detauser }=toRefs(details)
</script>

<style lang="scss">
	.mabxtop{
		position: relative;
		width: 684upx;
		// height: 348upx;
		background: #FFFFFF;
		border-radius: 20upx;
		margin: auto;
		margin-top: 20upx;
		padding: 60upx;
		box-sizing: border-box;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		>view{
			width: 100%;
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-bottom: 50upx;
			
			&:nth-last-child(1){
				margin-bottom: 0;
			}
			>view{
				width: 50%;
				display: flex;
				flex-direction: column;
				align-items: flex-start;
				>view:nth-of-type(1){
					font-size: 32upx;
					font-weight: 400;
					color: #020B18;
					word-wrap: break-word;
					word-break: break-all;
				}
				>view:nth-of-type(2){
					font-size: 28upx;
					font-weight: 400;
					color: #90A0AF;
				}
			}
		}
	}
	.bgimg{
		position: fixed;
		left: 0;
		top: 0;
		width: 100%;
		
	}
	.scvmabx{
		width: 684rpx;
		height: 45vh;
		margin: auto;
		margin-top: 20upx;
		.maxboxs{
			width: 100%;
			display: flex;
			flex-direction: column;
			align-items: center;
			.chuanhuo{
				border: #ff0000 ;
			}
			>.items{
				width: 690upx;
				display: flex;
				flex-direction: column;
				align-items: center;
				padding: 20upx 30upx;
				box-sizing: border-box;
				background-color: #ffffff;
				border-radius: 10upx;
				margin-bottom: 30upx;
				&:nth-last-child(1){
					margin-bottom: 20upx;
				}
				.tophd{
					width: 100%;
					display: flex;
					align-items: flex-start;
					justify-content: flex-start;
					padding: 15upx 25upx;
					box-sizing: border-box;
					border-bottom: 4upx solid #EEEEEE;
					>image{
						width: 48upx;
						height: 48upx;
						margin-right: 10upx;
						box-sizing: border-box;
					}
					>view{
						font-size: 32upx;
						color: #020B18;
						font-weight: 400;
						word-wrap: break-word;
						word-break: break-all;
						&:nth-of-type(1){
							width: 130upx;
						}
					}
					>view:nth-of-type(2){
						flex: 1;
					}
				}
				.numbxvie{
					width: 100%;
					display: flex;
					align-items: center;
					justify-content: space-around;
					padding: 15upx 25upx;
					box-sizing: border-box;
					.zhon{
						color: #D3832A;
					}
					.yish{
						color: #1197EB;
					}
					.weish{
						color: #020B18;
					}
					>view{
						display: flex;
						flex-direction: column;
						align-items: center;
						>view:nth-of-type(1){
							font-size: 36upx;
							margin-bottom: 12upx;
						}
						>view:nth-of-type(2){
							font-size: 28upx;
						}
					}
				}
			}
		}
	}
	.headtop {
		width: 684upx;
		padding: 20upx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		// margin-top: 20upx;
		background-color: #FFFFFF;
		padding: 20upx 30upx;
		box-sizing: border-box;
		position: relative;
		margin: auto;
		border-radius: 20upx;
		margin-top: 30upx;
		>view{
			flex: 1;
			>input{
				flex: 1;
				font-size: 28upx;
			}
		}
	}
	.hedtopt{
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
		background-color: #ffffff;
		padding: 36upx 32upx;
		box-sizing: border-box;
		.typto{
			display: flex;
			align-items: center;
			justify-content: space-between;
			width: 100%;
			font-size: 28upx;
			font-weight: 400;
			color: #092C4D;
			margin-bottom: 20upx;
			&:nth-last-child(1){
				margin-bottom: 0;
			}
			>view{
				flex: 1;
			}
		}
		
	}
</style>
