<template>
  <el-button :disabled="!content.ID||content.status!=30" @click="sendWeibo" :type="buttonType" :priv="'com.zving.cms.Catalog.Content.Publish.'+catalogId">
    <i class="fa fa-weibo"></i>发表到微博
  </el-button>
</template>
<script>
export default {
  props: {
    content: {
      type: Object
    },
    buttonType: {
      type: String,
      default: ''
    },
    catalogId: {
      type: [Number, String]
    }
  },
  methods: {
    async sendWeibo() {
      let resp = await axios.put(
        `/ui/contentcore/contents/${this.content.ID}/weibo/url`
      )
      if (resp.data.status === 1) {
        let url = `${resp.data.authorizeUrl}&redirect_uri=${resp.data.redirectUrl}/contentcore/contents/${this.content.ID}/weibo/send`
        window.open(url)
      } else {
        this.$msgbox({
          title: '错误',
          type: 'error',
          message: resp.data.message || '操作失败'
        })
      }
    }
  }
}
</script>
