<template>
  <div>
    <TitleBox titleText="装备在用率统计" @handleMore="handleMore" />

    <div class="topView">
      <div style="height: 100%; display: flex; align-items: center; justify-content: space-between">
        <div class="topTab" :class="{ active: tabIndex == 0 }" @click="changTab(0)">总体</div>
        <div class="topTab" :class="{ active: tabIndex == 1 }" @click="changTab(1)">线路</div>
        <div class="topTab" :class="{ active: tabIndex == 2 }" @click="changTab(2)">变电</div>
        <div class="topTab" :class="{ active: tabIndex == 3 }" @click="changTab(3)">电缆</div>
      </div>
      <div></div>
    </div>

    <div class="bottom-box">
      <div class="bottom-item" v-for="(item, index) in tableList" :key="index">
        <div class="item-top-title">
          <img v-if="index == 0" src="@/assets/images/nb-1.png" style="width: 27px; height: 31px" alt="" />
          <img v-if="index == 1" src="@/assets/images/nb-2.png" style="width: 27px; height: 31px" alt="" />
          <img v-if="index == 2" src="@/assets/images/nb-3.png" style="width: 27px; height: 31px" alt="" />
          <img v-if="index == 3" src="@/assets/images/nb-4.png" style="width: 27px; height: 31px" alt="" />
          <span>{{ item.name || '-' }}</span>
        </div>
        <div class="img-box">
          <img v-if="index == 0" src="@/assets/images/nb-img-1.png" flt="contain" alt="" />
          <img v-if="index == 1" src="@/assets/images/nb-img-2.png" flt="contain" alt="" />
          <img v-if="index == 2" src="@/assets/images/nb-img-3.png" flt="contain" alt="" />
          <img v-if="index == 3" src="@/assets/images/nb-img-4.png" flt="contain" alt="" />
        </div>
        <div class="bt-content">
          <div class="bt-content-item">
            <span class="dot"></span>
            <span style="margin-right: 10px">在用率</span>
            <span class="num">{{ item.proportion || 0 }}%</span>
          </div>
          <div class="bt-content-item">
            <span class="dot"></span>
            <span style="margin-right: 10px">周转率</span>
            <span class="num"
              >{{ item.turnoverRate || 0 }}
              <span class="unit-text">次/年</span>
            </span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import TitleBox from '../TitleBox'
import { getUsageStatisticsApi } from '@/api/wsScreen'

export default {
  name: 'Bottom2',
  components: {
    TitleBox,
  },
  data() {
    return {
      tabIndex: 0,
      tableList: [],
    }
  },
  created() {
    this.getInfo()
  },
  methods: {
    changTab(type) {
      console.log('🚀 ~ changTab ~ type:', type)
      this.tabIndex = type
      this.getInfo()
    },
    async getInfo() {
      try {
        let type = 0
        if (this.tabIndex == 0) {
          type = ''
        } else if (this.tabIndex == 1) {
          type = 1
        } else if (this.tabIndex == 2) {
          type = 2
        } else if (this.tabIndex == 3) {
          type = 3
        }
        const res = await getUsageStatisticsApi({ type })
        if (!res.data) return
        if (res.data.length > 4) {
          this.tableList = res.data.slice(0, 4)
        } else {
          this.tableList = res.data
        }
        console.log('🚀 ~ 装备在用率统计 ~ res:', res)
      } catch (error) {
        console.log('🚀 ~ 装备在用率统计 ~ error:', error)
      }
    },
    handleMore() {
      console.log('🚀 ~ methods.handleMore:')
    },
  },
}
</script>

<style lang="scss" scoped>
.num {
  font-family: OPPOSans;
  font-size: 16px;
}
.unit-text {
  font-family: Microsoft YaHei, Microsoft YaHei;
  font-weight: 400;
  font-size: 12px;
  color: #333;
}
.topView {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 15px;

  .topTab {
    margin-right: 10px;
    width: 60px;
    height: 24px;
    border-radius: 3px;
    border: 1px solid #cccccc;
    text-align: center;
    cursor: pointer;
  }
  .active {
    background: #2cbab2;
    color: #fff;
  }
}

.bottom-box {
  display: flex;
  align-items: center;

  .bottom-item {
    margin-right: 20px;
    width: 25%;
    height: 222px;
    background-image: url('~@/assets/images/item-bg.png');
    background-size: 100% 100%;
    box-shadow: 0px 3px 1px 0px #e9f0f3;
    border-radius: 5px;
    font-family: Microsoft YaHei, Microsoft YaHei;
    font-weight: 400;
    font-size: 14px;
    color: #333;

    &:last-child {
      margin-right: 0;
    }

    .item-top-title {
      padding-right: 5px;
      font-size: 13px;
      display: flex;
      align-items: center;
      justify-content: space-between;
    }

    .img-box {
      display: flex;
      align-items: center;
      justify-content: center;
      height: 90px;
    }

    .bt-content {
      margin-top: 20px;
      padding: 0 20px;
      .dot {
        width: 6px;
        height: 6px;
        background: #b7c7d5;
        border-radius: 50%;
        margin-right: 6px;
        flex-shrink: 0; // 👈 防止被挤扁
      }

      .bt-content-item {
        height: 40px;
        display: flex;
        align-items: center;
      }
    }
  }
}
</style>
