<template>
  <div class="play-list">
    <div class="list-box">
      <div class="list">
        <div class="item" v-for="item in list" :key="item.id">
          <div class="box" @click="_play(item.materialUrl)">
            <div class="img-box">
              <div class="img">
                <img :src="item.coverUrl" alt="" />
                <div class="state" v-if="item.materialUrl == playerInfo.playUrl">
                  播放中
                </div>
              </div>
            </div>
            <div class="title">{{ item.name }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getPlaylistList } from '@/plugins/API/apiAll';
import { mapGetters, mapMutations } from 'vuex';

export default {
  name: 'pc-menu-playLists',
  props: {
    listId: {}
  },
  data() {
    return {
      list: []
    };
  },
  computed: {
    ...mapGetters({
      channelInfo: 'channelInfo',
      playerInfo: 'playerInfo'
    })
  },
  mounted() {
    if (this.listId) {
      this._getPlaylistList();
    }
  },
  methods: {
    ...mapMutations({
      set_playerInfo: 'set_playerInfo'
    }),
    async _getPlaylistList() {
      const res = await getPlaylistList({
        uin: this.channelInfo.uin,
        listId: Number(this.listId)
      });
      if (res.code === 200 && res.errorCode === 0) {
        this.list = res.data.detail;
      }
    },
    _play(url) {
      const info = JSON.parse(JSON.stringify(this.playerInfo));
      info.playUrl = url;
      info.cameraId = '';
      this.set_playerInfo(info);
    }
  }
};
</script>
<style lang="less" scoped>
.play-list {
  position: relative;
  padding: 6px;
  height: 100%;
  .list-box {
    height: 100%;
    overflow: auto;
  }
}
.list {
  display: flex;
  flex-wrap: wrap;
  .item {
    flex: 0 0 auto;
    padding: 8px;
    width: 100% / 6;
    .box {
      display: flex;
      flex-direction: column;
      .img-box {
        flex: 1;
        .img {
          position: relative;
          padding-top: 100% * 9 /16;
          img {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            object-fit: cover;
          }
          .state {
            position: absolute;
            top: 0;
            left: 0;
            padding: 0 14px;
            height: 20px;
            line-height: 20px;
            font-size: 12px;
            color: #fff;
            &:before {
              content: '';
              display: block;
              position: absolute;
              top: 8px;
              left: 5px;
              width: 4px;
              height: 4px;
              border-radius: 100%;
              background: var(--main-color);
            }
          }
        }
      }
      .title {
        flex: 1;
        max-height: 40px;
        line-height: 20px;
        overflow: hidden;
        font-size: 14px;
        color: #fff;
        text-align: justify;
        word-break: break-all;
      }
    }
  }
}
</style>
