<template>
	<!-- <u-navbar title="备货列表" placeholder border=true :autoBack="true" leftIconSize='35'></u-navbar> -->
	<u-navbar title="备货列表"
	 bgColor='#D3832A' leftIconColor='#ffffff'
	titleStyle='color:#ffffff' placeholder 
	:autoBack="true" leftIconSize='35'></u-navbar>
	<view class="head">
		<view class="type1">
			<view>
				客户：{{details.customer}}
			</view>
			<view>
				备货区域：{{details.stockupArea}}
			</view>
		</view>
		<view class="type1">
			<view>
				计划件数：{{details.planNum}}
			</view>
			<view>
				扫描件数：{{details.scanNum}}
			</view>
		</view>
		<view class="type1">
			<view>
				库位号：{{details.warehouseArea}}
			</view>
			<view>
				托盘码：{{details.trays}}
			</view>
		</view>
		<!-- <view class="type1">
			<view>
				容器件数：300
			</view>
			<view>
				计划件数：300
			</view>
		</view> -->
		<view class="type2">
			<view>
				<!-- 完成件数：1 -->
			</view>
			<!-- <view>
				<view>备货托盘：无</view>
				<view>
					绑定托盘
				</view>
			</view> -->
			
		</view>
	</view>
	<view class="butbox">
		<!-- <uni-table border stripe :loading='false' emptyText="暂无更多数据" >
			<uni-tr>
				<uni-th align="center">订单号</uni-th>
				<uni-th align="center">包条码</uni-th>
				<uni-th align="center">货物类型</uni-th>
				<uni-th align="center">是否备货</uni-th>
				<uni-th width='50' align="center">备货</uni-th>
			</uni-tr>
			<uni-tr v-for="item in [1,2,3,4,5]">
				<uni-td>OP36351452{{item}}</uni-td>
				<uni-td>154124</uni-td>
				<uni-td>订制品</uni-td>
				<uni-td>是</uni-td>
				<uni-td>完成</uni-td>
			</uni-tr>
		</uni-table> -->
		<!-- <hd-table :dataSource="dataList" height="70vh" :stripe="true">
		  <hd-table-column prop="ordernumber" label="订单号"></hd-table-column>
		  <hd-table-column prop="PackageNo" label="包条码"></hd-table-column>
		  <hd-table-column prop="goodType" label="货物类型"></hd-table-column>
		  <hd-table-column prop="StockNot" label="是否备货"></hd-table-column>
		  <hd-table-column prop="StockUp" label="备货"></hd-table-column>
		</hd-table> -->
		<scroll-view scroll-y="true" class="scrollv">
			<view class="mabxs">
				<view class="ite" @click="showsdqs" v-for="item in dataList">
					<view>
						<view @click.stop="goorderdetail(item)">订单号：{{item.orderCode}}</view>
						<view>包条码：{{item.packageBarCode}}</view>
					</view>
					<view>
						<view>货物类型：{{item.goodsType==1?'定制品':''}}</view>
						<view>是否备货：{{item.isScanStr}}</view>
					</view>
					<view style="flex: 1;">
						<view style="flex: 1;">物料名称：{{item.materialName}}</view>
					</view>
				</view>
			</view>
		</scroll-view>
		<view class="prtbut" @click="prinbut">
			打印
		</view>
	</view>
	<tiplist ref="tiplists"></tiplist>
	<saomiao2></saomiao2>
</template>
	
