<template>
	<view class="order-infos">
		<!-- #ifdef MP-WEIXIN -->
		<view class="topbar"
			:style="rect?'height:'+rect.height+'px;line-height:'+rect.height+'px;margin-top:'+rect.top+'px':''">
			<!-- #endif -->
			<!-- #ifndef MP-WEIXIN -->
			<view class="topbar" :style="statusBarHeight?'margin-top:'+statusBarHeight+'px':''">
				<!-- #endif -->
				<view class="back-icon" :style="rect?'padding:'+(rect.height-24)+'rpx 20rpx':''">
					<u-icon name="arrow-left" size="24" color="#ffffff" @click="pageBack"></u-icon>
				</view>
				混装详情
			</view>
			<view class="after">
				<view class="order-info-card">
					<view class="order-card">
						<view class="order-info-title">
							<image class="img" src="../../subpages/static/czzn-img/order/orderInfo-tenant.png"
								mode="scaleToFill" />
							<view class="mid">
								<view class="info">
									<span class="label">
										{{$t('spare.orderCode')}}
									</span>
									<span class="type" v-if="orderInfo.orderType == '1'">{{ $t('order.temp') }}</span>
									<span class="type" v-if="orderInfo.orderType == '2'">{{ $t('order.fixed') }}</span>
									<!-- 									<view class="order-type" v-if="orderInfo.isMain==2">
										<u-tag :text="$t('order.mixed')" type="success"></u-tag>
									</view> -->
								</view>
								<text class="code">{{ orderInfo.code || '' }}</text>
							</view>
							<view class="orderStatus-info" v-if="orderInfo.orderType != '4'">
								<u--image width="100rpx" height="88rpx" v-if="orderInfo.orderStatus == 0"
									src="/subpages/static/czzn-img/state/not-factory.png"></u--image>
								<u--image width="100rpx" height="88rpx"
									v-if="orderInfo.orderStatus == 1 && orderInfo.weighingStatus == 0"
									src="/subpages/static/czzn-img/state/in-factory.png"></u--image>
								<u--image width="100rpx" height="88rpx" v-if="orderInfo.orderStatus == 2"
									src="/subpages/static/czzn-img/state/completed.png"></u--image>
								<u--image width="100rpx" height="88rpx"
									v-if="orderInfo.orderStatus == 1 && orderInfo.weighingStatus != 0"
									src="/subpages/static/czzn-img/state/weighed.png"></u--image>
								<u--image width="100rpx" height="88rpx" v-if="orderInfo.orderStatus == 4"
									src="/subpages/static/czzn-img/state/cancellation.png"></u--image>
							</view>
							<!-- <span class="type" v-if="orderInfo.orderType == '1'">{{ $t('order.temp') }}</span>
						<span class="type" v-if="orderInfo.orderType == '2'">{{ $t('order.fixed') }}</span> -->
							<view class="orderStatus-info" v-if="orderInfo.orderType == '4'">
								<u--image width="100rpx" height="88rpx" v-if="orderInfo.orderStatus == 0"
									src="/subpages/static/czzn-img/state/no-take-order.png"></u--image>
								<u--image width="100rpx" height="88rpx" v-if="orderInfo.orderStatus == 1"
									src="/subpages/static/czzn-img/state/start-take-order.png"></u--image>
								<u--image width="100rpx" height="88rpx" v-if="orderInfo.orderStatus == 2"
									src="/subpages/static/czzn-img/state/completed.png"></u--image>
								<u--image width="100rpx" height="88rpx"
									v-if="orderInfo.enabledMarkType == 1 || orderInfo.orderStatus == 4"
									src="/subpages/static//czzn-img/state/cancellation.png"></u--image>
							</view>
						</view>
						<view class="order-card-info">

							<p class="cell">
								<text class="label">{{ $t('order.orderDate') }}</text>
								<text class="info">{{ orderInfo.setDate || '' }}</text>
							</p>
							<p class="cell">
								<text class="label">{{ $t('order.vehicleType') }}</text>
								<text class="info"
									v-if="orderInfo.vehicleType == '101'">{{ $t('order.saleOrder') }}</text>
								<text class="info"
									v-if="orderInfo.vehicleType == '102'">{{ $t('order.purchaseOrder') }}</text>
								<text class="info"
									v-if="orderInfo.vehicleType == '103'">{{ $t('order.materialsOrder') }}</text>
								<text class="info"
									v-if="orderInfo.vehicleType == '104'">{{ $t('order.transferOrder') }}</text>
							</p>
							<p class="cell">
								<text class="label">{{ $t('order.companyName') }}</text>
								<text class="info">{{ orderInfo.companyName || '' }}</text>
							</p>
							<p class="cell">
								<text class="label">{{ $t('order.driver') }}</text>
								<text class="info">{{ orderInfo.driver || '' }}</text>
							</p>
							<p class="cell">
								<text class="label">{{ $t('order.vehicle') }}</text>
								<text class="info">{{ orderInfo.vehicle || '' }}</text>
							</p>

							<template
								v-if="orderInfo.orderStatus != 0 && orderInfo.weighingStatus == 1">
								<p class="cell">
									<text class="label">{{ $t('order.tareWeight') }}</text>
									<text class="info">{{ orderInfo.tareWeight || '0' }}</text>
								</p>
							</template>
							<template v-if="orderInfo.orderStatus != 0 && orderInfo.weighingStatus == 1">
								<p class="cell">
									<text class="label">{{ $t('order.inTime') }}</text>
									<text class="info">{{ orderInfo.inTime || '' }}</text>
								</p>
							</template>
							<template v-if="orderInfo.orderStatus != 0 && orderInfo.weighingStatus == 2">
								<p class="cell">
									<text class="label">{{ $t('order.outTime') }}</text>
									<text class="info">{{ orderInfo.outTime || '' }}</text>
								</p>
							</template>
							<template v-if="orderInfo.orderStatus == 2">
								<p class="cell">
									<text class="label">{{ $t('order.outDate') }}</text>
									<text class="info">{{ orderInfo.outDoorTime || '' }}</text>
								</p>
							</template>
							<template v-if="orderInfo.orderStatus == 2">
								<p class="cell" v-if="orderInfo.vehicleType=='101'||orderInfo.vehicleType=='102'">
									<text class="label"
										v-if="orderInfo.vehicleType=='101'">{{ $t('order.isBack') }}</text>
									<text class="label"
										v-if="orderInfo.vehicleType=='102'">{{ $t('order.isReturn') }}</text>
									<text class="info"
										:style="orderInfo.backFlag&&orderInfo.backFlag=='1'?'color:#3275F5;font-weight:bold':''">{{ orderInfo.backFlag&&orderInfo.backFlag=='1'?$t('driver.yes'):$t('driver.no') }}</text>
								</p>
							</template>
							<template>
								<p class="cell">
									<text class="label">{{ $t('order.endDate') }}</text>
									<text class="info">{{ orderInfo.orderValidDate || '永久' }}</text>
								</p>
							</template>
						</view>
					</view>
					<u-divider :text="$t('order.mixedMaterial')" textColor="#2979ff" lineColor="#2979ff"></u-divider>
					<view class="order-card"  style="border-bottom: 4rpx dashed #ccc;" v-for="(item, index) in orderHaxMixedList" :key="index">
						<!--<view class="order-info-title">
							<image class="img" src="../../subpages/static/czzn-img/order/orderInfo-tenant.png"
								mode="scaleToFill" />
							 <view class="mid">
								<view class="info">
									<span class="label">
										{{$t('spare.orderCode')}}
									</span>
									<span class="type" v-if="item.orderType == '1'">{{ $t('order.temp') }}</span>
									<span class="type" v-if="item.orderType == '2'">{{ $t('order.fixed') }}</span>
									<view class="order-type">
										<u-tag :text="$t('order.suppOrder')" type="error"></u-tag>
									</view>
								</view>
								<text class="code">{{ item.code || '' }}</text> 
							</view>
			 				<view class="orderStatus-info" v-if="item.orderType != '4'">
								<u--image width="100rpx" height="88rpx" v-if="item.orderStatus == 0"
									src="/subpages/static/czzn-img/state/not-factory.png"></u--image>
								<u--image width="100rpx" height="88rpx"
									v-if="item.orderStatus == 1 && item.weighingStatus == 0"
									src="/subpages/static/czzn-img/state/in-factory.png"></u--image>
								<u--image width="100rpx" height="88rpx" v-if="item.orderStatus == 2"
									src="/subpages/static/czzn-img/state/completed.png"></u--image>
								<u--image width="100rpx" height="88rpx"
									v-if="item.orderStatus == 1 && item.weighingStatus != 0"
									src="/subpages/static/czzn-img/state/weighed.png"></u--image>
								<u--image width="100rpx" height="88rpx" v-if="item.orderStatus == 4"
									src="/subpages/static/czzn-img/state/cancellation.png"></u--image>
							</view> 
						</view>-->
						<view class="order-card-info">

							<!-- 		<p class="cell">
								<text class="label">{{ $t('order.orderDate') }}</text>
								<text class="info">{{ item.setDate || '' }}</text>
							</p> -->
							<!-- 	<p class="cell">
								<text class="label">{{ $t('order.vehicleType') }}</text>
								<text class="info" v-if="item.vehicleType == '101'">{{ $t('order.saleOrder') }}</text>
								<text class="info"
									v-if="item.vehicleType == '102'">{{ $t('order.purchaseOrder') }}</text>
								<text class="info"
									v-if="item.vehicleType == '103'">{{ $t('order.materialsOrder') }}</text>
								<text class="info"
									v-if="item.vehicleType == '104'">{{ $t('order.transferOrder') }}</text>
							</p> -->
							<view class="cell">
								<text class="label">{{ $t('order.companyName') }}</text>
								<text class="info">{{ item.companyName || '' }}</text>
							</view>
							<view class="cell">
								<text class="label">{{ $t('order.materialName') }}</text>
								<text
									class="info">{{ item.materialName || '' }}[{{ item.orderNumber || '0' }}{{$t('customer_meter.unitT') }}]</text>
							</view>
							<view class="cell" v-if="userType=='4'">
								<p class="info" v-if="!item.queueId && item.weighingStatus=='1'">
									<button type='primary' shape="circle" color='#CCCCCC' size="small"
										@click="onAddQueueClick(item)">
										{{ $t('mine.load')+$t('mine.queue') }}
									</button>
								</p>
							</view>
							<!-- 		<p class="cell">
								<text class="label">{{ $t('order.orderNumber') }}</text>
								<text class="info">{{ item.orderNumber || '0' }}{{$t('customer_meter.unitT') }}</text>
							</p> -->
							<!-- <p class="cell">
								<text class="label">{{ $t('order.driver') }}</text>
								<text class="info">{{ item.driver || '' }}</text>
							</p>
							<p class="cell">
								<text class="label">{{ $t('order.vehicle') }}</text>
								<text class="info">{{ item.vehicle || '' }}</text>
							</p>
							<template v-if="item.orderStatus != 0 && item.weighingStatus != 0">
								<p class="cell">
									<text class="label">{{ $t('order.tareWeight') }}</text>
									<text class="info">{{ item.tareWeight || '0' }}</text>
								</p>
								<p class="cell">
									<text class="label">{{ $t('order.grossWeight') }}</text>
									<text class="info">{{ item.grossWeight || '0' }}</text>
								</p>
							</template>
							<template>
								<p class="cell">
									<text class="label">{{ $t('order.netWeight') }}</text>
									<text class="info">{{ item.netWeight || '0' }}</text>
								</p>
							</template>
							<template v-if="item.orderStatus != 0 && item.weighingStatus == 1">
								<p class="cell">
									<text class="label">{{ $t('order.inTime') }}</text>
									<text class="info">{{ item.inTime || '' }}</text>
								</p>
							</template>
							<template v-if="item.orderStatus != 0 && item.weighingStatus == 2">
								<p class="cell">
									<text class="label">{{ $t('order.outTime') }}</text>
									<text class="info">{{ item.outTime || '' }}</text>
								</p>
							</template>
							<template v-if="item.orderStatus == 2">
								<p class="cell">
									<text class="label">{{ $t('order.outDate') }}</text>
									<text class="info">{{ item.outDoorTime || '' }}</text>
								</p>
							</template> -->

						</view>
					</view>
				</view>
			</view>
			<u-toast ref="loadingToast"></u-toast>
		</view>
