<template>
  <div class="red-box" v-show="showRed && showRedInfo.id">
    <div class="info-box">
      <div class="head">
        手机扫描领取红包
      </div>
      <div class="ewm">
        <img :src="watchQr" />
      </div>
      <i class="close" @click="_closeRed"></i>
    </div>
  </div>
</template>

<script>
import QRCode from 'qrcode';
import { mapGetters, mapMutations } from 'vuex';
export default {
  name: 'pc-red-box',
  data() {
    return {
      watchQr: ''
    };
  },
  computed: {
    ...mapGetters({
      showRed: 'showRed',
      showRedInfo: 'showRedInfo'
    })
  },
  mounted() {
    this.makeQrcode();
  },
  methods: {
    ...mapMutations({
      set_showRed: 'set_showRed'
    }),
    makeQrcode() {
      QRCode.toDataURL(window.location.href)
        .then(url => {
          this.watchQr = url;
        })
        .catch(err => {
          console.error(err);
        });
    },
    _closeRed() {
      this.set_showRed(false);
    }
  }
};
</script>

<style lang="less" scoped>
.red-box {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 500;
  background-color: rgba(0, 0, 0, 0.3);
  .info-box {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 100;
    margin: auto;
    width: 330px;
    height: 480px;
    background: url('./img/red-bg.png') no-repeat 0 0;
    background-size: 100% 100%;
    .head {
      padding-top: 130px;
      color: #fff;
      font-size: 25px;
      text-align: center;
    }
    .ewm {
      position: absolute;
      bottom: 20px;
      left: calc(50% - 145px);
      width: 290px;
      height: 290px;
      img {
        display: block;
        width: 100%;
        height: 100%;
      }
    }
    .close {
      position: absolute;
      right: 0px;
      top: -10px;
      z-index: 2;
      width: 40px;
      height: 40px;
      background: url('./img/red-close.png') no-repeat center center;
      background-size: 100% 100%;
      cursor: pointer;
    }
  }
}
</style>
