<template>
  <el-button v-bind="$attrs" @click="handleClick"><slot /></el-button>
</template>

<script>
export default {
  name: 'PermissionButton',
  data() {
    return {
      hasPermission: true
    }
  },
  methods: {
    handleClick($event) {
      const { freeUseFlag, vipStatus } = this.$store.getters.vipInfo
      // 试用期 || 会员未到期
      this.hasPermission = freeUseFlag > 0 || [0, 3].indexOf(vipStatus) === -1
      if (this.hasPermission) {
        this.$emit('click', $event)
      } else {
        this.$confirm('对不起，您的会员账号已到期，请尽快续费，以免影响正常使用！', '提示', {
          confirmButtonText: '开通会员',
          cancelButtonText: '取消'
        })
          .then(() => {
            // jumpAction()
            // console.log('开通会员')
            this.$router.push('/vip/vip-open')
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: '已取消操作'
            })
          })
      }
    }
  }
}
</script>
