2020-10-29 19:11:46 +08:00
|
|
|
<template>
|
2020-10-30 15:16:25 +08:00
|
|
|
<div :class="['delete-button',(deleteObjs.length<1?'':'delete-button-light')]">
|
2021-02-04 11:21:00 +08:00
|
|
|
<el-button class="nz-btn nz-btn-size-normal nz-btn-style-light" :class="{'nz-btn-disabled' : deleteObjs.length<1}" @click="batchDelete" :id="id"><span><i class="nz-icon nz-icon-delete" ></i></span></el-button>
|
2020-10-29 19:11:46 +08:00
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
name: "deleteButton",
|
|
|
|
|
props:{
|
|
|
|
|
filterFunction:Function,
|
2021-03-08 11:20:57 +08:00
|
|
|
//deleteObjs: Object,
|
|
|
|
|
deleteObjs: Array,
|
2020-10-29 19:11:46 +08:00
|
|
|
api:String,
|
2021-02-04 11:21:00 +08:00
|
|
|
clickFunction:Function,
|
|
|
|
|
id:String
|
2020-10-29 19:11:46 +08:00
|
|
|
},
|
|
|
|
|
methods:{
|
|
|
|
|
batchDelete:function(){
|
|
|
|
|
if(this.deleteObjs.length<1) return;
|
|
|
|
|
if(this.clickFunction){
|
|
|
|
|
this.clickFunction();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.$confirm(this.$t("tip.confirmBatchDelete",[this.deleteObjs.length]), {
|
|
|
|
|
confirmButtonText: this.$t("tip.yes"),
|
|
|
|
|
cancelButtonText: this.$t("tip.no"),
|
|
|
|
|
type: 'warning'
|
|
|
|
|
}).then(() => {
|
2020-12-31 17:41:40 +08:00
|
|
|
this.$emit('before');
|
2020-10-29 19:11:46 +08:00
|
|
|
let params=this.filterParam();
|
|
|
|
|
this.$delete(this.api+params).then(response => {
|
|
|
|
|
if (response.code === 200) {
|
|
|
|
|
this.$message({duration: 2000, type: 'success', message: this.$t("tip.deleteSuccess")});
|
|
|
|
|
this.$emit('after')
|
|
|
|
|
} else {
|
|
|
|
|
this.$message.error(response.msg);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
filterParam:function(){
|
|
|
|
|
let filterFunction=this.filterFunction
|
|
|
|
|
if(!filterFunction){
|
|
|
|
|
filterFunction=(arr)=>{return "?ids="+arr.map(t=>t.id).join(',')};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return filterFunction(this.deleteObjs);
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
.delete-button{
|
|
|
|
|
margin-left: 16px;
|
2020-10-30 15:16:25 +08:00
|
|
|
opacity: 0.7;
|
|
|
|
|
border-radius: 2px;
|
2020-10-29 19:11:46 +08:00
|
|
|
}
|
|
|
|
|
.delete-button .nz-btn-disabled .nz-icon-delete{
|
2020-10-30 15:16:25 +08:00
|
|
|
opacity: 0.5;
|
|
|
|
|
color: #D14A2B;
|
|
|
|
|
}
|
|
|
|
|
.delete-button-light.delete-button{
|
|
|
|
|
border-radius: 2px;
|
|
|
|
|
}
|
|
|
|
|
.delete-button-light .nz-icon-delete{
|
|
|
|
|
color: #D14A2B;
|
2020-10-29 19:11:46 +08:00
|
|
|
}
|
|
|
|
|
</style>
|