<template>
  <div class="inline-16">
    <el-button :type="btnType?btnType:'text'" size="mini" @click="open" :disabled="disabled">{{$t(btnTitle?btnTitle:'删除')}}</el-button>
  </div>
</template>

<script>
export default {
  name: "index",
  props:['btnType','btnTitle','message','confirmButtonText','cancelButtonText','isNumber','nameId','nameKey','id','disabled'],
  data() {
    return {
      param: {
        id: this.nameId,
        content: {
          // "sa_contractid": this.$route.query.id,
          [this.nameKey]: [this.id],
        },
      },
    };
  },
  methods:{
    open() {
      this.$confirm(this.$t(this.message), this.$t('提示'), {
        confirmButtonText: this.$t(this.confirmButtonText?this.confirmButtonText:'确定'),
        cancelButtonText: this.$t(this.cancelButtonText?this.cancelButtonText:'取消'),
        type: 'warning'
      }).then(() => {
        this.onDel()
      }).catch(() => {
        this.$message({
          type: 'info',
          message: this.$t('已取消删除')
        });
      });
    },
    async onDel(){
      this.param.content[this.nameKey] = this.isNumber ? this.id : [this.id];
      const res = await this.$api.requested(this.param)
      this.tool.showMessage(res, () => {
        this.$emit("deleteSuccess");
      });
    }
  }
}
</script>

<style scoped>

</style>
