<template>
  <div class="units-content">
    <p>{{ units.title }}</p>
    <ul>
      <li
        v-for="(item, index) in units.children"
        :key="index"
        :class="{ active: activeUnit === item.euId }"
        :style="`--i: ${1 / units.children.length}`"
        @click="showUnit(item.euId)"
      >
        <!-- <div class="unit-title">{{ item.title }}</div>

                <div class="unit-intro">{{ item.intro }}</div>
                <div
                  class="unit-imgs"
                  v-if="item.imagesVo && item.imagesVo.length > 0"
                >
                  <div
                    class="img-item"
                    v-for="(i, idx) in item.imagesVo"
                    :key="idx"
                  >
                    <img :src="$getFullUrl(i.url)" alt="" />
                  </div>
                </div> -->
        <div class="unit-node">
          <div class="unit-imgs">
            <div
              class="img-item"
              v-if="item.imagesVo && item.imagesVo.length > 0"
            >
              <img :src="$getFullUrl(item.imagesVo[0].pressUrl || item.imagesVo[0].url)" alt="" />
            </div>
          </div>
          <div class="unit-content">
            <div class="unit-title">{{ item.title }}</div>

            <div class="unit-intro" v-html="item.intro"></div>
          </div>
        </div>
        <div class="units-title">
          <p>
            <span v-html="changeTitle(item.title)"></span>
          </p>
          <span></span>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  props: {
    units: {
      type: Object,
    },
  },
  data() {
    return {
      activeUnit: "",
    };
  },
  methods: {
    changeTitle(str) {
      return str.split("").join("<br>");
    },
    showUnit(id) {
      if (id === this.activeUnit) {
        this.activeUnit = " ";
      } else {
        this.activeUnit = id;
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.units-content {
  > p {
    font-size: 32px;
    font-weight: 600;
    text-align: center;
    font-family: "华文行楷";
  }
  ul {
    display: flex;
    flex-wrap: nowrap;
    overflow: auto;
    li {
      // margin-bottom: 20px;
      width: calc(var(--i) * 100%);
      transition: 0.6s;
      overflow: hidden;
      // flex-shrink: 0;
      position: relative;
      &.active {
        width: 100%;
        flex-shrink: 0;

        > .unit-node {
          filter: none;
          /* > .unit-imgs {
                  width: 100%;
                  .img-item {
                    width: 100%;
                    height: auto;
                    img {
                      width: 100%;
                      height: auto;
                    }
                  }
                } */
        }
        > .units-title {
          opacity: 0;
        }
      }
      &:hover {
        cursor: pointer;
      }
      .unit-title {
        font-size: 36px;
        font-family: KaiTi;
        font-weight: 400;
        // color: #4e392c;
        color: #bb4343;
        line-height: 83px;
        display: flex;
        justify-content: center;
      }
      .unit-intro {
        font-size: 16px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        // color: #444444;
        color: #e2e2e2;
        text-indent: 36px;
        // margin-bottom: 10px;
        // margin-top: 20px;
        line-height: 1.8;
      }
      .unit-imgs {
        width: 100%;
        // width: 500px;
        height: 100%;
        flex-shrink: 0;
        overflow: hidden;
        .img-item {
          width: 100%;
          display: flex;
          justify-content: center;
          align-items: center;
          // height: 100%;
          img {
            width: 100%;
            // height: 100%;
            transition: 0.6s;
          }
        }
      }
      .unit-node {
        width: 1200px;
        // width: calc(100vw - 26%);
        height: 550px;
        display: flex;
        overflow: hidden;
        transition: 0.6s;
        filter: sepia(0.6);
        position: relative;

        > .unit-content {
          padding: 10px 30px;
          flex: 1;
          flex-shrink: 0;
          // background-color: #fff;
          position: absolute;
          top: 0;
          right: 0;
          width: 50%;
          height: 100%;
          background-image: linear-gradient(
            to right,
            rgba(0, 0, 0, 0) 0%,
            rgba(0, 0, 0, 0.7) 40%
          );

          > .unit-title {
            position: absolute;
            top: 100px;
            left: 50%;
            transform: translateX(-50%);
          }
          > .unit-intro {
            position: absolute;
            top: 200px;
            height: 70%;
            padding: 0 80px;
          }
        }
      }
      .units-title {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        transition: 0.6s;
        > p {
          color: #fff;
          position: absolute;
          left: 0;
          top: 0;
          margin: 0;
          font-size: 28px;
          font-family: "楷体";
          padding: 16px;
          height: calc(100% - 32px);
          box-shadow: 10px 0px 21px 0 #9b7e3f inset;
        }
      }
    }
  }
}
</style>
