修改info页id数据
This commit is contained in:
@@ -76,6 +76,10 @@
|
|||||||
<!-- 对话框(添加 / 修改) -->
|
<!-- 对话框(添加 / 修改) -->
|
||||||
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
|
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
|
||||||
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
|
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
|
||||||
|
<!-- 添加隐藏的id输入框,确保id字段始终被提交 -->
|
||||||
|
<el-form-item prop="id" v-if="form.id" style="display: none;">
|
||||||
|
<el-input v-model="form.id" />
|
||||||
|
</el-form-item>
|
||||||
<el-form-item label="备注" prop="remark">
|
<el-form-item label="备注" prop="remark">
|
||||||
<el-input v-model="form.remark" placeholder="请输入备注" />
|
<el-input v-model="form.remark" placeholder="请输入备注" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
@@ -121,6 +125,8 @@ export default {
|
|||||||
title: "",
|
title: "",
|
||||||
// 是否显示弹出层
|
// 是否显示弹出层
|
||||||
open: false,
|
open: false,
|
||||||
|
// 用于修改操作的id
|
||||||
|
currentId: null,
|
||||||
// 查询参数
|
// 查询参数
|
||||||
queryParams: {
|
queryParams: {
|
||||||
pageNo: 1,
|
pageNo: 1,
|
||||||
@@ -159,11 +165,11 @@ export default {
|
|||||||
cancel() {
|
cancel() {
|
||||||
this.open = false;
|
this.open = false;
|
||||||
this.reset();
|
this.reset();
|
||||||
|
this.currentId = null; // 重置currentId
|
||||||
},
|
},
|
||||||
/** 表单重置 */
|
/** 表单重置 */
|
||||||
reset() {
|
reset() {
|
||||||
this.form = {
|
this.form = {
|
||||||
id: undefined,
|
|
||||||
remark: undefined,
|
remark: undefined,
|
||||||
role: undefined,
|
role: undefined,
|
||||||
};
|
};
|
||||||
@@ -188,32 +194,47 @@ export default {
|
|||||||
/** 修改按钮操作 */
|
/** 修改按钮操作 */
|
||||||
handleUpdate(row) {
|
handleUpdate(row) {
|
||||||
this.reset();
|
this.reset();
|
||||||
const id = row.id;
|
this.currentId = row.id;
|
||||||
getInfo(id).then(response => {
|
console.log('点击修改时的row.id:', this.currentId);
|
||||||
this.form = response.data;
|
getInfo(this.currentId).then(response => {
|
||||||
|
console.log('API返回的数据:', response.data);
|
||||||
|
// 确保form对象包含所有必要字段
|
||||||
|
this.form = {
|
||||||
|
remark: '',
|
||||||
|
role: undefined,
|
||||||
|
...response.data
|
||||||
|
};
|
||||||
this.open = true;
|
this.open = true;
|
||||||
this.title = "修改用户信息";
|
this.title = "修改用户信息";
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
/** 提交按钮 */
|
/** 提交按钮 */
|
||||||
submitForm() {
|
submitForm() {
|
||||||
|
// 先进行表单验证
|
||||||
this.$refs["form"].validate(valid => {
|
this.$refs["form"].validate(valid => {
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 修改的提交
|
|
||||||
if (this.form.id != null) {
|
// 判断是新增还是修改操作
|
||||||
updateInfo(this.form).then(response => {
|
const isUpdate = !!this.currentId;
|
||||||
this.$modal.msgSuccess("修改成功");
|
|
||||||
this.open = false;
|
// 准备提交数据
|
||||||
this.getList();
|
const submitData = { ...this.form };
|
||||||
});
|
|
||||||
return;
|
// 如果是修改操作,确保id存在且是数字类型
|
||||||
|
if (isUpdate) {
|
||||||
|
// 使用currentId而不是form.id,并确保是数字类型
|
||||||
|
submitData.id = parseInt(this.currentId);
|
||||||
}
|
}
|
||||||
// 添加的提交
|
|
||||||
createInfo(this.form).then(response => {
|
// 执行请求
|
||||||
this.$modal.msgSuccess("新增成功");
|
const requestPromise = isUpdate ? updateInfo(submitData) : createInfo(submitData);
|
||||||
|
|
||||||
|
requestPromise.then(response => {
|
||||||
|
this.$modal.msgSuccess(isUpdate ? "修改成功" : "新增成功");
|
||||||
this.open = false;
|
this.open = false;
|
||||||
|
this.currentId = null; // 重置currentId
|
||||||
this.getList();
|
this.getList();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user