<template>
	<view class="container">
	<view class="order-row" @click="goToOrderDetail()">
		<view class="shop-info" v-if="orderData">
			<text class="iconfont iconwode"></text>
			<text class="shop-name">{{orderData.nickname}}</text>
			<text class="order-type">{{getOrderType(orderData.orderStatus)}}</text>
		</view>
		<view class="goods-list" v-if="orderData">
			<view class="goods-row" v-for="(site, index) in orderData.products" :key="index">
				<image class="goods-img" :src="site.imgUrl" mode="aspectFill"></image>
				<view class="goods-info">
					<view class="goods-name">{{site.productName}}</view>
					<view class="goods-type">
						类型：{{site.productType == 1 ? '普通商品' : (site.productType == 2 ? '拍卖' : (site.productType == 3 ? '自助采摘' : '共享种植'))}}
					</view>
					<view class="goods-price-number">
						<text class="goods-unit">￥</text>
						<text class="goods-price">{{site.bizPrice}}</text>
						<text class="goods-number">x{{site.buyNum}}</text>
					</view>
				</view>
			</view>
		</view>
		<view class="pay-info" v-if="!isPick">总价￥{{getAllPrice()}}，实付￥{{orderData.paySum}}</view>
		<view class="handle-box" v-if="(tabIndex > 1 && tabIndex < 5) || (tabIndex == 5 && orderData.evaluateStatus == 2 && orderData.evaluateReplyStatus == 1)">
			<u-button size="medium" :plain="true" type="success" shape="circle" :ripple="true" :hair-line="false" class="handle-button"
			 v-if="tabIndex == 2 && orderData.auctionStatus != 1 && orderData.auctionStatus != 3" @click.stop="handleOrder(1)">发货</u-button>
			<u-button size="medium" :plain="true" type="success" shape="circle" :ripple="true" :hair-line="false" class="handle-button"
			 v-if="tabIndex == 3 || tabIndex == 4" @click.stop="handleOrder(2)">追踪物流</u-button>
			<u-button size="medium" :plain="true" type="success" shape="circle" :ripple="true" :hair-line="false" class="handle-button"
			 v-if="tabIndex == 5 && orderData.evaluateStatus == 2 && orderData.evaluateReplyStatus == 1" @click.stop="handleOrder(3)">回复</u-button>
			 <u-button size="medium" :plain="true" type="success" shape="circle" :ripple="true" :hair-line="false" class="handle-button"
			  v-if="!orderData.noPick && orderData.orderStatus == 2" @click.stop="handleOrder(6)">自助采摘</u-button>
		</view>
		<u-top-tips ref="uTips"></u-top-tips>
	</view>
	<view class="uni-popup-dialog" :hidden="show_qx">
		<view class="uni-dialog-title">
			<text class="uni-dialog-title-text">提示</text>
		</view>
		<view class="uni-dialog-content">
			<text class="uni-dialog-content-text">请在设置中开启摄像头权限和麦克风权限</text>
		</view>
		<view class="uni-dialog-button-group">
			<button class="uni-dialog-button uni-border-left" open-type="openSetting" @click="closeSetting">
				设置权限
			</button>
		</view>
	
	</view>
	<view class="qx_bg" :hidden="show_qx">
	</view>
	</view>
</template>

