<template>
  <div class="abs-full title1">
    <div class="m-tt">
      <h4>边坡监测</h4>
    </div>
    <div class="m-body">
      <div class="top">
        <div class="left">
          <img src="@/assets/images/dpNew2/icon0.png" alt="" />
        </div>
        <div class="right">
          <p>
            <span class="unit1">隐患数量</span
            ><span class="count1">{{ plansNum.hiddenNum || 0 }}</span
            ><span class="unit1">个</span>
          </p>
          <p>
            <span style="color:#59EDFF;">已经处理</span
            ><span class="count2">{{ plansNum.dealNum || 0 }}</span
            ><span class="unit2">个</span>
          </p>
        </div>
      </div>
      <div class="bottom bottom-yuan">
        <dl class="scrolling1">
          <dt>
            <span>隐患报警日期</span> <span>发现方式</span> <span>处置方式</span>
          </dt>
          <div class="list-wrap">
            <div class="list-content">
              <dd v-for="(item, index) in plansList" :key="index">
                <span>{{ item.alarmTime }}</span>
                <span>{{ item.discoveryMethod }}</span>
                <span :style="{ color: formateColor4yuan(item) }">{{item.alarmIfRes === 0 ? '未处理': '已处理'}}</span>
              </dd>
            </div>
          </div>
        </dl>
      </div>
    </div>
  </div>
</template>

<script>
import { listPlans } from "@/api/avoidanceSys/plans";
export default {
  props: {
    dataList: {
      type: Array,
      default: () => [{ name: "测试1:", y: 6.3 }],
    },
    colors: {
      type: Array,
      default: () => [
        "#27BAFF",
        "#EEE485",
        "#25D8A9",
        "#008ADD",
        "#25D8A9",
        "#EEE485",
        "#27BAFF",
        "#008ADD",
      ],
    },
  },
  data() {
    return {
      plansList: [],
      plansNum: {
        hiddenNum: 0,
        dealNum: 0,
      },
      option: {},
        // 应急预案
        interval4yuan: null,
      scrollPosition4yuan: 0,
      direction4yuan: 1, // 1 for down, -1 for up
      step4yuan: 1, // 每次滚动的像素
      intervalTime4yuan: 40, // 每次滚动的时间间隔（ms）
    };
  },

  watch: {},
  created() {},
  mounted() {
    this.getPlans()

    this.startScrolling(
          ".bottom-yuan .list-wrap",
          ".bottom-yuan .list-content",
          "yuan"
        );
  },

  methods: {
    getLevelNum4plans() {
      getLevelNum({}).then((response) => {
        this.plansNum = response || {};
      });
    },
    /** 查询应急预案信息列表 */
    getPlans() {
      listPlans({
        pageNum: 1,
        pageSize: 99999,
      }).then((response) => {
        this.plansList = response.voList;
        this.plansNum.hiddenNum = response.total[0]
        this.plansNum.dealNum = response.total[1]

        this.startScrolling(
          ".bottom-yuan .list-wrap",
          ".bottom-yuan .list-content",
          "yuan"
        );
      });
    },
    formateColor4yuan(item) {
      if (item.alarmIfRes === 0) {
        return "#01c0ff";
      }
      return "#e5d76a";
    },
    startScrolling(containerClass, contentClass, type) {
      const container = document.querySelector(containerClass);
      const content = document.querySelector(contentClass);
      var affixHeight = 0;
      if (type === "yanlian") {
        affixHeight = 80;
      } else if (type === "yuan") {
        affixHeight = 10;
      }
      if (this["interval4" + type]) {
        clearInterval(this["interval4" + type]);
      }
      this["interval4" + type] = setInterval(() => {
        this["scrollPosition4" + type] +=
          this["step4" + type] * this["direction4" + type];
        if (
          this["scrollPosition4" + type] + container.clientHeight >=
            content.scrollHeight + affixHeight ||
          this["scrollPosition4" + type] <= 0
        ) {
          this["direction4" + type] *= -1; // 改变滚动方向
        }
        content.style.transform = `translateY(-${
          this["scrollPosition4" + type]
        }px)`;
      }, this["intervalTime4" + type]);
    },
  },
};
</script>

