Commit b3de8baa authored by weishengfei's avatar weishengfei

refactor(components): 优化弹窗组件功能和逻辑

- 在 popup-tip 组件中添加关闭弹窗的事件
- 优化宝宝状态切换和修改逻辑
- 修复一些潜在的 bug 和性能问题
parent 0bf6541a
......@@ -56,6 +56,7 @@ import {
defineEmits
} from 'vue'
import { useUserStore } from "@/stores/user";
import { console } from 'inspector';
// 接受父组件参数
const props = defineProps({
type: {
......@@ -68,7 +69,7 @@ const userStore = useUserStore();
const babyInfo = ref(userStore.babyInfo)
// 回调函数
const emit = defineEmits([ 'statusChange'])
const emit = defineEmits([ 'statusChange', 'close'])
const isType = ref('0') // 0 添加状态或者宝宝 1 切换状态 2 修改状态 3 宝宝已达上限
......@@ -79,18 +80,20 @@ const babyBaseId = ref('')
const pregnancyStatus = computed(() => {
return isType.value == '0' ? '新增孕中'
: isType.value == '1' ? '切换孕中'
: isType.value == '2' ? '修改备孕'
: isType.value == '2' ? '修改备孕'
: '';
})
// 生长曲线和喂养记录
const babyStatus = computed(() => {
return isType.value == '0' ? '新增宝宝'
: isType.value == '1' ? '切换宝宝'
: isType.value == '2' ? '修改备孕'
: isType.value == '2' ? (babyInfo.value.babyStage == 0 ? '修改备孕' :
babyInfo.value.babyStage == 1 ? '修改孕中' : '')
: '';
})
// 跳转新增宝宝状态页面
const navigateToFn = () => {
emit('close')
const type = 'add'
uni.navigateTo({
url: `/pages/person/person?type=${type}`
......@@ -106,6 +109,7 @@ const switchState = async () => {
}
// 修改状态 需要对应备胎的id 跳转到编辑页面
const modifyState = async () => {
emit('close')
console.log('修改状态', babyBaseId.value)
await userStore.changeBabySelected(babyBaseId.value);
const type = "edit"
......@@ -143,7 +147,7 @@ onMounted(() => {
// 有宝宝状态
if (babyBaseInfo) {
// 2 判断宝宝信息是否达到上限 3个
if (babyBaseInfo.length == 3) {
if (babyBaseInfo.length >= 3) {
// 产检提醒和喂养记录
if (props.type == '1') {
// 判断有没有宝宝状态切换到宝宝状态
......@@ -154,15 +158,18 @@ onMounted(() => {
// 如果找到符合条件的 baby,取出它的 id 并赋值
babyBaseId.value = stageOneBaby.id;
} else { // 修改
// 判断没有备孕的状态
if (!babyBaseInfo.some(baby => baby.babyStage == 0)) {
isType.value = '3'
} else {
const stageZeroBaby = babyBaseInfo.find(baby => baby.babyStage == 0);
babyBaseId.value = stageZeroBaby.id;
isType.value = '2';
}
console.log('没有找到符合条件的 baby');
// // 判断没有备孕的状态
// if (!babyBaseInfo.some(baby => baby.babyStage == 0)) {
// isType.value = '3'
// } else {
// const stageZeroBaby = babyBaseInfo.find(baby => baby.babyStage == 0);
// babyBaseId.value = stageZeroBaby.id;
// isType.value = '2';
// }
babyBaseId.value = babyInfo.value.content.id;
isType.value = '2';
}
}
// 产检提醒
......@@ -175,7 +182,7 @@ onMounted(() => {
// 如果找到符合条件的 baby,取出它的 id 并赋值
babyBaseId.value = stageOneBaby.id;
} else { // 修改
// 判断没有备孕的状态
// // 判断没有备孕的状态
if (!babyBaseInfo.some(baby => baby.babyStage == 0)) {
isType.value = '3'
} else {
......@@ -183,6 +190,8 @@ onMounted(() => {
babyBaseId.value = stageZeroBaby.id;
isType.value = '2';
}
// babyBaseId.value = babyInfo.value.content.id;
// isType.value = '2';
}
}
} else {
......@@ -197,14 +206,15 @@ onMounted(() => {
// 如果找到符合条件的 baby,取出它的 id 并赋值
babyBaseId.value = stageOneBaby.id;
} else { // 修改
// 判断没有备孕的状态
if (!babyBaseInfo.some(baby => baby.babyStage == 0)) {
isType.value = '0'
} else {
const stageZeroBaby = babyBaseInfo.find(baby => baby.babyStage == 0);
babyBaseId.value = stageZeroBaby.id;
console.log('没有找到符合条件的 baby', babyInfo.value);
// // 判断没有备孕的状态
// if (!babyBaseInfo.some(baby => baby.babyStage == 0)) {
// isType.value = '0'
// } else {
// const stageZeroBaby = babyBaseInfo.find(baby => baby.babyStage == 0);
babyBaseId.value = babyInfo.value.content.id;
isType.value = '2';
}
// }
}
}
......@@ -226,6 +236,8 @@ onMounted(() => {
babyBaseId.value = stageZeroBaby.id;
isType.value = '2';
}
// babyBaseId.value = babyInfo.value.content.id;
// isType.value = '2';
}
}
}
......
......@@ -114,7 +114,7 @@
</view>
<!-- 提示弹窗 -->
<popup-tip v-if="isTip" type="2" @statusChange="onBabyChange"></popup-tip>
<popup-tip v-if="isTip" type="2" @statusChange="onBabyChange" @close="isTip = false"></popup-tip>
<!-- 使用封装后的日期选择器组件 -->
<DatePicker v-model:visible="visible" :default-date="time" @confirm="handleDateConfirm" />
......
......@@ -253,7 +253,7 @@
<BabyTestTipsPopup
v-model:visible="showBabyTestTipsPopup"
/>
<popup-tip v-if="isTip" type="1" @statusChange="onBabyChange1"></popup-tip>
<popup-tip v-if="isTip" type="1" @statusChange="onBabyChange1" @close="isTip = false"></popup-tip>
</template>
<script setup>
......
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