<template>
  <div >
<!--    <el-button type="text" size="mini" @click="releaseNotice">{{data.isontop === 0?'置顶':'取消置顶'}}</el-button>-->
    <el-button v-if="top" type="primary" size="small" plain @click="open">置顶</el-button>
    <el-button v-if="unTop" type="primary" size="small" plain  @click="unOpen">取消置顶</el-button>
  </div>
</template>

<script>
export default {
  props:['data'],
  data () {
    return {
      top:false,
      unTop:false
    }
  },
  methods:{
    async releaseNotice () {
      const res = await this.$api.requested({
        /*"classname": "webmanage.saletool.notice.notice",
        "method": this.data.isontop === 0?"topping":"cancelTopping",*/
        "id":"20221101095403",
        "content": {
          "sat_noticeid":this.data.sat_noticeid
        }
      })
      this.tool.showMessage(res,()=>{
        this.unTop = true
        this.top = false
        this.$emit('onSuccess')
      })
    },
    async unReleaseNotice () {
      const res = await this.$api.requested({
        /*"classname": "webmanage.saletool.notice.notice",
        "method": this.data.isontop === 0?"topping":"cancelTopping",*/
        "id":"20221101095503",
        "content": {
          "sat_noticeid":this.data.sat_noticeid
        }
      })
      this.tool.showMessage(res,()=>{
        this.top = true
        this.unTop = false
        this.$emit('onSuccess')
      })
    },
    open() {
      this.$confirm('确定置顶此通告吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.releaseNotice()
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消发布'
        });
      });
    },
    unOpen(){
      this.$confirm('确定取消置顶此通告吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.unReleaseNotice()
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消操作'
        });
      });
    }
  },
  mounted() {
    console.log("输出置顶情况123")
    console.log(this.data.isontop)
    if (this.data.isontop === 0){
      this.top = true
      this.unTop = false
    }else{
      this.top = false
      this.unTop = true
    }
  },
 /* created() {
    console.log("输出置顶情况")
    console.log(this.data.isontop)
    if (this.data.isontop === 0){
      this.top = true
      this.unTop = false
    }else{
      this.top = false
      this.unTop = true
    }
  }*/
}

</script>
<style>
</style>