index.vue 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <script setup lang="ts">
  2. import type { FeedFormQuestions, UserList } from '@/model/pet-manual'
  3. import FeedQuestionnaire from '@/components/FeedQuestionnaire.vue'
  4. import FeedStart from '@/components/FeedStart.vue'
  5. import FeedStep from '@/components/FeedStep.vue'
  6. import { PetBodyType } from '@/model/pet'
  7. import extremelyObese from '@/static/image/body-type/extremely-obese.svg'
  8. import extremelyThin from '@/static/image/body-type/extremely-thin.svg'
  9. import ideal from '@/static/image/body-type/ideal.svg'
  10. import obese from '@/static/image/body-type/obese.svg'
  11. import overWeight from '@/static/image/body-type/overweight.svg'
  12. import thin from '@/static/image/body-type/thin.svg'
  13. import underWeight from '@/static/image/body-type/underweight.svg'
  14. import veryThin from '@/static/image/body-type/very-thin.svg'
  15. import avatar from '@/static/image/pet-parameters/avatar.png'
  16. import ToolApi from '@/utils'
  17. interface StepInfo {
  18. step: number
  19. title: string
  20. }
  21. const titleName = ref<string>('喂养计算器')
  22. const safeHeight = ToolApi.getSafeHeight()
  23. const stage = ref<number>(0)
  24. const stepInfo = ref<StepInfo[]>([
  25. { step: 1, title: '身体状态信息' },
  26. { step: 2, title: '计算喂养计划' },
  27. { step: 3, title: '完成统计' },
  28. ])
  29. const controlFormDisplay = ref({
  30. display1: true,
  31. display2: false,
  32. display3: false,
  33. })
  34. const feedFormQuestions = ref<FeedFormQuestions[]>(
  35. [
  36. { title: '猫咪是否活跃?', question: [{ name: '活跃', key: 'isActive', value: true }, { name: '不活跃', key: 'isActive', value: false }], formType: 2 },
  37. { title: '猫咪是否绝育?', question: [{ name: '绝育', key: 'isSterilization', value: true }, { name: '未绝育', key: 'isSterilization', value: false }], formType: 2 },
  38. { title: '猫咪是否怀孕?', question: [{ name: '怀孕', key: 'isPregnant', value: true }, { name: '未怀孕', key: 'isPregnant', value: false }], formType: 2 },
  39. { title: '猫咪是否在哺乳?', question: [{ name: '哺乳中', key: 'isLactation', value: true }, { name: '未哺乳', key: 'isLactation', value: false }], formType: 2 },
  40. { title: '请选择猫咪的体型', question:
  41. [{ image: extremelyThin, name: '极度消廋', key: 'bodyType', value: PetBodyType.EXTREMELY_THIN }, { image: veryThin, name: '非常廋', key: 'bodyType', value: PetBodyType.VERY_THIN }, { image: thin, name: '消瘦', key: 'bodyType', value: PetBodyType.THIN }, { image: underWeight, name: '体重偏低', key: 'bodyType', value: PetBodyType.UNDERWEIGHT }, { image: ideal, name: '理想体重', key: 'bodyType', value: PetBodyType.IDEAL }, { image: overWeight, name: '体重偏重', key: 'bodyType', value: PetBodyType.OVERWEIGHT }, { image: obese, name: '肥胖', key: 'bodyType', value: PetBodyType.OBESE }, { image: extremelyObese, name: '极度肥胖', key: 'bodyType', value: PetBodyType.EXTREMELY_OBESE }], formType: 3 },
  42. ],
  43. )
  44. const userList = ref<UserList>({
  45. image: avatar,
  46. username: '子龙',
  47. type: ['年龄', '品种', '体重'],
  48. })
  49. function reset() {
  50. stage.value = 0
  51. controlFormDisplay.value = {
  52. display1: false,
  53. display2: false,
  54. display3: false,
  55. }
  56. }
  57. function handleReady() {
  58. reset()
  59. titleName.value = '喂养问卷'
  60. controlFormDisplay.value.display3 = true
  61. }
  62. function handleBackFeedStart() {
  63. reset()
  64. titleName.value = '喂养计算器'
  65. controlFormDisplay.value.display1 = true
  66. }
  67. function handleStep(step: number) {
  68. if (step === 2) {
  69. handleReady()
  70. stage.value = 1
  71. controlFormDisplay.value.display2 = true
  72. }
  73. else if (step === 7) {
  74. handleReady()
  75. stage.value = 2
  76. controlFormDisplay.value.display2 = true
  77. }
  78. }
  79. </script>
  80. <template>
  81. <view class="flex flex-col bg-[#F5F6F7] overflow-y-auto" :style="`height:calc(100vh - ${safeHeight}px)`">
  82. <view v-show="controlFormDisplay.display1">
  83. <FeedStart :step-info="stepInfo" @ready="handleReady" />
  84. </view>
  85. <view v-show="controlFormDisplay.display2" class="flex justify-center items-center w-full h-full">
  86. <FeedStep :list="stepInfo" :stage="stage" />
  87. </view>
  88. <view v-show="controlFormDisplay.display3">
  89. <FeedQuestionnaire :list="feedFormQuestions" :step-info="stepInfo" :user-list="userList" @back="handleBackFeedStart" @step="handleStep" />
  90. </view>
  91. </view>
  92. </template>
  93. <style scoped>
  94. </style>