<template>
	<view class="container details clearfix">
		<tui-skeleton
			v-if="!skeletonShow"
			backgroundColor="#fafafa"
			borderRadius="10rpx"
			:isLoading="true"
			:loadingType="5"
		/>
		<template v-else>
			<!-- 地址选择 -->
			<cm-address-temp ref="orderAddress" v-if="skeletonShow" :addressData="addressData" />
			<!-- 商品 -->
				<cm-goods-temp ref="goods" v-if="skeletonShow" :list="orderInfo.orderProductList" :orderInfo="orderInfo" />
			<!-- 订单信息 -->
			<cm-order-temp ref="information" v-if="skeletonShow" :information="orderInfo" />
			<!-- 发票信息 -->
			<cm-invice-temp ref="invoice" v-if="skeletonShow" :orderInvoice="orderInvoice" />
			<!-- 支付记录 -->
			<cm-payment-temp
				ref="payment"
				v-if="skeletonShow"
				:discernReceiptList="discernReceiptList"
				:receiptAmount="receiptAmount"
			/>
			<!-- 退款记录 -->
			<cm-refund-temp
				ref="refund"
				v-if="skeletonShow"
				:returnedPurchaseList="returnedPurchaseList"
				:returnedPurchaseFee="returnedPurchaseFee"
			/>
			<!-- 支付凭证记录 -->
			<cm-voucher-temp
				ref="voucher"
				v-if="skeletonShow && voucherList && voucherList.length > 0"
				:list="voucherList"
			/>
			<!-- 底部button -->
			<view class="button-content" :style="{ paddingBottom: isIphoneX ? '68rpx' : '34rpx' }">
				<view class="btn btn-query" v-if="btnState.isQuery" @click.stop="queryLogistics">查看物流</view>
				<view class="btn btn-cancel" v-if="btnState.isPay" @click.stop="btnConfirmPay">立即支付</view>
			</view>
		</template>
	</view>
</template>

<script>
import cmAddressTemp from './components/details/cm-address-temp' //地址信息
import cmGoodsTemp from './components/details/cm-goods-temp' //商品列表
import cmInviceTemp from './components/details/cm-invice-temp' //发票信息
import cmOrderTemp from './components/details/cm-order-temp' //订单信息
import cmPaymentTemp from './components/details/cm-payment-temp' //支付记录
import cmRefundTemp from './components/details/cm-refund-temp' //退款记录
import cmVoucherTemp from './components/details/cm-voucher-temp' //支付凭证记录

export default {
	components: {
		cmAddressTemp,
		cmGoodsTemp,
		cmOrderTemp,
		cmInviceTemp,
		cmPaymentTemp,
		cmRefundTemp,
		cmVoucherTemp,
	},
	data() {
		return {
			status: '',
			userId: '',
			orderId: '',
			shopOrderId: '',
			skeletonShow: false,
			cellPhone: '', //客服电话
			btnStatus: 0, //按钮组件状态
			addressData: {}, //地址信息初始化
			orderInfo: {}, //订单信息初始化
			orderInvoice: {}, //发票信息初始化
			returnedPurchaseList: {}, //退款信息初始化
			discernReceiptList: {}, //支付信息初始化
			voucherList: [], //支付凭证
			receiptAmount: 0, //支付金额
			returnedPurchaseFee: 0, //退款金额
			isIphoneX: this.$store.state.isIphoneX,
			popupShow: false,
			handlerPros: {},
			btnState: {
				isQuery: false,
				isPay: false
			},
			mapStateArr: [
				{ label: 'isQuery', val: [2, 3, 5, 6, 12, 13, 22, 23, 32, 33], status: true },
				{ label: 'isPay', val: [11, 12, 13, 21, 22, 23], status: true }
			]
		}
	},
	onLoad(option) {
		this.shopOrderId = option.shopOrderId
		this.userId = option.userId
		this.initOrderDetaileData()
	},
	methods: {
		async initOrderDetaileData() {
			try{
				const res = await this.OrderService.QueryOrderDetails({ shopOrderId: this.shopOrderId, userId: this.userId })
				const data = res.data
				this.skeletonShow = true
				this.status = data.shopOrder.status
				this.addressData = data.userInfo
				this.orderInfo = data.shopOrder
				this.orderInvoice = data.orderInvoice
				this.returnedPurchaseList = data.returnedPurchaseList
				this.discernReceiptList = data.discernReceiptList
				this.receiptAmount = data.order.receiptAmount
				this.returnedPurchaseFee = data.shopOrder.returnedPurchaseFee
				this.voucherList = data.voucher
				this.mapStateArr.forEach(el => {
					el.val.forEach(value => {
						if (this.status === value) {
							this.btnState[el.label] = el.status
						}
					})
				})
				
			}catch(error){
				this.$util.msg(error.msg, 2000)
			}
		},
		hanldePopupFn(data) {
			//监听活动内容
			this.popupShow = true
			this.handlerPros = data
		},
		queryLogistics() {
			//跳转查询物流页面
			this.$api.navigateTo('/pages/user/order/order-logistics?shopOrderId=' + this.shopOrderId)
		},
		btnConfirmPay() {
			// 立即支付点击事件
			this.getOrderPaymentValidation()
		},
		//监听根据付款状态做操作
		async getOrderPaymentValidation() {
			try{
				const res = await this.OrderService.OrderPaymentValidation({ shopOrderId: this.shopOrderId })
				this.$api.navigateTo(`/pages/user/order/order-pay-list?shopOrderId=${res.data.shopOrderId}`)
			}catch(error){
				this.$util.msg(error.msg, 2000)
			}
		},
	},
	onShow() {}
}
</script>

