feat: 喂养计划回显
This commit is contained in:
1 parent
f99dca56ef
commit
b730f7966b
4 files changed
+76
-8
No files matched your search
@@ -15,13 +15,13 @@ function handleTap() {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<view class="w-full relative rounded-3 overflow-hidden shadow-cell-group bg-[#fff]">
|
<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]">
|
<view class="text-[#999] text-xs absolute right-4 leading-[34px]">
|
||||||
{{ operationTitle }}
|
{{ operationTitle }}
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<image class="w-[343px] h-[179px] absolute right-0 top-0 " src="@/static/image/shape-bg.png" />
|
<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">
|
<view class="pl-4 relative flex gap-1 h-[44px] items-center text-xs" @tap="handleTap">
|
||||||
<view>{{ title }}</view>
|
<view>{{ title }}</view>
|
||||||
<view v-if="subtitle" class="text-[#D9D9D9]">
|
<view v-if="subtitle" class="text-[#D9D9D9]">
|
||||||
{{ subtitle }}
|
{{ subtitle }}
|
||||||
|
|||||||
+1
-1
@@ -64,5 +64,5 @@ export interface FeedingPlan extends BaseModel {
|
|||||||
|
|
||||||
export interface CreateFeedingPlanRequest extends Omit<FeedingPlan, keyof BaseModel> {
|
export interface CreateFeedingPlanRequest extends Omit<FeedingPlan, keyof BaseModel> {
|
||||||
petId: string
|
petId: string
|
||||||
products: { id: string, dailyUsageWeight: number }[]
|
products: { id: string, dailyUsageWeight: number, percentage: number }[]
|
||||||
}
|
}
|
||||||
@@ -37,6 +37,31 @@ async function selectPet(index: number) {
|
|||||||
currentIndex.value = index
|
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)
|
onMounted(fetchPets)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -54,9 +79,9 @@ onMounted(fetchPets)
|
|||||||
{{ item.name }}
|
{{ item.name }}
|
||||||
<view v-if="index === currentIndex" class="absolute w-[30%] h-[3px] bg-primary bottom-[-4px] rounded-full" />
|
<view v-if="index === currentIndex" class="absolute w-[30%] h-[3px] bg-primary bottom-[-4px] rounded-full" />
|
||||||
</view>
|
</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>
|
</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>
|
||||||
</view>
|
</view>
|
||||||
@@ -74,11 +99,11 @@ onMounted(fetchPets)
|
|||||||
</view>
|
</view>
|
||||||
<image class="w-[20px] h-[20px]" src="@/static/icons/edit.svg" />
|
<image class="w-[20px] h-[20px]" src="@/static/icons/edit.svg" />
|
||||||
</view>
|
</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" />
|
<ProductReadonlyItem v-for="item in feedingPlan.feedingPlanProducts" :key="item.product.id" :data="item" />
|
||||||
</SectionCard>
|
</SectionCard>
|
||||||
<SectionCard v-else title="喂养计划" subtitle="FEEDING PLAN" operation-title="无计划">
|
<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]" />
|
<image src="@/static/icons/plus-circle-2.svg" class="w-[47px] h-[47px]" />
|
||||||
<view class="text-xs text-disabled">
|
<view class="text-xs text-disabled">
|
||||||
添加您的喂养计划
|
添加您的喂养计划
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
type CreateFeedingPlanRequest,
|
type CreateFeedingPlanRequest,
|
||||||
type CreatePetRequest,
|
type CreatePetRequest,
|
||||||
FeedingGoal,
|
FeedingGoal,
|
||||||
|
type FeedingPlan,
|
||||||
Gender,
|
Gender,
|
||||||
type Pet,
|
type Pet,
|
||||||
PetBodyType,
|
PetBodyType,
|
||||||
@@ -256,11 +257,51 @@ export const useFeedingPlanStore = defineStore('feeding-plan', () => {
|
|||||||
return {
|
return {
|
||||||
id: item.product.id,
|
id: item.product.id,
|
||||||
dailyUsageWeight: item.dailyUsageWeight,
|
dailyUsageWeight: item.dailyUsageWeight,
|
||||||
|
percentage: item.percentage,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
await createFeedingPlan(feedingPlan.value)
|
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 {
|
return {
|
||||||
pet,
|
pet,
|
||||||
petTypeOptions,
|
petTypeOptions,
|
||||||
@@ -275,5 +316,7 @@ export const useFeedingPlanStore = defineStore('feeding-plan', () => {
|
|||||||
changePercentage,
|
changePercentage,
|
||||||
dailyCalories,
|
dailyCalories,
|
||||||
confirm,
|
confirm,
|
||||||
|
initPet,
|
||||||
|
initFeedingPlan,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
Reference in new issue
Block a user