<template>
	<!-- 运单详情 -->
	<view>
		<u-navbar title="" autoBack placeholder></u-navbar>
		<view class="card_order_detail">
			<view class="orderNumber">
				<view class="card_order_title">
					<span>运单号:</span>{{orderList.waybillNo}}
				</view>
				<span class="card_state"
					:style="{color:getState(orderList.status)}">{{orderStatus(orderList.status)}}</span>
			</view>
			<view class="title_delivery" v-if="productData && productData.length > 0">商品信息:</view>
			<x-productList :list="productData"></x-productList>
			<view class="card_prescription" v-if="orderList.prescription && orderList.prescription.length > 0">
				<span>处方:</span>
				<view style="display: flex;align-items: center;flex-wrap: wrap;">
					<view style="margin-top: 10rpx;margin-right: 20rpx;" v-for="(item,index) in orderList.prescription" :key="index">
						<u-image radius="4" :showLoading="true" :src="item" width="100px" height="80px"
							@click="getUrl(item)"></u-image>
					</view>
				</view>
			</view>
			<view class="title_delivery">收件人:</view>
			<x-orderCard :list="consigneeList"></x-orderCard>
			<view class="title_delivery" v-if="userInfo.type != 3">配送人:</view>
			<x-orderCard :list="delivererList" :deliverer="false" v-if="userInfo.type != 3"></x-orderCard>
			<view class="title_delivery">复核人:</view>
			<x-orderCard :list="senderList" :deliverer="false"></x-orderCard>
			<view class="card_humiture">
				<view class="title_claim" v-if="orderList.coolerBox.id">
					<span>保温箱:</span>
					<view style="width: auto;">
						<u-tag :text="orderList.coolerBox.name" plain size="mini" type="success"></u-tag>
					</view>
				</view>
				<view class="title_claim" v-if="orderList.iceRaftCode && orderList.iceRaftCode.length > 0">
					<span>冰排:</span>
					<view style="width: auto;margin-left: 10rpx;" v-for="(item1,index1) in orderList.iceRaftCode">
						<u-tag :text="item1" plain size="mini"></u-tag>
					</view>
				</view>
				<view class="card_anti_dismantle" v-if="orderList.tamperProofLabelImg">
					<span>防拆标签图片:</span>
					<view style="display: flex;">
						<view style="margin-right: 20rpx;" v-for="(item,index) in getimagetamper(orderList)"
							:key="index">
							<u-image radius="4" :showLoading="true" :src="item" width="80px" height="80px"
								@click="getUrl(item)"></u-image>
						</view>
					</view>
				</view>
				<view class="title_claim" v-if="orderList.tamperProofLabel">
					<span>防拆标签码:</span>
					<view style="width: auto;font-size: 28rpx;">
						{{orderList.tamperProofLabel}}
					</view>
				</view>
				<view class="title_claim"><span>备注:</span>{{orderList.remark}}</view>
			</view>
			<view class="card_examine" v-if="orderList.status != 3">
				<view class="examine_title center_in">
					<view class="line_back" @click="logistics">查看物流详情</view>
				</view>
				<view class="examine_title center_in">
					<view class="line_back" @click="goHumiture">查看温湿度</view>
				</view>
			</view>
			<view class="card_humiture1" v-if="orderList.status == 8">
				<view class="order_iamge_item" v-for="(item,index) in srcList" :key="index">
					<u-image :showLoading="true" :src="item.url" width="80px" height="80px" radius="2"></u-image>
					<view class="order_item_title">{{item.title}}</view>
				</view>
			</view>
			<view class="safeBottom" style="width: 100%;height: 180rpx;"></view>
		</view>
		<view class="btn_distribute" v-if="orderList.status == 4 && orderList.is_secondary_distribution">
			<u-button style="margin-bottom: 20rpx;" type="primary" @click="coolingRelease">分配订单</u-button>
		</view>
		<u-overlay :show="overlayShow" @click="overlayShow = false">
			<view class="center_in" style="width: 100%;height: 100%;">
				<image style="width: 100%;height: auto;" :src="overlayURL" mode="widthFix"></image>
			</view>
		</u-overlay>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				type: 'details',
				delivererList: {
					name: '',
					phone: '',
				},
				senderList: {
					name: '',
					phone: '',
				},
				consigneeList: {
					name: '',
					phone: '',
					address: '',
				},
				orderList: {},
				srcList: [{
					title: '运单签收图片',
					url: '',
				}, {
					title: '随货通行单图片',
					url: '',
				}, {
					title: '冷链交接单图片',
					url: '',
				}],
				userInfo: {},
				productData: [],
				overlayShow: false,
				overlayURL: '',
			}
		},
		onLoad(value) {
			var userInfo = this.$cache.getCache('userInfo')
			this.userInfo = userInfo
			this.type = value.type
		},
		onShow() {
			var orderList = this.$cache.getCache('orderDetails')
			this.orderList = orderList
			this.productData = orderList.drugs
			this.senderList.name = orderList.reCheck.nickName
			this.senderList.phone = orderList.reCheck.phone
			this.consigneeList.name = orderList.consigneeAddressName
			this.consigneeList.phone = orderList.consigneeAddressPhone
			this.consigneeList.address = orderList.consigneeAddressDetails
			this.delivererList.name = orderList.delivery.nickName
			this.delivererList.phone = orderList.delivery.phone
			if (orderList.status == 8) {
				const arr = orderList.ReceiptImg.split(',')
				this.srcList[0].url = arr[0]
				this.srcList[1].url = arr[1]
				this.srcList[2].url = arr[2]
			}
		},
		methods: {
			// 查看图片
			getUrl(event) {
				this.overlayURL = event
				this.overlayShow = true
			},
			// 分配订单
			coolingRelease() {
				uni.navigateTo({
					url: '/pages/order/distributionOrder?waybillNo=' + this.orderList.waybillNo
				});
			},
			// 物流详情
			logistics() {
				uni.navigateTo({
					url: '/pages/order/logisticsDetails'
				});
			},
			// 温湿度记录
			goHumiture() {
				uni.navigateTo({
					url: '/pages/order/humiture'
				});
			},
			// 运单状态
			orderStatus(value) {
				if (value == 3) {
					return '待配送'
				} else if (value == 4) {
					return '配送中'
				} else if (value == 5) {
					return '已送达'
				} else if (value == 6) {
					return '已拒收'
				}
			},
			// 运单文字颜色
			getState(value) {
				if (value == 3) {
					return '#9ddd54'
				} else if (value == 4) {
					return '#4bc7fc'
				} else if (value == 5) {
					return '#1cc723'
				} else if (value == 6) {
					return '#fe880e'
				}
			},
			getimagetamper(value) {
				let arr = value.tamperProofLabelImg.split(',')
				return arr
			},
		}
	}
