import {CheckOrderByTxid,LastUseTxid} from "../../api/pay"
export default {
    data() {
        return {
          params: {
            coin: '',
            chain: '',
            txid: ''
          },
          value:"",
          options: [{
            value: '10',
            label: '10'
          }, {
            value: '20',
            label: '20'
          }, {
            value: '50',
            label: '50'
          },{
            value: '100',
            label: '100'
          },{
            value: '200',
            label: '200'
          },{
            value: '500',
            label: '500'
          },{
            value: '1000',
            label: '1000'
          }],
          coinOptions: [{
            value: 'USDT',
            label: 'USDT'
          }, {
            value: 'USDC',
            label: 'USDC'
          }, {
            value: 'BUSD',
            label: 'BUSD'
          }],
          chainOptions: [{
            value: 'TRX',
            label: 'TRX'
          }, {
            value: 'ETH',
            label: 'ETH'
          }, {
            value: 'BSC',
            label: 'BSC'
          }],
          outerVisible:false,
          innerVisible:false,
          transactionData:{
            orderId:"",
            address:""
          },
          txidLoading:false,  
          dialogVisibleSuccess:false,
          balances:{
            total:0,
            usdc:"",
            usdt:"",
            userId:"",
            userName:""
  
          },
          bthDisabled:true,
          hashLoading:false,
          btnText:"pay.confirmSubmission",
          codeTimer:null,

        }
    },
    mounted() {
       this.fetchlastUseTxid()
    },
    methods: {
        //请求按钮状态是否禁用 及倒计时
        async fetchlastUseTxid(){
          this.hashLoading = true
          const {data} = await LastUseTxid()
          this.bthDisabled = !data.data.result
          let tim =data.data.time
           //判断定时器是否存在
          if (this.codeTimer) {
            clearInterval(this.codeTimer);
          }
          //倒计时
          this.codeTimer = setInterval(() => {
              tim--
              if (tim <= 0) {
                clearInterval(this.codeTimer)
                this.btnText = "pay.confirmSubmission"
                this.bthDisabled=false
              }else{
                this.btnText=`${this.$t(`pay.Disabled`)}:${tim}`
                this.bthDisabled=true

              }
           
          },1000)        


          this.hashLoading = false
  
        },


      //请求查询Txid
      async fetchTxid(params){
        this.txidLoading = true
        let timer
        const {data} = await CheckOrderByTxid(params)
        if (data.data) {
          this.balances=data.data //接口无数据测试 后端告知与余额数据结构一致
        }
       


        if (timer) {
          clearTimeout(timer)
        }
       

        if (data.code == 200) {
          this.dialogVisibleSuccess=true

          timer=setTimeout(()=>{
            this.dialogVisibleSuccess=false
            this.$router.push(`/personal`)
          },2000)
  
        }


        this.txidLoading = false


        console.log( this.txidLoading,456556);
      },
      //点击确认查询Txid
      handelTxid(){
        for (const key in this.params) { //判空
          if (this.params[key] == "") {
            this.$message({
              message: this.$t(`help.resubmit`),
              type: "error",
            });
            return
          }
        }

        this.fetchTxid(this.params)
      
      },
      Jump(){
        this.$router.push(`/Help`)
      }
    }
}