<template>
		<view class="wrap">
			<text style="margin-right: 20rpx;">
				{{title}}
			</text>
			<image src="../../../static/img/common/loading.gif" v-if="loadImg" style="width: 36rpx;height: 36rpx;">
				
			</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()
      }, 2000)
    }
    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/userOrder/getStatusById', data).then((res) => {
        if (res.code == '00') {
          //如果是组合票，直接跳订单列表页面
          let orderType=res.main.orderType
          if(orderType=='10'){
            uni.reLaunch({
							 url:this.afterBuyUrl+'?orderId=' + this.orderId+'&ifyukuaiCode='+this.ifyukuaiCode
            })
            return
          }
          this.status = res.main.orderStatus
          if (this.status == '2' || this.status == '4' || this.status == '5') {
            //1.跳订单列表，2.订单详情，3.停留该页面显示支付成功（ourPayment页面跳入时，无afterBuyUrl，停留在该页面）
            this.title='支付成功!'
            this.loadImg=false
            uni.reLaunch({
							 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>
