<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">
		<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>
	<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
		// details.scancode='23072506516-3'
		// scandata() 
	})
	onShow(() => {
		uni.$on('scancodedate', function (code) {
			if (code) {
				console.log(code);
				details.scancode = code
				scandata()
			}
		})
		initpage()
	})
	onHide(() => {
		uni.$off('scancodedate')
	})
	function goorderdetail(item) {
		uni.navigateTo({
			url: '/pagesHome/pages/orderDetails/orderDetails?orderCode=' + item.orderCode
		})
	}
	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)
		if (response.code !== 200) return
		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 {
				flex: 1;
				word-wrap: break-word;
				word-break: break-all;

				&:nth-of-type(1) {
					margin-right: 30upx;
				}
			}
		}

		>.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>