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

<template>
  <div class="content">
    <vue-seamless-scroll
      class="vue-scroll"
      :class-option="defaultOption"
      :data="roadList"
      v-if="roadList.length > 9"
    >
      <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>
    </vue-seamless-scroll>
    <template v-else>
      <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>
    </template>
  </div>
</template>
  
  <script>
import { roadStatisticList } from "@/api/xj/screen/road-screen";
import vueSeamlessScroll from "vue-seamless-scroll";
export default {
  name: "RoadStatistic",
  components: {
    vueSeamlessScroll,
  },
  props: {
    select: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      // 轮播配置
      defaultOption: {
        step: 0.2, // 数值越大速度滚动越快
        limitMoveNum: 1,
        hoverStop: true, // 是否开启鼠标悬停stop
        direction: 1, // 0向下 1向上 2向左 3向右
        openWatch: true, // 开启数据实时监控刷新dom
        singleHeight: 0, // 单步运动停止的高度(默认值0是无缝不停止的滚动)direction => 0/1
        singleWidth: 0, // 单步运动停止的宽度(默认值0是无缝不停止的滚动) direction => 2/3
        waitTime: 2000, // 单步运动停止的时间(默认值1000ms)
      },
      // 路产数据
      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%;
  overflow: hidden;
  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;
        background: linear-gradient(90deg, #0e183e 0%, #4087e8 100%);
      }

      .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>
  