<template>
  <div class="container">
    <div class="content">
      <div class="title">教材</div>
      <div class="items" v-if="show">
        <div v-for="item in list" :key="item.id" @click="toDetail(item)">
          <div class="inner">
            <img :src="item.coverImg" class="img" />
            <div>{{ item.name }}</div>
          </div>
        </div>
      </div>
      <van-empty v-else description="暂无数据" />
    </div>
  </div>
</template>

<script>
export default {
  name: "baseList",
  data() {
    return {
      list: [],
      show: true,
    };
  },
  async mounted() {
    const musicScoreList = sessionStorage.getItem('musicScoreList')
    if(musicScoreList) {
      this.list = JSON.parse(musicScoreList) // 从上面页面获取分类信息
    }
    this.show = this.list.length > 0 ? true : false
  },
  methods: {
    toDetail(item) {
      this.$emit('onDetail', {
        path: 'list',
        id: item.id
      })
    },
  },
};
</script>

<style lang="less" scoped>
.container{
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  .content{
    flex: 1;
    background-color: #F5F5F5;
    padding: 12px;

    .title{
      color: #333333;
      font-size: 18px;
      font-weight: 500;
      display: flex;
      align-items: center;
      &::before{
        content: '';
        display: block;
        width: 4px;
        height: 18px;
        border-radius: 2px;
        background-color: #01C1B5;
        margin-right: 6px;
      }
    }
    .items{
      display: flex;
      align-items: center;
      flex-wrap: wrap;
      >div{
        margin-top: 20px;
        width: 33.333%;
        text-align: center;
        .inner {
          width: 1.05rem;
          margin: 0 auto;
        }
        .img{
          margin-top: 0;
          width: 100%;
        }
        :global {
          .van-image, .van-image__error,.van-image__loading {
            width: 1.05rem;
            min-height: 1.34rem;
          }
        }
        >div{
          margin-top: 7px;
          font-size: 14px;
          font-weight: 500;
          color: #1A1A1A;
          line-height: 20px;
        }
      }
    }
  }
}

</style>