<script lang="ts" setup>
	import {
		onLoad,
		onShow,
		onHide,
		onUnload
	} from '@dcloudio/uni-app'
	import { distributionStockuporderInfo,distributionStockupstockupScan } from '@/api/user.js'
	import { detailType } from '@/interfaces/pagesHome/StockUplistScandetails'
	import { reactive, ref, toRefs, inject } from "vue";
	const util = (inject('utils') as any)
	let details=reactive<detailType>({
		dataList:[],
		stockArticleId:'',
		orderStatus:'',
		reservationId:'',
		stockListId:'',
		allocation:'',
		pallet:'',
		customer:'',
		stockupArea:'',
		planNum:'',
		scanNum:'',
		trays:'',
		warehouseArea:'',
		orderCode:'',
		scancode:'',
		stockupId:'',
		address:'',
		isscan:false,
		allocationId:'',
		status:'',
		typeService:''
	})
	const tiplists=ref(null)
	onLoad((op)=>{
		details.stockArticleId=op.stockArticleId
		details.status=op.status
		details.stockupId=op.stockupId
		details.orderStatus=op.orderStatus
		details.reservationId=op.reservationId
		details.allocationId=op.allocationId
		// details.stockListId=op.stockListId
		details.allocation=op.allocation
		details.pallet=op.pallet
		details.orderCode=op.orderCode
		details.typeService=op.typeService
		initpage()
		// details.scancode='23072506516-3'
		// scandata() 
		uni.$on('scancodedate', function(code) {
			if (code) {
				console.log(code);
				details.scancode=code
				scandata()
			}
		})
	})
		function goorderdetail(item){
			uni.navigateTo({
				url:'/pagesHome/pages/orderDetails/orderDetails?orderCode='+item.orderCode
			})
		}
	function prinbut(){
		let list=[],checklist=[]
		details.dataList.map((item,index)=>{
			list.push(item.packageBarCode)
			checklist.push(index)
		})
		tiplists.value.setdetails({
			title:'请选择需要打印的包条码',
			isshow:true,
			tipstate:2,
			list,
			checklist,
			inputtext:'',
			confirmTxt:'确认选择',
			isonecheck:false,
			success:(deta)=>{
				if(deta.checklist.length==0){
					uni.showToast({
						title:'请选择包条码',
						icon:'none'
					})
					return
				}
				// #ifdef APP
				deta.checklist.map(item=>{
					let text = '! 0 200 200 500 1\r\n'
					text += 'SETBOLD 2\r\n'
					text += `T 56 0 0 0 ${details.dataList[item]?.orderCode}\r\n`
					text += 'LINE 0 50 420 50 3\r\n'
					text += `T 55 0 0 60 客户\r\n`
					text += 'LINE 40 50 40 110 3\r\n'
					text += `T 55 0 50 60 ${details.customer}\r\n`
					text += 'LINE 40 80 420 80 3\r\n'
					text += `T 55 0 50 90 ${details.address}\r\n`
					text += 'LINE 0 110 420 110 3\r\n'
					text += `T 55 0 0 120 物料\r\n`
					text += 'LINE 40 110 40 140 3\r\n'
					text += `T 55 0 50 120 ${details.dataList[item]?.materialName}\r\n`
					text += 'LINE 0 140 420 140 3\r\n'
					text += 'B QR 150 150 M 2 U 4\r\n'
					text += `MA,${details.dataList[item]?.packageBarCode}\r\n`
					text += 'ENDQR\r\n'
					text += `T 55 0 140 260 ${details.dataList[item]?.packageBarCode}\r\n`
					text += 'FORM\r\n'
					text += 'PRINT\r\n'
					let sylist = util.initbl()
					console.log(sylist);
					sylist.map(item => {
						console.log(item);
						if (item.uuids) {
							util.getbl(item, text)
						}
					})
				})
				// #endif
				tiplists.value.setdetails({isshow:false})
			},
			cancel:(details)=>{
				tiplists.value.setdetails({isshow:false})
			},
			close:(details)=>{
				tiplists.value.setdetails({isshow:false})
			}
		})
	}
	function showsdqs(){
		tiplists.value.setdetails({
			isshow:true,
			tipstate:1,
			title:'请输入扫描的码',
			placeholder:'请输入扫描的码',
			inputtext:'',
			success:(detail)=>{
				details.scancode=detail.inputtext
				scandata()
				tiplists.value.setdetails({isshow:false})
			},
			cancel:()=>{
				tiplists.value.setdetails({isshow:false})
			},
			close:()=>{
				tiplists.value.setdetails({isshow:false})
			}
		})
	}
	async function scandata(){
		let data={
			scanType:1,
			orderCode:details.orderCode,
			packetBarCode:details.scancode,
			stockupArea:details.stockupArea,
			reservationId:details.reservationId,
			allocationId:details.allocationId,
			stockupId:details.stockupId,
			typeService:details.typeService
		}
		let res=await distributionStockupstockupScan(data)
		console.log(res);
		if(res.code==200){
			details.isscan=true
			initpage()
		}
	}
	async function initpage(){
		let data={
			orderStatus:details.orderStatus,
			reservationId:details.reservationId,
			stockArticleId:details.stockArticleId,
			// stockListId:details.stockListId,
			allocationId:details.allocationId,
			allocation:details.allocation,
			pallet:details.pallet,
			stockupId:details.stockupId,
			status:details.status,
			typeService:details.typeService
		}
		let response=await distributionStockuporderInfo(data)
		console.log(response);
		details.dataList=response.data.packageList
		details.customer=response.data.customer
		details.stockupArea=response.data.stockupArea
		details.planNum=response.data.planNum
		details.scanNum=response.data.scanNum
		details.trays=response.data.trays
		details.warehouseArea=response.data.warehouseArea
		details.address=response.data.address
		if(Number(details.scanNum)>0&&details.isscan){
			util.ttsspke(details.scanNum+'件')
		}
	}
	const { dataList }=toRefs(details)
