<template>
  <!-- <div class="synthesis-container"> -->
  <div class="synthesis-left">
    <div class="synthesis-left-top">
      <div class="synthesis-left-top-container">
        <div class="synthesis-left-top-left">
          <div>行业安全生产得分</div>
          <div>
            单位排行榜
          </div>
        </div>
        <!-- <div class="synthesis-left-top-right">
          <el-image style="width: 100px; height: 100%" :src="require('@/assets/images/jcgl_bj.png')"
            fit="cover"></el-image>
        </div> -->
      </div>
    </div>
    <div v-if="orgLevel == '2'" class="tab-container">
      <el-tabs v-model="activeTab" type="card" @tab-click="onTabClick">
        <el-tab-pane :label="item.label" :name="item.value" v-for="(item, i) in tabList" :key="i" />
      </el-tabs>
    </div>
    <div class="synthesis-left-content" :class="{ 'is-city': orgLevel == '2' }">
      <div class="synthesis-left-content-title">
        <span class="col-1">
          排序
        </span>
        <span class="col-2">
          名称
        </span>
        <span class="col-3">
          分数
        </span>
      </div>
      <div class="synthesis-left-content-list">
        <div v-for="(item, index) in tableData" :key="index" class="synthesis-left-content-item">
          <span class="rank-col-1">
            <span class="rank-col-1-num" :class="{ 'col-1': index == 0, 'col-2': index == 1, 'col-3': index == 2 }">
              {{ (index + 1) < 10 ? '0' + (index + 1) : (index + 1) }} </span>
            </span>
            <span class="rank-col-2">
              {{ item.orgName }}
            </span>
            <span class="rank-col-3">
              {{ new Big(item.rankingSumScore || 0).round(2).toString() }}
            </span>
        </div>
      </div>

    </div>
  </div>
</template>

<script setup>

import { ref, onMounted, defineProps, defineExpose } from 'vue'
import { getApi } from "@/api/tobAcco_api.js"
import { getItem, setItem } from "@/utils/storage"
import Big from "@/utils/big.js"

const props = defineProps({
  year: {
    type: [Number, String],
  }
})

const tableData = ref([])
const activeTab = ref('1');
/** 账号级别 1：省 2：市 3：县 4：县 */
const orgLevel = ref(getItem("deptId").orgLevel?.[0])
const tabList = ref([
  { label: '市级', value: '1' },
  { label: '县级', value: '0' },
])
/**
 * 获取表格数据
 */
const getTableDetail = () => {
  /** 是否市级 */
  let isCity
  if (orgLevel.value == '1') { // 省级一定是市级
    isCity = true
  } else if (orgLevel.value == '2') { // 市级 可以选“市”或者“县”
    isCity = activeTab.value == '1' ? true : false
  } else { // 其他级别一定是县级
    isCity = false
  }
  getApi({ year: props.year, isCity: isCity }, "/mosty-jcgl/rankScore/getCityScoreRank").then((res) => {
    if (Array.isArray(res)) {
      tableData.value = Array.isArray(res) ? res : []
    } else {
      tableData.value = []
    }
  })
}
const onTabClick = () => {
  getTableDetail()
}
onMounted(() => {
  getTableDetail()
})
defineExpose({
  getTableDetail
})
//
</script>

<style lang="scss" scoped>
@import "@/views/dutyBook/jgryandzz/talentPool/tabContainer.scss";

.tab-container {
  margin-top: 5px;
  background-color: #fff;
}

.synthesis-left {
  width: 320px;
  height: 100%;
  margin-right: 10px;
  flex-shrink: 0;

  .synthesis-left-top {
    background-color: var(--el-color-primary);
    height: 80px;
    padding: 10px;

    .synthesis-left-top-container {
      display: flex;
      justify-content: space-between;

      .synthesis-left-top-left {
        // padding: 20px;
        font-size: 20px;
        font-weight: bolder;
        font-style: italic;
      }

      .synthesis-left-top-right {
        width: 100px;
        height: 100px;
      }
    }
  }

  .synthesis-left-content {
    height: calc(100% - 85px);
    padding: 10px;
    font-weight: bolder;
    color: #000;
    background-color: #fff;
    &.is-city {
      height: calc(100% - 85px - 45px);
    }
    .synthesis-left-content-title {
      display: flex;
      border-radius: 2px;
      background-color: #f0f0f0;

      .col-1 {
        display: inline-block;
        width: 50px;
        text-align: center;
        padding: 6px 10px;
      }

      .col-2 {
        display: inline-block;
        // width: 180px;
        flex: 1;
        text-align: center;
        padding: 6px 10px;
      }

      .col-3 {
        display: inline-block;
        width: 100px;
        text-align: center;
        padding: 6px 10px;
      }
    }

    .synthesis-left-content-list {
      height: calc(100% - 30px);
      overflow: auto;

      .synthesis-left-content-item {
        display: flex;
        border-bottom: 1px solid #ededee;

        .rank-col-1 {
          display: inline-block;
          width: 20px;
          text-align: center;
          padding: 6px 10px;

          .rank-col-1-num {
            display: inline-block;
            width: 22px;
            height: 22px;
            text-align: center;
            line-height: 22px;
            border-radius: 50%;
            color: #fff;
            background-color: var(--el-color-primary);

            &.col-1 {
              background-color: #f4a90c;
            }

            &.col-2 {
              background-color: #8ba4b0;
            }

            &.col-3 {
              background-color: #e2a254;
            }
          }
        }

        // 名称
        .rank-col-2 {
          display: inline-block;
          flex: 1;
          // width: 180px;
          text-align: center;
          padding: 6px 0px 6px 15px;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }

        .rank-col-3 {
          display: inline-block;
          width: 50px;
          text-align: center;
          padding: 6px 5px;
          color: var(--el-color-primary);
        }
      }
    }
  }
}

.synthesis-right {
  flex: 1;
  padding-top: 10px;

  .synthesis-right-top {
    display: flex;
    height: 280px;
    width: 100%;
  }
}
</style>
