<!--
 * @Author: SunTao 328867980@qq.com
 * @Date: 2024-10-18 15:22:31
 * @LastEditors: SunTao 328867980@qq.com
 * @LastEditTime: 2024-10-25 16:11:56
 * @FilePath: \znxjxt-ui\src\views\big-screen\road-components\road-statistic.vue
 * @Description: 道路资产大屏-路产统计
-->

<template>
  <div class="content">
    <div
      class="road-div"
      v-for="(item, index) in roadList"
      :key="`road-${index}`"
    >
      <div class="road-top">
        <div class="road-top-name">
          <a>{{ index + 1 < 10 ? "0" + (index + 1) : index + 1 }}</a
          >{{ item.label }}
        </div>
        <div class="road-top-value">
          <span>{{ item.value }}</span
          ><a>个</a>
        </div>
      </div>
      <div class="road-bottom">
        <div
          class="road-bottom-div"
          :style="{ width: `${item.rate * 100}%` }"
          :class="`bottom-${index}`"
        ></div>
      </div>
    </div>
  </div>
</template>
  
  <script>
import { roadStatisticList } from "@/api/xj/screen/road-screen";
export default {
  name: "RoadStatistic",
  props: {
    select: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      roadList: [],
    };
  },
  watch: {
    select: {
      handler() {
        this.getRoadList();
      },
      immediate: true,
    },
  },
  created() {},
  methods: {
    /* 获取路产统计信息 */
    getRoadList() {
      roadStatisticList({ type: this.select }).then(({ code, data }) => {
        if (code === 200) {
          let sum = 0;
          data.forEach((element) => {
            sum += element.value;
          });
          this.roadList = data.map((item) => {
            return {
              ...item,
              rate: item.value / sum,
            };
          });
        }
      });
    },
  },
};
</script>
  
  <style lang="scss" scoped>
.content {
  width: 100%;
  height: 100%;
  color: #ffffff;

  .road-div {
    height: 2.5rem;
    width: 100%;
    padding: 0 1.5rem;
    display: flex;
    flex-direction: column;
    justify-content: center;

    > div {
      display: flex;
      align-items: center;
      justify-content: space-between;
    }

    .index {
      width: 4.5rem;
    }

    .name {
      width: 5rem;
    }

    .value {
      width: 6.5rem;
    }

    .road-top {
      .road-top-name {
        line-height: 1.5rem;
        color: #c7daf2;

        a {
          display: inline-block;
          width: 1.5rem;
          color: #808c9f;
        }
      }

      .road-top-value {
        span {
          font-family: "DouYu";

          color: #c7daf2;
          background: linear-gradient(
            to bottom,
            #ffffff,
            #2773d0
          ); /*设置渐变的方向从左到右 颜色从ff0000到ffff00*/
          background-clip: text; /*将设置的背景颜色限制在文字中*/
          -webkit-text-fill-color: transparent; /*给文字设置成透明*/
        }

        a {
          margin-left: 0.5rem;
          font-size: 0.8rem;
          color: #808c9f;
        }
      }
    }

    .road-bottom {
      width: 100%;
      height: 0.5rem;
      background-color: rgba(50, 72, 127, 0.3);
      position: relative;

      .img {
        position: absolute;
        width: 100%;
        height: 100%;
      }

      .road-bottom-div {
        width: 100%;
        height: 100%;
        display: flex;
      }

      .bottom-0 {
        background: linear-gradient(90deg, #0e183e 0%, #4087e8 100%);
      }

      .bottom-1 {
        background: linear-gradient(90deg, #0e183e 0%, #08b4a6 100%);
      }

      .bottom-2 {
        background: linear-gradient(90deg, #0e183e 0%, #be8b13 100%);
      }

      .bottom-3 {
        background: linear-gradient(90deg, #0e183e 0%, #4087e8 100%);
      }
      .bottom-4 {
        background: linear-gradient(90deg, #0e183e 0%, #08b4a6 100%);
      }
      .bottom-5 {
        background: linear-gradient(90deg, #0e183e 0%, #be8b13 100%);
      }
      .bottom-6 {
        background: linear-gradient(90deg, #0e183e 0%, #4087e8 100%);
      }
      .bottom-7 {
        background: linear-gradient(90deg, #0e183e 0%, #08b4a6 100%);
      }
      .bottom-8 {
        background: linear-gradient(90deg, #0e183e 0%, #be8b13 100%);
      }
      .bottom-9 {
        background: linear-gradient(90deg, #0e183e 0%, #4087e8 100%);
      }
    }
  }
}
</style>
  