<template>
	<u-navbar title="空置托盘" bgColor='#D3832A' leftIconColor='#ffffff' titleStyle='color:#ffffff' placeholder
		:autoBack="true" leftIconSize='35'></u-navbar>
	<scroll-view class="scvmabx" scroll-y="true">
		<view class="maxboxs">
			<view class="items" v-for="item in datalist">
				<view class="tophd1">
					<view >
						<image src="/pagesHome/static/topicons.png"></image>
						<!-- <view></view> -->
						<view>{{item.dataCode}}</view>
					</view>
				</view>
				<view class="tophd" v-if="item.dataName">
					<image src="/pagesHome/static/uname.png"></image>
					<view>物料名称：</view>
					<view>{{item.dataName}}</view>
				</view>
				<view class="tophd" v-if="item.sku">
					<image src="/pagesHome/static/uname.png"></image>
					<view>SKU：</view>
					<view>{{item.sku}}</view>
				</view>
				<view class="tophd" v-if="item.cargoUnit">
					<image src="/pagesHome/static/uname.png"></image>
					<view>物料单位：</view>
					<view>{{item.cargoUnit}}</view>
				</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>
		</view>
	</scroll-view>
	<view @click="removetray" class="flbuts">空置</view>
	<saomiao2></saomiao2>
	<tips ref="tip"></tips>
</template>

<script lang="ts" setup>
	import {
		onLoad,
		onShow,
		onHide,
		onUnload
	} from '@dcloudio/uni-app'
	import {
		warehouseTrayTypetrayToNullScanTrayCode,
		warehouseTrayTypetrayToNull
	} from '@/api/user.js'
	import { reactive, ref, toRefs } from "vue";
	const tip=ref(null)
	let details=reactive({
		datalist:[],
		scancode:'',
		statetype:'',
		trayCodes:''
	})
	onLoad(()=>{
		uni.$on('scancodedate', function (code) {
			if (code) {
				// console.log(code);
				details.scancode = code
				scandata()
			}
		})
		
	})
	async function scandata(){
		let data={
			trayCode:details.scancode
		}
		let res=await warehouseTrayTypetrayToNullScanTrayCode(data)
		if(res.code==200){
			console.log(res);
			details.datalist=res.data?.list
			details.statetype=res.data?.type
			if(res.data?.list?.length>0){
				details.trayCodes=details.scancode
			}
		}else{
			uni.showToast({
				title:res.msg,
				icon:'none'
			})
		}
	}
	function removetray(){
		tip.value.setdetails({
			title:'提示',
			content:'确认空置托盘？',
			confirmTxt:'确认',
			isshow:true,
			isshowcancel:true,
			success:async ()=>{
				let data={
					trayCode:details.trayCodes,
				}
				let res=await warehouseTrayTypetrayToNull(data)
				if(res.code==200){
					uni.showToast({
						title:'空置托盘成功',
						icon:'none'
					})
					tip.value.setdetails({
						title:'提示',
						content:'空置托盘成功',
						confirmTxt:'确认',
						isshow:true,
						isshowcancel:false,
						success:()=>{
							tip.value.setisshow(false)
						},
						cancel:()=>{
							tip.value.setisshow(false)
						},
						close:()=>{
							tip.value.setisshow(false)
						}
					})
					details.datalist=[]
					details.trayCodes=''
					tip.value.setisshow(false)
				}else {
					uni.showToast({
						title:res.msg,
						icon:'none'
					})
				}
			},
			cancel:()=>{
				tip.value.setisshow(false)
			},
			close:()=>{
				tip.value.setisshow(false)
			}
		})
	}
	const {
		statetype,
		datalist
	}=toRefs(details)
</script>

<style lang="scss">
	.flbuts{
		width: 320upx;
		height: 88upx;
		background: #D3832A;
		border-radius: 8upx 8upx 8upx 8upx;
		opacity: 1;
		display: flex;
		align-items: center;
		justify-content: center;
		color: #ffffff;
		margin: auto;
		position: fixed;
		left: 50%;
		transform: translate(-50%);
		bottom: 60upx;
	}
	.bgimg{
		position: absolute;
		left: 0;
		top: 0;
		width: 100%;
		
	}
	.scvmabx{
		width: 100%;
		height:88vh;
		margin-top: 20upx;
		.maxboxs{
			width: 100%;
			display: flex;
			flex-direction: column;
			align-items: center;
			>.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;
					}
					>view{
						font-size: 32upx;
						color: #020B18;
						font-weight: 400;
						word-wrap: break-word;
						word-break: break-all;
						&:nth-of-type(2){
							flex: 1;
						}
					}
				}
				.tophd1{
					width: 100%;
					display: flex;
					align-items: center;
					justify-content: space-between;
					padding: 15upx 25upx;
					box-sizing: border-box;
					border-bottom: 4upx solid #EEEEEE;
					>image{
						width: 48upx;
						height: 48upx;
						margin-right: -20upx;
						// margin-right: 10upx;
					}
					>view{
						display: flex;
						align-items: center;
						>image{
							width: 48upx;
							height: 48upx;
							margin-right: 10upx;
						}
					}
				}
				.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;
						}
					}
				}
				.type1{
					width: 100%;
					display: flex;
					align-items: center;
					justify-content: space-between;
					margin-bottom: 20upx;
					>view{
						display: flex;
						align-items: center;
						font-size: 28upx;
						>view:nth-of-type(1){
							color: #90A0AF;
						}
						>view:nth-of-type(2){
							color: #092C4D;
						}
					}
					
				}
			}
		}
	}
</style>
