index.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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. uni.showToast({ title: typeof error === 'string' ? error : '获取宠物列表失败', icon: 'none' })
  69. } finally {
  70. uni.hideNavigationBarLoading()
  71. uni.stopPullDownRefresh()
  72. }
  73. }
  74. onShow(() => {
  75. pageNum.value = 1
  76. loadPets()
  77. })
  78. onPullDownRefresh(() => {
  79. pageNum.value = 1
  80. loadPets()
  81. })
  82. onReachBottom(() => {
  83. if (hasMore.value) {
  84. pageNum.value++
  85. loadPets(true)
  86. }
  87. })
  88. const onSearch = () => {
  89. pageNum.value = 1
  90. loadPets()
  91. }
  92. const goToAdd = () => uni.navigateTo({ url: '/pages/my/pet/add/index' })
  93. const goToDetail = (pet) => uni.navigateTo({ url: `/pages/my/pet/detail/index?id=${pet.id}` })
  94. const goToEdit = (pet) => uni.navigateTo({ url: `/pages/my/pet/edit/index?id=${pet.id}` })
  95. const handleCardClick = (pet) => {
  96. goToEdit(pet)
  97. }
  98. const onDelete = (pet) => {
  99. uni.showModal({
  100. title: '提示',
  101. content: '确认删除该宠物档案吗?',
  102. success: async (res) => {
  103. if (res.confirm) {
  104. try {
  105. uni.showLoading({ title: '处理中...' })
  106. await delPet(pet.id)
  107. uni.hideLoading()
  108. uni.showToast({ title: '删除成功', icon: 'success' })
  109. // 刷新当前页数据
  110. loadPets()
  111. } catch (error) {
  112. uni.hideLoading()
  113. uni.showToast({ title: typeof error === 'string' ? error : '删除失败', icon: 'none' })
  114. }
  115. }
  116. }
  117. })
  118. }
  119. </script>
  120. <style lang="scss" scoped>
  121. /* 此部分与原文件保持一致 */
  122. .pet-list-page {
  123. min-height: 100vh;
  124. background-color: #f2f2f2;
  125. padding-bottom: 40rpx;
  126. }
  127. .action-bar {
  128. display: flex;
  129. align-items: center;
  130. padding: 20rpx 24rpx;
  131. background-color: #fff;
  132. gap: 16rpx;
  133. }
  134. .search-box {
  135. flex: 1;
  136. height: 72rpx;
  137. display: flex;
  138. align-items: center;
  139. background: #f5f5f5;
  140. border-radius: 36rpx;
  141. padding: 0 24rpx;
  142. gap: 12rpx;
  143. box-sizing: border-box;
  144. }
  145. .search-icon {
  146. font-size: 28rpx;
  147. line-height: 1;
  148. flex-shrink: 0;
  149. }
  150. .search-input {
  151. flex: 1;
  152. font-size: 26rpx;
  153. background: transparent;
  154. height: 72rpx;
  155. line-height: 72rpx;
  156. }
  157. .add-btn {
  158. height: 72rpx;
  159. line-height: 72rpx;
  160. padding: 0 28rpx;
  161. font-size: 25rpx;
  162. font-weight: bold;
  163. background: linear-gradient(90deg, #ffd53f, #ff9500);
  164. color: #fff;
  165. border: none;
  166. border-radius: 36rpx;
  167. margin: 0;
  168. white-space: nowrap;
  169. text-align: center;
  170. }
  171. .list-container {
  172. padding: 24rpx;
  173. }
  174. .pet-card {
  175. display: flex;
  176. background: #fff;
  177. border-radius: 24rpx;
  178. overflow: hidden;
  179. margin-bottom: 24rpx;
  180. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.04);
  181. }
  182. .pet-photo {
  183. width: 210rpx;
  184. height: 280rpx;
  185. flex-shrink: 0;
  186. }
  187. .card-info {
  188. flex: 1;
  189. padding: 24rpx;
  190. display: flex;
  191. flex-direction: column;
  192. }
  193. .info-top {
  194. display: flex;
  195. justify-content: space-between;
  196. align-items: center;
  197. margin-bottom: 8rpx;
  198. }
  199. .pet-name {
  200. font-size: 34rpx;
  201. font-weight: 800;
  202. color: #333;
  203. }
  204. .owner-name {
  205. font-size: 24rpx;
  206. color: #999;
  207. }
  208. .pet-meta {
  209. font-size: 26rpx;
  210. color: #666;
  211. margin-bottom: 16rpx;
  212. }
  213. .health-overview {
  214. display: flex;
  215. align-items: center;
  216. gap: 16rpx;
  217. margin-bottom: 20rpx;
  218. }
  219. .health-badge {
  220. font-size: 22rpx;
  221. color: #2e7d32;
  222. background: #e8f5e9;
  223. padding: 4rpx 16rpx;
  224. border-radius: 8rpx;
  225. }
  226. .vaccine-info {
  227. font-size: 22rpx;
  228. color: #795548;
  229. background: #efebe9;
  230. padding: 4rpx 16rpx;
  231. border-radius: 8rpx;
  232. }
  233. .card-footer {
  234. margin-top: auto;
  235. border-top: 2rpx solid #EEEEEE;
  236. padding-top: 20rpx;
  237. }
  238. .action-btn-group {
  239. display: flex;
  240. justify-content: flex-end;
  241. gap: 16rpx;
  242. }
  243. .btn-item {
  244. font-size: 24rpx;
  245. height: 56rpx;
  246. line-height: 56rpx;
  247. padding: 0 24rpx;
  248. border-radius: 28rpx;
  249. border: 2rpx solid;
  250. color: #666;
  251. text-align: center;
  252. white-space: nowrap;
  253. }
  254. .btn-item.detail {
  255. background: #fdf6ec;
  256. border-color: #f5d89a;
  257. color: #b88230;
  258. }
  259. .btn-item.edit {
  260. background: #ecf5ff;
  261. border-color: #a0cfff;
  262. color: #409eff;
  263. }
  264. .btn-item.delete {
  265. color: #f56c6c;
  266. border-color: #fbc4c4;
  267. background: #fef0f0;
  268. }
  269. </style>