<template>
  <div class="qrcode-box">
    <div class="watch">
      <div class="watch-btn">
        <div class="icon"></div>
        <span class="title">手机观看</span>
      </div>
      <div class="watch-qr">
        <img :src="watchQr" alt="" />
      </div>
    </div>
  </div>
</template>

<script>
import QRCode from 'qrcode';
export default {
  name: 'pc-qrcode-box',
  data() {
    return {
      watchQr: ''
    };
  },
  mounted() {
    this.makeQrcode();
  },
  methods: {
    makeQrcode() {
      QRCode.toDataURL(window.location.href)
        .then(url => {
          this.watchQr = url;
        })
        .catch(err => {
          console.error(err);
        });
    }
  }
};
</script>
<style lang="less" scoped>
.qrcode-box {
  padding: 0 50px;
  height: 100%;
  .watch {
    display: inline-block;
    position: relative;
    z-index: 100;
    height: 100%;
    width: 100px;
    text-align: center;
    .watch-btn {
      color: #999999;
      cursor: pointer;
      .icon {
        vertical-align: middle;
        display: inline-block;
        width: 16px;
        height: 16px;
        background: url(./img/icon-sj.png) no-repeat center center;
        background-size: 100% 100%;
      }
      .title {
        vertical-align: middle;
        font-size: 18px;
      }
    }
    &:hover {
      .watch-qr {
        display: block;
      }
    }
    .watch-qr {
      position: absolute;
      bottom: 100%;
      left: calc(50% - 100px);
      display: none;
      padding: 10px;
      width: 200px;
      height: 200px;
      background: #27282e;
      &::after {
        content: '';
        position: absolute;
        bottom: -24px;
        left: calc(50% - 12px);
        display: inline-block;
        width: 0;
        height: 0;
        border: 12px solid;
        border-color: #27282e transparent transparent transparent;
      }
      img {
        width: 100%;
        height: 100%;
      }
    }
  }
}
</style>
