|
@@ -63,8 +63,35 @@ const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
|
|
|
res = await $api(`teacher/${user.value._id}`, "GET", {});
|
|
|
else
|
|
|
res = await $api(`student/${user.value._id}`, "GET", {});
|
|
|
- if (res.errcode == "0")
|
|
|
+ if (res.errcode == "0") {
|
|
|
+ if (res.data.cardType) {
|
|
|
+ const data = cardTypeList.value.find((i) => i.value === res.data.cardType);
|
|
|
+ if (data)
|
|
|
+ res.data.cardType_name = data.label;
|
|
|
+ }
|
|
|
+ if (res.data.education) {
|
|
|
+ const data = educationList.value.find((i) => i.value === res.data.education);
|
|
|
+ if (data)
|
|
|
+ res.data.education_name = data.label;
|
|
|
+ }
|
|
|
+ if (res.data.learnStatus) {
|
|
|
+ const data = learnStatusList.value.find((i) => i.value === res.data.learnStatus);
|
|
|
+ if (data)
|
|
|
+ res.data.learnStatus_name = data.label;
|
|
|
+ }
|
|
|
+ if (res.data.grade) {
|
|
|
+ const data = gradeList.value.find((i) => i.value === res.data.grade);
|
|
|
+ if (data)
|
|
|
+ res.data.grade_name = data.label;
|
|
|
+ }
|
|
|
+ if (res.data.subject) {
|
|
|
+ const data = subjectList.value.find((i) => i.value === res.data.subject);
|
|
|
+ if (data)
|
|
|
+ res.data.subject_name = data.label;
|
|
|
+ }
|
|
|
form.value = res.data;
|
|
|
+ common_vendor.index.setStorageSync("user", { ...res.data, role_type: user.value.role_type });
|
|
|
+ }
|
|
|
}
|
|
|
};
|
|
|
const deletePic = (event) => {
|
|
@@ -128,13 +155,29 @@ const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
|
|
|
if (!obj.phone || obj.phone.trim() === "") {
|
|
|
errors2.phone = "请填写手机号!";
|
|
|
}
|
|
|
+ if (!obj.is_show || obj.is_show.trim() === "") {
|
|
|
+ errors2.is_show = "请选择是否公开!";
|
|
|
+ }
|
|
|
if (Object.keys(errors2).length > 0) {
|
|
|
return errors2;
|
|
|
}
|
|
|
return null;
|
|
|
};
|
|
|
+ const mergeObjectsWithoutDuplicates = async (obj1, obj2) => {
|
|
|
+ return Object.keys({ ...obj1, ...obj2 }).reduce((acc, key) => {
|
|
|
+ if (!acc.hasOwnProperty(key)) {
|
|
|
+ if (key == "cardType_name" || key == "education_name" || key == "learnStatus_name" || key == "grade_name" || key == "subject_name") {
|
|
|
+ delete acc[key];
|
|
|
+ } else {
|
|
|
+ acc[key] = obj1.hasOwnProperty(key) ? obj1[key] : obj2[key];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return acc;
|
|
|
+ }, {});
|
|
|
+ };
|
|
|
const formSubmit = async (e) => {
|
|
|
- const errorsInfo = await validateObject(form.value);
|
|
|
+ const data = await mergeObjectsWithoutDuplicates(e.detail.value, form.value);
|
|
|
+ const errorsInfo = await validateObject(data);
|
|
|
if (errorsInfo) {
|
|
|
errors.value = errorsInfo;
|
|
|
for (const key in errorsInfo) {
|
|
@@ -143,8 +186,19 @@ const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
- console.log("所有字段都已填写");
|
|
|
- console.log(form.value);
|
|
|
+ errors.value = {};
|
|
|
+ let res;
|
|
|
+ if (user.value.role_type == "Teacher")
|
|
|
+ res = await $api(`teacher/${form.value._id}`, "POST", data);
|
|
|
+ else
|
|
|
+ res = await $api(`student/${form.value._id}`, "POST", data);
|
|
|
+ if (res.errcode == "0") {
|
|
|
+ await search();
|
|
|
+ common_vendor.index.showToast({
|
|
|
+ title: "保存成功",
|
|
|
+ icon: "success"
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
};
|
|
|
common_vendor.provide("form", form);
|