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() {
-
+
{{ operationTitle }}
-
-
+
+
{{ title }}
{{ subtitle }}
diff --git a/src/model/pet.ts b/src/model/pet.ts
index 850bb9c..e44527a 100644
--- a/src/model/pet.ts
+++ b/src/model/pet.ts
@@ -64,5 +64,5 @@ export interface FeedingPlan extends BaseModel {
export interface CreateFeedingPlanRequest extends Omit {
petId: string
- products: { id: string, dailyUsageWeight: number }[]
+ products: { id: string, dailyUsageWeight: number, percentage: number }[]
}
diff --git a/src/pages/feed-plan/index.vue b/src/pages/feed-plan/index.vue
index 6564ba8..b08c9de 100644
--- a/src/pages/feed-plan/index.vue
+++ b/src/pages/feed-plan/index.vue
@@ -37,6 +37,31 @@ async function selectPet(index: number) {
currentIndex.value = index
}
+const feedingPlanStore = useFeedingPlanStore()
+
+async function handleAddFeedingPlan() {
+ feedingPlanStore.initPet(currentPet.value)
+ uni.navigateTo({
+ url: '/pages/feed-plan-calculator/index',
+ })
+}
+
+function handleAddPet() {
+ uni.navigateTo({
+ url: '/pages/start-filing/index',
+ })
+}
+
+async function handleEdit() {
+ if (!feedingPlan.value)
+ return
+ feedingPlanStore.initPet(currentPet.value)
+ feedingPlanStore.initFeedingPlan(feedingPlan.value)
+ uni.navigateTo({
+ url: '/pages/feed-plan-calculator/index',
+ })
+}
+
onMounted(fetchPets)
@@ -54,9 +79,9 @@ onMounted(fetchPets)
{{ item.name }}
-
+
-
+
待添加
@@ -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,
}
})