<template>
  <div class="view-code">
    <div class="container">
      <div v-if="isPayment" class="title">
        应付{{ coin }}：<span class="count">{{ count }}</span
        >个
      </div>
      <div v-else class="block"></div>
      <VueQr
        class="qr-code"
        :text="locationUrl"
        :size="180"
        :callback="vueQrCb"
      />
      <div v-if="isPayment" class="tip">
        <div>使用{{ coin }}钱包扫一扫扫描二维码支付</div>
        <div>下载链接：{{ downloadUrl }}</div>
      </div>
      <div>
        <a class="btn-save" download="二维码.png" :href="dataUrl">保存二维码</a>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import VueQr from 'vue-qr';

import { Component, Prop, Vue } from 'vue-property-decorator';

@Component({
  components: {
    VueQr,
  },
})
export default class ViewCode extends Vue {
  @Prop() private locationUrl!: string;
  @Prop() private isPayment!: boolean;
  @Prop() private coin!: string;
  @Prop() private downloadUrl!: string;

  get count() {
    try {
      const payUrl = JSON.parse(this.locationUrl);
      const amount = payUrl.amount;
      return amount;
    } catch (err) {
      return '--';
    }
  }

  private dataUrl = '';

  get hash() {
    return this.$route.query.hash;
  }
  private vueQrCb(dataUrl: string) {
    this.dataUrl = dataUrl;
  }
}
</script>
<style lang="scss" scoped>
.view-code {
  min-height: 100vh;
  background: #333648;
  display: flex;
  justify-content: center;
  .container {
    margin-top: 52px;
    text-align: center;
    width: 332px;
    height: 408px;
    background: #ffffff;
    box-shadow: 0px 2px 10px 0px rgba(0, 0, 0, 0.09);
    border-radius: 5px;
    border-radius: 10px;
    .block{
      height: 65px;
    }
    .title {
      margin-top: 37px;
      margin-bottom: 13px;
      font-size: 16px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #1f292d;
      .count {
        color: #ff1818;
      }
    }
    .qr-code {
    }
    .tip {
      font-size: 12px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #929292;
      line-height: 20px;
    }
    .btn-save {
      display: inline-block;
      margin-top: 28px;
      width: 200px;
      height: 40px;
      background: linear-gradient(180deg, #4667fa 0%, #5b77f4 100%);
      box-shadow: 0px 2px 15px 0px rgba(63, 121, 254, 0.42);
      border-radius: 4px;
      line-height: 40px;
      font-size: 14px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #ffffff;
    }
  }
}
</style>