<style scoped lang="scss">
.abs-full {
  position: relative;
  display: flex;
  flex-direction: column;
  //padding:.08rem .10rem;
  //background:no-repeat center center url('~@/assets/images/layout/side_l_md.png');background-size:100% 100%;
  // background-color: rgba(29, 57, 110, 0.65);
  &.title1 {
    height: rem;
    width: 4.76rem;
    background: no-repeat center center
      url("~@/assets/images/dpNew2/title1.png");
    background-size: 100% 100%;
  }
  background: linear-gradient(
    to right,
    rgba(0, 60, 144, 0.9),
    /* #003c90 - 90% 不透明度 */ rgba(0, 44, 106, 0.7)
      /* #002c6a - 70% 不透明度 */
  );
}
.m-tt {
  height: 0.48rem;
  width: 100%;

  position: absolute;
  top: 0.07rem;
  left: 0.2rem;
  h4 {
    height: 100%;
    line-height: 0.48rem;
    margin: 0;
    font-size: 0.22rem;
    letter-spacing: 0.01rem;
    padding-left: 0.4rem;
    font-family: Source Han Sans SC;
    font-weight: bold;
    color: #ffffff;
    text-shadow: 0px 3px 8px rgba(19, 80, 113, 0.48);
    background: linear-gradient(180deg, #ffffff 54.00390625%, #28caff 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
  }
}

.m-body {
  display: flex;
  flex-direction: column;
  padding: 0.2rem;
  padding-top: 0.5rem;
  .top {
    display: flex;
    align-items: center;
    justify-content: start;
    gap: 0.3rem;
    .left {
      img {
        margin-top: 0.3rem;
      }
    }
    .right {
      p {
        background-image: url("~@/assets/images/dpNew2/underline.png");
        background-repeat: no-repeat;
        background-position: center center;
        background-size: 100% 100%;
        width: 3.2rem;
        height: 0.53rem;
        padding-left: 0.5rem;
        margin-bottom: 0.25rem;

        &:last-child {
          margin-bottom: 0;
        }
        span:nth-child(1) {
          font-family: PingFang SC;
          font-weight: 500;
          font-size: 0.22rem;
        //   color: #ffffff;
          margin-right: 0.3rem;
        }
        .count2 {
          font-family: diget year;
          font-weight: normal;
          font-size: 0.42rem;
          color: #ffffff;
          text-shadow: 0px 0.04rem 0.3rem rgba(5, 54, 78, 0.48);
          background: linear-gradient(180deg, #dff2ff 0%, #36acff 100%);
          -webkit-background-clip: text;
          -webkit-text-fill-color: transparent;
          margin-right: 0.1rem;
        }
        .unit2 {
          font-family: PingFang SC;
          font-weight: bold;
          font-size: 0.21rem;
          color: #1e6bb2;
        }
        .count1{
          font-family: diget year;
          font-weight: normal;
          font-size: 0.42rem;
          color: #ffffff;
          text-shadow: 0px 0.04rem 0.3rem rgba(5, 54, 78, 0.48);
          background: linear-gradient(180deg, #fffae4 0%, #ffe25d 100%);
          -webkit-background-clip: text;
          -webkit-text-fill-color: transparent;
          margin-right: 0.1rem;
        }
        .unit1 {
          font-family: PingFang SC;
          font-weight: bold;
          font-size: 0.21rem;
          color: #dfe224;
        }
      }
    }
  }
  .bottom {
    height: 2.8rem;
    overflow: hidden;
    margin-top: 0.16rem;
    .scrolling1 {
      min-height: 2.55rem;
      max-height: 2.55rem;
      overflow-y: auto;
      border-radius: 4px 4px 0px 0px;
      border: 1px solid #0aabff;
      // opacity: 0.5;
      dt {
        height: 0.42rem;
        line-height: 0.42rem;
        // margin-top: 0.05rem;
        color: #0adfff;
        display: grid;
        grid-template-columns: 1.5rem 0.8rem 0.9rem 0.8rem;
        background: linear-gradient(
          0deg,
          rgba(17, 146, 255, 0.6) 0%,
          rgba(14, 108, 159, 0.6) 100%
        );

        font-family: PingFang SC;
        font-weight: 500;
        font-size: 0.18rem;
        text-align: center;
        background: linear-gradient(
          0deg,
          rgba(17, 146, 255, 0.6) 0%,
          rgba(14, 108, 159, 0.6) 100%
        );
        border-radius: 4px 4px 0px 0px;
        border: 1px solid #0aabff;
        // opacity: 0.5;
      }
      dd {
        height: 0.4rem;
        // margin-bottom: 0.08rem;
        margin-left: 0;
        color: #d3dfeb;
        margin-right: 0px;
        display: grid;
        grid-template-columns: 1.5rem 0.8rem 0.9rem 0.8rem;
        // background-color: rgba(37,102,195,.3);
        text-align: center;
        font-size: 0.14rem;
        align-items: center;
        border-bottom: 0.01rem solid #1f77c2;
      }
    }
  }
  .bottom-yuan {
    height: 3rem;
    .scrolling1 {
      min-height: 2.8rem;
      max-height: 2.8rem;
      overflow: hidden;
      .list-wrap {
        position: relative;
        height: 2.4rem;
        overflow: hidden;
        // margin-top: 0.4rem;
      }
      .list-content {
        position: absolute; /* 绝对定位 */
        transition: transform 0.2s ease; /* 添加平滑过渡 */
        // top: 0.4rem;
      }
      dt {
        grid-template-columns: 2rem 0.8rem 0.9rem 0.8rem;
      }
      dd {
        grid-template-columns: 2rem 0.8rem 0.9rem 0.8rem;
      }
    }
  }
}

</style>