<template>
  <div>
    <div class="banner">
      <div v-for="(item, index) in list" :key="index" class="roadList">
        <el-popover
          :title="item.project_name"
          trigger="click"
          popper-class="popover"
          :placement="item.position"
          v-model="item.isShow"
          visible-arrow="true"
          @show="handleShow(item)"
        >
          <div>
            <!-- 我的项目 -->
            <div v-for="(it, indexItem) in item.projectList" :key="indexItem" class="project_name">
              <AppLink :data="it">
                {{ it.name }}
              </AppLink>
            </div>
            <!-- 未来可选项目 -->
            <template v-if="item.checkList.length">
              <div class="line"></div>
              <div class="el-popover__title">未来可选目标:</div>
              <div v-for="(it, indexItem) in item.checkList" :key="it.name" class="project_name">
                <AppLink :data="it">
                  {{ it.name }}
                </AppLink>
              </div>
            </template>
          </div>
          <div slot="reference" class="roadList_con">
            <img :src="item.icon" alt="" />
            <div class="title">{{ item.title }}</div>
          </div>
        </el-popover>
      </div>
      <div class="homeList">
        <div class="homeList_con" v-for="(itemRoad, index) in homeListNew" :key="index">
          <el-popover
            trigger="click"
            popper-class="popover"
            :placement="itemRoad.position"
            v-model="itemRoad.isShow"
            :title="itemRoad.project_name"
            @show="handleShow(itemRoad)"
          >
            <div>
              <!-- 我的项目 -->
              <div v-for="(it, indexItem) in itemRoad.itemList" :key="indexItem" class="project_name">
                <AppLink :data="it">
                  {{ it.name }}
                </AppLink>
              </div>
            </div>
            <div slot="reference" class="homeList_con_item">
              <img :src="itemRoad.icon" alt="" />
              <div class="title">{{ itemRoad.title }}</div>
            </div>
          </el-popover>
        </div>
      </div>
    </div>
    <div class="content">
      <ProjectCard
        title="在线国际学位"
        :list="internationalDegreeProjectList"
        baseUrl="/internationalDegree"
      ></ProjectCard>
      <ProjectCard title="留学中心" :list="studyAbroadProjectList" baseUrl="/studyAbroad"></ProjectCard>
    </div>
  </div>
</template>

<script>
import { roadMapList, homeMapList } from '@/assets/roadMap'
import AppLink from '@/components/Link.vue'
import ProjectCard from '@/components/ProjectCard.vue'

export default {
  components: { AppLink, ProjectCard },

  computed: {
    // 个人报名列表
    learning() {
      return this.$store.state.user.learning_info || []
    },
    // 在读
    learningInfo() {
      if (this.learning.length) {
        return this.learning.filter(item => item.status === '1')
      } else {
        return []
      }
    },
    // 毕业
    graduateInfo() {
      if (this.learning.length) {
        return this.learning.filter(item => item.status === '0')
      } else {
        return []
      }
    },
    // 毕业 休学 在读
    otherInfo() {
      if (this.learning.length) {
        return this.learning.filter(item => item.status !== '3' || item.status !== '4')
      } else {
        return []
      }
    },
    // 展示信息
    list() {
      // status 状态（0：毕业，1：在读，2：休学，3：未开通，4：退学）
      if (this.learning.length > 0) {
        this.roadList.forEach(item => {
          // 最新在读显示 弹框 显示我的项目
          if (item.projectList.find(it => it.tenant === this.learningInfo[0].tenant)) {
            item.isShow = true
            item.project_name = '我的项目:'
          } else if (
            !this.otherInfo.find(item => item.status === '1') &&
            this.otherInfo.find(item => item.status === '0')
          ) {
            this.graduateInfo[0].isShow = true
            this.graduateInfo[0].project_name = '我的项目:'
          }
          const arr = []
          this.otherInfo.forEach(itL => {
            item.projectList.forEach(itP => {
              if (itL.tenant === itP.tenant) {
                arr.push(itP)
                item.project_name = '我的项目:'
              }
            })
          })
          if (item.project_name === '我的项目:') {
            item.projectList = arr
          }
        })
        return this.roadList
      } else {
        return this.roadList
      }
    },
    homeListNew() {
      if (this.learning.length > 0) {
        console.log(this.homeList, '0000')
        this.homeList.map(item => {
          // 最新在读显示 弹框 显示我的项目
          if (item.itemList.find(it => it.tenant === this.learningInfo[0].tenant)) {
            item.isShow = true
            item.project_name = '我的项目:'
          } else if (
            !this.otherInfo.find(item => item.status === '1') &&
            this.otherInfo.find(item => item.status === '0')
          ) {
            this.graduateInfo[0].isShow = true
            this.graduateInfo[0].project_name = '我的项目:'
          }
          const arr = []
          this.otherInfo.forEach(itL => {
            item.itemList.forEach(itP => {
              if (itL.tenant === itP.tenant) {
                arr.push(itP)
                item.project_name = '我的项目:'
              }
            })
          })
          if (item.project_name === '我的项目:') {
            item.itemList = arr
          }
        })
        return this.homeList
      } else {
        return this.homeList
      }
    }
  },
  data() {
    return {
      roadList: roadMapList,
      homeList: homeMapList,
      internationalDegreeProjectList: [
        {
          imgUrl: 'https://webapp-pub.ezijing.com/www/h5/lifeLearning/img1.png',
          href: 'https://kelley.ezijing.com/'
        },
        {
          imgUrl: 'https://webapp-pub.ezijing.com/www/h5/lifeLearning/img2.png',
          href: 'https://ciis.ezijing.com/'
        },
        {
          imgUrl: 'https://webapp-pub.ezijing.com/www/h5/lifeLearning/img3.png',
          href: 'https://marywood.ezijing.com/'
        }
      ],
      // 热门专业
      studyAbroadProjectList: [
        {
          imgUrl: 'https://webapp-pub.ezijing.com/www/h5/lifeLearning/img4.png',
          href: 'https://cbu-plus.ezijing.com/'
        },
        {
          imgUrl: 'https://webapp-pub.ezijing.com/www/h5/lifeLearning/img5.png',
          href: 'https://marywood-plus.ezijing.com/'
        },
        {
          imgUrl: 'https://webapp-pub.ezijing.com/www/h5/lifeLearning/img6.png',
          href: 'https://sbu-plus.ezijing.com/'
        }
      ]
    }
  },
  methods: {
    handleShow(val) {
      const allList = [...this.list, ...this.homeListNew]
      if (allList) {
        allList.map(item => {
          if (item.title !== val.title) {
            item.isShow = false
          }
        })
      }
    }
  }
}
</script>

