<template>
  <div class="inline-16">
    <el-button :type="data.status === '结束' || !data.disabled?'':'primary'" :disabled="data.status === '结束' || !data.disabled" size="mini" @click="onShow">{{data.status === '新建'?'发 布':data.status === '结束'?'发 布':'取消发布'}}</el-button>
  </div>
</template>

<script>
export default {
  props:['data'],
  data () {
    return {}
  },
  methods:{
    onShow() {
      if (this.data.status === '新建'){
        this.$confirm('确定发布该活动吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          closeOnClickModal:false
        }).then(() => {
          this.changeStatus()
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消发布'
          });
        });
      }else {
        this.$confirm('确定取消发布该活动吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          closeOnClickModal:false
        }).then(() => {
          this.changeStatus()
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消撤销发布'
          });
        });
      }
    },
    async changeStatus () {
      if (this.data.status === '新建') {
        const res = await this.$api.requested({
          "classname": "webmanage.saletool.orderclue.ordercluecampaign",
          "method": "release",
          "content": {
            "sat_campaignids": [this.data.sat_campaignid]
          }
        })
        this.tool.showMessage(res,()=>{
          this.$emit('onSuccess')
        })
      } else {
        const res = await this.$api.requested({
          "classname": "webmanage.saletool.orderclue.ordercluecampaign",
          "method": "undercarriage",
          "content": {
            "sat_campaignids": [this.data.sat_campaignid]
          }
        })
        this.tool.showMessage(res,()=>{
          this.$emit('onSuccess')
        })
      }
    }
  }
}

</script>
<style>
</style>