<!--
 * @Author: your name
 * @Date: 2022-10-07 14:10:51
 * @LastEditTime: 2022-10-14 15:49:47
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \rsga\src\views\moduleHome\warningCenter\components\ranking.vue
-->
<template>
  <!-- <div v-if="dataLoad" class="empty-box">数据加载中...</div> -->
  <ul class="rankingBox" v-if="list.length > 0">
    <li v-for="item in list" :key="item.yj_gzyid">
      <template v-if="item.yj_gzymc">
        <div class="leftBox">
          <div class="top">
            <span class="dian blue"></span>
            <span @click="routerPush(item)" class="name text_title">{{
              item.yj_gzymc
            }}</span>
          </div>

          <div class="jdtBox">
            <div
              class="jdt"
              :style="{
                width: (parseInt(item.total) / totalWidth) * 100 + '%',
              }"
            ></div>
          </div>
        </div>
        <div class="rightBox">
          <span class="numb">{{ item.total }}</span> 次
        </div>
      </template>
    </li>
  </ul>
  <van-empty description="暂无数据" v-if="list.length === 0" />
</template>

<script setup>
import { dateFormat } from "../../../../utils/tools.js";
import { getGzyYj } from "../../../../api/yjxx.js";
import { ref, reactive, watch, onMounted } from "vue";
import { getRecentDay } from "../../../../utils/tools";
import router from "../../../../router/index.js";
const props = defineProps({
  type: {
    type: Number,
    default: 0,
  }
});
watch(()=> props.type, (val)=>{
  getList()
})
const list = ref([]);
const totalWidth = ref(0);
const dataLoad = ref(true);
function getList() {
  getGzyYj({
    kssj: getRecentDay(props.type, 'ymd'),
    jssj: dateFormat(),
  })
    .then((res) => {
      list.value = res;
      if (list.value && list.value.length > 0) {
        dataLoad.value = false;
        totalWidth.value = Math.max(
          ...list.value
            .filter((item) => !item.yj_gzymc === false)
            .map((item) => item.total)
        );
      }
    })
    .catch((err) => {
      dataLoad.value = false;
    });
}
function routerPush(row) {
  router.push({
    path: "/yyzx/yjtjInfo/gzyInfo",
    query: row,
  });
}
onMounted(() => {
  getList();
});
</script>

<style lang="scss" scoped>
ul.rankingBox {
  height: 55vw;
  overflow: auto;
  margin-top: 1.5vw;
  li {
    display: flex;
    justify-content: space-between;
    padding-top: 8px;
    .leftBox {
      flex: 1;
      .top {
        height: 28px;
        display: flex;
        align-items: center;
        .name {
          font-size: 14px;
          vertical-align: middle;
          flex: 50;
        }
        .dian {
          flex: 1.455;
          display: inline-block;
          width: 2vw !important;
          height: 2vw !important;
          border-radius: 50%;
          background: #4896ff;
          margin-right: 0.5vw;
        }
      }
      .jdtBox {
        height: 7px;
        background: #dbdbdb;
        border-radius: 4px;
        overflow: hidden;
        .jdt {
          background: #00c0fa;
          height: 100%;
          border-radius: 4px;
        }
      }
    }
    .rightBox {
      width: 68px;
      text-align: right;
      color: #4896ff;
      font-size: 14px;
      line-height: 50px;
      height: 34px;
      .numb {
        font-size: 14px;
        color: #333;
      }
    }
  }
}
</style>
