index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <script setup lang="ts">
  2. import type { Pet } from '@/model/pet'
  3. import { getOwnPets } from '@/api/pet'
  4. import avatar from '@/static/image/pet-parameters/avatar.png'
  5. import addBtn from '@/static/image/pet-plan/add_btn.png'
  6. import card from '@/static/image/pet-plan/card.png'
  7. import editBtn from '@/static/image/pet-plan/edit.png'
  8. import userAddBtn from '@/static/image/pet-plan/user_add_btn.png'
  9. interface User {
  10. name: string
  11. image: string
  12. label: string[]
  13. isClick: boolean
  14. plan: { image: string, name: string, weight: string, energy: string, label: string[] }[]
  15. }
  16. const pets = ref<Pet[]>([])
  17. async function fetchPets() {
  18. pets.value = await getOwnPets()
  19. }
  20. onMounted(fetchPets)
  21. const userList = ref<User[]>([])
  22. const clickUser = computed(() => {
  23. return userList.value.filter(user => user.isClick === true)
  24. })
  25. function resetUserClick() {
  26. userList.value.forEach(i => (i.isClick = false))
  27. }
  28. function handleUser(index: number) {
  29. resetUserClick()
  30. userList.value[index].isClick = true
  31. }
  32. function handleAdd() {
  33. uni.navigateTo({ url: '/pages/start-filing/index' })
  34. }
  35. function handleEdit() {
  36. uni.navigateTo({ url: '/pages/feed-calculator/index' })
  37. }
  38. </script>
  39. <template>
  40. <view class="flex flex-col bg-[#F5F6F7] overflow-y-auto h-screen">
  41. <!-- 喂养计划未注册 -->
  42. <view v-if="pets.length === 0" class="w-[calc(100% - 32px)] min-h-[135px] rounded-lg m-[16px] relative">
  43. <image :src="card" class="w-full h-full absolute z-20" />
  44. <view class="z-20 absolute w-full mt-[35px] flex flex-col">
  45. <image :src="addBtn" class="w-[47px] h-[47px] mx-auto" @click="handleAdd" />
  46. <text class="text-[12px] text-[#D9D9D9] mx-auto mt-[6px]" @click="handleAdd">
  47. 添加你的喂养计划
  48. </text>
  49. </view>
  50. <view class="w-[111px] h-[42px] bg-[black] absolute top-0 right-0 rounded-tr-xl z-10">
  51. <text class="text-[#999] absolute right-5 top-2 text-[12px]">
  52. 无计划
  53. </text>
  54. </view>
  55. <view class="absolute right-0 top-0 w-[78px] h-[24px] z-20" @tap="handleAdd" />
  56. </view>
  57. <!-- 喂养计划已注册 -->
  58. <view v-else>
  59. <view class="w-[calc(100% - 32px)] m-[16px] flex items-center">
  60. <view v-for="(item, index) in userList" :key="index" class="text-[16px] font-500 mr-[12px] flex flex-col items-center justify-center" :style="{ fontSize: item.isClick ? '20px' : '16px', color: item.isClick ? '#4545E5' : 'black', fontWeight: item.isClick ? '600' : '500' }" @click="handleUser(index)">
  61. <text>{{ item.name }}</text>
  62. <view v-if="item.isClick" class="w-[16px] h-[3px] bg-[#4545E5]" />
  63. </view>
  64. <image :src="userAddBtn" class="w-[24px] h-[24px]" @tap="handleAdd" />
  65. </view>
  66. <view v-for="(item, index) in clickUser" :key="index" class="w-[calc(100% - 32px)] min-h-[129px] rounded-lg m-[16px] relative bg-[white] p-[16px] flex items-center">
  67. <image :src="avatar" class="w-[64px] h-[64px] rounded-full" />
  68. <view class="ml-[16px] min-h-[54px] flex-1">
  69. <text class="font-600">
  70. {{ item.name }}
  71. </text>
  72. <view class="flex gap-2 flex-wrap mt-[6px]">
  73. <view v-for="(label, labelIndex) in item.label" :key="labelIndex" class="px-[8px] py-[4px] rounded bg-[#f3f3f3] text-[#999] text-[12px]">
  74. {{ label }}
  75. </view>
  76. </view>
  77. </view>
  78. <image :src="editBtn" class="w-[20px] h-[20px]" />
  79. </view>
  80. <view class="w-[calc(100% - 32px)] min-h-[135px] rounded-lg bg-[white] mx-[16px] relative">
  81. <image :src="card" class="w-full h-[130px] absolute z-20" />
  82. <view class="absolute z-20 w-full rounded-lg">
  83. <view class="ml-[12px] mt-[5px]">
  84. <text class="text-[12px]">
  85. 喂养计划
  86. </text>
  87. <text class="text-[12px] text-[#D9D9D9]">
  88. FEEDING PLAN
  89. </text>
  90. </view>
  91. </view>
  92. <view class="absolute z-20 w-full rounded-lg bg-[white] top-[30px]">
  93. <view v-for="(item, index) in clickUser[0].plan" :key="index" class="w-full mt-3 pl-[10px] pr-[20px] flex " :class="[clickUser[0].plan.length - 1 === index ? 'rounded-b-lg' : 'plan_card_bottom']">
  94. <image :src="item.image" class="w-[80px] h-[80px]" />
  95. <view class="ml-[12px] mt-[10px] flex-1">
  96. <text class="font-600">
  97. {{ item.name }}
  98. </text>
  99. <view class="flex gap-2 flex-wrap mt-[16px]">
  100. <view v-for="(label, labelIndex) in item.label" :key="labelIndex" class="px-[8px] py-[4px] rounded bg-[#f3f3f3] text-[12px] ">
  101. {{ label }}
  102. </view>
  103. </view>
  104. </view>
  105. <view v-if="index === 0" class="flex flex-col mt-[10px]">
  106. <view class="text-[12px] font-600 flex justify-end">
  107. 每日
  108. </view>
  109. <view class="flex items-end">
  110. <text class="source_family font-700 text-[20px]">
  111. {{ item.weight }}
  112. </text>
  113. <text class="poppins_family font-500 text-[12px]">
  114. g
  115. </text>
  116. </view>
  117. <view class="source_family text-[9px] text-[#CDCDCD] mt-[10px] flex justify-end">
  118. {{ item.energy }}
  119. </view>
  120. </view>
  121. <view v-else class="flex flex-col mt-[2px] relative items-center top-[8px] right-0">
  122. <view class="absolute z-20 top-[-10px] right-0 flex items-center justify-center w-full">
  123. <view class="w-[25px] h-[25px] rounded-full bg-[#4545e5] text-[10px] text-[white] flex items-center justify-center ">
  124. </view>
  125. </view>
  126. <view class="h-[52px] bg-[#D9D9D9] rounded-2xl px-[4px]">
  127. <view class="mt-[14px] flex items-end justify-center ">
  128. <text class="text-[16px] font-700">
  129. {{ item.weight }}
  130. </text>
  131. <text class="text-[12px] font-500">
  132. g
  133. </text>
  134. </view>
  135. <view class="text-[9px] text-[#7C7C7C] flex justify-center">
  136. {{ item.energy }}
  137. </view>
  138. </view>
  139. </view>
  140. </view>
  141. </view>
  142. <view class="w-[111px] h-[42px] bg-[black] absolute top-0 right-0 rounded-tr-xl z-10">
  143. <text class="text-[#999] absolute right-5 top-2 text-[12px]">
  144. 编辑计划
  145. </text>
  146. </view>
  147. <view class="absolute right-0 top-0 w-[78px] h-[24px] z-20" @tap="handleEdit" />
  148. </view>
  149. </view>
  150. </view>
  151. </template>
  152. <style scoped>
  153. .select_user_span{
  154. color: #4545E5;
  155. }
  156. .user_span{
  157. color:black;
  158. }
  159. .source_family{
  160. font-family: Source Han Sans CN, sans-serif;
  161. }
  162. .poppins_family{
  163. font-family: Poppins, sans-serif;
  164. }
  165. .plan_card_bottom{
  166. border-bottom: 0.5px solid #EAEAEA;
  167. }
  168. </style>