</script>

<style lang="scss" scoped>
	.card_order_detail {
		margin: 20rpx;
	}

	.orderNumber {
		display: flex;
		justify-content: space-between;
		align-items: center;
		background-color: #fff;
		border-radius: 10rpx;
		padding: 15rpx;
	}

	.card_order_title {
		span {
			font-size: 28rpx;
			color: #909399;
			margin-right: 10rpx;
		}
	}

	.card_state {
		color: #606266;
		font-size: 30rpx;
	}

	.title_delivery {
		font-size: 30rpx;
		font-weight: 600;
		margin: 10rpx 0rpx 10rpx 10rpx;
	}

	.card_prescription {
		margin-top: 20rpx;
		padding: 20rpx;
		border-radius: 10rpx;
		background-color: #fff;

		span {
			font-size: 28rpx;
			color: #909399;
			margin-bottom: 10rpx;
		}
	}

	.card_humiture {
		margin-top: 30rpx;
		// border-radius: 20rpx;
		padding: 1rpx 20rpx;
		background-color: #fff;
		border-top-right-radius: 10rpx;
		border-top-left-radius: 10rpx;
	}

	.card_humiture1 {
		display: flex;
		justify-content: space-around;
		align-items: center;
		flex-wrap: wrap;
		margin-top: 10rpx;
		border-radius: 10rpx;
		padding: 20rpx;
		background-color: #fff;
	}

	.order_iamge_item {
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.order_item_title {
		font-weight: 600;
		margin-top: 10rpx;
		font-size: 26rpx;
	}

	.title_claim {
		display: flex;
		margin: 20rpx 0rpx 6rpx 0rpx;

		span {
			display: flex;
			align-items: center;
			font-size: 28rpx;
			color: #909399;
			margin-right: 10rpx;
		}
	}

	.line_back {
		font-size: 30rpx;
		margin: 20rpx 0rpx;
		color: #3c9cff;
	}

	.card_anti_dismantle {
		display: flex;
		flex-direction: column;

		span {
			font-size: 28rpx;
			color: #909399;
			margin-bottom: 10rpx;
		}
	}

	.card_ice_list {
		display: flex;
		flex-direction: row;
		flex-wrap: wrap;
	}

	.card_ice_item {
		margin-right: 10rpx;
		margin-bottom: 10rpx;
		padding: 6rpx 10rpx;
		border-radius: 6rpx;
		border: 1rpx solid #e7e6e4;
	}

	.ice_title {
		font-size: 28rpx;
	}

	.icon_ice {
		font-size: 34rpx;
		color: #19be6b;
		margin-right: 5rpx;
	}

	.ice_code {
		font-size: 24rpx;
	}

	.card_examine {
		display: flex;
		align-items: center;
		border-top: 1rpx solid #e7e6e4;
		background-color: #fff;
		border-bottom-left-radius: 10rpx;
		border-bottom-right-radius: 10rpx;
	}

	.examine_title {
		flex: 1;
		height: 80rpx;
	}

	.examine_title:nth-child(1) {
		border-right: 1rpx solid #e7e6e4;
	}

	.btn_distribute {
		position: fixed;
		z-index: 2;
		bottom: 0;
		left: 0;
		right: 0;
		padding: 20rpx 30rpx 20rpx 30rpx;
		background-color: #fff;
		padding-bottom: constant(safe-area-inset-bottom); //兼容 IOS<11.2
		padding-bottom: env(safe-area-inset-bottom); //兼容 IOS>11.2
		border-top: 1rpx solid #E4E7ED;
	}
</style>