<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>Videos</el-breadcrumb-item>
    </el-breadcrumb>
    <p class="title">Videos</p>
    <div class="line"></div>
    <ul class="item" v-loading="listLoading">
      <li v-for="item in videoList" :key="item.id">
        <div class="item-content">
          <video
            id="my-player"
            class="video-js"
            width="330"
            height="186"
            controls="controls"
            onMouseOver="this.play()"
            onMouseOut="this.pause()"
            muted
          >
            <source :src="item.url" />
          </video>
        </div>
        <p class="item-title">{{ item.title }}</p>
      </li>
    </ul>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
      @pagination="getList"
    />
    <div v-if="!videoList.length">
      <el-empty description="No Data"></el-empty>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      total: 0,
      listQuery: {
        page: 1,
        limit: 12,
      },
      videoList: [],
      listLoading: true,
    };
  },
  async created() {
    await this.getList();
  },
  methods: {
    getList() {
      this.$axios
        .post("/resources/video/list", {
          state: "au",
          page: this.listQuery.page,
          limit: this.listQuery.limit,
        })
        .then((res) => {
          if (res.code == 1) {
             res.result.data.forEach((item) => {
              item.url =
                !this.$mediaRegExp.test(item.url)
                  ? this.$OSS_PREFIX +
                    item.url
                  : item.url;
            });
            this.videoList = res.result.data;
            this.total = res.result.total;
            this.listLoading = false;
          }
          this.$nextTick(() => {
            window.scroll(0, 0);
          });
        })
        .catch(() => {
          this.listLoading = false;
          this.videoList = [];
        });
    },
  },
};
</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 {
  margin: 20px auto;
  display: flex;
  justify-content: flex-start;
  flex-wrap: wrap;
  font-family: Proxima Nova;
  li {
    width: 330px;
    height: 240px;
    background: #ffffff;
    box-shadow: 0px 0px 4px 0px rgba(0, 0, 0, 0.15);
    margin-right: 25px;
    margin-bottom: 30px;
    &:nth-of-type(4n) {
      margin-right: 0;
    }
    .item-title {
      height: 54px;
      font-size: 18px;
      font-weight: 400;
      color: #00213b;
      line-height: 54px;
      padding-left: 20px;
    }
  }
}
: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>