<script>
	const NET = require('@/utils/request')
	const API = require('@/config/api')
	export default {
		props: {
			tabIndex: {
				default: 1
			},
			isPick: {
				default: false
			},
			orderData: {
				default: {
					auctionStatus: 0,
					orderId: 0,
					orderStatus: 0,
					evaluateReplyStatus: 0,
					nickname: '',
					logisticsNum: '',
					payStatus: 0,
					paySum: 0,
					products: [{
						bizPrice: 0,
						buyNum: 0,
						imgUrl: '',
						originalPrice: 0,
						productId: 0,
						productName: '',
						productType: 0,
						shoppingcartId: 0,
						tenantCode: ''
					}],
					supplierName: '',
					noPick: true
					
				}
			},
		},
		data() {
			return {
				show_qx:true
			}
		},
		onLoad() {},
		methods: {
			closeSetting:function(){
				this.show_qx=true;
			},
			//  获取订单总价
			getAllPrice() {
				let price = this.orderData.products.reduce((total, site) => {
					return total + site.bizPrice * site.buyNum
				}, 0)
				return price.toFixed(2)
			},
			//  获取订单类型
			getOrderType(type) {
				switch (type) {
					case 1:
						return '待付款'
						break;
					case 2:
						return '待发货'
						break;
					case 3:
						return '已发货'
						break;
					case 4:
						return '已收货'
						break;
					case 5:
						return '已完成'
						break;
					default:
						return '已取消'
				}
			},
			//  获取拍卖状态
			getAuctionType(type) {
				switch (type) {
					case 1:
						return '竞拍中'
						break;
					case 2:
						return '竞拍成功'
						break;
					case 3:
						return '竞拍失败'
						break;
				}
			},
			//  操作区分
			handleOrder(type) {
				if (type == 1) {
					//  发货
					uni.navigateTo({
						url: '/pagesMain/bindOrder?orderId=' + this.orderData.orderId
					});
				} else if (type == 2) {
					//  追踪物流
					uni.navigateTo({
						url: '/pagesMain/logisticsDeatil?logisticCode=' + this.orderData.logisticsNum
					});
				} else if (type == 3) {
					//  回复
					uni.navigateTo({
						url: '/pagesMain/evaluateForm?orderId=' + this.orderData.orderId + '&mid='+this.orderData.mid
					});
				} else if (type == 6) {
					// 自助采摘
					var that=this;
					wx.getSetting({
					  success(res) {
						if (!res.authSetting['scope.camera']){
						  that.show_qx=false;
						}else if (!res.authSetting['scope.record']){
						  that.show_qx=false;
						}else{
							uni.navigateTo({
								url: '/pagesMedia/pickVideo?tenantCode=' + that.orderData.tenantCode + '&orderId=' + that.orderData.orderId
							});
						}
					  }
					})
					
				}
			},
			//  跳转订单详情
			goToOrderDetail() {
				if (!this.isPick) {
					uni.navigateTo({
						url: '/pagesMain/orderDetail?orderId=' + this.orderData.orderId + '&orderStatus=' + this.orderData.orderStatus
					});
				} else {
					//  自助采摘
					var that=this;
					wx.getSetting({
					  success(res) {
						if (!res.authSetting['scope.camera']){
						  that.show_qx=false;
						}else if (!res.authSetting['scope.record']){
						  that.show_qx=false;
						}else{
							uni.navigateTo({
								url: '/pagesMedia/pickVideo?tenantCode=' + that.orderData.tenantCode + '&orderId=' + that.orderData.orderId
							});
						}
					  }
					})
					
				}
			},
		}
	}
</script>

