diff --git a/src/components/SectionCard.vue b/src/components/SectionCard.vue index 8bfa5de..3c0a0a3 100644 --- a/src/components/SectionCard.vue +++ b/src/components/SectionCard.vue @@ -15,13 +15,13 @@ function handleTap() { - + 待添加 @@ -74,11 +99,11 @@ onMounted(fetchPets) - + - + 添加您的喂养计划 diff --git a/src/stores/feeding-plan.ts b/src/stores/feeding-plan.ts index 5514a9e..2a3a822 100644 --- a/src/stores/feeding-plan.ts +++ b/src/stores/feeding-plan.ts @@ -6,6 +6,7 @@ import { type CreateFeedingPlanRequest, type CreatePetRequest, FeedingGoal, + type FeedingPlan, Gender, type Pet, PetBodyType, @@ -256,11 +257,51 @@ export const useFeedingPlanStore = defineStore('feeding-plan', () => { return { id: item.product.id, dailyUsageWeight: item.dailyUsageWeight, + percentage: item.percentage, } }) await createFeedingPlan(feedingPlan.value) } + const initPet = (payload: Pet) => { + // @ts-expect-error @ts-ignore + pet.value = { + birthday: payload.birthday, + bodyType: payload.bodyType, + gender: payload.gender, + isActive: payload.isActive, + isLactation: payload.isLactation, + isPregnant: payload.isPregnant, + isSterilization: payload.isSterilization, + name: payload.name, + photo: payload.photo, + type: payload.type, + weight: payload.weight, + } + savedPet.value = payload + feedingPlan.value.targetWeight = calculateIdealWeight() + rer.value = calculateRER(pet.value.weight) + } + const savedFeedingPlan = ref(null) + + const initFeedingPlan = (payload: FeedingPlan) => { + // @ts-expect-error @ts-ignore + feedingPlan.value = { + feedingGoal: payload.feedingGoal, + targetWeight: payload.targetWeight, + petId: savedPet.value?.id || '', + products: payload.feedingPlanProducts.map((item) => { + return { + id: item.product.id, + dailyUsageWeight: item.dailyUsageWeight, + } + }), + } + savedFeedingPlan.value = payload + selectedProducts.value = payload.feedingPlanProducts + dailyCalories.value = Math.floor(rer.value * derRate.value) + } + return { pet, petTypeOptions, @@ -275,5 +316,7 @@ export const useFeedingPlanStore = defineStore('feeding-plan', () => { changePercentage, dailyCalories, confirm, + initPet, + initFeedingPlan, } })