<template>
  <div>
    <div class="banner">
      <div v-for="(item, index) in list" :key="index" class="banner_roadList">
        <el-popover
          :title="item.project_name"
          trigger="hover"
          popper-class="popover"
          :placement="item.position"
          v-model="item.isShow"
          visible-arrow="true"
          @show="handleShow(item)"
        >
          <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="(itTwo, index) in item.checkList" :key="itTwo.name" class="project_name">
              <AppLink :data="itTwo">
                {{ itTwo.name }}
              </AppLink>
            </div>
          </template>

          <div slot="reference" class="banner_roadList_con">
            <img :src="item.icon" alt="" />
            <div class="item_title">{{ item.title }}</div>
          </div>
        </el-popover>
      </div>
      <div class="banner_homeList">
        <div v-for="(itemRoad, indexRoad) in homeList" :key="indexRoad">
          <el-popover trigger="hover" popper-class="popover" :placement="itemRoad.position" v-model="itemRoad.isShow">
            <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="banner_homeList_con">
              <img :src="itemRoad.icon" alt="" />
              <div class="item_title">{{ itemRoad.title }}</div>
            </div>
          </el-popover>
        </div>
      </div>
    </div>
    <div class="w1200">
      <ProjectCard
        title="在线国际学位"
        :list="internationalDegreeProjectList"
        baseUrl="/internationalDegree"
      ></ProjectCard>
      <ProjectCard title="留学中心" :list="studyAbroadProjectList" baseUrl="/studyAbroad"></ProjectCard>
    </div>
  </div>
</template>

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

export default {
  components: { ProjectCard, AppLink },
  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
      }
    }
  },
  data() {
    return {
      roadList: roadMapList,
      homeList: homeList,
      // 热门专业
      internationalDegreeProjectList: [
        {
          imgUrl: 'https://webapp-pub.ezijing.com/www/pc/internationalDegree/project_kelley.png',
          href: 'https://kelley.ezijing.com/'
        },
        {
          imgUrl: 'https://webapp-pub.ezijing.com/www/pc/internationalDegree/project_ciis.png',
          href: 'https://ciis.ezijing.com/'
        },
        {
          imgUrl: 'https://webapp-pub.ezijing.com/www/pc/internationalDegree/project_marywood.png',
          href: 'https://marywood.ezijing.com/'
        }
      ],
      // 热门专业
      studyAbroadProjectList: [
        {
          imgUrl: 'https://webapp-pub.ezijing.com/www/pc/studyAbroad/project_cbu.png',
          href: 'https://cbu-plus.ezijing.com/'
        },
        {
          imgUrl: 'https://webapp-pub.ezijing.com/www/pc/studyAbroad/project_marywood_plus_1.png',
          href: 'https://marywood-plus.ezijing.com/'
        },
        {
          imgUrl: 'https://webapp-pub.ezijing.com/www/pc/studyAbroad/project_sbu.png',
          href: 'https://sbu-plus.ezijing.com/'
        }
      ]
    }
  },
  methods: {
    // 展示时触发 ，只显示一个
    handleShow(val) {
      if (this.list) {
        this.list.map(item => {
          if (item.title !== val.title) {
            item.isShow = false
          }
        })
      }
    }
  }
}
</script>

<style lang="scss">
.el-popper[x-placement^='left'].popover .popper__arrow {
  right: -7px;
}
.el-popper[x-placement^='top'].popover .popper__arrow {
  bottom: -7px;
}
.el-popper[x-placement^='right'].popover .popper__arrow {
  left: -7px;
}
.el-popper[x-placement^='bottom'].popover .popper__arrow {
  top: -7px;
}
.el-popover.popover {
  background: rgba(255, 255, 255, 0.39);
  border-radius: 20px;
  padding: 26px 22px 40px 27px;
  .el-popover__title {
    font-weight: 400;
    color: #ffffff;
    font-size: 18px;
  }
  .project_name {
    font-size: 22px;
    font-weight: bold;
    color: #ffffff;
    cursor: pointer;
  }
  .project_name:hover {
    text-shadow: 2px 2px 5px rgb(143, 141, 141);
  }
  .line {
    width: 281px;
    border: 1px dashed #ccc;
    margin: 20px 0 20px 0;
  }
}

.banner {
  width: 100%;
  min-width: 1200px;
  background: url(https://webapp-pub.oss-cn-beijing.aliyuncs.com/www/pc/lifeLearning/banner.jpg);
  background-size: 100% 100%;
  height: 650px;
  position: relative;
  .banner_roadList {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    .banner_roadList_con:hover {
      text-shadow: 2px 2px 5px rgb(143, 141, 141);
    }

    .banner_roadList_con {
      display: flex;
      justify-content: center;
      align-items: center;
      flex-direction: column;
      cursor: pointer;

      .item_title {
        font-size: 20px;
        font-weight: bold;
        color: #ffffff;
      }
    }
  }
  .banner_roadList:nth-child(1) {
    position: absolute;
    top: 325px;
    left: 21.5%;
  }
  .banner_roadList:nth-child(2) {
    position: absolute;
    top: 270px;
    left: 40%;
  }
  .banner_roadList:nth-child(3) {
    position: absolute;
    top: 250px;
    left: 47%;
  }
  .banner_roadList:nth-child(4) {
    position: absolute;
    top: 140px;
    left: 58%;
  }
  .banner_roadList:nth-child(5) {
    position: absolute;
    top: 105px;
    left: 68%;
  }
  .banner_homeList {
    width: 50%;
    position: absolute;
    left: 50%;
    bottom: 52px;
    transform: translate(-50%, -50%);
    display: flex;
    justify-content: space-around;
    align-items: center;
    .banner_homeList_con:hover {
      text-shadow: 2px 2px 5px rgb(143, 141, 141);
    }
    .banner_homeList_con {
      display: flex;
      justify-content: center;
      align-items: center;
      flex-direction: column;
      cursor: pointer;
      .item_title {
        font-size: 20px;
        font-weight: bold;
        color: #ffffff;
      }
    }
  }
}
.w1200 {
  width: 1200px;
  margin: 84px auto;
}
</style>