</script>

<style lang="scss">
	.butbox{
		display: flex;
		flex-direction: column;
		width: 686upx;
		margin: auto;
		margin-top: 20upx;
		box-sizing: border-box;
		padding: 16upx 0upx;
		background-color: #ffffff;
		border-radius: 8upx;
		.scrollv{
			width: 100%;
			height: 50vh;
			// padding: 10upx;
			box-sizing: border-box;
			.mabxs{
				display: flex;
				flex-direction: column;
				align-items: center;
				padding-top: 5upx;
				.ite{
					width: 93%;
					// width: 100%;
					display: flex;
					flex-direction: column;
					align-items: center;
					padding: 10upx;
					box-sizing: border-box;
					border-radius: 8upx;
					box-shadow: 0upx 2upx 10upx 0upx #e2e2e3;
					margin-bottom: 20upx;
					>view{
						display: flex;
						align-items: center;
						justify-content: space-between;
						width: 100%;
						margin-bottom: 10upx;
						&:nth-last-child(1){
							margin-bottom: none;
						}
						>view{
							width: 50%;
							// flex: 1;
							font-size: 28upx;
							font-weight: 400;
							color: #092C4D;
						}
					}
				}
			}
		}
		.prtbut{
			margin: auto;
			margin-top: 20upx;
			width: 320upx;
			height: 88upx;
			background: #D3832A;
			border-radius: 8upx;
			font-size: 32upx;
			font-weight: 400;
			color: #FFFFFF;
			display: flex;
			align-items: center;
			justify-content: center;
		}
	}
	.head{
		display: flex;
		flex-direction: column;
		align-items: center;
		width: 100%;
		padding: 20upx;
		box-sizing: border-box;
		background-color: #ffffff;
		>.type1{
			width: 100%;
			display: flex;
			align-items: center;
			margin: 14upx 0;
			font-size: 28upx;
			font-weight: 400;
			color: #092C4D;
			>view{
				width: 50%;
			}
		}
		>.type2{
			width: 100%;
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin: 14upx 0;
			font-size: 28upx;
			font-weight: 400;
			color: #092C4D;
			>view:nth-of-type(2){
				width: 50%;
				display: flex;
				align-items: center;
				>view:nth-of-type(2){
					font-size: 28upx;
					font-weight: 400;
					color: #0086F1;
					margin-left: 20upx;
				}
			}
		}
	}
</style>
