feat: 喂养计划

This commit is contained in:
ilhamtahir committed 2025-01-21 09:09:42 +08:00
1 parent dfadf3a8f0
commit b2d41fd537
22 files changed
+506 -17

No files matched your search

@@ -1,4 +1,6 @@
<script setup lang="ts">
import type { Product } from '@/model/product'
import { useFeedingPlanStore } from '@/stores/feeding-plan'
import { useProductStore } from '@/stores/product'
const productStore = useProductStore()
@@ -6,6 +8,13 @@ const productStore = useProductStore()
onMounted(() => {
productStore.fetchAllProducts()
})
const feedingPlanStore = useFeedingPlanStore()
function selectProduct(product: Product) {
feedingPlanStore.addProductToSelected(product)
uni.navigateBack()
}
</script>
<template>
@@ -22,7 +31,7 @@ onMounted(() => {
</view>
</view>
<view class="w-full bg-white rounded-tr-xl shadow-cell-group">
<view v-for="product in productStore.productList" :key="product.id" class="py-4 px-8 flex gap-3 items-center border-b-1">
<view v-for="product in productStore.productList" :key="product.id" class="py-4 px-8 flex gap-3 items-center border-b-1" @tap="() => selectProduct(product)">
<image :src="product.photo" class="w-[80px] h-[80px]" />
<view class="h-full flex flex-col gap-4">
<view class="font-semibold">
@@ -0,0 +1,54 @@
<script setup lang="ts">
import ProductReadonlyItem from '@/components/ProductReadonlyItem.vue'
const feedingPlanStore = useFeedingPlanStore()
async function handleConfirm() {
await feedingPlanStore.confirm()
uni.navigateTo({
url: '/pages/feed-plan/index',
})
}
</script>
<template>
<view class="p-4 flex flex-col items-center gap-4">
<view v-if="feedingPlanStore.pet" class="shadow-cell-group w-full px-4 py-8 bg-[white] rounded-3 flex items-center gap-4">
<image class="w-[64px] h-[64px] rounded-full" src="@/static/image/pet-default-avatar.png" />
<view class="flex-1">
<view class="font-semibold mb-1.5">
{{ feedingPlanStore.pet.name }}
</view>
<view class="flex gap-2 flex-wrap">
<view v-for="petTag in feedingPlanStore.petTags" :key="petTag.key" class="px-2 py-0.5 bg-[#f3f3f3] rounded-0.75 text-[#000] text-xs">
{{ petTag.value }}
</view>
</view>
</view>
<image class="w-[99px] h-[101px]" src="@/static/svg/complete-badge.svg" />
</view>
<SectionCard v-if="feedingPlanStore.selectedProducts.length" class="w-full" title="产品比例" subtitle="FEEDING PLAN" operation-title="重新编辑">
<view v-for="(item, index) in feedingPlanStore.selectedProducts" :key="item.product.id" class="p-4 flex flex-col gap-3">
<view class="w-full flex justify-between">
<view class="font-semibold">
{{ item.product.name }}
</view>
<view class="w-[48px] h-[28px] flex items-center justify-center rounded-1 bg-[#f3f3f3] font-semibold">
{{ feedingPlanStore.selectedProducts[index].percentage }}%
</view>
</view>
<BSlider readonly :model-value="item.percentage" @change="(value) => feedingPlanStore.changePercentage(item.product.id, value)" />
</view>
</SectionCard>
<view v-if="feedingPlanStore.selectedProducts.length" class="w-full relative rounded-3 overflow-hidden shadow-cell-group bg-[#fff]">
<ProductReadonlyItem v-for="item in feedingPlanStore.selectedProducts" :key="item.product.id" :data="item" />
</view>
<BButton class="fixed bottom-6 mb-safe-bottom z-3" @tap="handleConfirm">
确认
</BButton>
</view>
</template>
<style scoped>
</style>
+29 -5
View File
@@ -1,15 +1,25 @@
<script setup lang="ts">
import AddFeedingPlan from '@/components/AddFeedingPlan.vue'
import ProductItem from '@/components/ProductItem.vue'
import { useFeedingPlanStore } from '@/stores/feeding-plan'
function goToChooseProductPage() {
uni.navigateTo({
url: '/pages/feed-plan-calculator/choose-product',
})
}
const feedingPlanStore = useFeedingPlanStore()
function handleNext() {
uni.navigateTo({
url: '/pages/feed-plan-calculator/confirm',
})
}
</script>
<template>
<view class="w-full h-full bg-regular flex flex-col items-center">
<view class="w-full bg-regular flex flex-col items-center">
<view class="mt-[54px] flex flex-col gap-1 mb-[60px] items-center">
<view class="gradient-text text-[48px] font-bold">
400<text class="text-[24px] font-semibold">
@@ -19,16 +29,30 @@ function goToChooseProductPage() {
<view class="font-semibold">
总热量
</view>
<view class="text-xs text-disabled font-semibold">
<view v-if="!feedingPlanStore.selectedProducts.length" class="text-xs text-disabled font-semibold">
(未添加产品)
</view>
</view>
<image src="@/static/svg/plate.svg" class="w-[289px] h-[176px] mb-[50px]" />
<view class="w-full px-4 mb-[52px]">
<view class="w-full px-4 mb-[52px] flex flex-col gap-3">
<SectionCard v-if="feedingPlanStore.selectedProducts.length" title="产品比例" subtitle="FEEDING PLAN" operation-title="推荐比例">
<view v-for="(item, index) in feedingPlanStore.selectedProducts" :key="item.product.id" class="p-4 flex flex-col gap-3">
<view class="w-full flex justify-between">
<view class="font-semibold">
{{ item.product.name }}
</view>
<view class="w-[48px] h-[28px] flex items-center justify-center rounded-1 bg-[#f3f3f3] font-semibold">
{{ feedingPlanStore.selectedProducts[index].percentage }}%
</view>
</view>
<BSlider :model-value="item.percentage" @change="(value) => feedingPlanStore.changePercentage(item.product.id, value)" />
</view>
</SectionCard>
<ProductItem v-for="item in feedingPlanStore.selectedProducts" :key="item.product.id" :data="item" />
<AddFeedingPlan @tap="goToChooseProductPage" />
</view>
<BButton disabled>
确认
<BButton class="fixed bottom-6 mb-safe-bottom z-3" :disabled="!feedingPlanStore.selectedProducts.length" @tap="handleNext">
下一步
</BButton>
</view>
</template>
@@ -70,6 +70,9 @@ function handleAnswer(answer: PetCard) {
async function confirm() {
await feedingPlanStore.persistentPet()
uni.navigateTo({
url: '/pages/feed-plan-calculator/index',
})
}
</script>