金额准换单位

126 阅读1分钟

<template>
  <div class="top-item">
    <p class="left-t"><img src="../assets/device.png" width="50">总支出</p>
    <p class="right-t">
      <span class="t-i">{{ totalCost }}</span>{{ unit }}
    </p>
  </div>
</template>

<script>
export default {
  name: 'hospitalTotalCost',
  data() {
    return {
      listLoading: false,
      unit: '元',
      totalCost: 0
    }
  },
  mounted() {
    this.init(this.totalCost)
  },
  methods: {
    init(data) {
      if (data > 100000000 || data < -100000000) {
        this.totalCost = (data / 100000000).toFixed(2)
        this.unit = '亿元'
      } else if (data > 100000 || data < -100000) {
        this.totalCost = (data / 10000).toFixed(2)
        this.unit = '万元'
      } else {
        this.totalCost = data
        this.unit = '元'
      }
    },
    jumpPage(url, params) {
      this.$router.push({ name: url, params: params ? params : '' })
    }
  }
}
</script>
<style lang="scss" scoped>
$color: #01a699;

.top-item {
  height: 100%;
  line-height: 10vh;
  background-color: #ffffff;
  border-left: 5px solid $color;
  overflow: hidden;
}

.left-t {
  float: left;
  font-size: 24px;
  margin-left: 50px;

  img {
    vertical-align: middle;
    margin-right: 10px;
  }
}

.right-t {
  float: right;
  font-size: 20px;
  color: $color;
  margin-right: 40px;
  color: #343434;
}

.t-i {
  font-size: 40px;
  color: $color;
  font-style: normal;
}
</style>