<style lang="scss">
page {
	height: auto;
	background: #f7f7f7;
}
.details {
	padding-bottom: 180rpx;
}
.btn-hover {
	background: #ffffff;
}
.animation {
	/* transition: transform 0.3s ease;*/
	transition-property: transform;
	transition-duration: 0.3s;
	transition-timing-function: ease;
}
.invoice-balance {
	width: 702rpx;
	height: auto;
	padding: 0 24rpx;
	background: #ffffff;
	float: left;
	margin-top: 24rpx;
	margin-bottom: 24rpx;
	.balabce-t {
		width: 100%;
		height: 86rpx;
		line-height: 86rpx;
		font-size: $font-size-28;
		color: $text-color;
		float: left;
		.balabce-t-le {
			float: left;
			font-weight: bold;
		}
		.balabce-t-ri {
			float: right;
			display: flex;
			align-items: center;
			.money {
				display: flex;
				float: left;
			}
			.checkbox-box {
				display: flex;
				width: 60rpx;
				float: left;
				height: 100%;
				font-size: $font-size-24;
				.checkbox {
					width: 40rpx;
					text-align: right;
					box-sizing: border-box;
					text-align: center;
					text-decoration: none;
					border-radius: 0;
					-webkit-tap-highlight-color: transparent;
					overflow: hidden;
				}
			}
		}
	}
	.balabce-b {
		width: 100%;
		float: left;
		overflow: hidden;
		.balabce-b-text {
			width: 100%;
			line-height: 58rpx;
			font-size: $font-size-24;
			color: #ff2a2a;
			text-align: right;
			float: right;
		}
		&.balabce-b--hide {
			padding: 0 0;
			height: 0px;
			line-height: 0px;
		}
	}
}
.button-content {
	width: 702rpx;
	padding: 0 24rpx;
	height: auto;
	background: #ffffff;
	position: fixed;
	bottom: 0;
	left: 0;
	.btn {
		width: 160rpx;
		height: 64rpx;
		margin: 22rpx;
		line-height: 64rpx;
		font-size: $font-size-26;
		color: #ffffff;
		text-align: center;
		float: right;
		border-radius: 32rpx;
	}
	.btn-query {
		background: linear-gradient(135deg, rgba(255, 212, 129, 1) 0%, rgba(198, 129, 0, 1) 100%);
	}
	.btn-cancel {
		background: #ffffff;
		color: #666666;
		float: left;
		// margin: 22rpx 0;
		margin-right: 15rpx;
		border: 2rpx solid #999999;
	}
}
</style>
