<template>
	<view>
		<view class="inner-box">
			<!-- 商品列表 -->
			<view class="goods-list">
				<view v-for="(item,index) in carts" :key="index" class="item" @click="showDetail(item)">
					<view class="img-box">
						<image :src="item.productImage" mode="aspectFill"></image>
					</view>
					<view class="info-box">
						<view>
							<view class="name-box ellipsis2">
								<view class="tag">{{utils.getDictLabelName("storeProductType",item.productType)}}</view>{{item.productName}}
							</view>
							<view class="spec ellipsis2">{{item.productAttrName}}</view>
						</view>
						<view class="price-num">
							<view class="price">
								<text class="unit">¥</text>
								<text class="num">{{item.price.toFixed(2)}}</text>
							</view>
							<view class="num">x{{item.cartNum}}</view>
						</view>
					</view>
				</view>
				<!-- 小计 -->
				<view class="sub-total">
					<text class="label">订单金额：</text>
					<view class="price">
						<text class="unit">¥</text>
						<text class="num">{{price.totalPrice.toFixed(2)}}</text>
					</view>
				</view>
			</view>
			 
		</view>
		<!-- 底部按钮 -->
		<view class="btn-foot">
			<view class="right">
				<view class="total">
					<text class="label">实付金额：</text>
					<view class="price">
						<text class="unit">¥</text>
						<text class="num">{{price.payPrice.toFixed(2)}}</text>
					</view>
				</view>
				 
				<view class="btn" @click="submitOrder">支付{{price.payPrice.toFixed(2)}}</view>
			</view>
		</view>
		<view class="message-box" v-if="messageShow">
			<view class="left">
				<image src="/static/images/close24.png" mode="" @click="closeOrder()" ></image>
				<view class="text ellipsis">您有{{count0}}个待支付订单</view>
			</view>
			<view class="btn" @click="showOrder()">查看</view>
		</view>
	</view>
</template>

<script>
	import {getOrderCount} from '@/api/storeOrder'
	import {getSalesOrder,addUserCart} from '@/api/companyOrder.js'
	export default {
		data() {
			return {
				count0:0,
				messageShow:false,
				orderKey:null,
				price:{
					totalPrice:0.00,
					payPrice:0.00,
				},
				carts:[],
				
			}
		},
		onLoad(option) {
			if(this.utils.isLogin()){
				this.getOrderCount();
			}
			console.log("qxj option:"+JSON.stringify(option));
			this.orderKey=option.orderKey;
			this.getSalesOrder();
			 
		},
		methods: {
			showOrder(){
				this.utils.isLogin().then(res => {
					if(res){
						uni.navigateTo({
							url: '/pages_user/user/storeOrder?status=0'
						})
					}
				})
			},
			closeOrder(){
				this.messageShow=false;
			},
			getOrderCount(){
				getOrderCount().then(
					res => {
						if(res.code==200){
							this.count0=res.count0;
							if(this.count0>0){
								this.messageShow=true;
							}
						} 
					},
					rej => {}
				);
			},
			showDetail(item) {
				uni.navigateTo({
					url: './productShowDetails?productId='+item.productId
				})
			},
			getSalesOrder(item){
				var that=this;
				var data={createOrderKey:this.orderKey}
				getSalesOrder(data).then(
					res => {
						if(res.code==200){
							this.carts=res.carts;
							this.carts.forEach(function(element) {
								that.price.totalPrice+=element.price*element.cartNum;
							});
							that.price.payPrice=res.totalMoney
						}else{
							uni.showToast({
								icon:'none',
								title: res.msg,
							});
						}
					},
					rej => {}
				);
			},
			// 提交订单
			submitOrder() {
				this.utils.isLogin().then(res => {
					if(res){
						var data={createOrderKey:this.orderKey}
						addUserCart(data).then(
							res => {
								if(res.code==200){
									uni.navigateTo({
										url: '/pages_shopping/shopping/confirmCreateOrder?type=buy&cartIds='+res.cartIds.toString()+"&companyId="+res.companyId+"&companyUserId="+res.companyUserId+"&createOrderKey="+this.orderKey
									})
								}else{
									uni.showToast({
										icon:'none',
										title: res.msg,
									});
								}
							},
							rej => {}
						);
						//将购物车产品更新为自己的购物车 
					}
				})
				
			},
		}
	}
