<template>
		<view class="wrap">
			<text style="margin-right: 20rpx;">
				{{title}}
			</text>
			<image src="../../../static/img/common/loading.gif" v-if="loadImg" style="width: 32rpx;height: 32rpx;">
				
			</image>
		</view>
</template>

<script>
	export default {
		data() {
			return {
				title: "正在出票中...", //标题
				orderId: "", //订单Id
				status: "", //出票状态
				timer: "", //计时器
				loadImg: true, //控制加载图片显示隐藏
				afterBuyUrl:'',//页面跳转地址
				ifyukuaiCode: '' //是否是渝快码跳入，渝快码跳入需要在H5端另外走流程
			}
		},
		onLoad(option) {
			this.orderId = option.orderId||''
			this.afterBuyUrl = option.afterBuyUrl||''
			this.ifyukuaiCode=option.ifyukuaiCode||''
			this.ticketStatus()
			let  intFun=()=>{ //页面初始化
				this.timer = setTimeout(()=>{
					if (this.status == "2" || this.status == "4" || this.status == "5") {
						return
					}
					if (this.status == "3") {
						return
					}
					this.ticketStatus()
					intFun()
				}, 1200)
			}
			intFun()
		},
		onHide() {
			if (this.timer) {
				clearInterval(this.timer)
			}
		},
		onUnload() {
			if (this.timer) {
				clearInterval(this.timer)
			}
		},
		methods: {
			//---出票状态
			ticketStatus() { 
				let data = {
					orderId: this.orderId
				}
				this.$request("order/order/getStatusById", data).then((res) => {
					if (res.code == "00") {
						this.status = res.data
						if (this.status == "2" || this.status == "4" || this.status == "5") {
							uni.redirectTo({
							 url:this.afterBuyUrl+'?orderId=' + this.orderId+'&ifyukuaiCode='+this.ifyukuaiCode
							})
						}
						if (this.status == "3") {
							this.title = "出票失败..."
							this.loadImg = false
						}
					} else {
						uni.showToast({
						  title: res.message,
						  icon: 'none'
						})
					}
				})
			}
		}
	}
</script>

<style scoped="scoped">
	.wrap {
		padding-top: 150rpx;
		text-align: center;
		font-size: 36rpx;
		color: #ffbc00;
		display: flex;
		align-items: center;
		justify-content: center;
	}
</style>
