<template>
	<view style="width: 100%;">
		<view class="card_ordermang" v-for="(item,index) in orderList" :key="index" @click="goOrderDetails(item)">
			<view class="head_ordermang space_between">
				<view class="waybill_title">运单号:<span>{{item.waybillNo}}</span></view>
				<span class="card_state" :style="{color:getState(item.status)}">{{orderStatus(item.status)}}</span>
			</view>
			<view class="card_specification">
				<view class="specification_title">
					<u-tag :text="item.temperatureInterval" plain size="mini" type="success"
						@click="goOrderDetails(item)"></u-tag>
				</view>
				<view class="specification_title">
					<u-tag :text="item.deliveryCondition" plain size="mini" type="primary"
						@click="goOrderDetails(item)"></u-tag>
				</view>
				<view class="specification_title">
					<u-tag :text="item.cargoType" plain size="mini" type="warning"
						@click="goOrderDetails(item)"></u-tag>
				</view>
			</view>
			<view class="title_ordermang"><span>收货地址:</span>{{item.consigneeAddressDetails}}</view>
			<view class="title_ordermang"><span>收货电话:</span>{{item.consigneeAddressPhone}}</view>
			<view class="title_ordermang"><span>下单时间:</span>{{item.orderTime}}</view>
			<view class="btn_printil"
				v-if="item.status == 2 && userInfo.userType === 'sys' || item.status == 3 && userInfo.userType === 'sys'"
				@click.stop="printBarCode(item)">
				<u-button size="small" type="primary" text="打印条码"></u-button>
			</view>
			<view class="btn_printil" v-if="item.status == 8 && userInfo.userType == 'sys'"
				@click.stop="humidityRecording(item)">
				<u-button size="small" type="warning" text="打印温湿度记录"></u-button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: 'xOrderManagement',
		props: {
			// 订单列表
			orderList: {
				type: Array,
				default: () => [],
			},
			userInfo: {
				type: Object,
				default: () => {},
			}
		},
		data() {
			return {}
		},
		mounted() {
			// console.log(this.userInfo, 26)
		},
		methods: {
			// 打印条码
			printBarCode(value) {
				this.$cache.setCache('commodity', JSON.stringify(value))
				uni.navigateTo({
					url: '/pages/order/quantum?waybillNo=' + value.waybillNo + '&printType=barCode'
				});
			},
			// 打印温湿度记录
			humidityRecording(value) {
				this.$cache.setCache('commodity', JSON.stringify(value))
				uni.navigateTo({
					url: '/pages/order/quantum?waybillNo=' + value.waybillNo + '&printType=record'
				});
			},
			// 订单详情
			goOrderDetails(value) {
				this.$cache.setCache('orderDetails', value)
				uni.navigateTo({
					url: '/pages/order/orderDetails?type=details'
				});
			},
			// 订单状态
			orderStatus(value) {
				if (this.userInfo.userType == 'sys') {
					if (this.userInfo.type == 2) {
						// 仓管
						if (value == 3) {
							return '未入库'
						} else if (value == 5) {
							return '已入库'
						} else {
							return '已出库'
						}
					} else if (this.userInfo.type == 3) {
						// 司机
						if (value == 2) {
							return '未装车'
						} else if (value == 4) {
							return '已装车'
						} else if (value == 6) {
							return '已下车'
						} else {
							return '已签收'
						}
					}
				} else {
					if (value == 1 || value == 2 || value == 3) {
						return '未发货'
					} else if (value == 4 || value == 5 || value == 6 || value == 7) {
						return '已发货'
					} else {
						return '已签收'
					}
				}
			},
			// 订单文字颜色
			getState(value) {
				if (this.userInfo.userType == 'sys') {
					if (this.userInfo.type == 2) {
						// 仓管
						if (value == 3) {
							return '#ff9900'
						} else if (value == 5) {
							return '#19be6b'
						} else {
							return '#606266'
						}
					} else if (this.userInfo.type == 3) {
						// 司机
						if (value == 2) {
							return '#ff9900'
						} else if (value == 4) {
							return '#19be6b'
						} else if (value == 6) {
							return '#19be6b'
						} else {
							return '#606266'
						}
					}
				} else {
					if (value == 1 || value == 2 || value == 3) {
						return '#ff9900'
					} else if (value == 4 || value == 5 || value == 6 || value == 7) {
						return '#19be6b'
					} else {
						return '#606266'
					}
				}
			}
		}
	}
</script>

<style lang="scss">
	.card_ordermang {
		background-color: #fff;
		padding: 20rpx;
		border-radius: 20rpx;
		margin: 20rpx;
	}

	.head_ordermang {
		margin-bottom: 10rpx;
	}

	.title_ordermang {
		margin-top: 10rpx;
		font-size: 26rpx;
		color: #909399;

		span {
			font-size: 26rpx;
			color: #909399;
			margin-right: 10rpx;
		}
	}

	.waybill_title {
		font-size: 32rpx;

		span {
			margin-left: 10rpx;
		}
	}

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

	.card_specification {
		display: flex;
		align-items: center;
	}

	.specification_title {
		margin-right: 20rpx;
	}

	.btn_printil {
		margin-top: 20rpx;
	}
</style>