<template>
  <div class="user-assets">
    <div class="title">
      账户资产
      <!-- <span @click="Queryrecord">燃料记录</span> -->
    </div>
    <div class="content-info">
      <div class="g-flex-center">
        <el-progress
          type="circle"
          :percentage="sum"
          class="gas"
          :show-text="false"
          :width="150"
          :stroke-width="10"
          color="#6DD230FF"
        ></el-progress>
      </div>
      <div class="gas-info">
        <p>可上链次数</p>
        <h2>{{ balance || 0 }}</h2>
      </div>
      <!-- <p class="surplus">
        <span @click="Recharge">充值燃料</span>
      </p> -->
    </div>
  </div>
</template>
<script>
import { GO_URLS } from "@/config/URLS";
let UrlPrefixObj = require("@/config/UrlPrefix");
export default {
  data() {
    return {
      balance: 0,
    };
  },
  props: ["infos"],
  computed: {
    sum: function () {
      if (this.balance > 0) {
        return this.balance / 1000;
      } else {
        return 0;
      }
    },
  },
  mounted() {
    setTimeout(() => {
      this.getBalance();
    }, 500);
  },
  methods: {
    Queryrecord() {
      if (this.infos.auth_suc === 0) {
        this.$message({
          message: "请先进行认证！",
          type: "warning",
        });
        return false;
      }
      window.open(
        UrlPrefixObj.model.MAINNET_BLOCKCHAIN_BROWSER +
          "?address=" +
          this.infos.addr
      );
    },
    Recharge() {
      if (this.infos.auth_suc === 0) {
        this.$message({
          message: "请先进行认证！",
          type: "warning",
        });
        return false;
      }
      this.$router.push({ path: "/choosePackage" });
    },
    //   获取
    async getBalance(params) {
      // auth_suc	是否认证成功	int	0：未认证成功 1：认证成功
      if (this.infos.auth_suc === 0) {
        return false;
      }
      const res = await this.$ajax({
        type: "GET",
        url: GO_URLS.getBalance,
        params: {
          user_id: JSON.parse(String(sessionStorage.getItem("user"))).id,
        },
      });
      if (res) {
        this.balance = res.data.chain_times;
      }
    },
  },
};
</script>
<style scoped lang="less">
* {
  margin: 0;
}
.g-flex-center {
  display: flex;
  justify-content: center;
  align-items: center;
}
.pop-up {
  width: 580px;
  height: 320px;
  background: rgba(255, 255, 255, 1);
  box-shadow: 0px 0px 20px 0px rgba(61, 118, 249, 0.18);
  h1 {
    height: 66px;
    font-size: 22px;
    font-weight: 500;
    text-align: center;
    color: rgba(0, 0, 0, 1);
    line-height: 66px;
    border-bottom: 1px solid #e8e8e8;
  }
  .pop-up-center {
    overflow: hidden;
    height: 124px;

    .pop-up-center__right,
    .pop-up-center__left {
      float: left;
    }
    .pop-up-center__left {
      width: 178px;
      padding-top: 26px;

      .imgbox {
        width: 94px;
        float: right;
        margin-right: 20px;
        height: 94px;
        img {
          width: 100%;
          height: 100%;
        }
      }
    }
    .pop-up-center__right {
      .pop-up-center__right-top {
        font-size: 14px;
        font-weight: 400;
        line-height: 58px;
        color: rgba(121, 125, 132, 1);
        span {
          display: inline-block;
          width: 100px;
          height: 30px;
          cursor: pointer;
          line-height: 30px;
          text-align: center;
          border-radius: 4px;
          border: 1px solid rgba(74, 144, 226, 1);
          font-size: 12px;
          font-weight: 400;
          color: rgba(74, 144, 226, 1);
        }
      }
      .pop-up-center__right-center {
        padding: 12px 22px;
        width: 306px;
        height: 42px;
        background: rgba(245, 249, 252, 1);
        font-size: 14px;
        font-weight: 400;
        color: rgba(121, 125, 132, 1);
        line-height: 20px;
      }
    }
  }
  .pop-up-tip_title {
    font-size: 14px;
    padding-left: 64px;
    padding-top: 28px;
    font-weight: 400;
    color: rgba(74, 144, 226, 1);
    line-height: 20px;
  }
  .pop-up-tip_content {
    font-size: 14px;
    font-weight: 400;
    padding-top: 8px;
    padding-left: 64px;
    color: rgba(121, 125, 132, 1);
    line-height: 20px;
  }
}
.surplus {
  text-align: center;
  margin-top: 16px;
  span {
    color: rgba(74, 144, 226, 1);
    cursor: pointer;
    width: 85px;
    display: inline-block;
    height: 30px;
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    line-height: 30px;
    border-radius: 4px;
    border: 1px solid #4d7cfe;
  }
}
.user-assets {
  height: 350px;
  width: 49.5%;
  border-radius: 4px;
}
.title {
  padding-left: 28px;
  line-height: 60px;
  color: #979797;
  font-size: 14px;
  background: #fff;
  span {
    float: right;
    font-size: 14px;
    cursor: pointer;
    padding-right: 30px;
    font-weight: 400;
    color: rgba(74, 144, 226, 1);
  }
}
.content-info {
  position: relative;
  margin-top: 1px;
  height: 290px;
  background: #fff;
}
.gas {
  margin-top: 50px;
  transform: scale(-1, 1);
}
.gas-info {
  width: 100%;
  position: absolute;
  top: 100px;
}
.gas-info p {
  text-align: center;
  font-size: 12px;
  font-family: PingFangSC-Regular;
  font-weight: 400;
  color: #979797;
}
.gas-info h2 {
  margin-top: 5px;
  text-align: center;
  font-family: PingFangSC-Regular;
  font-weight: 400;
}
.tip {
  text-align: center;
  font-size: 12px;
  font-family: PingFangSC-Regular;
  font-weight: 400;
  color: #979797;
  line-height: 40px;
}
</style>

