<template>
  <div class="user-assets">
    <div class="title">账户资产</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">
        <!-- <sy-button mode="elementBtn" size="large" @click="Recharge"
          >充值燃料</sy-button
        > -->
        <span @click="Recharge">充值燃料</span>
      </p>
    </div>
  </div>
</template>
<script lang="ts">
import { GO_URLS, syButton } from "cqk-sy-ui";
import { defineComponent } from "vue";
import { ElMessage, ElProgress } from "element-plus";
import { $ajax } from "@/service";

export default defineComponent({
  components: {
    ElProgress,
    syButton,
  },
  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: {
    Recharge() {
      if (this.infos.auth_suc === 0) {
        ElMessage({
          message: "请先进行认证！",
          type: "warning",
        });
        return false;
      }
      this.$router.push({ path: "/choosePackage" });
    },
    //   获取
    async getBalance() {
      // auth_suc	是否认证成功	int	0：未认证成功 1：认证成功
      if (this.infos.auth_suc === 0) {
        return false;
      }
      const res = await $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="scss">
* {
  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: var(--sy-blue);
    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 var(--sy-blue);
  }
}
.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>
