瀏覽代碼

fix: bug修复

IlhamTahir 8 月之前
父節點
當前提交
22f6bd7ff5

+ 5 - 1
src/api/pet.ts

@@ -1,4 +1,4 @@
-import type { CreatePetRequest, Pet } from '@/model/pet'
+import type { CreatePetRequest, Pet, PetVariety } from '@/model/pet'
 import httpClient from '@/api/httpClient'
 
 export function createPet(createPetRequest: CreatePetRequest) {
@@ -8,3 +8,7 @@ export function createPet(createPetRequest: CreatePetRequest) {
 export function getOwnPets() {
   return httpClient.get<Pet[]>('/pets/own')
 }
+
+export function petVarietiesList() {
+  return httpClient.get<PetVariety[]>('/pet-varieties/list')
+}

+ 4 - 0
src/components/PickerItem.vue

@@ -12,6 +12,10 @@ const emits = defineEmits<{
   'update:modelValue': [string | number]
 }>()
 
+if (props.options.length && !props.modelValue) {
+  emits('update:modelValue', props.options[0].value)
+}
+
 function bindPickerChange(e: { detail: { value: number | string } }) {
   const currentIndex = e.detail.value as number
   emits('update:modelValue', props.options[currentIndex].value)

+ 4 - 36
src/components/PopupInput.vue

@@ -1,8 +1,5 @@
 <script setup lang="ts">
-import type { UniPopupDialogInstance } from '@uni-helper/uni-types'
-import type { UniPopupInstance } from '@uni-helper/uni-ui-types'
-
-const props = withDefaults(defineProps<{
+withDefaults(defineProps<{
   modelValue: string | number
   placeholder?: string
   suffix?: string
@@ -10,47 +7,18 @@ const props = withDefaults(defineProps<{
   placeholder: '请输入内容',
 })
 
-const emits = defineEmits<{
+defineEmits<{
   'update:modelValue': [string | number]
 }>()
-
-const uniPopupRef = ref<UniPopupInstance | null>(null)
-const uniPopupDialogRef = ref<UniPopupDialogInstance | null>(null)
-
-function dialogInputConfirm(value: any) {
-  if (value === '') {
-    uni.showToast({
-      title: props.placeholder,
-      icon: 'none',
-    })
-    return
-  }
-  emits('update:modelValue', value as (string | number))
-  if (uniPopupRef.value && uniPopupRef.value.close) {
-    uniPopupRef.value.close()
-  }
-}
-
-function handleClick() {
-  if (uniPopupRef.value && uniPopupRef.value.open) {
-    uniPopupRef.value.open()
-  }
-}
 </script>
 
 <template>
-  <view class="w-full" @click="handleClick">
-    {{ modelValue }}
+  <view class="w-full flex items-center gap-2">
+    <input class="text-right" :value="modelValue" :placeholder="placeholder" @input="$emit('update:modelValue', modelValue)">
     <text v-if="suffix">
       {{ suffix }}
     </text>
   </view>
-  <uni-popup ref="uniPopupRef" type="dialog">
-    <uni-popup-dialog
-      ref="uniPopupDialogRef" mode="input" title="输入内容" :value="modelValue" :placeholder="placeholder"
-      @confirm="dialogInputConfirm"
-    />
-  </uni-popup>
 </template>
 
 <style scoped>

+ 5 - 0
src/model/pet.ts

@@ -14,6 +14,7 @@ export interface Pet extends TraceableModel {
   type: PetType
   weight: number
   feedingPlan: FeedingPlan
+  varietyName: string
 }
 
 export interface CreatePetRequest extends Omit<Pet, keyof TraceableModel> {
@@ -66,3 +67,7 @@ export interface CreateFeedingPlanRequest extends Omit<FeedingPlan, keyof BaseMo
   petId: string
   products: { id: string, dailyUsageWeight: number, percentage: number }[]
 }
+
+export interface PetVariety extends BaseModel {
+  name: string
+}

+ 1 - 5
src/pages/feed-questionnaire/index.vue

@@ -58,11 +58,7 @@ function reset() {
 function handleReady() {
   reset()
   titleName.value = '喂养问卷'
-  controlFormDisplay.value.display2 = true
-  setTimeout(() => {
-    reset()
-    controlFormDisplay.value.display3 = true
-  }, 2000)
+  controlFormDisplay.value.display3 = true
 }
 function handleBackFeedStart() {
   reset()

+ 13 - 4
src/pages/start-filing/index.vue

@@ -9,12 +9,18 @@ import ToolApi from '@/utils'
 const safeHeight = ToolApi.getSafeHeight()
 
 const feedSloganBottom = ref<number>(13)
+
+const feedingPlanStore = useFeedingPlanStore()
 function handleNext() {
+  if (!feedingPlanStore.pet.varietyName) {
+    uni.showToast({
+      title: '请选择品种',
+      icon: 'error',
+    })
+    return
+  }
   uni.navigateTo({ url: '/pages/feed-questionnaire/index' })
 }
-
-const feedingPlanStore = useFeedingPlanStore()
-
 const disabled = computed(() => {
   return feedingPlanStore.pet.type === PetType.DOG
 })
@@ -35,9 +41,12 @@ const disabled = computed(() => {
         </Cell>
       </CellGroup>
       <CellGroup class="w-full bg-[#fff] shadow-cell-group rounded-3 overflow-hidden">
-        <Cell title="品种" border>
+        <Cell title="类别" border>
           <PickerItem v-model="feedingPlanStore.pet.type" :options="feedingPlanStore.petTypeOptions" />
         </Cell>
+        <Cell title="品种" border>
+          <PickerItem v-model="feedingPlanStore.pet.varietyName" :options="feedingPlanStore.petVarietiesOptions" />
+        </Cell>
         <Cell title="性别" border>
           <PickerItem v-model="feedingPlanStore.pet.gender" :options="feedingPlanStore.genderOptions" />
         </Cell>

+ 20 - 1
src/stores/feeding-plan.ts

@@ -1,7 +1,7 @@
 import type { FeedingPlanProduct } from '@/model/feeding-plan'
 import type { Product } from '@/model/product'
 import { createFeedingPlan, updateFeedingPlan } from '@/api/feeding-plan'
-import { createPet } from '@/api/pet'
+import { createPet, petVarietiesList } from '@/api/pet'
 import {
   type CreateFeedingPlanRequest,
   type CreatePetRequest,
@@ -25,6 +25,23 @@ export const useFeedingPlanStore = defineStore('feeding-plan', () => {
     { value: Gender.FEMALE, label: '女孩' },
   ]
 
+  const petVarietiesOptions = ref<{
+    value: string
+    label: string
+  }[]>([])
+
+  const fetchPetVarieties = async () => {
+    const result = await petVarietiesList()
+    petVarietiesOptions.value = result.map((item) => {
+      return {
+        value: item.name,
+        label: item.name,
+      }
+    })
+  }
+
+  fetchPetVarieties()
+
   const dailyCalories = ref(400)
   // @ts-expect-error @ts-ignore
   const pet = ref <CreatePetRequest>({
@@ -39,6 +56,7 @@ export const useFeedingPlanStore = defineStore('feeding-plan', () => {
     photo: '',
     type: PetType.CAT,
     weight: 0,
+    varietyName: '',
   })
 
   const savedPet = ref<Pet | null>(null)
@@ -326,5 +344,6 @@ export const useFeedingPlanStore = defineStore('feeding-plan', () => {
     confirm,
     initPet,
     initFeedingPlan,
+    petVarietiesOptions,
   }
 })