<template>
   <view ref="form" v-if="orderId">
     <web-view :src="html" ></web-view>
   </view>
</template>

<script>
export default {
  name: "index",
  data(){
    return{
      baseUrl: 'http://pay.huansi.net/#/payorder/',
      orderId: '',
      timer: null,
      loading: false,
      // html: 'http://pay.huansi.net/#/payorder/1483979726701785089'
    }
  },
  computed:{
    html(){
      return `${this.baseUrl}${this.orderId}`
    }
  },
  methods:{
     checkStatus(){
       if(this.loading){
         return;
       }
       this.loading = true;
       this.$http("stylelibraryorder.listingDetailsByCode",this.orderId)
          .then(res =>{
          let {
            code, data,msg
          } = res;
          if(code === 200){
            if(data.status === 2){
              uni.showToast({
                title: msg,
                complete:() =>{
                  this.$Router.back();
                }
              })
            }
          }else{
            uni.showToast({
              title: msg
            })
          }
        }).then(res =>{
         this.loading = false;
       })

    }
  },
  created() {
     this.orderId = this.$Router.currentRoute.query.id;
  },
  onShow() {
    if(this.ticker){
      clearInterval(this.ticker);
    }else {
      this.ticker = setInterval(this.checkStatus, 1000);
    }
    //
    // this.$once("hooks:onHide", () =>{
    //   clearInterval(this.ticker);
    // })
  },
  onHide(){
    clearInterval(this.ticker);
  }
}
</script>

<style scoped>

</style>