</script>

<style lang="scss">
	.inner-box{
		padding: 20upx 20upx 140upx;
		 
		.goods-list{
			margin-top: 20upx;
			padding: 0 30upx;
			background-color: #FFFFFF;
			border-radius: 16upx;
			.item{
				padding: 30upx 0;
				border-bottom: 1px solid #EDEEEF;
				display: flex;
				align-items: center;
				.img-box{
					width: 160upx;
					height: 160upx;
					margin-right: 30upx;
					image{
						width: 100%;
						height: 100%;
					}
				}
				.info-box{
					width: calc(100% - 190upx);
					height: 160upx;
					display: flex;
					flex-direction: column;
					justify-content: space-between;
					.name-box{
						font-size: 28upx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #111111;
						line-height: 40upx;
						.tag{
							display: inline-block;
							padding: 0 6upx;
							height: 30upx;
							background: linear-gradient(90deg, #66b2ef 0%,#018C39 100%);
							border-radius: 4upx;
							margin-right: 10upx;
							font-size: 22upx;
							font-family: PingFang SC;
							font-weight: bold;
							color: #FFFFFF;
							line-height: 30upx;
							float: left;
							margin-top: 7upx;
						}
					}
					.spec{
						margin-top: 10upx;
						font-size: 24upx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #999999;
						line-height: 1;
					}
					.price-num{
						display: flex;
						align-items: center;
						justify-content: space-between;
						.price{
							display: flex;
							align-items: flex-end;
							.unit{
								font-size: 24upx;
								font-family: PingFang SC;
								font-weight: 500;
								color: #111111;
								line-height: 1.2;
								margin-right: 4upx;
							}
							.num{
								font-size: 32upx;
								font-family: PingFang SC;
								font-weight: 500;
								color: #111111;
								line-height: 1;
							}
						}
						.num{
							font-size: 24upx;
							font-family: PingFang SC;
							font-weight: 500;
							color: #999999;
							line-height: 1;
						}
					}
				}
			}
			.sub-total{
				height: 88upx;
				display: flex;
				align-items: center;
				justify-content: flex-end;
				.label{
					font-size: 24upx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #999999;
				}
				.price{
					display: flex;
					align-items: flex-end;
					.unit{
						font-size: 24upx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #FF6633;
						line-height: 1.2;
						margin-right: 4upx;
					}
					.num{
						font-size: 32upx;
						font-family: PingFang SC;
						font-weight: bold;
						color: #FF6633;
						line-height: 1;
					}
				}
			}
		}
		.points{
			height: 88upx;
			padding: 0 30upx;
			background: #FFFFFF;
			border-radius: 16upx;
			 
			display: flex;
			align-items: center;
			justify-content: space-between;
			.left{
				display: flex;
				align-items: center;
				image{
					width: 28upx;
					height: 28upx;
					margin-right: 20upx;
				}
				.text{
					font-size: 28upx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #666666;
				}
			}
			.right{
				display: flex;
				align-items: center;
				.text{
					font-size: 28upx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #111111;
					 
				}
				image{
					margin-left: 15upx;
					width: 14upx;
					height: 24upx;
				}
			}
		}
		.remarks{
			height: 88upx;
			padding: 0 30upx;
			background: #FFFFFF;
			border-radius: 16upx;
			margin-top: 20upx;
			display: flex;
			align-items: center;
			input{
				width: 100%;
				font-size: 28upx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #000000;
			}
			.input{
				font-size: 28upx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #999999;
			}
		}
	}
	
	
	.btn-foot{
		box-sizing: border-box;
		width: 100%;
		height: 121upx;
		background: #FFFFFF;
		 
		display: flex;
		align-items: center;
		justify-content: flex-end;
		position: fixed;
		left: 0;
		bottom: 0;
		z-index: 99;
		.right{
			display: flex;
			align-items: center;
			.total{
				display: flex;
				align-items: flex-end;
				margin-right: 15upx;
				.label{
					font-size: 26upx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #999999;
					line-height: 1.5;
				}
				.price{
					display: flex;
					align-items: flex-end;
					.unit{
						font-size: 26upx;
						font-family: PingFang SC;
						font-weight: bold;
						color: #FF6633;
						line-height: 1.2;
						margin-right: 10upx;
					}
					.num{
						font-size: 32upx;
						font-family: PingFang SC;
						font-weight: bold;
						color: #FF6633;
						line-height: 1;
					}
				}
			}
			.btn{
				margin-right: 15upx;
				padding: 20rpx 30rpx;
				text-align: center;
				font-size: 30upx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #FFFFFF;
				background:#018C39;
				border-radius: 44upx;
			}
		}
	}
</style>
<style lang="less" scoped>
	.coupon {
	  height: 100%;
	}
	/*优惠券列表公共*/
	.coupon-list {
	}
	.coupon-list .item {
	  display: flex;
	  flex-direction: column;
	  justify-content: center;
	  align-items: center;
	  width: 100%;
	  height: 1.7 * 100rpx;
	  margin-bottom: 0.16 * 100rpx;
	}
	
	.coupon-list .item .money {
	  background-size: 100% 100%;
	  width: 2.4 * 100rpx;
	  height: 100%;
	  color: #fff;
	  font-size: 0.36 * 100rpx;
	  font-weight: bold;
	  text-align: center;
	  display: flex;
	  flex-direction: column;
	  align-items: center;
	  justify-content: center;
	  position: relative;
	  
	}
	.coupon-list .item .money .img{
	  position: absolute;
	  width: 2.4 * 100rpx;
	  height: 100%;
	  color: #fff;
	  
	}
	
	.coupon-list .item .money .num {
	  font-size: 0.6 * 100rpx;
	}
	.coupon-list .item .money .pic-num {
	  font-size: 20rpx;
	  z-index: 99;
	}

	
	.coupon-list .item .text {
	  width: 4.5 * 100rpx;
	  padding: 0 0.17 * 100rpx 0 0.24 * 100rpx;
	  background-color: #fff;
	  box-sizing: border-box;
	}
	
	.coupon-list .item .text .condition {
	  font-size: 0.3 * 100rpx;
	  color: #282828;
	  height: 0.93 * 100rpx;
	  line-height: 0.93 * 100rpx;
	  border-bottom: 1px solid #f0f0f0;
	}
	
	.coupon-list .item .text .data {
	  font-size: 0.2 * 100rpx;
	  color: #999;
	  height: 0.76 * 100rpx;
	}
	
	.coupon-list .item .text .data .bnt {
	  width: 1.36 * 100rpx;
	  height: 0.44 * 100rpx;
	  border-radius: 0.22 * 100rpx;
	  font-size: 0.22 * 100rpx;
	  color: #fff;
	  text-align: center;
	  line-height: 0.44 * 100rpx;
	  background-color: red;
	}
	
	.coupon-list .item .text .data .bnt.gray {
	  background-color: #ccc;
	}
	.message-box{
		box-sizing: border-box;
		width: 693upx;
		height: 84upx;
		background: #F3FFFD;
		border: 1px solid #C7E9E5;
		box-shadow: 0px 4upx 12upx 0px rgba(90, 203, 138, 0.16);
		border-radius: 16upx;
		position: fixed;
		left: 50%;
		transform: translateX(-50%);
		bottom: 128upx;
		z-index: 99;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0 20upx 0 30upx;
		.left{
			width: 80%;
			display: flex;
			align-items: center;
			image{
				width: 24upx;
				height: 24upx;
				margin-right: 18upx;
			}
			.text{
				width: 90%;
				font-size: 28upx;
				font-family: PingFang SC;
				font-weight: 500;
				color:#018C39;
			}
		}
		.btn{
			width: 100upx;
			height: 48upx;
			line-height: 48upx;
			text-align: center;
			font-size: 24upx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
			border: 1px solid #D2E6FF;
			background: linear-gradient(135deg, #66b2ef 0%,#018C39 100%);
			border-radius: 24upx;
			margin-left: 30upx;
		}
	}
</style>

