confirm() {
this.$refs["form"].validate(valid => {
if (valid) {
if (this.detail) {
// 判断是否有修改 有则传
let data = { id: this.detail };
const form = this.editForm;
let isEdit = false;
for (let i in form) {
if (form[i]) {
isEdit = true;
data[i] = form[i];
}
}
if (isEdit) {
request("post", "cms/role/update", data).then(res => {
if (res.code == "200") {
this.$message.success(this.$t("tag.editSuccess"));
this.$emit("roleChange", { show: false, isAdd: true });
this.$refs["form"].resetFields();
this.editForm ={
name: "",
remark: ""
}
} else {
return false;
}
});
}else{
this.$emit("roleChange", { show: false, isAdd: false });
this.$refs["form"].resetFields();
}
} else {
let data = {
name: this.form.name
};
if (this.form.remark) {
data.remark = this.form.remark;
}
this.isLoading=true;
request("put", "cms/role/add", data).then(res => {
if (res.code == "200") {
this.$message.success(this.$t("tag.addSuccess"));
this.$emit("roleChange", { show: false, isAdd: true });
this.$refs["form"].resetFields();
this.editForm ={
name: "",
remark: ""
}
}
this.isLoading=false;
}).catch(err=>{
this.isLoading=false;
});
}
}
});
},
新增和编辑的写法
最新推荐文章于 2024-11-25 10:34:11 发布