<template>
	<view class="details clearfix">
		<view class="container-details" v-show="isRequest">
			<!-- 地址信息 -->
			<view class="address-section clearfix">
				<view class="address-content">
					<view class="info-item">
						<text class="label">买家名称：{{orderInfo.userInfo.name}}</text>
					</view>
					<view class="info-item">
						<text class="label">收货人：{{orderInfo.userInfo.receiver}}</text>
						<text class="label" :style="{marginLeft:40+'rpx'}">联系方式：{{orderInfo.userInfo.mobile}}</text>
					</view>
					<view class="info-item">
						<text class="label">收货地址：<text style="color: #666666;">{{orderInfo.userInfo.address}}</text></text>
					</view>
				</view>
				<image  src="../../../static/temp/line@3x.png" mode=""></image>
			</view>
			<!-- 商品 -->
			<view class="goods-list">
				<view class="goods-item clearfix">
					<view class="productlist" v-for="(pros,idx) in orderInfo.orderProductList" :key="idx">
						<view class="goods-pros-t">
							<view class="pros-left">
								<view class="pros-img"><image :src="pros.image" alt="" mode="aspectFill"/></view>
							</view>
							<view class="pros-product">
								<view class="producttitle">{{pros.aliasName ? pros.aliasName : ''}}</view>
								<view class="productspec">规格：{{pros.productUnit ? pros.productUnit : ''}}</view>
								<view class="product-view">
									<view class="view-num price">¥{{ pros.price | NumFormat }}</view>
									<view class="view-num num"> <text class="small">X</text> {{pros.num+pros.presentNum}}</view>
								</view>
								<view class="product-view">
									<view class="view-num">已发货：{{pros.shipmentsNum}}</view>
									<view class="view-num">已退货：{{pros.returnedNum}}</view>
									<view class="view-num">已取消：{{pros.actualCancelNum}}</view>
								</view>
							</view>	
						</view>
						<view class="product-total">
							<view class="total">
								合计： <text>¥{{ pros.totalAmount | NumFormat }}</text>
							</view>
						</view>	
					</view>	
					
					<view class="goods-pros-m" v-if="orderInfo.note">
						<view class="m-text">留言：</view>
						<view class="m-input">
							<view class="text">{{orderInfo.note ? orderInfo.note : ''}}</view>
						</view>	
					</view>
					<view class="goods-pros-b">
						<view class="count">共{{orderInfo.itemCount}}件商品</view>
						<view class="money">商品总额：<text class="red">¥{{orderInfo.productAmount | NumFormat}}</text> </view>
					</view>
				</view>
			</view>
			<!-- 订单信息 -->
			<view class="information-content clearfix">
				<view class="order-title">
					<view class="order-title-t">
						<view class="order-title-num">订单编号：{{ orderInfo.shopOrderNo }}</view>
						<view class="order-title-tip">结算状态：<text :style="{color:setStatusText(orderInfo.payStatus)}">{{ orderInfo.payStatus | payStatusType }}</text></view>
					</view>
					<view class="order-title-t">
						<view class="order-title-num">下单时间：{{ orderInfo.orderTime }}</view>
						<view class="order-title-tip">发货状态：<text class="status" :style="{color:setStatusText(orderInfo.receiptStatus)}">{{ orderInfo.sendOutStatus | sendOutStatusType }}</text></view>
					</view>
					<template v-if="isOpenInfoFlag">
						<view class="order-title-t">
							<view class="order-title-num">结算商品金额：<text class="red">¥{{orderInfo.shopProductAmount | NumFormat}}</text></view>
							<view class="order-title-tip">结算税费：<text class="red">¥{{orderInfo.shopTaxFee | NumFormat}}</text></view>
						</view>
						<view class="order-title-t">
							<view class="order-title-num">结算运费：<text class="red">¥{{orderInfo.shopPostFee | NumFormat}}</text></view>
							<view class="order-title-tip">总结算金额：<text class="red">¥{{orderInfo.shouldPayShopAmount | NumFormat}}</text></view>
						</view>
						<view class="order-title-t">
							<view class="order-title-num">已结算金额：<text class="red">¥{{orderInfo.payedShopAmount | NumFormat}}</text></view>
							<view class="order-title-tip"></view>
						</view>
					</template>	
				</view>
				<view class="order-more" v-if="isOpenFlag">
					<view class="btnInfo" @click="OpenFlagShow">查看更多<label class="iconfont icon-xiangxiajiantou"></label></view>
				</view>
			</view>
			<!-- 结算记录 -->
			<view class="information-record clearfix">
				<view class="record-title">
					<view class="record-title-l">结算记录</view>
				</view>
				<view class="record-list" v-if="payShopRecord.length>0">
					<view class="record-item" v-for="(item,index) in payShopRecord" :key="index">
						<view class="item-time mm">￥{{item.payAmount | NumFormat}}</view>
						<view class="item-time tt">{{item.payTime ? item.payTime : '无'}}</view>
					</view>
				</view>
				<view class="record-empty" v-else>
				 	<text>暂无结算记录</text>
				</view>
			</view>	
			<!-- 底部button -->
			<order-button ref="orderButton" 
						  v-if= "isRequest" 
						  :status= "btnStatus" 
						  :shareCode= "shareCode"
						   @buttonConfirm="handButtonConfirm">
			</order-button>
		</view>
		<share-alert  :shopOrderId="shopOrderId" 
					  v-if="isShareModal"  
					  @shareConfirm ='onShareAppMessage'>
		</share-alert>		
	</view>
