|
|
|
|
@ -52,7 +52,7 @@
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import * as StudentApi from '@/api/infra/demo'
|
|
|
|
|
import * as StudentApi from '@/api/infra/demo';
|
|
|
|
|
import ImageUpload from '@/components/ImageUpload';
|
|
|
|
|
import FileUpload from '@/components/FileUpload';
|
|
|
|
|
import Editor from '@/components/Editor';
|
|
|
|
|
@ -104,18 +104,16 @@
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
/** 打开弹窗 */
|
|
|
|
|
open(id) {
|
|
|
|
|
async open(id) {
|
|
|
|
|
this.dialogVisible = true;
|
|
|
|
|
this.reset();
|
|
|
|
|
const that = this;
|
|
|
|
|
// 修改时,设置数据
|
|
|
|
|
if (id) {
|
|
|
|
|
this.formLoading = true;
|
|
|
|
|
try {
|
|
|
|
|
StudentApi.getStudent(id).then(res=>{
|
|
|
|
|
that.formData = res.data;
|
|
|
|
|
that.title = "修改学生";
|
|
|
|
|
})
|
|
|
|
|
const res = await StudentApi.getStudent(id);
|
|
|
|
|
this.formData = res.data;
|
|
|
|
|
this.title = "修改学生";
|
|
|
|
|
} finally {
|
|
|
|
|
this.formLoading = false;
|
|
|
|
|
}
|
|
|
|
|
@ -123,83 +121,44 @@
|
|
|
|
|
this.title = "新增学生";
|
|
|
|
|
},
|
|
|
|
|
/** 提交按钮 */
|
|
|
|
|
submitForm() {
|
|
|
|
|
async submitForm() {
|
|
|
|
|
// 校验主表
|
|
|
|
|
await this.$refs["formRef"].validate();
|
|
|
|
|
// 校验子表
|
|
|
|
|
try {
|
|
|
|
|
await this.$refs['studentContactFormRef'].validate();
|
|
|
|
|
} catch (e) {
|
|
|
|
|
this.subTabsName = 'studentContact';
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
await this.$refs['studentTeacherFormRef'].validate();
|
|
|
|
|
} catch (e) {
|
|
|
|
|
this.subTabsName = 'studentTeacher';
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.formLoading = true;
|
|
|
|
|
try {
|
|
|
|
|
const that = this;
|
|
|
|
|
let data = this.formData;
|
|
|
|
|
let validate = false;
|
|
|
|
|
// 校验主表
|
|
|
|
|
this.getRef("formRef").validate(valid => {
|
|
|
|
|
validate = valid;
|
|
|
|
|
});
|
|
|
|
|
// 校验子表
|
|
|
|
|
this.validateSubFrom01().then(() => {
|
|
|
|
|
// 全部校验通过-拼接子表的数据
|
|
|
|
|
// 拼接子表的数据
|
|
|
|
|
data.studentContacts = that.getRef('studentContactFormRef').getData();
|
|
|
|
|
data.studentTeacher = that.getRef('studentTeacherFormRef').getData();
|
|
|
|
|
}).catch((err) => {
|
|
|
|
|
validate = false;
|
|
|
|
|
that.subTabsName = err.replace("FormRef", ""); // 定位到没有校验通过的子表单
|
|
|
|
|
})
|
|
|
|
|
// 所有表单校验通过后方可提交
|
|
|
|
|
if (!validate) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const data = this.formData;
|
|
|
|
|
// 拼接子表的数据
|
|
|
|
|
data.studentContacts = this.$refs['studentContactFormRef'].getData();
|
|
|
|
|
data.studentTeacher = this.$refs['studentTeacherFormRef'].getData();
|
|
|
|
|
// 修改的提交
|
|
|
|
|
if (data.id) {
|
|
|
|
|
StudentApi.updateStudent(data).then(response => {
|
|
|
|
|
that.$modal.msgSuccess("修改成功");
|
|
|
|
|
that.dialogVisible = false;
|
|
|
|
|
that.$emit('success');
|
|
|
|
|
});
|
|
|
|
|
await StudentApi.updateStudent(data);
|
|
|
|
|
this.$modal.msgSuccess("修改成功");
|
|
|
|
|
this.dialogVisible = false;
|
|
|
|
|
this.$emit('success');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// 添加的提交
|
|
|
|
|
StudentApi.createStudent(data).then(response => {
|
|
|
|
|
that.$modal.msgSuccess("新增成功");
|
|
|
|
|
that.dialogVisible = false;
|
|
|
|
|
that.$emit('success');
|
|
|
|
|
});
|
|
|
|
|
}finally {
|
|
|
|
|
await StudentApi.createStudent(data);
|
|
|
|
|
this.$modal.msgSuccess("新增成功");
|
|
|
|
|
this.dialogVisible = false;
|
|
|
|
|
this.$emit('success');
|
|
|
|
|
} finally {
|
|
|
|
|
this.formLoading = false;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
getRef(refName){
|
|
|
|
|
return this.$refs[refName];
|
|
|
|
|
},
|
|
|
|
|
/** 校验子表单 */
|
|
|
|
|
validateSubFrom(item) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
this.getRef(item).validate()
|
|
|
|
|
.then(() => {
|
|
|
|
|
resolve();
|
|
|
|
|
})
|
|
|
|
|
.catch(() => {
|
|
|
|
|
reject(item);
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
/** 校验所有子表单 */
|
|
|
|
|
validateSubFrom01() {
|
|
|
|
|
// 需要校验的表单 ref
|
|
|
|
|
const validFormRefArr = [
|
|
|
|
|
"studentContactFormRef",
|
|
|
|
|
"studentTeacherFormRef",
|
|
|
|
|
];
|
|
|
|
|
const validArr = []; // 校验
|
|
|
|
|
for (const item of validFormRefArr) {
|
|
|
|
|
validArr.push(this.validateSubFrom(item));
|
|
|
|
|
}
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
// 校验所有
|
|
|
|
|
Promise.all(validArr).then(() => {
|
|
|
|
|
resolve();
|
|
|
|
|
}).catch((err) => {
|
|
|
|
|
reject(err);
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
/** 表单重置 */
|
|
|
|
|
reset() {
|
|
|
|
|
@ -215,7 +174,7 @@
|
|
|
|
|
memo: undefined,
|
|
|
|
|
};
|
|
|
|
|
this.resetForm("formRef");
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|