<style lang="less" scoped>
	.order-row {
		width: 100%;
		float: left;
		margin: 0 0 15px 0;
		background: #FFFFFF;
		border-radius: 10px;

		.shop-info {
			width: 100%;
			height: 48px;
			float: left;
			box-sizing: border-box;
			padding: 13px 15px 12px 15px;
			border-bottom: 1px solid #EEEEEE;
			line-height: 22px;

			.iconwode {
				font-size: 22px;
				color: #333333;
			}

			.shop-name {
				font-size: 15px;
				font-family: PingFang SC;
				color: #333333;
				margin: 0 8px 0 10px;
			}

			.iconshangjia {
				font-size: 12px;
				color: #999999;
			}

			.order-type {
				float: right;
				font-size: 15px;
				font-family: PingFang SC;
				color: #52A63A;
			}
		}

		.goods-list {
			width: 100%;
			float: left;
			box-sizing: border-box;
			padding: 10px 15px 0 15px;

			.goods-row {
				width: 100%;
				height: 90px;
				float: left;
				display: flex;
				margin-bottom: 10px;

				.goods-img {
					width: 90px;
					height: 90px;
					border-radius: 5px;
					object-fit: cover;
				}

				.goods-info {
					width: calc(100% - 106px);
					height: 90px;
					margin-left: 16px;

					.goods-name {
						width: 100%;
						height: 36px;
						float: left;
						font-size: 14px;
						font-family: PingFang SC;
						color: #333333;
						line-height: 18px;
						overflow: hidden;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-line-clamp: 2;
						-webkit-box-orient: vertical;
						word-wrap: break-word;
					}

					.goods-type {
						height: 20px;
						float: left;
						background: #F0F0F0;
						border-radius: 4px;
						padding: 0 8px;
						margin: 6px 0;
						font-size: 10px;
						font-family: PingFang SC;
						color: #666666;
						line-height: 20px;
					}

					.goods-price-number {
						width: 100%;
						height: 20px;
						float: left;
						line-height: 20px;
						font-family: PingFang SC;
						color: #333333;

						.goods-unit {
							font-size: 12px;
						}

						.goods-price {
							font-size: 15px;
							margin-right: 6px;
						}

						.goods-number {
							font-size: 12px;
						}
					}
				}
			}
		}

		.pay-info {
			width: 100%;
			float: left;
			box-sizing: border-box;
			padding: 20px 15px 16px 15px;
			font-size: 12px;
			font-family: PingFang SC;
			color: #333333;
			line-height: 16px;
			text-align: right;
		}

		.handle-box {
			width: calc(100% - 30px);
			height: 51px;
			float: left;
			margin: 0 15px;
			box-sizing: border-box;
			padding: 10px 0;
			border-top: 1px solid #EEEEEE;
			text-align: right;

			.handle-button {
				height: 30px;
				margin-left: 8px;
				margin-bottom: 10px;
				line-height: 28px;
				text-align: center;
				box-sizing: border-box;
				display: inline-block;
				border-radius: 15px;

				/deep/button {
					padding: 0 12px;
					border: 1px solid #BFBFBF !important;
					background-color: #FFFFFF!important;
					color: #333333 !important;
				}
			}
		}
	}
	.uni-popup-dialog {
		width: 80vw;
		border-radius: 15px;
		background-color: #fff;
		position: fixed;
		margin-left: 10vw;
		top: 34vh;
		z-index: 11;
	}
	
	.uni-dialog-title {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		justify-content: center;
		padding-top: 15px;
		padding-bottom: 5px;
	}
	
	.uni-dialog-title-text {
		font-size: 16px;
		font-weight: 500;
	}
	
	.uni-dialog-content {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		justify-content: center;
		align-items: center;
		padding: 5px 15px 15px 15px;
		text-align: center;
	}
	
	.uni-dialog-content-text {
		font-size: 14px;
		color: #6e6e6e;
	}
	
	.uni-dialog-button-group {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		border-top-color: #f5f5f5;
		border-top-style: solid;
		border-top-width: 1px;
	}
	
	.uni-dialog-button {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		    background: rgba(0, 0, 0, 0);
		    border: none;
		flex: 1;
		flex-direction: row;
		justify-content: center;
		align-items: center;
		height: 45px;
	}
	
	.uni-border-left {
		border-left-color: #f0f0f0;
		border-left-style: solid;
		border-left-width: 0px;
	}
	
	.uni-dialog-button-text {
		font-size: 14px;
	}
	
	.uni-button-color {
		color: #007aff;
	}
	
	.uni-dialog-input {
		flex: 1;
		font-size: 14px;
	}
	
	.uni-popup__success {
		color: #4cd964;
	}
	
	.uni-popup__warn {
		color: #f0ad4e;
	}
	
	.uni-popup__error {
		color: #dd524d;
	}
	
	.uni-popup__info {
		color: #909399;
	}
	.qx_bg{
		width: 100vw;
		height: 100vh;
		background: rgba(0, 0, 0, 0.25);
		position: fixed;
		top: 0px;
		left: 0px;
		z-index: 10;
	}
</style>