</template>

<script>
	import headerBack from '@/components/cm-module/headerNavbar/header-back' 		 	 //自定义导航
	import orderAddress from '@/components/cm-module/orderDetails/orderAddress' 		 //地址信息
	import goodsList from '@/components/cm-module/orderDetails/goodsList'		 		 //商品列表
	import orderButton from '@/components/cm-module/orderDetails/supplierDetaileButton'	//底部按钮
	import shareAlert from '@/components/cm-module/modelAlert/supplierShareAlert'	  //分享弹窗
	export default {
		components:{
			headerBack,
			orderAddress,
			goodsList,
			orderButton,
			shareAlert,
		},
		data() {
			return {
				nvabarData: {		//顶部自定义导航
					showCapsule: 1, // 是否显示左上角图标  1表示显示  0表示不显示,
					showSearch: 0,
					title: '订单详情', // 导航栏 中间的标题
					haveBack:false,
					textLeft:this.$store.state.isIphone
				},
				windowHeight: '',
				isIphoneX:this.$store.state.isIphoneX,
				CustomBar:this.CustomBar,// 顶部导航栏高度
				state:0,
				userID:'',
				shopOrderId:'',
				shareCode:'',				//分享码
				payStatus:0,
				btnStatus:0,				//按钮组件状态
				isRequest:false,			//是否加载完成渲染子组件
				isOrderShare:false,
				isShareModal:false,
				orderInfo:{},				//订单信息
				payShopRecord:[],			//结算记录
				isOpenInfoFlag:false,
				isOpenFlag:true
				
			}
		},
		onLoad(option){
			console.log(option.shopOrderId)
			this.shopOrderId = option.shopOrderId
			this.initShopOrderDetails()
		},
		filters:{
			sendOutStatusType(value) {
				if (value === null) {
				  return '未发货'
				} else if(value === 1) {
				  return '待发货'
				} else if(value === 2) {
				  return '部分发货'
				} else{
				  return '已发货'
				}
			},
			payStatusType(value) {
				if (value === 1) {
				  return '待结算'
				} else if (value === 2) {
				  return '部分结算'
				} else {
				  return '已结算'
				}
			},
			NumFormat(value) {//处理金额
				//处理金额
				if (!value) return '0.00'
				let number = parseFloat(Number(value))
				return number
			},
		},	
		methods: {
			initShopOrderDetails(){//初始化页面数据@参数：订单ID
				this.ShopService.GetShopOrderDetails({ shopOrderId : this.shopOrderId }).then(response =>{
					this.orderInfo  = response.data.shopOrder
					this.btnStatus = this.orderInfo.sendOutStatus
					this.payShopRecord = response.data.payShopRecord
					this.isRequest = true
				}).catch(err =>{
					this.$util.msg(err.msg,2000)
				})
			},
			handButtonConfirm(data){//监听点击时间的按钮类型并执行...
				this.handShowAlert(data)
			},
			handShowAlert(type){//判断点击的按钮类型并执行...
				switch(type){
					case 'record':
						this.$api.navigateTo('/pages/supplier/deliver/deliver-record?shopOrderId='+this.shopOrderId)
						break
					case 'deliver':
						this.$api.navigateTo('/pages/supplier/deliver/deliver-goods?shopOrderId='+this.shopOrderId)
						break
				}
			},
			setStatusText(status){
				let textColor=''
				switch(status){
					case 1:
						textColor = '#FF2A2A'
						break
					case 2:
						textColor = '#E15616'
						break
					case 3:
						textColor = '#38CB3D'
						break
				}
				return textColor
			},
			OpenFlagShow(){//查看更多
				this.isOpenInfoFlag = true
				this.isOpenFlag = false
			},
			onShareCode(){
				this.isShareModal = true
			},
			onShareAppMessage(res){//分享转发
				this.isShareModal = false
				if (res.from === 'button') {
					// 来自页面内转发按钮
			    }
				return {
					title: '您有订单待处理，请点击查看~',
					path: `/pages/supplier/login/share-info?authority=3&shopOrderId=${this.shopOrderId}`,
					imageUrl:'https://img.caimei365.com/group1/M00/03/95/Cmis216Sk_SABnOFABZCgCzFV_g063.png'
				}
			}
		},
		onPullDownRefresh() {//下拉刷新
			this.initShopOrderDetails()
			uni.stopPullDownRefresh()
		},
		onShow() {

		}
	}
