<template>
  <main class="app-main">
    <h1 class="app-main__title" v-if="title">{{ title }}</h1>
    <div class="app-main-inner">
      <ul class="app-main-tabs">
        <li v-for="(item, index) in tabs" :class="genClassName(item)" :key="index" @click="handleClick(item.path)">
          {{ item.name }}
        </li>
      </ul>
      <section class="app-main-container">
        <slot></slot>
        <article class="app-main-article">
          <div>
            <slot name="article"></slot>
          </div>
        </article>
        <slot name="footer"></slot>
      </section>
    </div>
  </main>
</template>
<script>
export default {
  name: 'AppFrame',
  props: {
    title: { type: String },
    tabs: { type: Array, default: () => [] }
  },
  data() {
    return {}
  },
  computed: {
    activeTab() {
      const tabs = [...this.tabs].reverse()
      const found = tabs.find(item => item.path === this.$route.path)
      return found || tabs.find(item => this.$route.fullPath.includes(item.path))
    }
  },
  methods: {
    handleClick(path) {
      this.$router.push({ path })
    },
    genClassName(data) {
      if (!this.activeTab) return ''
      return this.activeTab.path === data.path ? 'is-active' : ''
    }
  }
}
</script>
<style lang="scss">
.is-pc {
  .app-main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 60px 0;
  }
  .app-main__title {
    font-size: 28px;
    font-weight: 500;
    line-height: 1;
    color: #aa1941;
    padding-bottom: 30px;
  }
  .app-main-inner {
    display: flex;
    align-items: flex-start;
  }
  .app-main-tabs {
    min-width: 160px;
    background: #fff;
    padding: 40px 0;
    margin-right: 50px;
    li {
      position: relative;
      padding: 0 20px;
      height: 40px;
      font-size: 22px;
      line-height: 40px;
      text-align: center;
      color: #777777;
      cursor: pointer;
      &.is-active {
        color: rgba(170, 25, 65, 1);
        &::after {
          content: '';
          position: absolute;
          top: 0;
          left: 0;
          width: 8px;
          height: 40px;
          background: rgba(170, 25, 65, 1);
        }
      }
    }
    li + li {
      margin-top: 60px;
    }
  }
  .app-main-container {
    flex: 1;
    overflow: hidden;
    .banner {
      width: 100%;
      display: block;
      height: 320px;
    }
  }
  .app-main-article {
    padding: 50px;
    background: #fff;
  }
}
.is-h5 {
  .app-main-tabs {
    display: flex;
    overflow-x: auto;
    li {
      margin-left: 0.3rem;
      font-size: 0.14rem;
      line-height: 0.38rem;
      color: #333;
      white-space: nowrap;
      &.is-active {
        border-bottom: 0.02rem solid #aa1941;
      }
    }
  }
  .banner {
    display: block;
    width: 100%;
    height: 1.2rem;
    object-fit: cover;
  }
  .app-main-article {
    padding: 0.2rem 0.15rem;
    background: #fff;
  }
}

.app-main-article img {
  max-width: 100%;
}
</style>
