index.vue 6.2 KB

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