feat: 喂养计划回显

This commit is contained in:
ilhamtahir committed 2025-01-22 06:43:47 +08:00
1 parent f99dca56ef
commit b730f7966b
4 files changed
+76 -8

No files matched your search

+3 -3
View File
@@ -15,13 +15,13 @@ function handleTap() {
<template>
<view class="w-full relative rounded-3 overflow-hidden shadow-cell-group bg-[#fff]">
<view v-if="operationTitle" class="w-[111px] h-[44px] bg-[#1a1a1a] absolute right-0 top-0" @tap="handleTap">
<view v-if="operationTitle" class="w-[111px] h-[44px] bg-[#1a1a1a] absolute right-0 top-0">
<view class="text-[#999] text-xs absolute right-4 leading-[34px]">
{{ operationTitle }}
</view>
</view>
<image class="w-[343px] h-[179px] absolute right-0 top-0 " src="@/static/image/shape-bg.png" />
<view class="pl-4 relative flex gap-1 h-[44px] items-center text-xs">
<image class="w-[343px] h-[179px] absolute right-0 top-0" src="@/static/image/shape-bg.png" />
<view class="pl-4 relative flex gap-1 h-[44px] items-center text-xs" @tap="handleTap">
<view>{{ title }}</view>
<view v-if="subtitle" class="text-[#D9D9D9]">
{{ subtitle }}
+1 -1
View File
@@ -64,5 +64,5 @@ export interface FeedingPlan extends BaseModel {
export interface CreateFeedingPlanRequest extends Omit<FeedingPlan, keyof BaseModel> {
petId: string
products: { id: string, dailyUsageWeight: number }[]
products: { id: string, dailyUsageWeight: number, percentage: number }[]
}
+29 -4
View File
@@ -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)
</script>
@@ -54,9 +79,9 @@ onMounted(fetchPets)
{{ item.name }}
<view v-if="index === currentIndex" class="absolute w-[30%] h-[3px] bg-primary bottom-[-4px] rounded-full" />
</view>
<image src="@/static/icons/plus-circle.svg" class="w-[24px] h-[24px]" />
<image src="@/static/icons/plus-circle.svg" class="w-[24px] h-[24px]" @tap="handleAddPet" />
</template>
<view v-else class="text-primary text-xl relative flex justify-center font-semibold">
<view v-else class="text-primary text-xl relative flex justify-center font-semibold" @tap="handleAddPet">
待添加
</view>
</view>
@@ -74,11 +99,11 @@ onMounted(fetchPets)
</view>
<image class="w-[20px] h-[20px]" src="@/static/icons/edit.svg" />
</view>
<SectionCard v-if="feedingPlan" title="喂养计划" subtitle="FEEDING PLAN" operation-title="编辑计划">
<SectionCard v-if="feedingPlan" title="喂养计划" subtitle="FEEDING PLAN" operation-title="编辑计划" :on-operation-click="handleEdit">
<ProductReadonlyItem v-for="item in feedingPlan.feedingPlanProducts" :key="item.product.id" :data="item" />
</SectionCard>
<SectionCard v-else title="喂养计划" subtitle="FEEDING PLAN" operation-title="无计划">
<view class="w-full h-[120px] flex flex-col items-center justify-center gap-1.5">
<view class="w-full h-[120px] flex flex-col items-center justify-center gap-1.5" @tap="handleAddFeedingPlan">
<image src="@/static/icons/plus-circle-2.svg" class="w-[47px] h-[47px]" />
<view class="text-xs text-disabled">
添加您的喂养计划
+43
View File
@@ -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<FeedingPlan | null>(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,
}
})