<!-- 订单详情-确认收货 -->
<template>
	<navBar title="确认收货" navbgClass="nav-bgXin" fontColor='#fff' :scrollTop="scrollTop"></navBar>
	<view class="bg-img">
		<image :src="`${$imgUrl}order/bg-order.png`" mode="scaleToFill" class="icon"></image>
	</view>
	<view class="content">
		<view class="status">
			<text>待收货</text>
		</view>
		<view>
			<text>创建时间：</text>
			<text>{{getOrderTime(state.orderInfo.insertTime)}}</text>
		</view>
		<view class="order">
			<view class="num">
				<text>订单号：</text>
				<text>{{state.orderInfo.orderNo}}</text>
			</view>
			<view class="name">
				<text>产品名称：</text>
				<text>{{state.orderInfo.productName ?state.orderInfo.productName: ''}}</text>
			</view>
		</view>
		
		<view class="message" v-if="state.orderInfo.cardId">
			<view class="message-top1">
				<view class="msg">
					<view class="vehiclePlate">
						<text>订单车牌：</text>
						<text>{{state.orderInfo.vehiclePlate}}</text>
					</view>
					<view>
						<text>发货卡号：</text>
						<text>{{state.orderInfo.cardId ?state.orderInfo.cardId: ''}}</text>
					</view>
					<view >
						<text>发货签号：</text>
						<text>{{state.orderInfo.obuId ?state.orderInfo.obuId: ''}}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
    <view class="btn-wrap">
		<view class="hint">请核对实收货物与上述货物编号是否一致！</view>
		<submit-button title="确认收货" @submit="$util.confirm('是否确认收到货？', confirmReceipt, '收货确认')"></submit-button>
	</view>
</template>

<script setup lang="ts">
	// import orderInfoItem from "./components/order-info-item";
	import navBar from "@/components/nav-bar/nav-bar2.vue";
	import { reactive,ref } from "vue";
	import { onLoad,onPageScroll } from "@dcloudio/uni-app";
	import {requestNew } from "@/utils/network/request.js";
	import {confirm,getOrderTime } from "@/utils/utils";
	import {orderReceiveGoods,orderDetailQuery } from "@/utils/network/api";
	import { getItem, StorageKeys } from "@/utils/storage";
    const scrollTop = ref(0); //滚动距离
//监听页面滚动
	onPageScroll((e) => {
		scrollTop.value = e.scrollTop;
	});
	const state = reactive({
		//订单信息
		orderInfo: {} as any,
	});

	//确认收货
	const confirmReceipt = (e) => {
		const options = {
			type: 2,
			data: {
				opId: getItem(StorageKeys.OpenId),
				orderId:state.orderInfo.orderNo
			},
			method: "POST",
			showLoading: true,
		};
		requestNew(orderReceiveGoods, options).then((res) => {
			confirm(
				"您已完成订单收货",
				() => {
					uni.$emit("refreshOrder");
					uni.navigateBack();
				},
				"收货完成",
				false
			);
		});
	}
	//确认收货
	const confirmReceiptClick = (e) => {
		navTo("/pages/bluetooth/bluetooth?routeType=5&id=" + state.orderInfo.id); //去连接蓝牙
	};

	//获取订单详情
	const getOrderDetails = (id) => {
		const options = {
			type: 2,
			data: { id: id },
			method: "POST",
			showLoading: true,
		};
		requestNew(orderDetailQuery, options).then((res) => {
			console.log("获取订单详情",res)
			state.orderInfo =res.data;
		});
	};

	onLoad((options) => {
		getOrderDetails(options.id);
	});
</script>

<style>
	page {
		background: #E9EDF0;
		padding-bottom: 30rpx;
		font-size: 28rpx;
	}
</style>
<style lang="scss" scoped>
	.hint {
		font-size: 28rpx;
		color: #CCB375;
		text-align: center;
	}

	.btn {
		margin: 500rpx 40rpx 50rpx;
	}
	.bg-img {
		width: 100%;
		position: absolute;
		z-index: 0;
	
		.icon {
			width: 100%;
			height: 534rpx;
		}
	}
	.content {
		position: relative;
		color: white;
		padding:0 30rpx ;
		padding-top: 200rpx;
	}
	.status>text{
		font-weight: bold;
		font-size: 40rpx;
		line-height: 82rpx;
	}
	.order{
		height: 136rpx;
		background:linear-gradient(to bottom,rgb(188, 195, 205),#ffffff);;
		border-radius: 12rpx 12rpx 12rpx 12rpx;
		border: 1rpx solid #FFFFFF;
		color: black;
		font-weight: 400;
		font-size: 30rpx;
		margin-top: 80rpx;
		padding: 20rpx;
		box-sizing: border-box;
	}
	.order>.num{
		color: #111111;
	}
	.order>.name{
		color: #666666;
		margin-top: 10rpx;
	}
	.message{
		background: white;
		border-radius: 12rpx 12rpx 12rpx 12rpx;
		border: 1rpx solid #FFFFFF;
		color: #666666;
		margin-top: 30rpx;
		padding: 20rpx 20rpx 0 20rpx;
	}
	.message-top1{
		display: flex;
		padding-bottom: 20rpx;
		align-items: center;
	}
	.message-top1>.msg>view{
		line-height: 50rpx;
	}
	.message-top{
		display: flex;
		border-bottom: 2rpx solid #E6E9EB;
		padding-bottom: 20rpx;
	}
	.vehiclePlate{
		font-weight: 400;
		font-size: 30rpx;
		color: #111111;
	}
	.btn-wrap{
		position: fixed;
        bottom: 0;
		left: 0;
		background-color: white;
		width: 100%;
		border-radius: 30rpx 30rpx 0rpx 0rpx;
		padding: 0 50rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-evenly;
		box-sizing: border-box;
		height: 188rpx;
	}
</style>