与牧同行-小程序用户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

197 lines
5.3 KiB

  1. Page({
  2. /**
  3. * 页面的初始数据
  4. */
  5. data: {
  6. diagnosisData: {
  7. id: 1,
  8. status: 'replied',
  9. createdAt: '2025-02-21',
  10. userInfo: {
  11. avatar: '/images/avatars/user1.jpg',
  12. nickName: '张小明'
  13. },
  14. petInfo: {
  15. type: '狗',
  16. age: 3,
  17. gender: '公'
  18. },
  19. description: '最近三天食欲不振,精神萎靡,偶尔呕吐黄色泡沫,大便偏软带血丝,体温正常但鼻头干燥。已经尝试喂食清淡食物但无改善。昨晚开始呼吸似乎有些急促。',
  20. images: [
  21. '/images/pet1.jpg',
  22. '/images/pet2.jpg',
  23. '/images/pet3.jpg'
  24. ],
  25. replies: [
  26. {
  27. id: 1,
  28. vet: {
  29. avatar: '/images/vets/vet1.jpg',
  30. name: '李医生',
  31. title: '主治兽医',
  32. hospital: '爱宠动物医院',
  33. years: 8
  34. },
  35. content: '根据您的描述,狗狗可能出现了消化系统问题。呕吐黄色泡沫通常是胃液,结合大便带血丝的情况,建议立即禁食12小时观察。可以少量喂水,但不要喂食。如果症状持续或加重,建议立即带往医院进行血常规和粪便检查。',
  36. createdAt: '2025-02-21',
  37. likes: 12,
  38. liked: false
  39. },
  40. {
  41. id: 2,
  42. vet: {
  43. avatar: '/images/vets/vet2.jpg',
  44. name: '王医生',
  45. title: '资深兽医',
  46. hospital: '萌宠医疗中心',
  47. years: 12
  48. },
  49. content: '同意李医生的建议。此外,呼吸急促需要特别关注,可能是疼痛或炎症反应。建议测量肛温,正常范围是38-39℃。如果超过39.5℃需要紧急处理。可以检查牙龈颜色,正常应为粉色,发白或发紫需要立即就医。',
  50. createdAt: '2025-02-21',
  51. likes: 8,
  52. liked: true
  53. }
  54. ]
  55. },
  56. refreshing: false
  57. },
  58. /**
  59. * 生命周期函数--监听页面加载
  60. */
  61. onLoad(options) {
  62. if (options.id) {
  63. // 根据id加载问诊数据
  64. this.loadDiagnosisData(options.id);
  65. }
  66. },
  67. // 加载问诊数据
  68. loadDiagnosisData(id) {
  69. // 这里应该是API请求,暂时使用模拟数据
  70. // TODO: 替换为实际API调用
  71. console.log('加载问诊数据:', id);
  72. // 确保时间数据正确显示
  73. this.setData({
  74. 'diagnosisData.createdAt': new Date().toISOString(),
  75. 'diagnosisData.replies[0].createdAt': new Date(Date.now() - 2 * 60 * 60 * 1000).toISOString(),
  76. 'diagnosisData.replies[1].createdAt': new Date(Date.now() - 4 * 60 * 60 * 1000).toISOString()
  77. });
  78. },
  79. // 格式化时间 - 确保正确显示
  80. formatTime(dateString) {
  81. if (!dateString) return '刚刚';
  82. try {
  83. const date = new Date(dateString);
  84. const now = new Date();
  85. const diff = now - date;
  86. const diffSeconds = Math.floor(diff / 1000);
  87. const diffMinutes = Math.floor(diff / (1000 * 60));
  88. const diffHours = Math.floor(diff / (1000 * 60 * 60));
  89. const diffDays = Math.floor(diff / (1000 * 60 * 60 * 24));
  90. if (diffSeconds < 60) {
  91. return '刚刚';
  92. } else if (diffMinutes < 60) {
  93. return `${diffMinutes}分钟前`;
  94. } else if (diffHours < 24) {
  95. return `${diffHours}小时前`;
  96. } else if (diffDays === 1) {
  97. return '昨天';
  98. } else if (diffDays < 7) {
  99. return `${diffDays}天前`;
  100. } else {
  101. const month = date.getMonth() + 1;
  102. const day = date.getDate();
  103. const hours = date.getHours().toString().padStart(2, '0');
  104. const minutes = date.getMinutes().toString().padStart(2, '0');
  105. return `${month}${day}${hours}:${minutes}`;
  106. }
  107. } catch (error) {
  108. console.error('时间格式化错误:', error);
  109. return '刚刚';
  110. }
  111. },
  112. // 返回上一页
  113. goBack() {
  114. wx.navigateBack();
  115. },
  116. // 分享
  117. onShare() {
  118. wx.showActionSheet({
  119. itemList: ['分享给好友', '保存到相册'],
  120. success: (res) => {
  121. if (res.tapIndex === 0) {
  122. wx.showToast({
  123. title: '已分享',
  124. icon: 'success'
  125. });
  126. }
  127. }
  128. });
  129. },
  130. // 下拉刷新
  131. onRefresh() {
  132. this.setData({
  133. refreshing: true
  134. });
  135. setTimeout(() => {
  136. this.setData({
  137. refreshing: false
  138. });
  139. wx.showToast({
  140. title: '刷新成功',
  141. icon: 'success'
  142. });
  143. }, 1000);
  144. },
  145. // 预览图片
  146. previewImage(e) {
  147. const current = e.currentTarget.dataset.url;
  148. const urls = e.currentTarget.dataset.urls;
  149. wx.previewImage({
  150. current,
  151. urls
  152. });
  153. },
  154. // 点赞/取消点赞
  155. toggleLike(e) {
  156. const index = e.currentTarget.dataset.index;
  157. const replies = [...this.data.diagnosisData.replies];
  158. const reply = replies[index];
  159. if (reply.liked) {
  160. // 取消点赞
  161. reply.liked = false;
  162. reply.likes = Math.max(0, (reply.likes || 1) - 1);
  163. wx.showToast({
  164. title: '已取消',
  165. icon: 'none'
  166. });
  167. } else {
  168. // 点赞
  169. reply.liked = true;
  170. reply.likes = (reply.likes || 0) + 1;
  171. wx.showToast({
  172. title: '已点赞',
  173. icon: 'success'
  174. });
  175. }
  176. this.setData({
  177. 'diagnosisData.replies': replies
  178. });
  179. // 震动反馈
  180. wx.vibrateShort();
  181. }
  182. });