</script>

<style lang="scss">
	page {
		background:#F7F7F7;
	}
	.details{
		padding-bottom: 130rpx;
		width: 100%;
		height: auto;
	}
	.container-details{
		background:#F7F7F7;
	}
	.information-content{
		width: 702rpx;
		height: auto;
		padding:10rpx 24rpx;
		background: #FFFFFF;
		margin: 24rpx 0;
		.order-more{
			width: 100%;
			height: auto;
			float: left;
			.btnInfo{
				width: 140rpx;
				height: 40rpx;
				border: 2rpx solid #e1e1e1;
				border-radius: 6rpx;
				padding: 5rpx;
				text-align: center;
				color: #b2b2b2;
				margin: 20rpx auto;
				font-size:  $font-size-24;
				.iconfont{
					position: relative;
					top: 5rpx;
					right: -3rpx;
				}
			}
		}
		.order-title{
			width: 100%;
			height: auto;
			float: left;
			.order-title-t{
				width: 100%;
				height: 58rpx;
				float: left;
				font-size: $font-size-28;
				line-height: 58rpx;
				.order-title-num{
					float: left;
					text-align: left;
					color: #666666;
					.red{
						color: #f94b4b;
						font-weight: bold;
					}
				}
				.order-title-tip{
					float: right;
					text-align: right;
					font-size: $font-size-28;
					color: #666666;
					.red{
						color: #f94b4b;
						font-weight: bold;
					}
					.status{
						color: $color-system;
					}
				}
			}
			.order-title-b{
				width: 100%;
				height: 40rpx;
				float: left;
				margin-top: 8rpx;
				font-size: $font-size-28;
				line-height: 40rpx;
				color: #999999;
				text-align: left;
			}
		}
		.info-item{
			height: 58rpx;
			width: 100%;
			display: flex;
			.item-view{
				flex: 1;
				line-height: 58rpx;
				font-size: $font-size-28;
				color: #333333;
			}
		}
	}
	.address-section{
		width: 100%;
		margin-bottom: 24rpx;
		.address-content{
			width: 100%;
			height: auto;
			padding:10rpx 24rpx;
			background: #FFFFFF;
			box-sizing: border-box;
			float: left;
			.info-item{
				width: 100%;
				display: flex;
				line-height: 50rpx;
				font-size: $font-size-28;
				color: #333333;
			}
		}
		image{
			float: left;
			width: 100%;
			height: 6rpx;
		}
	}
	
	.goods-list{
		width: 100%;
		height: auto;
		background: #F7F7F7;
		.goods-item{
			width: 702rpx;
			padding:24rpx;
			height: auto;
			background: #FFFFFF;
			margin-bottom: 24rpx;
			&:last-child{
				margin-bottom: 0;
			}
		}
		.productlist{
			width: 100%;
			height: auto;
		}	
		.goods-pros-t{
			display: flex;
			width: 100%;
			height: auto;
			padding: 12rpx 0;
			.pros-left{
				width: 210rpx;
				height: 100%;
				margin:0 26rpx 0 0;
			}
			.pros-img{
				width: 210rpx;
				height: 210rpx;
				border-radius: 10rpx;
				border:1px solid #f3f3f3;
				image{
					width: 100%;
					height: 100%;
					border-radius: 10rpx;
				}
			}
		}
		.product-total{
			width: 100%;
			height: 60rpx;
			float: left;
			border-bottom: 1px solid #E1E1E1;
			.total{
				float: right;
				font-size: 28rpx;
				line-height: 60rpx;
				color: #333333;
				font-weight: bold;
				text{
					color: #f94b4b;
				}
			}
		}
		.pros-product{
			width: 468rpx;
			height: 100%;
			line-height: 36rpx;
			font-size: $font-size-26;	
			position: relative;
			.icon-genghuan{
				position: absolute;
				top: 50%;
				right: 0;
				font-size: $font-size-44;
				color: $color-system;
			}
			.product-view{
				width: 100%;
				height: auto;
				display: flex;
				.view-num{
					flex: 1;
					text-align: left;
					font-size: $font-size-26;
					color: #666666;
					line-height: 44rpx;
					.small{
						font-size: $font-size-20;
						color: #999999;
					}
					&.price{
						flex: 9;
						color: #f94b4b;
						font-weight: bold;
					}
					&.num{
						flex: 1;
						text-align: right;
					}
				}
			}
			.producttitle{
				width: 100%;
				display: inline-block;
				height: auto;							
				text-overflow:ellipsis;
				display: -webkit-box;
				word-break: break-all;
				-webkit-box-orient: vertical;
				-webkit-line-clamp: 2;
				overflow: hidden;
				margin-bottom: 8rpx;
				font-size: $font-size-28;
			}
			.productspec{
				height: 44rpx;
				color: #666666;
				line-height: 44rpx;
			}
			.productprice{
				height: 48rpx;
				position: absolute;
				width: 100%;
				bottom: 0;
				.price{
					line-height: 48rpx;
					font-size: $font-size-28;
					width: 48%;
					color: #f94b4b;
					float: left;
				}
				.count{
					height: 100%;
					float: right;
					position: relative;
					.small{
						color: #666666;
					}
				}
			}
		}
		.goods-pros-m{
			width: 100%;
			height: auto;
			line-height: 76rpx;
			font-size: $font-size-26;
			color: $text-color;
			float: left;
			padding: 10rpx 0;
			border-bottom: 1px solid #F7F7F7;
			.m-text{
				width: 82rpx;
				float: left;
				padding-right: 20rpx;
				font-weight:bold;
			}
			.m-input{
				display: -webkit-box;
				display: -webkit-flex;
				display: flex;
				-webkit-box-align: center;
				-webkit-align-items: center;
				align-items: center;
				position: relative;
				width: 600rpx;
				height: auto;
				padding: 20rpx 0 10rpx 0;
				background: #FFFFFF;
				.text{
					width: 100%;
					height: 100%;
					font-size: $font-size-26;
					line-height: 36rpx;
					color: #333333;
				}
			}
		}
		.goods-pros-b{
			width:100%;
			height: 40rpx;
			margin-top: 12rpx;
			float: left;
			.count{
				float: left;
				font-size: $font-size-28;
				line-height: 40rpx;
				color: $text-color;
				display: flex;
				justify-content: flex-end;
			}
			.money{
				float: right;
				font-size: $font-size-28;
				line-height: 40rpx;
				color: $text-color;
				display: flex;
				justify-content: flex-end;
				.red{
					color: #f94b4b;
					font-weight: bold;
				}
			}
		}
	}
	.information-record{
		width: 100%;
		height: auto;
		padding: 20rpx 24rpx;
		box-sizing: border-box;
		background-color: #FFFFFF;
		.record-title{
			width: 100%;
			font-size: $font-size-28;
			color: $text-color;
			text-align: left;
			line-height: 40rpx;
			margin-bottom: 12rpx;
			float: left;
			.record-title-l{
				font-weight: bold;
				float: left;
			}
			.record-title-r{
				float: right;
				.red{
					color: #FF2A2A;
					font-weight: bold;
				}
			}
		}
		.record-empty{
			font-size: $font-size-26;
			color: #999999;
			text-align: left;
			line-height: 40rpx;
		}
		.record-list{
			width: 100%;
			height: auto;
			float: left;
			margin-top: 12rpx;
			.record-item{
				height: 40rpx;
				width: 100%;
				padding: 12rpx 0;
				font-size: $font-size-28;
				line-height: 40rpx;
				float: left;
				display: flex;
				justify-content: center;
				flex-direction: row;
				.item-time{
					&.mm{
						flex: 1;
						color: $text-color;
						text-align: left;
					}
					&.tt{
						flex: 1;
						color: #999999;
						text-align: right;
					}
				}
			}
		}
	}
	.button-template{
		width: 100%;
		height: auto;
		position: fixed;
		bottom: 0;
		left: 0;
		background: #FFFFFF;
		.button-content{
			width: 702rpx;
			padding:0 24rpx;
			height: auto;
			float: left;
			position: relative;
			.btn{
				width: 160rpx;
				height:  64rpx;
				margin:22rpx;
				line-height: 64rpx;
				font-size:$font-size-26;
				color: #FFFFFF;
				text-align: center;
				border-radius: 10rpx;
				float: right;
			}
			.btn-color{
				background: $btn-confirm;
				margin: 22rpx 0 22rpx 22rpx;
				.tips{
					width: 160rpx;
					height: 34rpx;
					padding: 10rpx 10rpx;
					background:linear-gradient(45deg,rgba(0,0,0,1) 0%,rgba(87,87,87,1) 100%);
					box-shadow:0px 2px 4px 0px rgba(0,0,0,0.2);
					border-radius: 8rpx;
					position: absolute;
					color: #FFFFFF;
					line-height: 34rpx;
					font-size: $font-size-24;
					text-align: left;
					right: 24rpx;
					top: -45rpx;
					&:before{
						content: "";
						width: 25rpx;
						height: 25rpx;
						background:linear-gradient(45deg,rgba(0,0,0,1) 0%,rgba(87,87,87,1) 100%);
						position: absolute;
						bottom: -8rpx;
						right: 30rpx;
						z-index: -1;
						transform:rotate(45deg);
					}
				}
			}
		}
	}
</style>
