Commit aa82a575 authored by tao.huang's avatar tao.huang

fix: 保存延迟

parent e40ec048
......@@ -82,7 +82,7 @@
}"
>
<text class="form-label">
{{getlabelFn(item)}}
{{ getlabelFn(item) }}
<!-- {{ item.label }} -->
<text v-if="item.required" class="required">*</text>
</text>
......@@ -232,7 +232,7 @@ import { showLoading, hideLoading } from "../../utils/index.js";
import { updateBabyInfo, getGestationalWeeks } from "../../api/user.js";
import { usePageCfgStore } from "../../stores/pageCfg";
import md from "../../md.js";
import { jump, JumpType } from '../../utils/index.js';
import { jump, JumpType } from "../../utils/index.js";
const userStore = useUserStore();
const pageType = ref("add");
const babyId = ref("");
......@@ -512,12 +512,11 @@ const onRadioChange = (e, name) => {
formData.value[name] = e.detail.value;
};
const sleep =(delay) => {
const sleep = (delay) => {
return new Promise((resolve) => {
setTimeout(()=> resolve(), delay)
})
}
setTimeout(() => resolve(), delay);
});
};
const onSubmit = async (e) => {
md.sensorLogTake({
......@@ -587,14 +586,8 @@ const onSubmit = async (e) => {
hideLoading();
if (res.success) {
data?.id &&
userStore.setBabyNickCache(data?.id, formData.value.babyName);
data?.id && userStore.setBabyNickCache(data?.id, formData.value.babyName);
uni.showToast({
title: "提交成功",
icon: "success",
});
uni.navigateBack();
// jump({
// type: JumpType.INNER,
// url: "/pages/index/index"
......@@ -605,6 +598,12 @@ const onSubmit = async (e) => {
await userStore.loadBabyInfo();
await userStore.loadHomeInfo();
hideLoading();
uni.showToast({
title: "提交成功",
icon: "success",
});
uni.navigateBack();
} else {
uni.showToast({
title: res.message,
......@@ -683,21 +682,18 @@ function onDateStatusChange(status) {
}
return true;
}
const getlabelFn =(item) =>{
const getlabelFn = (item) => {
if (item.name === "babyBirthday") {
item.label = formData.value.babyStage == 1 ? '预产日期':'宝宝出生日期'
item.label = formData.value.babyStage == 1 ? "预产日期" : "宝宝出生日期";
}
return item.label
}
return item.label;
};
// getLabelByValue 支持所有映射字段
const getLabelByValue = (item, value) => {
if (item.name === "babyStage") {
return babyStageMap.find((i) => i.value === value)?.label || "";
}
if (item.name === "babyType") {
return babyTypeMap.find((i) => i.value === value)?.label || "";
}
......@@ -708,8 +704,12 @@ const getLabelByValue = (item, value) => {
// // 添加根据切换状态修改文案
if (item.name === "babyBirthday") {
// console.log("🚀 ~ getLabelByValue ~ formData:", formData.value, item)
item.placeholder = formData.value.babyBirthday? formData.value.babyBirthday : formData.value.babyStage == 1 ? '请选择预产日期':'请选择出生日期'
return item.placeholder
item.placeholder = formData.value.babyBirthday
? formData.value.babyBirthday
: formData.value.babyStage == 1
? "请选择预产日期"
: "请选择出生日期";
return item.placeholder;
}
return value;
};
......@@ -749,7 +749,6 @@ const initData = () => {
// 更新表单项的选项数据
formItems.value.forEach((item) => {
if (item.name === "contentPreference") {
item.range = contentLikeOptions.value;
} else if (item.name === "productPreference") {
......@@ -770,7 +769,6 @@ const initData = () => {
formData.value.babyStage == 2 ? "请选择出生日期" : "请选择预产日期";
}
});
};
onMounted(() => {
......@@ -783,13 +781,13 @@ onMounted(() => {
});
onLoad((options) => {
console.log("🚀 ~ options-新增和修改:", options)
console.log("🚀 ~ options-新增和修改:", options);
// debugger;
pageType.value = options.type || "add";
babyId.value = options.id || "";
if (pageType.value === "edit") {
const baby = userStore.babyInfo;
console.log("🚀 ~ baby:", baby)
console.log("🚀 ~ baby:", baby);
formData.value.babyStage = baby.babyStage ?? 2;
formData.value.babyName = baby.babyName || "";
formData.value.babyBirthday = baby.content?.babyBirthday || "";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment