<template>
  <div class="main">
    <!-- 搜索 -->
    <search-bar readonly @click.native="$router.push({ name: 'search' })"></search-bar>
    <!-- banner -->
    <div class="banner">
      <!-- <img src="img/home_banner.png" /> -->
      <img src="https://zws-imgs-pub.ezijing.com/static/public/a75cfc8e05ad90005db9814e02fc1e27.png">
    </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.url" />
          </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 in popularList"
          :key="item.id"
          @click="$router.push({ name: 'groupItem', params: { id: item.id } })"
        >
          <div class="popular-item-pic">
            <img :src="item.logo" />
          </div>
          <div class="popular-item-main">{{item.org_name}}</div>
        </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: [
        { url: 'img/home_nav_01.png', title: '公益行', type: 1 },
        { url: 'img/home_nav_02.png', title: '去游学', type: 2 },
        { url: 'img/home_nav_03.png', title: '直播课', type: 3 },
        // { url: 'img/home_nav_04.png', title: '找工作', type: 4 },
        { url: 'img/home_nav_04.png', title: '运动家', type: 5 }
      ],
      popularList: []
    }
  },

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

  beforeMount() {
    this.getPopular()
  }
}
</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-bottom: 10px;
  display: flex;
  justify-content: space-between;
}
.top-bar-item {
  flex: 1;
  height: 70px;
  font-size: 16px;
  font-weight: 400;
  line-height: 70px;
  color: #fff;
  text-align: center;
  cursor: pointer;
}
.top-bar-item__group {
  background: url('~@/assets/img/home_group_bg.png') no-repeat center;
  background-size: cover;
}
.top-bar-item__activity {
  background: url('~@/assets/img/home_activity_bg.png') no-repeat center;
  background-size: cover;
}
.popular-list {
  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: 18px;
  margin-right: 15px;
  width: 165px;
  height: 140px;
  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: 95px;
  img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
}
.popular-item-main {
  font-size: 13px;
  color: #1b1b1b;
  text-align: center;
  padding: 8px 10px;
}
</style>
