feat: 产品选择列表

This commit is contained in:
ilhamtahir committed 2025-01-20 08:01:53 +08:00
1 parent a55a6d3586
commit dfadf3a8f0
25 files changed
+351 -54

No files matched your search

@@ -0,0 +1,116 @@
<script setup lang="ts">
import type { FeedFormQuestions, PetCard, StepInfo, UserList } from '@/model/pet-manual'
import FeedForm from '@/pages/feed-questionnaire/components/FeedForm.vue'
import FeedSlogan from '@/pages/feed-questionnaire/components/FeedSlogan.vue'
import ProgressBar from '@/pages/feed-questionnaire/components/ProgressBar.vue'
import avator from '@/static/image/pet-parameters/avatar.png'
const props = defineProps<{
list: FeedFormQuestions[]
stepInfo: StepInfo[]
userList: UserList
}>()
const emits = defineEmits<{
back: [void]
step: [number]
}>()
const step = ref<number>(0)
const addPage = ref<number>(1)
const isUserPage = ref<boolean>(false)
const aimList = ref<string[]>(['增肥', '减肥'])
const aimIndex = ref<number>(0)
const weightList = ref<string[]>(['6kg', '7kg'])
const weightIndex = ref<number>(0)
function handleAimChange(e: CustomEvent, type: string) {
if (type === 'aim') {
aimIndex.value = e.detail.value
}
else if (type === 'weight') {
weightIndex.value = e.detail.value
}
}
const progressNumber = computed<number>(() => {
return Math.ceil((step.value + 1) / (props.list.length + addPage.value) * 100)
})
const feedSloganBottom = computed<number>(() => {
return props.list[step.value]?.formType === 3 ? 40 : 70
})
const feedProgressTitle = computed<string>(() => {
return step.value === 0 ? '返回' : '上一题'
})
function handlePrevious() {
if (step.value === props.list.length - 1 + addPage.value) {
isUserPage.value = false
}
if (step.value > 0) {
step.value -= 1
}
else {
emits('back')
}
}
const feedingPlanStore = useFeedingPlanStore()
function handleAnswer(answer: PetCard) {
if (answer.key) {
feedingPlanStore.setPetValue(answer.key, answer.value)
}
if (step.value === 2 || step.value === 7) {
emits('step', step.value)
}
if (step.value === props.list.length - 1) {
isUserPage.value = true
}
if (step.value < props.list.length - 1 + addPage.value) {
step.value += 1
}
}
async function confirm() {
await feedingPlanStore.persistentPet()
}
</script>
<template>
<ProgressBar :progress="progressNumber" :title-name="feedProgressTitle" @previous="handlePrevious" />
<FeedForm v-if="!isUserPage" :form-type="props.list[step].formType" :answer-list="props.list[step].question" :title="props.list[step].title" @next="handleAnswer" />
<FeedSlogan :bottom="feedSloganBottom" />
<view v-if="isUserPage">
<view class="w-[calc(100% - 32px)] h-[96px] bg-[white] rounded-3 mt-[31px] p-[16px] mx-[16px] flex flex-col justify-center">
<view class="flex gap-4">
<image :src="avator" class="w-[64px] h-[64px] rounded-full" />
<view class="mt-[5px] ">
<text class="font-bold text-[16px] ">
{{ feedingPlanStore.pet.name }}
</text>
<view class="mt-[8px] flex gap-2">
<view v-for="item in feedingPlanStore.petTags" :key="item.key" class="text-[12px] text-[#999] bg-[#F3F3F3] rounded-[3px] py-[2px] px-[8px]">
{{ item.value }}
</view>
</view>
</view>
</view>
</view>
<CellGroup>
<Cell title="喂养目标" border>
<PickerItem v-model="feedingPlanStore.feedingPlan.feedingGoal" :options="feedingPlanStore.feedingGoalOptions" />
</Cell>
<Cell title="目标体重">
<PopupInput v-model="feedingPlanStore.feedingPlan.targetWeight" placeholder="请输入目标体重" />
</Cell>
</CellGroup>
<view class="flex items-center justify-center">
<button class="w-[176px] h-[47px] flex items-center justify-center bg-[#4545E5] border-none text-[white] rounded-3xl mt-[210px]" @tap="confirm">
下一步
</button>
</view>
</view>
</template>
<style scoped>
.card_border_bottom{
border-bottom: 1px solid #E5E5E5;
}
</style>