<template>
  <div class="com-main com-width-1400 com-margin-auto">
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">Home</el-breadcrumb-item>
      <el-breadcrumb-item> NewsLetter</el-breadcrumb-item>
    </el-breadcrumb>
    <p class="title">NewsLetter</p>
    <div class="line"></div>
    <div class="item" v-loading="listLoading">
      <ul>
        <book-card
          v-for="item in newsLetterInfo"
          :key="item.id"
          :cardData="item"></book-card>
      </ul>
      <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
      @pagination="getInfoList"
    />
    </div>
    <div v-if="!newsLetterInfo.length">
      <el-empty description="No Data"></el-empty>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      total: 0,
      listQuery: {
        page: 1,
        limit: 20,
      },
      newsLetterInfo: [],
      listLoading: true,
    };
  },
  async created() {
    await this.getInfoList();
  },
  methods: {
    getInfoList() {
      this.$axios
        .get("others/au/newsletter",{
          page: this.listQuery.page,
          limit: this.listQuery.limit,
        })
        .then((res) => {
          if (res.code == 1) {
            this.total = res.result.total;
             res.result.data.forEach((item) => {
              item.filepath =
                !this.$mediaRegExp.test(item.filepath)
                  ? this.$OSS_PREFIX +
                    item.filepath
                  : item.filepath;
                  item.img =
                !this.$mediaRegExp.test(item.img)
                  ? this.$OSS_PREFIX +
                    item.img
                  : item.img;
            });
            this.newsLetterInfo = res.result.data;
            this.listLoading = false;
          }
           this.$nextTick(() => {
            window.scroll(0, 0);
          });
        })
        .catch(() => {
          this.listLoading = false;
          this.newsLetterInfo = [];
        });
    },
  },
};
</script>

<style lang="scss" scoped>
.title {
  height: 50px;
  font-size: 35px;
  font-family: Proxima Nova;
  font-weight: bold;
  color: #00213B;
  text-align: center;
  line-height: 50px;
}
.line {
  width: 99px;
  height: 4px;
  background: #e90000;
  margin: 15px auto;
}
.item {
  ul {
    width: 940px;
    margin: 0 auto;
    display: flex;
    justify-content: flex-start;
    flex-wrap: wrap;
  }
}
:deep(.el-pagination.is-background) {
  .el-pager {
    li.number {
      background-color: #f8f8f8;
      border-radius: 50%;
      color: #a7a7a7;
    }
    li:not(.disabled).active {
      background-color: #00213b;
      color: #d4d7da;
    }
  }
  .btn-prev,
  .btn-next {
    border-radius: 50%;
    background-color: #fff;
    .el-icon-arrow-left:before {
      content: "";
    }
    .el-icon-arrow-right:before {
      content: "";
    }
  }
}
</style>