</template>

<script>
	import {
		getOrderInfo,
		getOrderMixedInfo,
		createQueue,
	} from '../../api/order'
	export default {
		data() {
			return {
				orderInfo: {},
				orderHaxMixedList: [],
				rect: undefined,
				statusBarHeight: null,
				options: {},
				userType:"0",
			}
		},
		onLoad(options) {
			this.options = options;
			//3：客商，4：司机
			this.userType = this.options.userType
			this.bindOrderInfo()
			let sysInfo = uni.getSystemInfoSync(); //状态栏的高度
			this.statusBarHeight = sysInfo.statusBarHeight;
			// #ifdef MP-WEIXIN
			this.rect = wx.getMenuButtonBoundingClientRect();
			// #endif
			console.log(this.rect, this.statusBarHeight);
		},
		methods: {
			bindOrderInfo() {
				getOrderInfo(this.options).then(res => {
					if (res.statusCode == 200) {
						this.orderInfo = res.data.data
						console.log("当前订单信息、", this.orderInfo);
						this.bindMixedOrderInfo();
					}
				})
			},
			bindMixedOrderInfo() {
				getOrderMixedInfo(this.options).then(res => {
					if (res.statusCode == 200) {
						this.orderHaxMixedList = res.data.data
						console.log("获取到已拼车订单信息、", this.orderHaxMixedList);
					}
				})
			},
			pageBack() {
				uni.navigateBack({
					delta: 1
				})
			},
			//订单作废
			onAddQueueClick(item) {
				let that = this
				uni.showModal({
					content: that.$t('driver.startLoad'),
					showCancell: true,
					success: function(res) {
						if (res.confirm) {
							let data = {
								orderId: item.id
							};
							that.$refs.loadingToast.show({
								type: "loading",
								message: that.$t('base.common.loading'),
								duration: "1000000"
							})
							createQueue(data).then(res => {
								that.$refs.loadingToast.hide()
								if (res.statusCode == 200) {
									uni.showToast({
										title: that.$t('mine.operateOk'),
										icon: 'none',
										duration: 2000
									})
									that.getOrderInfo()
								}
							}).catch(res => {
								debugger
								that.$refs.loadingToast.hide()
							})

						} else if (res.cancell) {
							that.$refs.loadingToast.hide()
							console.log('用户点击取消');
						}
					}
				});
			},
		}
	}
</script>
<style>
	/* #ifndef APP-NVUE */
	view {
		display: flex;
		box-sizing: border-box;
		flex-direction: column;
	}

	page {
		box-sizing: border-box;
		/* padding: 40rpx 40rpx 80rpx; */
		height: 100%;
		background: url('../../subpages/static/czzn-img/order/orderInfo-bg.jpg') no-repeat;
		background-size: 750rpx auto;
		background-color: #f5f7fa;
	}

	/* #endif*/
</style>
<style lang="scss" scoped>
	@import '../../common/css/public.scss';
</style>