Commit dfb801a1 authored by 王炽's avatar 王炽

切换宝宝处理

parent 472fa500
......@@ -48,7 +48,7 @@
</template>
<script setup>
import { ref, defineEmits, defineProps } from 'vue'
import { ref, defineEmits, defineProps, onMounted } from 'vue'
const props = defineProps({
visible: {
......@@ -141,6 +141,10 @@ const onFeedChange = (feedOption, index) => {
const closePopup = () => {
emit('update:visible', false)
}
onMounted(() => {
})
</script>
<style lang="less" scoped>
......
......@@ -18,12 +18,12 @@
v-for="(baby, index) in babyList"
:key="index"
class="baby-item"
:class="{ selected: selectedIndex === index }"
:class="{ selected: selectIndex === index }"
@click="selectBaby(index)"
>
<!-- 选中背景 -->
<image
v-if="selectedIndex === index"
v-if="selectIndex === index"
class="baby-item-bg"
:src="`${$baseUrl}shengzhangTool/1001/changeBaby/babyItemBg.png`"
mode="aspectFit"
......@@ -32,21 +32,21 @@
<!-- 宝宝头像 -->
<image
class="baby-avatar"
:src="baby.avatar || `${$baseUrl}shengzhangTool/1001/avatar.png`"
:src="baby.avatar || `https://course.feihe.com/momclub-picture/common/default_avatar.png`"
mode="aspectFill"
/>
<!-- 宝宝信息 -->
<view class="baby-info">
<view class="baby-name-row">
<text class="baby-name">{{ baby.name }}</text>
<text class="baby-name">{{ baby.babyName }}</text>
<image
class="gender-icon"
:src="baby.gender === 1 ? `${$baseUrl}shengzhangTool/1001/sex1.png` : `${$baseUrl}shengzhangTool/1001/sex0.png`"
mode="aspectFit"
/>
</view>
<text class="baby-birthday">宝宝生日: {{ baby.birthday }}</text>
<text class="baby-birthday">宝宝生日: {{ baby.babyBirthday }}</text>
</view>
</view>
</view>
......@@ -65,23 +65,33 @@
</template>
<script setup>
import { ref, defineEmits, defineProps } from 'vue'
import { ref, defineEmits, defineProps, onMounted } from 'vue'
import { useUserStore } from "@/stores/user";
// const props = defineProps({
// visible: {
// type: Boolean,
// default: false
// },
// babyList: {
// type: Array,
// default: () => []
// },
// selectedIndex: {
// type: Number,
// default: 0
// }
// })
const props = defineProps({
visible: {
type: Boolean,
default: false
},
babyList: {
type: Array,
default: () => []
},
selectedIndex: {
type: Number,
default: 0
}
})
const userStore = useUserStore();
const emit = defineEmits(['update:visible', 'update:selectedIndex', 'change'])
const selectHandle = () => {
......@@ -93,14 +103,16 @@ const handleOkTouchStart = () => {
isOkPressed.value = true
}
const handleOkTouchEnd = () => {
const handleOkTouchEnd = async () => {
isOkPressed.value = false
const index = selectIndex.value;
// 发送事件 通知主页面
emit('change', props.babyList[index], index)
await userStore.changeBabySelected(babyList.value[index].id);
// 发送事件 通知主页面
emit('change', babyList.value[index])
closePopup();
}
const closePopup = () => {
......@@ -112,6 +124,20 @@ const selectBaby = (index) => {
selectIndex.value = index;
emit('update:selectedIndex', index);
}
const babyList = ref([]);
onMounted(() => {
babyList.value = userStore.babyInfo?.allBabyBaseInfo;
if(babyList.value === null){
babyList.value = [];
}
const selectedIndexInList = babyList.value.findIndex(item => item.selected === true)
console.log('选中宝宝的索引:', selectedIndexInList)
selectIndex.value = selectedIndexInList;
})
</script>
<style lang="less" scoped>
......
......@@ -273,7 +273,7 @@ const babyName = ref('宝宝名称')
const babyAge = ref('8月龄')
const babyBirthday = ref('2024-10-20')
const babyGender = ref('M')
const babyAvatar = ref(`shengzhangTool/1001/avatar.png`);
const babyAvatar = ref(`https://course.feihe.com/momclub-picture/common/default_avatar.png`);
const shengzhangStore = useShengzhangStore();
......@@ -474,7 +474,7 @@ const onHeadBlur = (e) => {
const changeBaby = () => {
console.log('切换宝宝')
showBabySwitchPopup.value = true
currentBabyIndex.value = 0 // 默认选中第一个宝宝
// currentBabyIndex.value = 0 // 默认选中第一个宝宝
}
const viewRecords = () => {
......@@ -500,6 +500,9 @@ const convertFeedingType = (type) => {
const submitData = throttleTap(async () => {
showLoading.value = true;
if(headCircumference.value == 0){
headCircumference.value = null;
}
const submitData = {
babyId: babyId.value,
height: height.value,
......@@ -566,25 +569,15 @@ const selectedFeedText = ref('母乳+奶粉混合喂养')
// 示例宝宝列表数据
const babyList = ref([
{
name: '宝宝名称',
gender: 1, // 1: 男孩, 0: 女孩
birthday: '2024-10-20',
avatar: `shengzhangTool/1001/avatar.png`
},
{
name: '宝宝名称',
gender: 0,
birthday: '2022-04-20',
avatar: `shengzhangTool/1001/avatar.png`
}
])
// 处理宝宝选择变化
const onBabyChange = (baby, index) => {
console.log('选择了宝宝:', baby, index)
const onBabyChange = async (baby) => {
console.log('选择了宝宝:', baby)
// 这里可以更新页面上的宝宝信息
// 比如更新宝宝名称、性别、生日等
await refreshBabyInfo();
}
// 处理喂养方式选择变化
......@@ -696,9 +689,24 @@ onLoad((options) => {
})
onMounted(async () => {
await refreshBabyInfo();
})
const refreshBabyInfo = async () => {
const userStore = useUserStore();
babyId.value = userStore.babyInfo?.content?.id;
console.log('babyId.value=', babyId.value);
// babyList.value = userStore.babyInfo?.allBabyBaseInfo;
// if(babyList.value === null){
// babyList.value = [];
// }
//切换宝宝默认选中处理
// selectedIndex.value = userStore.babyInfo?.allBabyBaseInfo.findIndex(
// (item) => item.selected
// );
const {data} = await growthHome(babyId.value);
selectedDate.value = formatDate(new Date());
......@@ -719,8 +727,7 @@ onMounted(async () => {
}else{
guideIndex.value = 0;
}
})
}
</script>
......
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