与牧同行-小程序用户端
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.
 

198 lines
5.3 KiB

Page({
/**
* 页面的初始数据
*/
data: {
diagnosisData: {
id: 1,
status: 'replied',
createdAt: '2025-02-21',
userInfo: {
avatar: '/images/avatars/user1.jpg',
nickName: '张小明'
},
petInfo: {
type: '狗',
age: 3,
gender: '公'
},
description: '最近三天食欲不振,精神萎靡,偶尔呕吐黄色泡沫,大便偏软带血丝,体温正常但鼻头干燥。已经尝试喂食清淡食物但无改善。昨晚开始呼吸似乎有些急促。',
images: [
'/images/pet1.jpg',
'/images/pet2.jpg',
'/images/pet3.jpg'
],
replies: [
{
id: 1,
vet: {
avatar: '/images/vets/vet1.jpg',
name: '李医生',
title: '主治兽医',
hospital: '爱宠动物医院',
years: 8
},
content: '根据您的描述,狗狗可能出现了消化系统问题。呕吐黄色泡沫通常是胃液,结合大便带血丝的情况,建议立即禁食12小时观察。可以少量喂水,但不要喂食。如果症状持续或加重,建议立即带往医院进行血常规和粪便检查。',
createdAt: '2025-02-21',
likes: 12,
liked: false
},
{
id: 2,
vet: {
avatar: '/images/vets/vet2.jpg',
name: '王医生',
title: '资深兽医',
hospital: '萌宠医疗中心',
years: 12
},
content: '同意李医生的建议。此外,呼吸急促需要特别关注,可能是疼痛或炎症反应。建议测量肛温,正常范围是38-39℃。如果超过39.5℃需要紧急处理。可以检查牙龈颜色,正常应为粉色,发白或发紫需要立即就医。',
createdAt: '2025-02-21',
likes: 8,
liked: true
}
]
},
refreshing: false
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
if (options.id) {
// 根据id加载问诊数据
this.loadDiagnosisData(options.id);
}
},
// 加载问诊数据
loadDiagnosisData(id) {
// 这里应该是API请求,暂时使用模拟数据
// TODO: 替换为实际API调用
console.log('加载问诊数据:', id);
// 确保时间数据正确显示
this.setData({
'diagnosisData.createdAt': new Date().toISOString(),
'diagnosisData.replies[0].createdAt': new Date(Date.now() - 2 * 60 * 60 * 1000).toISOString(),
'diagnosisData.replies[1].createdAt': new Date(Date.now() - 4 * 60 * 60 * 1000).toISOString()
});
},
// 格式化时间 - 确保正确显示
formatTime(dateString) {
if (!dateString) return '刚刚';
try {
const date = new Date(dateString);
const now = new Date();
const diff = now - date;
const diffSeconds = Math.floor(diff / 1000);
const diffMinutes = Math.floor(diff / (1000 * 60));
const diffHours = Math.floor(diff / (1000 * 60 * 60));
const diffDays = Math.floor(diff / (1000 * 60 * 60 * 24));
if (diffSeconds < 60) {
return '刚刚';
} else if (diffMinutes < 60) {
return `${diffMinutes}分钟前`;
} else if (diffHours < 24) {
return `${diffHours}小时前`;
} else if (diffDays === 1) {
return '昨天';
} else if (diffDays < 7) {
return `${diffDays}天前`;
} else {
const month = date.getMonth() + 1;
const day = date.getDate();
const hours = date.getHours().toString().padStart(2, '0');
const minutes = date.getMinutes().toString().padStart(2, '0');
return `${month}${day}${hours}:${minutes}`;
}
} catch (error) {
console.error('时间格式化错误:', error);
return '刚刚';
}
},
// 返回上一页
goBack() {
wx.navigateBack();
},
// 分享
onShare() {
wx.showActionSheet({
itemList: ['分享给好友', '保存到相册'],
success: (res) => {
if (res.tapIndex === 0) {
wx.showToast({
title: '已分享',
icon: 'success'
});
}
}
});
},
// 下拉刷新
onRefresh() {
this.setData({
refreshing: true
});
setTimeout(() => {
this.setData({
refreshing: false
});
wx.showToast({
title: '刷新成功',
icon: 'success'
});
}, 1000);
},
// 预览图片
previewImage(e) {
const current = e.currentTarget.dataset.url;
const urls = e.currentTarget.dataset.urls;
wx.previewImage({
current,
urls
});
},
// 点赞/取消点赞
toggleLike(e) {
const index = e.currentTarget.dataset.index;
const replies = [...this.data.diagnosisData.replies];
const reply = replies[index];
if (reply.liked) {
// 取消点赞
reply.liked = false;
reply.likes = Math.max(0, (reply.likes || 1) - 1);
wx.showToast({
title: '已取消',
icon: 'none'
});
} else {
// 点赞
reply.liked = true;
reply.likes = (reply.likes || 0) + 1;
wx.showToast({
title: '已点赞',
icon: 'success'
});
}
this.setData({
'diagnosisData.replies': replies
});
// 震动反馈
wx.vibrateShort();
}
});