index.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. <uni-icons type="search" size="14" color="#999"></uni-icons>
  8. <input type="text" v-model="searchKeyword" placeholder="搜索宠物名/主人" class="search-input" confirm-type="search" @confirm="onSearch" />
  9. </view>
  10. <button size="mini" class="add-btn" @click="goToAdd">+ 新增档案</button>
  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. <text class="btn-item detail" @click.stop="goToDetail(pet)">详情</text>
  29. <text class="btn-item edit" @click.stop="goToEdit(pet)">编辑</text>
  30. <text class="btn-item delete" @click.stop="onDelete(pet)">删除</text>
  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. display: flex;
  135. align-items: center;
  136. background: #f5f5f5;
  137. border-radius: 32rpx;
  138. padding: 12rpx 20rpx;
  139. gap: 12rpx;
  140. }
  141. .search-input {
  142. flex: 1;
  143. font-size: 26rpx;
  144. background: transparent;
  145. }
  146. .add-btn {
  147. font-size: 24rpx;
  148. font-weight: bold;
  149. background: linear-gradient(90deg, #ffd53f, #ff9500);
  150. color: #333;
  151. border: none;
  152. border-radius: 32rpx;
  153. padding: 12rpx 28rpx;
  154. white-space: nowrap;
  155. }
  156. .list-container {
  157. padding: 24rpx;
  158. }
  159. .pet-card {
  160. display: flex;
  161. background: #fff;
  162. border-radius: 24rpx;
  163. overflow: hidden;
  164. margin-bottom: 24rpx;
  165. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.04);
  166. }
  167. .pet-photo {
  168. width: 210rpx;
  169. height: 280rpx;
  170. flex-shrink: 0;
  171. }
  172. .card-info {
  173. flex: 1;
  174. padding: 24rpx;
  175. display: flex;
  176. flex-direction: column;
  177. }
  178. .info-top {
  179. display: flex;
  180. justify-content: space-between;
  181. align-items: center;
  182. margin-bottom: 8rpx;
  183. }
  184. .pet-name {
  185. font-size: 34rpx;
  186. font-weight: 800;
  187. color: #333;
  188. }
  189. .owner-name {
  190. font-size: 24rpx;
  191. color: #999;
  192. }
  193. .pet-meta {
  194. font-size: 26rpx;
  195. color: #666;
  196. margin-bottom: 16rpx;
  197. }
  198. .health-overview {
  199. display: flex;
  200. align-items: center;
  201. gap: 16rpx;
  202. margin-bottom: 20rpx;
  203. }
  204. .health-badge {
  205. font-size: 22rpx;
  206. color: #2e7d32;
  207. background: #e8f5e9;
  208. padding: 4rpx 16rpx;
  209. border-radius: 8rpx;
  210. }
  211. .vaccine-info {
  212. font-size: 22rpx;
  213. color: #795548;
  214. background: #efebe9;
  215. padding: 4rpx 16rpx;
  216. border-radius: 8rpx;
  217. }
  218. .card-footer {
  219. margin-top: auto;
  220. border-top: 1rpx solid #f8f8f8;
  221. padding-top: 16rpx;
  222. }
  223. .action-btn-group {
  224. display: flex;
  225. justify-content: flex-end;
  226. gap: 16rpx;
  227. }
  228. .btn-item {
  229. font-size: 24rpx;
  230. padding: 8rpx 20rpx;
  231. border-radius: 12rpx;
  232. border: 1rpx solid #eee;
  233. color: #666;
  234. }
  235. .btn-item.detail {
  236. background: #fdf6ec;
  237. border-color: #faecd8;
  238. color: #e6a23c;
  239. }
  240. .btn-item.delete {
  241. color: #f56c6c;
  242. border-color: #fde2e2;
  243. background: #fef0f0;
  244. }
  245. </style>