<style lang="scss">
.el-popover.popover {
  background: rgba(255, 255, 255, 0.39);
  border-radius: 0.1rem;
  padding: 0.13rem 0.11rem 0.2rem 0.13rem;

  .el-popover__title {
    font-weight: 400;
    color: #ffffff;
    font-size: 0.09rem;
  }
  .project_name {
    font-size: 0.11rem;
    font-weight: bold;
    color: #ffffff;
    text-shadow: 2px 2px 5px #aa1941;
    cursor: pointer;
  }
  .line {
    width: 90%;
    border: 1px dashed #ccc;
    margin: 0.1rem 0 0.1rem 0;
  }
}
.banner {
  width: 100%;
  height: 6.31rem;
  background: url(https://webapp-pub.oss-cn-beijing.aliyuncs.com/www/h5/lifeLearning/banner.png);
  background-size: 100% 100%;
  position: relative;
  z-index: 1;
  .roadList {
    height: 0.8rem;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    position: absolute;
    .roadList_con {
      display: flex;
      justify-content: center;
      align-items: center;
      flex-direction: column;
      cursor: pointer;
    }
    .title {
      font-size: 0.14rem;
      font-weight: 500;
      color: #ffffff;
    }
  }
  .roadList:nth-child(1) {
    position: absolute;
    z-index: 100000;
    top: 0.35rem;
    left: 50%;
    transform: translateX(-50%);
    img {
      width: 0.2rem;
    }
  }
  .roadList:nth-child(2) {
    position: absolute;
    z-index: 100000;
    top: 1.43rem;
    left: 50%;
    transform: translateX(-50%);
    img {
      width: 0.21rem;
    }
  }
  .roadList:nth-child(3) {
    position: absolute;
    z-index: 100000;
    top: 2.5rem;
    left: 50%;
    transform: translateX(-50%);
    img {
      width: 0.32rem;
    }
  }
  .roadList:nth-child(4) {
    position: absolute;
    z-index: 100000;
    top: 3.57rem;
    left: 50%;
    transform: translateX(-50%);

    img {
      width: 0.25rem;
    }
  }
  .roadList:nth-child(5) {
    position: absolute;
    z-index: 100000;
    top: 4.44rem;
    left: 50%;
    transform: translateX(-50%);

    img {
      width: 0.19rem;
    }
  }
  .homeList {
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: absolute;
    top: 5.35rem;
    left: 50%;
    transform: translateX(-50%);
    width: 70%;

    .homeList_con {
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      .project_name {
        font-size: 0.11rem;
        font-weight: bold;
        color: #ffffff;
        cursor: pointer;
      }
      .homeList_con_item {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        cursor: pointer;

        .title {
          font-size: 0.14rem;
          font-weight: 500;
          color: #ffffff;
        }
        img {
          width: 0.4rem;
          height: 100%;
        }
      }
    }
  }
}
.content {
  padding: 0.28rem 0.21rem 0 0.21rem;
  .content_top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    .top_title {
      font-size: 0.17rem;
      font-weight: bold;
      color: #424242;
    }
    .top_more {
      font-size: 0.1rem;
      font-weight: 300;
      color: #9b9b9b;
    }
  }
  .content_bottom {
    width: 100%;
    img {
      width: 100%;
      height: 100%;
    }
  }
}
.content1 {
  margin-bottom: 0.28rem;
}
</style>
