<template>
  <div class="camera">
    <div
      class="box"
      :class="{ 'z-active': playerInfo.playUrl == item.playUrl }"
      v-for="item in list"
      :key="item.id"
      @click="_changePlayer(item.playUrl, item.id)"
    >
      <div class="name">{{ item.name }}</div>
      <img class="img" v-if="item.thumbnail" :src="item.thumbnail" alt="" />
      <div class="icon" v-else></div>
    </div>
  </div>
</template>

<script>
import { getCaremaList } from '@/plugins/API/apiAll';
import { mapGetters, mapMutations } from 'vuex';
export default {
  name: 'camera-box',
  data() {
    return {
      list: []
    };
  },
  computed: {
    ...mapGetters({
      channelInfo: 'channelInfo',
      playerInfo: 'playerInfo'
    })
  },
  mounted() {
    this._getCaremaList();
  },
  methods: {
    ...mapMutations({
      set_playerInfo: 'set_playerInfo'
    }),
    // 获取多机位
    async _getCaremaList() {
      const res = await getCaremaList({
        id: this.channelInfo.id,
        uin: this.channelInfo.uin
      });
      if (res.code === 200 && res.errorCode === 0) {
        const list = res.data || [];
        this.list = list.filter(x => {
          return x.display;
        });
      }
    },
    _changePlayer(url, id) {
      const info = JSON.parse(JSON.stringify(this.playerInfo));
      info.playUrl = url;
      info.cameraId = id;
      this.set_playerInfo(info);
    }
  }
};
</script>

<style lang="less" scoped>
.camera {
  height: 0.53rem;
  padding: 0.04rem 0.06rem;
  overflow-x: auto;
  background-color: #f6f6f6;
  white-space: nowrap;
  font-size: 0;
  .box {
    display: inline-block;
    position: relative;
    margin-right: 0.06rem;
    width: 0.8rem;
    height: 0.45rem;
    border-radius: 0.02rem;
    border: 0.01rem solid transparent;
    overflow: hidden;
    .img {
      display: block;
      width: 100%;
      height: 100%;
      background-color: #333333;
    }
    .icon {
      width: 100%;
      height: 100%;
      background: #4a4a4a url(./img/icon-video.png) no-repeat center center;
      background-size: 20% auto;
    }
    .name {
      position: absolute;
      top: 0.02rem;
      left: 0.02rem;
      font-size: 0.06rem;
      color: #fff;
    }
    &.z-active {
      border-color: var(--main-color);
    }
  }
}
</style>
