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

fix: 保存延迟

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