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