index.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. <template>
  2. <view class="pet-detail-page">
  3. <nav-bar title="宠物档案详情" bgColor="#ffecd2" color="#333"></nav-bar>
  4. <view class="pet-hero">
  5. <view class="hero-bg"></view>
  6. <view class="hero-content">
  7. <image :src="petInfo.avatarUrl || petInfo.avatar || defaultAvatar" class="hero-avatar" mode="aspectFill"></image>
  8. <view class="hero-main">
  9. <text class="pet-name">{{ petInfo.name || '加载中...' }}</text>
  10. <view class="tag-list">
  11. <text class="gender-icon" :class="petInfo.gender === 1 ? 'male' : 'female'">{{ petInfo.gender === 1 ? '♂' : '♀' }}</text>
  12. <text class="size-tag">{{ sizeLabel }}</text>
  13. </view>
  14. </view>
  15. <text class="pet-summary">{{ petInfo.breed }} · {{ petInfo.age || 0 }}岁 · {{ petInfo.weight || 0 }}kg</text>
  16. </view>
  17. </view>
  18. <view class="detail-container">
  19. <!-- 基础信息 -->
  20. <view class="section-card">
  21. <view class="section-header">
  22. <view class="title-line"></view>
  23. <text class="section-title">基础信息</text>
  24. </view>
  25. <view class="info-grid">
  26. <view class="info-item">
  27. <text class="label">所属主人</text>
  28. <text class="value">{{ petInfo.ownerName || petInfo.userName || petInfo.customerName || '-' }}</text>
  29. </view>
  30. <view class="info-item">
  31. <text class="label">主人电话</text>
  32. <text class="value">{{ petInfo.ownerPhone || petInfo.phonenumber || '-' }}</text>
  33. </view>
  34. <view class="info-item col-2">
  35. <text class="label">性格关键词</text>
  36. <text class="value">{{ petInfo.personality || '无' }}</text>
  37. </view>
  38. <view class="info-item col-2">
  39. <text class="label">萌宠性格</text>
  40. <text class="value block">{{ petInfo.cutePersonality || '暂无详细描述' }}</text>
  41. </view>
  42. </view>
  43. </view>
  44. <!-- 家庭信息 -->
  45. <view class="section-card">
  46. <view class="section-header">
  47. <view class="title-line"></view>
  48. <text class="section-title">家庭信息</text>
  49. </view>
  50. <view class="info-grid">
  51. <view class="info-item">
  52. <text class="label">房屋类型</text>
  53. <text class="value">{{ houseTypeLabel }}</text>
  54. </view>
  55. <view class="info-item">
  56. <text class="label">入门方式</text>
  57. <text class="value">{{ entryMethodLabel }}</text>
  58. </view>
  59. <view class="info-item col-2" v-if="petInfo.entryMethod === 'password'">
  60. <text class="label">门锁密码</text>
  61. <text class="value highlight">{{ petInfo.entryPassword || '-' }}</text>
  62. </view>
  63. <view class="info-item col-2" v-if="petInfo.entryMethod === 'key'">
  64. <text class="label">钥匙存放处</text>
  65. <text class="value">{{ petInfo.keyLocation || '-' }}</text>
  66. </view>
  67. </view>
  68. </view>
  69. <!-- 健康状况 -->
  70. <view class="section-card">
  71. <view class="section-header">
  72. <view class="title-line"></view>
  73. <text class="section-title">健康状况</text>
  74. </view>
  75. <view class="info-grid">
  76. <view class="info-item">
  77. <text class="label">健康状态</text>
  78. <text class="value" :class="healthClass">{{ petInfo.healthStatus || '未知' }}</text>
  79. </view>
  80. <view class="info-item">
  81. <text class="label">疫苗情况</text>
  82. <text class="value">{{ petInfo.vaccineStatus || '未记录' }}</text>
  83. </view>
  84. <view class="info-item">
  85. <text class="label">攻击倾向</text>
  86. <text class="value" :class="petInfo.aggression ? 'red' : ''">{{ petInfo.aggression ? '是' : '否' }}</text>
  87. </view>
  88. <view class="info-item col-2">
  89. <text class="label">既往病史</text>
  90. <text class="value block">{{ petInfo.medicalHistory || '无' }}</text>
  91. </view>
  92. <view class="info-item col-2">
  93. <text class="label">过敏史</text>
  94. <text class="value block">{{ petInfo.allergies || '无' }}</text>
  95. </view>
  96. </view>
  97. </view>
  98. <!-- 备注信息 -->
  99. <view class="section-card" v-if="petInfo.remark">
  100. <view class="section-header">
  101. <view class="title-line"></view>
  102. <text class="section-title">补充备注</text>
  103. </view>
  104. <view class="remark-content">
  105. {{ petInfo.remark }}
  106. </view>
  107. </view>
  108. </view>
  109. <view class="footer-bar">
  110. <button class="edit-btn" @click="goToEdit">编辑档案</button>
  111. </view>
  112. </view>
  113. </template>
  114. <script setup>
  115. // @Author: Antigravity
  116. import { ref, computed } from 'vue'
  117. import { onLoad } from '@dcloudio/uni-app'
  118. import { getPet } from '@/api/archieves/pet'
  119. import navBar from '@/components/nav-bar/index.vue'
  120. import customerEnums from '@/json/customer.json'
  121. const defaultAvatar = 'https://images.unsplash.com/photo-1552053831-71594a27632d?q=80&w=600&auto=format&fit=crop'
  122. const petId = ref(null)
  123. const petInfo = ref({})
  124. const genderOptions = { 0: '未知', 1: '公', 2: '母' }
  125. const sizeOptions = { 'small': '小型', 'medium': '中型', 'large': '大型' }
  126. const { houseTypeOptions, entryMethodOptions } = customerEnums
  127. onLoad((options) => {
  128. if (options.id) {
  129. petId.value = options.id
  130. fetchDetail()
  131. }
  132. })
  133. const fetchDetail = async () => {
  134. try {
  135. uni.showLoading({ title: '加载中...' })
  136. const res = await getPet(petId.value)
  137. petInfo.value = res || {}
  138. uni.hideLoading()
  139. } catch (e) {
  140. uni.hideLoading()
  141. console.error('获取详情失败', e)
  142. uni.showToast({ title: typeof e === 'string' ? e : '获取详情失败', icon: 'none' })
  143. }
  144. }
  145. const sizeLabel = computed(() => sizeOptions[petInfo.value.size] || '未知体型')
  146. const houseTypeLabel = computed(() => {
  147. const opt = houseTypeOptions.find(o => o.value === petInfo.value.houseType)
  148. return opt ? opt.label : '未记录'
  149. })
  150. const entryMethodLabel = computed(() => {
  151. const opt = entryMethodOptions.find(o => o.value === petInfo.value.entryMethod)
  152. return opt ? opt.label : '未记录'
  153. })
  154. const healthClass = computed(() => {
  155. const s = petInfo.value.healthStatus
  156. if (s === '健康') return 'green'
  157. if (s === '疾病') return 'red'
  158. return 'orange'
  159. })
  160. const goToEdit = () => {
  161. uni.navigateTo({
  162. url: `/pages/my/pet/edit/index?id=${petId.value}`
  163. })
  164. }
  165. </script>
  166. <style lang="scss" scoped>
  167. .pet-detail-page {
  168. min-height: 100vh;
  169. background: #f4f6f9;
  170. padding-bottom: calc(160rpx + env(safe-area-inset-bottom));
  171. }
  172. .pet-hero {
  173. position: relative;
  174. height: 460rpx;
  175. width: 100%;
  176. display: flex;
  177. flex-direction: column;
  178. align-items: center;
  179. justify-content: center;
  180. overflow: hidden;
  181. }
  182. .hero-bg {
  183. position: absolute;
  184. top: 0; left: 0; right: 0; bottom: 0;
  185. background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
  186. }
  187. .hero-avatar {
  188. width: 200rpx;
  189. height: 200rpx;
  190. border-radius: 50%;
  191. border: 6rpx solid #fff;
  192. box-shadow: 0 8rpx 32rpx rgba(0,0,0,0.12);
  193. z-index: 5;
  194. flex-shrink: 0;
  195. }
  196. .hero-content {
  197. position: relative;
  198. z-index: 5;
  199. display: flex;
  200. flex-direction: column;
  201. align-items: center;
  202. margin-top: 20rpx;
  203. padding: 0 48rpx;
  204. }
  205. .hero-main {
  206. display: flex;
  207. align-items: center;
  208. justify-content: center;
  209. margin-bottom: 12rpx;
  210. gap: 16rpx;
  211. }
  212. .pet-name {
  213. font-size: 44rpx;
  214. font-weight: 800;
  215. color: #333;
  216. }
  217. .tag-list {
  218. display: flex;
  219. gap: 12rpx;
  220. }
  221. .size-tag {
  222. padding: 6rpx 20rpx;
  223. border-radius: 30rpx;
  224. font-size: 22rpx;
  225. background: rgba(255, 255, 255, 0.85);
  226. color: #555;
  227. }
  228. .gender-icon {
  229. font-size: 36rpx;
  230. margin-right: 8rpx;
  231. }
  232. .gender-icon.male { color: #409eff; }
  233. .gender-icon.female { color: #f56c6c; }
  234. .pet-summary {
  235. font-size: 26rpx;
  236. color: #777;
  237. text-align: center;
  238. }
  239. .detail-container {
  240. margin-top: -40rpx;
  241. position: relative;
  242. z-index: 10;
  243. padding: 0 24rpx;
  244. }
  245. .section-card {
  246. background: #fff;
  247. border-radius: 24rpx;
  248. padding: 32rpx;
  249. margin-bottom: 24rpx;
  250. box-shadow: 0 4rpx 12rpx rgba(0,0,0,0.02);
  251. }
  252. .section-header {
  253. display: flex;
  254. align-items: center;
  255. margin-bottom: 32rpx;
  256. }
  257. .title-line {
  258. width: 8rpx;
  259. height: 32rpx;
  260. background: #ff9500;
  261. border-radius: 4rpx;
  262. margin-right: 16rpx;
  263. }
  264. .section-title {
  265. font-size: 32rpx;
  266. font-weight: bold;
  267. color: #333;
  268. }
  269. .info-grid {
  270. display: grid;
  271. grid-template-columns: 1fr 1fr;
  272. gap: 32rpx 24rpx;
  273. }
  274. .info-item {
  275. display: flex;
  276. flex-direction: column;
  277. gap: 8rpx;
  278. }
  279. .info-item.col-2 {
  280. grid-column: span 2;
  281. }
  282. .label {
  283. font-size: 24rpx;
  284. color: #999;
  285. }
  286. .value {
  287. font-size: 26rpx;
  288. color: #333;
  289. font-weight: 500;
  290. }
  291. .value.block {
  292. line-height: 1.6;
  293. color: #666;
  294. font-weight: normal;
  295. }
  296. .value.highlight {
  297. color: #ff9500;
  298. font-weight: bold;
  299. }
  300. .value.green { color: #4caf50; }
  301. .value.red { color: #f44336; }
  302. .value.orange { color: #ff9800; }
  303. .remark-content {
  304. font-size: 28rpx;
  305. color: #666;
  306. line-height: 1.6;
  307. }
  308. .footer-bar {
  309. position: fixed;
  310. bottom: 0;
  311. left: 0;
  312. right: 0;
  313. background: #fff;
  314. padding: 20rpx 32rpx calc(20rpx + env(safe-area-inset-bottom));
  315. box-shadow: 0 -4rpx 16rpx rgba(0,0,0,0.05);
  316. z-index: 100;
  317. }
  318. .edit-btn {
  319. width: 100%;
  320. height: 88rpx;
  321. background: linear-gradient(90deg, #ffd53f, #ff9500);
  322. color: #fff;
  323. border: none;
  324. border-radius: 44rpx;
  325. font-size: 32rpx;
  326. font-weight: bold;
  327. line-height: 88rpx;
  328. }
  329. </style>