index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <template>
  2. <view class="pet-list-page">
  3. <nav-bar title="宠物档案"></nav-bar>
  4. <!-- 顶部操作栏 -->
  5. <view class="action-bar">
  6. <view class="search-box">
  7. <text class="search-icon">🔍</text>
  8. <input type="text" v-model="searchKeyword" placeholder="搜索宠物名/主人" class="search-input" confirm-type="search" @confirm="onSearch" />
  9. </view>
  10. <view class="add-btn" @click="goToAdd">+ 新增档案</view>
  11. </view>
  12. <!-- 宠物档案卡片列表 -->
  13. <view class="list-container">
  14. <view class="pet-card" v-for="pet in pets" :key="pet.id" @click="handleCardClick(pet)">
  15. <image :src="pet.avatarUrl || '/static/default-avatar.png'" class="pet-photo" mode="aspectFill"></image>
  16. <view class="card-info">
  17. <view class="info-top">
  18. <text class="pet-name">{{ pet.name }}</text>
  19. <text class="owner-name">{{ pet.ownerName || '-' }}</text>
  20. </view>
  21. <text class="pet-meta">{{ pet.breed || '-' }} · {{ pet.age || 0 }}岁</text>
  22. <view class="health-overview">
  23. <text class="health-badge">{{ pet.healthStatus || '健康' }}</text>
  24. <text class="vaccine-info">疫苗: {{ pet.vaccineStatus || '无' }}</text>
  25. </view>
  26. <view class="card-footer">
  27. <view class="action-btn-group">
  28. <view class="btn-item detail" @click.stop="goToDetail(pet)">详情</view>
  29. <view class="btn-item edit" @click.stop="goToEdit(pet)">编辑</view>
  30. <view class="btn-item delete" @click.stop="onDelete(pet)">删除</view>
  31. </view>
  32. </view>
  33. </view>
  34. </view>
  35. <view v-if="pets.length === 0" style="text-align: center; color: #999; padding: 50rpx 0; font-size: 28rpx;">
  36. 暂无宠物数据
  37. </view>
  38. </view>
  39. </view>
  40. </template>
  41. <script setup>
  42. import { ref } from 'vue'
  43. import { onShow, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app'
  44. import navBar from '@/components/nav-bar/index.vue'
  45. import { listPet, delPet } from '@/api/archieves/pet'
  46. const pets = ref([])
  47. const searchKeyword = ref('')
  48. const pageNum = ref(1)
  49. const pageSize = ref(10)
  50. const hasMore = ref(true)
  51. const loadPets = async (isLoadMore = false) => {
  52. try {
  53. uni.showNavigationBarLoading()
  54. const res = await listPet({
  55. pageNum: pageNum.value,
  56. pageSize: pageSize.value,
  57. keyword: searchKeyword.value
  58. })
  59. const rows = res?.rows || []
  60. if (isLoadMore) {
  61. pets.value = [...pets.value, ...rows]
  62. } else {
  63. pets.value = rows
  64. }
  65. hasMore.value = pets.value.length < (res?.total || 0)
  66. } catch (error) {
  67. console.error('获取宠物列表失败:', error)
  68. } finally {
  69. uni.hideNavigationBarLoading()
  70. uni.stopPullDownRefresh()
  71. }
  72. }
  73. onShow(() => {
  74. pageNum.value = 1
  75. loadPets()
  76. })
  77. onPullDownRefresh(() => {
  78. pageNum.value = 1
  79. loadPets()
  80. })
  81. onReachBottom(() => {
  82. if (hasMore.value) {
  83. pageNum.value++
  84. loadPets(true)
  85. }
  86. })
  87. const onSearch = () => {
  88. pageNum.value = 1
  89. loadPets()
  90. }
  91. const goToAdd = () => uni.navigateTo({ url: '/pages/my/pet/add/index' })
  92. const goToDetail = (pet) => uni.navigateTo({ url: `/pages/my/pet/detail/index?id=${pet.id}` })
  93. const goToEdit = (pet) => uni.navigateTo({ url: `/pages/my/pet/edit/index?id=${pet.id}` })
  94. const handleCardClick = (pet) => {
  95. goToEdit(pet)
  96. }
  97. const onDelete = (pet) => {
  98. uni.showModal({
  99. title: '提示',
  100. content: '确认删除该宠物档案吗?',
  101. success: async (res) => {
  102. if (res.confirm) {
  103. try {
  104. uni.showLoading({ title: '处理中...' })
  105. await delPet(pet.id)
  106. uni.hideLoading()
  107. uni.showToast({ title: '删除成功', icon: 'success' })
  108. // 刷新当前页数据
  109. loadPets()
  110. } catch (error) {
  111. uni.hideLoading()
  112. }
  113. }
  114. }
  115. })
  116. }
  117. </script>
  118. <style lang="scss" scoped>
  119. /* 此部分与原文件保持一致 */
  120. .pet-list-page {
  121. min-height: 100vh;
  122. background-color: #f2f2f2;
  123. padding-bottom: 40rpx;
  124. }
  125. .action-bar {
  126. display: flex;
  127. align-items: center;
  128. padding: 20rpx 24rpx;
  129. background-color: #fff;
  130. gap: 16rpx;
  131. }
  132. .search-box {
  133. flex: 1;
  134. height: 72rpx;
  135. display: flex;
  136. align-items: center;
  137. background: #f5f5f5;
  138. border-radius: 36rpx;
  139. padding: 0 24rpx;
  140. gap: 12rpx;
  141. box-sizing: border-box;
  142. }
  143. .search-icon {
  144. font-size: 28rpx;
  145. line-height: 1;
  146. flex-shrink: 0;
  147. }
  148. .search-input {
  149. flex: 1;
  150. font-size: 26rpx;
  151. background: transparent;
  152. height: 72rpx;
  153. line-height: 72rpx;
  154. }
  155. .add-btn {
  156. height: 72rpx;
  157. line-height: 72rpx;
  158. padding: 0 28rpx;
  159. font-size: 25rpx;
  160. font-weight: bold;
  161. background: linear-gradient(90deg, #ffd53f, #ff9500);
  162. color: #fff;
  163. border: none;
  164. border-radius: 36rpx;
  165. margin: 0;
  166. white-space: nowrap;
  167. text-align: center;
  168. }
  169. .list-container {
  170. padding: 24rpx;
  171. }
  172. .pet-card {
  173. display: flex;
  174. background: #fff;
  175. border-radius: 24rpx;
  176. overflow: hidden;
  177. margin-bottom: 24rpx;
  178. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.04);
  179. }
  180. .pet-photo {
  181. width: 210rpx;
  182. height: 280rpx;
  183. flex-shrink: 0;
  184. }
  185. .card-info {
  186. flex: 1;
  187. padding: 24rpx;
  188. display: flex;
  189. flex-direction: column;
  190. }
  191. .info-top {
  192. display: flex;
  193. justify-content: space-between;
  194. align-items: center;
  195. margin-bottom: 8rpx;
  196. }
  197. .pet-name {
  198. font-size: 34rpx;
  199. font-weight: 800;
  200. color: #333;
  201. }
  202. .owner-name {
  203. font-size: 24rpx;
  204. color: #999;
  205. }
  206. .pet-meta {
  207. font-size: 26rpx;
  208. color: #666;
  209. margin-bottom: 16rpx;
  210. }
  211. .health-overview {
  212. display: flex;
  213. align-items: center;
  214. gap: 16rpx;
  215. margin-bottom: 20rpx;
  216. }
  217. .health-badge {
  218. font-size: 22rpx;
  219. color: #2e7d32;
  220. background: #e8f5e9;
  221. padding: 4rpx 16rpx;
  222. border-radius: 8rpx;
  223. }
  224. .vaccine-info {
  225. font-size: 22rpx;
  226. color: #795548;
  227. background: #efebe9;
  228. padding: 4rpx 16rpx;
  229. border-radius: 8rpx;
  230. }
  231. .card-footer {
  232. margin-top: auto;
  233. border-top: 2rpx solid #EEEEEE;
  234. padding-top: 20rpx;
  235. }
  236. .action-btn-group {
  237. display: flex;
  238. justify-content: flex-end;
  239. gap: 16rpx;
  240. }
  241. .btn-item {
  242. font-size: 24rpx;
  243. height: 56rpx;
  244. line-height: 56rpx;
  245. padding: 0 24rpx;
  246. border-radius: 28rpx;
  247. border: 2rpx solid;
  248. color: #666;
  249. text-align: center;
  250. white-space: nowrap;
  251. }
  252. .btn-item.detail {
  253. background: #fdf6ec;
  254. border-color: #f5d89a;
  255. color: #b88230;
  256. }
  257. .btn-item.edit {
  258. background: #ecf5ff;
  259. border-color: #a0cfff;
  260. color: #409eff;
  261. }
  262. .btn-item.delete {
  263. color: #f56c6c;
  264. border-color: #fbc4c4;
  265. background: #fef0f0;
  266. }
  267. </style>