<template>
  <span class="free-btn" @click.stop.prevent="btnClick">免费试用</span>
</template>

<script>
export default {
  name: "freeTrialBtn",
  props: {
    myType: {
      type: String,
      default: 'kaoshi'
    },
    select: {
      type: Boolean,
      default: false,
    }
  },
  data() {
    return {
      visible: false,
    }
  },
  methods: {
    isPC() {
      const browserWidth = document.documentElement.clientWidth;
      if (browserWidth <= 768) {
        return false;
      } else {
        return true;
      }
    },
    btnClick() {

      if (this.select) {
        this.$emit('need-select')
        return false;
      }
      // 执行业务
      this.FreeTrial();
      // 执行通知
      if (this.isPC()) {
        this.$emit('active-pc', this.myType)
      } else {
        this.$emit('active-h5', this.myType)
      }
    },
    FreeTrial() {
      if (!this.isPC()) {
        // H5
        if (this.myType === 'kaoshi') {
          window.open('https://qg.qtavip.com/mdistqg/#/webRegisterQg?flug=1')
        } else {
          window.open('https://qg.qtavip.com/mdistqg/#/webRegisterQg?flug=2')
        }
      } else {
        if (this.myType === 'kaoshi') {
          window.open('https://qg.qtavip.com/a/register?flug=1')
        } else {
          window.open('https://qg.qtavip.com/a/register?flug=2')
        }
      }
    },
  }
}
</script>

<style lang="scss">
.free-btn {
  width: 154px;
  height: 48px;
  line-height: 48px;
  background: #00b96b;
  border-radius: 24px;
  color: #fff;
  cursor: pointer;
  display: inline-block;
  text-align: center;
  @media (max-width: 768px) {
    width: 44%;height:35px;line-height:35px;max-width: 120px;margin: 0 3%;display: inline-block;
    padding: 0;text-align: center;font-size: 14px;
  }
}

.free-btn.shouye {
  height: 55px;
  width: 180px;
  line-height: 55px;
  color: #00b96b;
  background: #fff;
}
</style>
