{
label: "车辆状况",
prop: "busStatus",
type: "switch",
dicData: [
{
label: "关",
value: 2
},
{
label: "开",
value: 1
}
],
value: 1,
slot: true,
rules: [
{
required: true,
message: "请选择车辆状况",
trigger: "blur"
}
]
},
<template slot="busStatus"
slot-scope="scope">
<avue-switch :value="scope.row.busStatus==1?true:false"
@click="rowState(scope.row)"></avue-switch>
</template>
rowState(row){
let self = this
let text = ''
const state = row.busStatus
if (state == 1) {
text = '停用'
} else {
text = '启用'
}
this.$confirm('确定' + text +'车辆吗?', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(() => {
const linkageState = state == 1 ? 0 : 1 //将true和false有改为0或者1传给后端\
row.busStatus = linkageState;
return update(row)//改变状态的接口
})
.then(() => {
self.onLoad(this.page);
self.$message({
type: "success",
message: "操作成功!"
});
})
.catch(() =>{
row.busStatus = row.busStatus === 0 ? 1 : 0
self.onLoad(this.page);
})
},
效果