<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Epusdt - 优雅的usdt支付中间件</title>
  <link rel="stylesheet" href="/static/reset.css">
  <style>
    .main {
      width: 320px;
      margin: 0 auto;
      min-height: 100vh;
      padding-top: 20px;
      box-sizing: border-box;
    }

    .main .logo {
      width: 65px;
      height: 65px;
      margin: 0 auto 20px;
    }

    .main .site {
      font-size: 14px;
      font-weight: bold;
      text-align: center;
      padding-bottom: 20px;
    }

    .main .logo img {
      width: 100%;
      height: 100%;
    }

    .main .gray-text {
      font-size: 14px;
      text-align: center;
      color: #bebebe;
      line-height: 1.5;
      margin-bottom: 15px;
    }

    .main .red-text {
      font-size: 14px;
      text-align: center;
      color: #f00;
      line-height: 1.5;
      margin-bottom: 15px;
    }

    .qr-code-container {
      padding: 20px;
      width: 90%;
      margin: 0 auto 20px;
      background-color: #fff;
      border-radius: 10px;
    }

    .qr-code-container h2 {
      font-size: 20px;
      text-align: center;
      color: #333;
      margin: 20px;
    }

    .qr-code-container h2 small {
      color: #bebebe;
      font-size: 80%;
      padding-left: 5px;
    }

    .address-text {
      font-size: 12px;
      text-align: center;
      color: #888;
      margin-bottom: 20px;
    }

    .qr-code {
      width: 220px;
      height: 220px;
      border: 1px solid #f2f2f2;
      margin: 20px auto;
      padding: 10px;
      box-sizing: border-box;
    }

    .qr-code>img {
      width: 100%;
      height: 100%;
      display: block;
    }

    .timer {
      width: 140px;
      margin: 0 auto;
      font-size: 14px;
    }

    .timer .label {
      display: flex;
      align-items: center;
    }

    .timer .label,
    .timer .value {
      display: flex;
      align-items: center;
      padding: 5px 0;
    }

    .timer .label span {
      color: #999;
    }

    .timer .value span {
      color: #333;
      font-size: 16px;
    }

    .timer .label span,
    .timer .value span {
      flex: 1;
      text-align: center;
    }

  </style>
</head>

<body>
  <div class="main">
    <div class="logo">
      <img src="data:image/png;base64,[encoded data, 10892 characters]" />
    </div>
    <div class="site">
      订单编号：{{.TradeId}}
    </div>
    <div class="gray-text">当前USDT支付区块网络协议为TRC20</div>
    <div class="red-text">！!到账金额需要与下方显示的金额一致，否则系統无法确认！！</div>
    <div class="red-text">尝试点击钱包地址或金额可直接复制👇</div>
    <div class="qr-code-container">
      <h2><span id="copy-amount" data-clipboard-text="{{.ActualAmount}}">{{.ActualAmount}}</span>
             <small>USDT</small></h2>
      <p class="address-text" id="copy-token" data-clipboard-text="{{.Token}}">
        {{.Token}}
      </p>
      <div class="qr-code">

      </div>
      <div class="timer">
        <div class="value">
          <span class="hours">00</span>
          <i>:</i>
          <span class="minutes">00</span>
          <i>:</i>
          <span class="seconds">00</span>
        </div>
        <div class="label">
          <span>时</span>
          <span>分</span>
          <span>秒</span>
        </div>
      </div>
    </div>
  </div>
  </div>
</body>
</html>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery.qrcode/1.0/jquery.qrcode.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/clipboard.js/2.0.10/clipboard.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/layer/3.5.1/layer.min.js"></script>
<script>
  // 支付时间倒计时
  function clock() {
    let timeout = new Date({{.ExpirationTime}});
    let now = new Date();
    let ms = timeout.getTime() - now.getTime();//时间差的毫秒数
    let second = Math.round(ms / 1000);
    let minute = Math.floor(second / 60);
    let hour = Math.floor(minute / 60);
    if(minute > 60) minute %= 60
    if (ms <= 0) {
      layer.alert("支付超时，请重新发起支付！", {icon: 5});
      return;
    }
    $('.hours').text(hour.toString().padStart(2, '0'));
    $('.minutes').text(minute.toString().padStart(2, '0'));
    $('.seconds').text((second % 60).toString().padStart(2, '0'));
    return setTimeout(clock, 1000);
  }
  setTimeout(clock, 1000);

  $('.qr-code').qrcode({
    text: "{{.Token}}",
    width: 200,
    height: 200,
    foreground: "#000000",
    background: "#ffffff",
    typeNumber: -1
  });

  // 金额复制
  var copyAmount = new ClipboardJS('#copy-amount');
  copyAmount.on('success', function (e) {
    layer.msg('复制金额成功', {icon: 1});
  });
  copyAmount.on('error', function (e) {
    layer.msg('复制金额失败', {icon: 5});
  });

  // 钱包复制
  var copyToken = new ClipboardJS('#copy-token');
  copyToken.on('success', function (e) {
    layer.msg('复制钱包地址成功', {icon: 1});
  });
  copyToken.on('error', function (e) {
    layer.msg('复制钱包地址失败', {icon: 5});
  });

  function checkOrderStatus() {
    $.ajax({
      type: "GET",
      dataType: "json",
      url: "/pay/check-status/{{.TradeId}}",
      timeout: 10000,
      success: function (response, status) {
        if (response.data.status == 2) {
          layer.msg('支付成功，正在跳转中...', {icon: 16, shade: 0.01, time: 20000});
          window.location.href = {{.RedirectUrl}};
        } else {
          setTimeout("checkOrderStatus()", 2000);
        }
      },
      //Ajax请求超时，继续查询
      error: function (e) {
        setTimeout("checkOrderStatus()", 2000);
      }
    });
  }
  window.onload = checkOrderStatus();
</script>
