<template>
	<view class="page">
		<loadSke :loading='loading'>
			<view class="remind-top">首页->我的->我的订单</view>
			<view class="des-box">
				<view>
					<view v-if="true" class="code-box">
						<image class="qrcode" :src="orderDes.goodsPictureUrl" mode="widthFix"></image>
						<view class="code">
							<text>充值用户</text>
							<text>{{orderDes.charge_account}}</text>
						</view>
					</view>
				</view>
				<view class="order-num">
					<text>订单号：{{outTradeNo}}</text>
					<text>{{orderDes.orderStatusDesc}}</text>
					<text v-if="orderDes.orderStatus==3">{{orderDes.recharge_description}}</text>
				</view>
				<view class="des">
					<text class="film-name">充值商品</text>
					<view class="film-time">
						<text>购买时间</text>
						<text>{{orderDes.create_time}}</text>
					</view>
					<view class="film-address">
						<text>购买商品</text>
						<text>{{orderDes.product_name}}</text>
					</view>
					<view class="film-video">
						<text>购买数量</text>
						<text>{{orderDes.buy_num}}</text>
					</view>
					<view class="film-seat">
						<text>购买价格</text>
						<text>{{orderDes.total}}</text>
					</view>
				</view>
			</view>
		</loadSke>
	</view>
</template>

<script>
	export default {
		data: () => ({
			orderDes: {},
			loading: true,
			outTradeNo: null,
			pollingTiemId: null
		}),
		onLoad: function(option) {
			this.outTradeNo = option.outTradeNo
		},
		mounted() {
			this.init()
		},
		methods: {
			async init() {
				let orderRes = await this.$api.order.getWxOrder(this.outTradeNo)
				this.orderDes = orderRes.data
				// 直接查询的接口
				// await this.$api.fulu.orderInfoGet({
				// 	customer_order_no: this.outTradeNo
				// })
				this.loading = false
				if (this.orderDes.orderStatus == 1) {
					this.polling()
				}
			},
			polling() {
				this.pollingTiemId = setInterval(async () => {
					let orderRes = await this.$api.order.getWxOrder(this.outTradeNo)
					this.orderDes = orderRes.data
					if (this.orderDes.orderStatus != 1) {
						clearInterval(this.pollingTiemId)
					}
				}, 3000)
			}
		},
		beforeDestroy() {
			clearInterval(this.pollingTiemId)
		}
	}
</script>

<style lang="scss">
	.page {
		padding-bottom: 20rpx;
	}

	.remind {
		padding-top: 36rpx;
		font-size: 26rpx;
		font-weight: 400;
		color: #0F0404;
		text-align: center;
	}

	.remind-top {
		margin-top: 36rpx;
		font-size: 26rpx;
		font-weight: 400;
		color: #ff0000;
		text-align: center;
	}

	.des-box {
		width: 564rpx;
		background: #FFFFFF;
		border-radius: 20rpx;
		margin: auto;
		margin-top: 30rpx;

		.code-box {
			display: flex;
			flex-direction: column;
			align-items: center;
			padding-bottom: 38rpx;

			.code {
				margin-top: 43rpx;

				text {
					font-size: 26rpx;
					font-weight: 400;
					color: #666666;
					margin-right: 20rpx;

					&:nth-child(2) {
						color: #0F0404;
					}
				}
			}

			.qrcode {
				margin-top: 43rpx;
				width: 360rpx;
				height: 360rpx;
			}

			.qrcode-loading {
				margin-top: 43rpx;
				width: 100%;
			}
		}

		.order-num {
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			align-items: center;
			padding: 34rpx 31rpx;
			border-top: 1rpx dashed #D9D9D9;
			border-bottom: 1rpx dashed #D9D9D9;
			position: relative;

			&::after {
				content: '';
				width: 24rpx;
				height: 24rpx;
				border-radius: 50%;
				background-color: #F1F1F1;
				position: absolute;
				top: 0;
				left: 0;
				transform: translate(-50%, -50%);
			}

			&::before {
				content: '';
				width: 24rpx;
				height: 24rpx;
				border-radius: 50%;
				background-color: #F1F1F1;
				position: absolute;
				top: 0;
				right: 0;
				transform: translate(50%, -50%);
			}

			text {
				&:nth-child(1) {
					margin-top: 60rpx;
					word-break: break-all;
					font-size: 22rpx;
					font-weight: 400;
					color: #666666;
				}

				&:nth-child(2) {
					margin-top: 10rpx;
					padding: 10rpx;
					display: flex;
					justify-content: center;
					align-items: center;
					background: #FFE5E5;
					border-radius: 20rpx;
					border-top-left-radius: 0;
					border-bottom-left-radius: 0;
					font-size: 20rpx;
					font-weight: 400;
					color: #E31818;
					position: absolute;
					left: 0;
					top: 20rpx;
				}

				&:nth-child(3) {
					margin-top: 10rpx;
					padding: 10rpx;
					display: flex;
					justify-content: center;
					align-items: center;
					font-size: 20rpx;
					font-weight: 400;
					color: #E31818;
				}
			}
		}

		.des {
			padding: 45rpx 30rpx;
			border-bottom: 1rpx dashed #D9D9D9;
			display: flex;
			flex-direction: column;

			.film-name {
				font-size: 30rpx;
				font-weight: 400;
				color: #0F0404;
			}

			text {
				font-size: 26rpx;
				font-weight: 400;
				color: #666666;
				margin-right: 20rpx;
				white-space: nowrap;
			}

			.film-time {
				text:nth-child(2) {
					color: #999999;
				}
			}

			.film-address {
				display: flex;
				justify-content: flex-start;
				align-items: stretch;

				text:nth-child(2) {
					color: #999999;
					white-space: pre-wrap;
				}
			}

			.film-video {
				display: flex;
				justify-content: flex-start;
				align-items: stretch;

				text:nth-child(2) {
					color: #999999;
					white-space: pre-wrap;
				}
			}

			.film-seat {
				display: flex;
				justify-content: flex-start;
				align-items: stretch;
				margin-top: 10rpx;

				.seat-box {
					display: flex;
					flex-wrap: wrap;

					text {
						height: 40rpx;
						padding: 4rpx 15rpx;
						margin-bottom: 10rpx;
						background: #EBEBEB;
						border-radius: 4rpx;
						color: #999999;
					}
				}
			}
		}

		.price {
			padding: 40rpx 30rpx;

			text {
				font-size: 26rpx;
				font-weight: 400;
				color: #666666;
				margin-right: 20rpx;

				&:nth-child(2) {
					color: #E31818;
				}
			}
		}
	}
</style>
