<template>
  <view class="item-container" @click="$emit('click')">
    <view class="item-box">
      <view class="item-box-left">
        <!-- <image
          class="img-item"
          :src="data.imgCover"
          mode="scaleToFill"
        /> -->
        <image 
          class="img-item"
          :src="data.cover || data.imgCover || (data.imgPath ? baseUrl + '/api/fileRelevant/getImg?imgType=2&imgId=' + data.imgPath : '/static/images/default-book.png')"
          mode="scaleToFill"
          @error="onImgError"
        ></image>
      </view>
      <view class="item-box-right">
        <view class="item-title line-clamp-2">{{ data.title || data.name  || '暂无标题' }}</view>
        <text class="item-author">{{ data.author || '佚名' }}</text>
        <text class="item-publish">{{ data.publisher || '暂无出版社数据' }}</text>
        <!-- <view class="item-desc line-clamp-2">{{ data.desc || '暂无简介' }}</view> -->
        <!-- <view class="item-bottom-box">
          <view class="hot-box">
            <text class="hot-text">{{ hotNumber(data.views) }} 热度</text>
          </view> 
        </view>-->
      </view>
    </view>
  </view>
</template>

<script>
import config from '@/utils/config';

export default {
  name: "book-list-item",
  props: {
    data: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      baseUrl: config.baseUrl
    }
  },
  methods: {
    onImgError(e) {
      e.target.src = "/static/images/default-book.png";
    },
    hotNumber(num) {
      if (!num) return "0";
      if (num >= 10000) {
        return (num / 10000).toFixed(1) + "w";
      }
      return num;
    }
  }
};
</script>

<style lang="scss" scoped>
.item-container {
  padding-bottom: 10px;
  .item-box {
    display: flex;
    justify-content: flex-start;
    align-items: flex-start;
    // margin: 0 10px;
    padding: 10px;
    background-color: #fff;
    border-radius: 6px;
    // box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    border-bottom: 1px solid #f4f4f4;
    .item-box-left {
      margin-right: 8px;
      .img-item{
        width: 64px;
        height: 90px;
        margin: 0 12px 0 0;
        border-radius: 5px;
      }
    }
    .item-box-right {
      display: flex;
      flex-direction: column;
      justify-content: flex-start;
      flex: 1;
      .item-title {
        font-size: 15px;
        font-weight: bold;
        color: #000;
        padding-bottom: 10px;
      }
      .item-author,
      .item-publish {
        font-size: 12px;
        color: #888;
        padding-bottom: 10px;
      }
      .hot-text {
        font-size: 12px;
        color: #ff4444;
      }
      .item-desc {
        padding-top: 5px;
        font-size: 13px;
        color: #666;
        line-height: 1.4;
      }
      .item-bottom-box {
        margin-top: 8px;
        display: flex;
        justify-content: space-between;
        align-items: center;

      }
    }
  }
}
</style>