<template>
  <div class="cross-distance">
    <div
        class="cross-item"
        :class="{ distance: item.distance }"
        v-for="item in crossData"
        :key="item.id"
    >
      <p :class="{active:active===item.crossName}" style="cursor: pointer" @click="crossClick(item.crossName)"
         class="name" :title="item.crossName">
        {{ item.crossName }}
      </p>
      <div class="item-box">
        <i style="cursor: pointer" @click="crossClick(item.crossName)" class="title-icon"></i>
        <div class="distance-line" v-if="item.distanceToNextCross">
          <span>{{ item.distanceToNextCross }}米</span>
          <span class="distance-icon el-icon-caret-right"></span>
        </div>
      </div>
      <p class="second" v-if="type !== 'areaLine'">{{ item.offset }}秒</p>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      active: '',
      crossData: [
        {
          name: "相城大道与朱径支路交叉口",
          second: "11",
          distance: "377",
          endName: "相城大道起点",
        },
        {name: "相城大道起点", distance: "377", second: "11"},
        {name: "相城大道终点", second: "11", distance: "377"},
        {name: "相城大道起点", distance: "366", second: "11"},
        {name: "相城大道终点", second: "11"},
      ],
    };
  },
  props: ["contentData", "type", 'canClick'],
  mounted() {
    console.log('contentData', this.contentData)
    this.crossData = this.contentData.greenwaveCrossList;
    if (this.crossData.length) {
      setTimeout(() => {
        if (this.canClick) {
          this.crossClick(this.crossData[0].crossName)
        }
      }, 0)
    }
  },
  methods: {
    crossClick(crossName) {
      console.log('in zujian', crossName)
      this.$emit('crossClick', crossName)
      if (this.canClick) {
        this.active = crossName
      }
    }
  }
};
</script>

<style lang="less" scoped>
.cross-distance {
  display: flex;
  color: #c1c6ce;

  .active {
    background: radial-gradient(#025186, rgba(2, 81, 134, 0.8), transparent, transparent);
  }

  .cross-item {
    position: relative;
    flex: 1;

    &:nth-last-child(1) {
      max-width: 60px;
      flex: none;

      .name {
        min-width: 160px;
        // text-align: left !important;
        right: 0;
      }
    }

    &.distance {
      flex: 1;
    }

    .name {
      position: absolute;
      // left: 50px;
      margin-bottom: 10px;
      display: flex;
      justify-content: space-between;
      font-size: 16px;
      // overflow: hidden;
      // text-overflow: ellipsis;
      // white-space: nowrap;
      // width: 98%;
      display: block;
    }

    .item-box {
      display: flex;
      align-items: center;
      margin: 0 16px;
      margin-top: 30px;

    }

    justify-content: space-between;

    .second {
      margin-top: 0;
      width: 63px;
      height: 57px;
      line-height: 57px;
      text-align: center;
      background: url("../../../../assets/images/dialogImg/second-bg.png") no-repeat;
      background-size: 100% 100%;
    }

    .title-icon {
      display: inline-block;
      width: 28px;
      height: 31px;
      background: url("../../../../assets/images/dialogImg/title-icon.svg") no-repeat;
      background-size: 100% 100%;
    }

    .distance-line {
      position: relative;
      margin: 0 auto;
      top: 10px;
      width: 90%;
      text-align: center;
      border-top: 2px dashed #999;

      .distance-icon {
        position: absolute;
        right: -20px;
        bottom: 8px;
        font-size: 24px;
        color: #999;
      }
    }
  }
}
</style>
