<template>
  <div class="play-list">
    <div class="list-box">
      <div class="list" :class="{ 'z-list': !type }">
        <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 class="toggle" @click="_toggle">
      <div class="icon-block" v-if="!type"></div>
      <div class="icon-list" v-else></div>
    </div>
  </div>
</template>

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

export default {
  name: 'menu-playLists',
  props: {
    listId: {}
  },
  data() {
    return {
      type: true,
      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);
    },
    _toggle() {
      this.type = !this.type;
    }
  }
};
</script>
<style lang="less" scoped>
.play-list {
  position: relative;
  padding: 0.06rem;
  height: 100%;
  .list-box {
    height: 100%;
    overflow: auto;
  }
}
.list {
  display: flex;
  flex-wrap: wrap;
  .item {
    flex: 0 0 auto;
    padding: 0.06rem;
    width: 50%;
    .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 0.14rem;
            height: 0.2rem;
            line-height: 0.2rem;
            font-size: 0.12rem;
            color: #fff;
            &:before {
              content: '';
              display: block;
              position: absolute;
              top: 0.08rem;
              left: 0.05rem;
              width: 0.04rem;
              height: 0.04rem;
              border-radius: 100%;
              background: var(--main-color);
            }
          }
        }
      }
      .title {
        flex: 1;
        max-height: 0.4rem;
        line-height: 0.2rem;
        overflow: hidden;
        font-size: 0.13rem;
        color: #333333;
        text-align: justify;
        word-break: break-all;
      }
    }
  }
  &.z-list {
    .item {
      width: 100%;
      .box {
        flex-direction: unset;
        .img-box {
          margin-right: 0.1rem;
        }
      }
    }
  }
}
.toggle {
  position: absolute;
  bottom: 0.6rem;
  right: 0.1rem;
  width: 0.3rem;
  height: 0.3rem;
  border-radius: 100%;
  background: linear-gradient(#4285ec 0%, #72b8ff 97%, #00c4ff 100%);
  .icon-block {
    width: 100%;
    height: 100%;
    background: url(./img/icon-block.png) no-repeat center center;
    background-size: 50% auto;
  }
  .icon-list {
    width: 100%;
    height: 100%;
    background: url(./img/icon-list.png) no-repeat center center;
    background-size: 50% auto;
  }
}
@media screen and (min-width: 500px) {
  .list .item {
    width: 20%;
  }
  .toggle {
    display: none;
  }
}
</style>
