index.vue 8.8 KB

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