<template>
  <div class="hotbook-box">
    <div class="most-book" @click="handleDetails(0)">
      <div class="most-book-img">
        <img :src="bookdata[0].cover ? bookdata[0].cover : ''" :onerror="defaultImg">
      </div>
      <div class="most-book-txt book-rack">
        <div class="txt">
          <h3>书名：{{ bookdata[0].nbName }}</h3>
          <p>作者：{{ bookdata[0].nbAuthor }}</p>
          <p>出版社：{{ bookdata[0].nbAuthor }}</p>
          <p>出版时间：{{ bookdata[0].nbPublisherdate }}</p>
        </div>
      </div>
    </div>
    <ul class="hotbook-list">
      <li v-for="(item,index) in bookList" :key="index" @click="handleDetails(index)">
        <img :src="item.cover ? item.cover : ''" :onerror="defaultImg">
        <p class="book-name">{{ item.nbName }}</p>
      </li>
    </ul>
    <BookDetails ref="detailDom" />
  </div>
</template>

<script>
import BookDetails from './bookDetails.vue'
export default {
  name: 'BookList',
  components: { BookDetails },
  props: {
    bookdata: {
      type: Array,
      default: function() {
        return []
      }
    }
  },
  data() {
    return {
      defaultImg: 'this.src="' + require('@/assets/images/default-img.png') + '"'
    }
  },
  computed: {
    bookList() {
      const arr = this.bookdata.slice(1)
      return arr
    }
  },
  methods: {
    handleDetails(index) {
      this.$refs.detailDom.bookData = this.bookdata[index]
      this.$refs.detailDom.dialogVisible = true
      console.log(this.bookdata[0])
    }
  }

}
</script>

<style lang="scss" scoped>
@import "~@/assets/styles/index.scss";
.hotbook-box{
  overflow: hidden;
  overflow-y: auto;
  height: calc(100vh - 180px);
}
.book-rack{
  margin: 160px 40px 28px 40px;
  padding: 38px 40px 40px 400px;
  height: 272px;
}
.most-book{
  position: relative;
  .most-book-img{
    position: absolute;
    left: 90px;
    bottom: 20px;
    width: 318px;
    height: 382px;
    overflow: hidden;
    img{
      width: 100%;
      vertical-align: middle;
    }
  }
  .txt{
    // margin-left: 452px;
    color: #333;
    h3{
      font-size: 40px;
      font-weight: normal;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
    p{
      font-size: 30px;
      margin-top: 8px;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
  }
}
.hotbook-list{
  margin: 0 40px;
  display: flex;
  flex-wrap: wrap;
  // justify-content: space-between;
  li{
    margin-bottom: 20px;
    margin-left: 48px;
    width: 300px;
    overflow: hidden;
    // text-align: center;
    img{
      width: 100%;
      vertical-align: middle;
      height: 360px;
    }
    .book-name{
      width: 100%;
      overflow: hidden;
      text-overflow:ellipsis;
      white-space: nowrap;
    }
  }
  & li:nth-child(3n+1){
    margin-left: 0;
  }
}
</style>
