<template>
  <div class="main">
    <!-- 搜索 -->
    <search-bar readonly @click.native="$router.push({ name: 'search' })"></search-bar>
    <!-- banner -->
    <div class="banner">
      <van-swipe :autoplay="3000" indicator-color="white">
        <van-swipe-item>
          <router-link to="/vote/index"><img src="img/home_banner2.jpg" /></router-link>
        </van-swipe-item>
        <van-swipe-item><img src="img/home_banner.png" /></van-swipe-item>
      </van-swipe>
    </div>
    <!-- 导航 -->
    <div class="nav">
      <ul class="nav-list">
        <li class="nav-item" v-for="(item, index) in navList" :key="index" @click="handleNavClick(item)">
          <div class="pic">
            <img :src="item.src" />
          </div>
          <div class="title">{{ item.title }}</div>
        </li>
      </ul>
    </div>
    <!-- 排行榜 -->
    <div class="top-bar">
      <ul class="top-bar-list">
        <li class="top-bar-item top-bar-item__group" @click="$router.push({ name: 'group' })">组织排行</li>
        <li class="top-bar-item top-bar-item__activity" @click="$router.push({ name: 'activity' })">活动排行</li>
      </ul>
    </div>
    <card title="热门推荐">
      <div class="popular-list">
        <div class="popular-item" v-for="(item, index) in popularList" :key="index">
          <a :href="item.href">
            <div class="popular-item-pic">
              <img :src="item.src" />
            </div>
            <div class="popular-item-main">{{ item.title }}</div>
          </a>
        </div>
      </div>
    </card>
    <card title="最新活动">
      <activity-list :params="{ newest: 1 }"></activity-list>
    </card>
    <tab-bar></tab-bar>
  </div>
</template>

<script>
// components
import SearchBar from '@/components/SearchBar'
import TabBar from '@/components/TabBar'
import Card from '@/components/Card'
import ActivityList from '@/components/ActivityList'
import * as api from '@/api'

export default {
  name: 'HomeIndex',
  components: { SearchBar, TabBar, Card, ActivityList },

  data() {
    return {
      navList: [
        { src: 'img/home_nav_01.png', title: '公益行', type: 1 },
        { src: 'img/home_nav_02.png', title: '去游学', type: 2 },
        { src: 'img/home_nav_03.png', title: '直播课', type: 3 },
        // { src: 'img/home_nav_04.png', title: '找工作', type: 4 },
        { src: 'img/home_nav_04.png', title: '运动家', type: 5 }
      ],
      popularList: [
        {
          title: '紫荆-索菲亚FMBA项目',
          src: 'img/home_sofia.png',
          href: 'https://pages.ezijing.com/sofia-mba/mobile/channel.html?channel_num=29756'
        },
        {
          title: '紫荆-Kelley金融硕士项目',
          src: 'img/home_kelley.png',
          href: 'https://pages.ezijing.com/sofia-mba/mobile/channel.html?channel_num=29756'
        }
      ]
    }
  },

  methods: {
    handleNavClick({ type }) {
      this.$router.push({ name: 'activity', query: { type } })
    },
    getPopular() {
      api.getPopular().then(response => {
        this.popularList = response
      })
    }
  }
}
</script>

<style lang="scss">
.banner {
  margin: 0 -15px;
  img {
    width: 100%;
  }
}
.nav {
  padding: 30px 0 20px;
}
.nav-list {
  display: flex;
  justify-content: center;
  align-items: center;
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  .pic {
    width: 40px;
    height: 40px;
    img {
      width: 100%;
    }
  }
  .title {
    margin-top: 4px;
    color: #666;
  }
}
.top-bar-list {
  margin-left: -5px;
  margin-right: -5px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
}
.top-bar-item {
  width: 1.75rem;
  height: 0.7rem;
  font-size: 16px;
  font-weight: 400;
  line-height: 0.7rem;
  color: #fff;
  text-align: center;
  cursor: pointer;
}
.top-bar-item__group {
  background: url('~@/assets/img/home_group_bg.png') no-repeat center;
  background-size: contain;
}
.top-bar-item__activity {
  background: url('~@/assets/img/home_activity_bg.png') no-repeat center;
  background-size: contain;
}
.popular-list {
  display: flex;
  justify-content: space-between;
  // display: flex;
  // overflow-x: auto;
  // overflow-y: hidden;
  // margin-left: -15px;
  // margin-right: -15px;
  // -webkit-overflow-scrolling: touch;
}
.popular-item {
  flex-shrink: 0;
  margin-bottom: 0.18rem;
  // margin-right: 0.15rem;
  width: 1.65rem;
  min-height: 1.4rem;
  background: #ffffff;
  box-shadow: 0px 2px 6px 0px rgba(74, 9, 25, 0.05);
  border-radius: 6px;
  overflow: hidden;
  // &:first-child {
  //   margin-left: 15px;
  // }
}
.popular-item-pic {
  height: 0.95rem;
  img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
}
.popular-item-main {
  font-size: 13px;
  color: #1b1b1b;
  text-align: center;
  padding: 0.08rem 0.1rem;
}
</style>
