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

605 lines
19 KiB

Page({
data: {
// 药品数据
medicineData: null,
// 是否收藏
isFavorite: false,
// 加载状态
loading: true,
// 分享配置
shareTitle: '',
sharePath: '',
shareImageUrl: ''
},
onLoad: function(options) {
// 获取传递过来的药品ID
const medicineId = options.id;
if (medicineId) {
// 根据ID加载药品数据
this.loadMedicineData(medicineId);
} else {
wx.showToast({
title: '药品信息不存在',
icon: 'error',
duration: 2000,
complete: () => {
setTimeout(() => {
wx.navigateBack();
}, 1500);
}
});
}
},
onShow: function() {
// 检查收藏状态
this.checkFavoriteStatus();
},
onShareAppMessage: function() {
// 分享配置
return {
title: this.data.shareTitle || '专家推荐药品',
path: this.data.sharePath || '/pages/index/index',
imageUrl: this.data.shareImageUrl || '/images/share-default.jpg'
};
},
// 根据ID加载药品数据
loadMedicineData: function(id) {
this.setData({ loading: true });
// 模拟网络请求,实际项目中应该从服务器获取
setTimeout(() => {
const mockData = this.getMockData();
const medicine = mockData.find(item => item.id == id);
if (medicine) {
this.setData({
medicineData: medicine,
loading: false,
shareTitle: `${medicine.name} - ${medicine.expert.name}专家推荐`,
sharePath: `/pages/detail/detail?id=${medicine.id}`,
shareImageUrl: medicine.image
});
// 更新页面标题
wx.setNavigationBarTitle({
title: medicine.name
});
} else {
this.setData({ loading: false });
wx.showToast({
title: '药品信息加载失败',
icon: 'error',
duration: 2000,
complete: () => {
setTimeout(() => {
wx.navigateBack();
}, 1500);
}
});
}
}, 500);
},
// 获取模拟数据(应与列表页保持一致)
getMockData: function() {
return [
{
id: 1,
name: "阿莫西林胶囊",
manufacturer: "华北制药股份有限公司",
specification: "0.25g*24粒/盒",
category: "prescription",
categoryText: "处方药",
indication: "用于敏感菌所致的呼吸道感染、泌尿系统感染等",
price: 25.8,
originalPrice: 32.0,
isHot: true,
salesCount: 1280,
stock: 150,
image: "https://via.placeholder.com/300x300/3a7ff3/ffffff?text=阿莫西林",
expert: {
name: "张明华",
title: "主任医师",
hospital: "北京协和医院",
avatar: "https://via.placeholder.com/100x100/3a7ff3/ffffff?text=张",
reason: "本品为广谱抗生素,对多数革兰氏阳性菌和革兰氏阴性菌均有良好的抗菌作用,是临床常用的一线抗生素。",
expertise: "呼吸内科",
years: 15,
recommendTime: "2024-01-15"
},
store: {
name: "仁和堂大药房",
address: "北京市朝阳区建国路88号",
phone: "010-88888888",
businessHours: "8:00-22:00",
features: "24小时营业,专业药师咨询,医保定点药店",
distance: "1.2",
latitude: 39.9042,
longitude: 116.4074,
rating: 4.8,
images: [
"/pagesA/images/5.png",
"/pagesA/images/6.jpg",
"/pagesA/images/6.jpg"
]
},
details: {
usage: "口服。成人一次0.5g,每6~8小时1次,一日剂量不超过4g。",
precautions: "青霉素过敏者禁用,用药期间可能出现腹泻、恶心等胃肠道反应。",
storage: "密封,在干燥处保存。",
validity: "24个月"
}
},
{
id: 2,
name: "连花清瘟胶囊",
manufacturer: "石家庄以岭药业股份有限公司",
specification: "0.35g*24粒/盒",
category: "chinese",
categoryText: "中成药",
indication: "用于治疗流行性感冒属热毒袭肺证",
price: 28.5,
originalPrice: 35.0,
isHot: true,
salesCount: 2560,
stock: 89,
image: "https://via.placeholder.com/300x300/4CAF50/ffffff?text=连花清瘟",
expert: {
name: "李芳",
title: "副主任医师",
hospital: "上海瑞金医院",
avatar: "https://via.placeholder.com/100x100/4CAF50/ffffff?text=李",
reason: "在新冠肺炎疫情防控中显示出良好效果,具有清瘟解毒、宣肺泄热的功效,适用于流感治疗。",
expertise: "中医科",
years: 12,
recommendTime: "2024-01-14"
},
store: {
name: "同济堂药店",
address: "上海市黄浦区南京东路100号",
phone: "021-66666666",
businessHours: "9:00-21:00",
features: "中药配方齐全,提供代煎服务,老字号药店",
distance: "2.5",
latitude: 31.2304,
longitude: 121.4737,
rating: 4.7,
images: [
"https://via.placeholder.com/400x300/FF9800/ffffff?text=中药柜台"
]
},
details: {
usage: "口服。一次4粒,一日3次。",
precautions: "风寒感冒者不适用,高血压、心脏病患者慎用。",
storage: "密封,置阴凉干燥处。",
validity: "36个月"
}
},
{
id: 3,
name: "维生素C片",
manufacturer: "养生堂药业有限公司",
specification: "100mg*60片/瓶",
category: "health",
categoryText: "保健品",
indication: "用于预防和治疗维生素C缺乏症",
price: 18.9,
originalPrice: 24.0,
isHot: false,
salesCount: 890,
stock: 320,
image: "https://via.placeholder.com/300x300/FF9800/ffffff?text=维生素C",
expert: {
name: "王建国",
title: "执业药师",
hospital: "广州中医药大学附属医院",
avatar: "https://via.placeholder.com/100x100/FF9800/ffffff?text=王",
reason: "增强免疫力,促进铁吸收,抗氧化作用明显,适合日常保健和预防感冒。",
expertise: "临床药学",
years: 8,
recommendTime: "2024-01-13"
},
store: {
name: "老百姓大药房",
address: "广州市天河区体育西路189号",
phone: "020-77777777",
businessHours: "7:30-23:00",
features: "连锁品牌,价格实惠,会员优惠,支持医保",
distance: "0.8",
latitude: 23.1358,
longitude: 113.3269,
rating: 4.6,
images: []
},
details: {
usage: "口服。成人一次1片,一日1次。",
precautions: "不宜长期过量服用,肾功能不全者慎用。",
storage: "避光,密封保存。",
validity: "24个月"
}
},
{
id: 4,
name: "布洛芬缓释胶囊",
manufacturer: "中美天津史克制药有限公司",
specification: "0.3g*20粒/盒",
category: "otc",
categoryText: "非处方药",
indication: "用于缓解轻至中度疼痛如头痛、关节痛、偏头痛等",
price: 22.5,
originalPrice: 28.0,
isHot: true,
salesCount: 1870,
stock: 120,
image: "https://via.placeholder.com/300x300/9C27B0/ffffff?text=布洛芬",
expert: {
name: "陈晓东",
title: "主任医师",
hospital: "武汉同济医院",
avatar: "https://via.placeholder.com/100x100/9C27B0/ffffff?text=陈",
reason: "解热镇痛效果确切,缓释剂型作用持久,胃肠道刺激小,适合各种疼痛的缓解。",
expertise: "疼痛科",
years: 20,
recommendTime: "2024-01-12"
},
store: {
name: "九州通大药房",
address: "武汉市江汉区解放大道688号",
phone: "027-55555555",
businessHours: "8:30-21:30",
features: "药品齐全,支持线上订购,送货上门",
distance: "3.2",
latitude: 30.5928,
longitude: 114.3052,
rating: 4.9,
images: [
"https://via.placeholder.com/400x300/3F51B5/ffffff?text=现代药店",
"https://via.placeholder.com/400x300/E91E63/ffffff?text=专业服务"
]
},
details: {
usage: "口服。成人一次1粒,一日2次。",
precautions: "胃肠道溃疡患者禁用,不宜长期服用。",
storage: "密封,在阴凉干燥处保存。",
validity: "36个月"
}
},
{
id: 5,
name: "盐酸左氧氟沙星片",
manufacturer: "浙江医药股份有限公司",
specification: "0.5g*6片/盒",
category: "prescription",
categoryText: "处方药",
indication: "用于敏感细菌引起的呼吸系统、泌尿系统感染",
price: 42.8,
originalPrice: 56.0,
isHot: false,
salesCount: 560,
stock: 75,
image: "https://via.placeholder.com/300x300/2196F3/ffffff?text=左氧氟沙星",
expert: {
name: "刘涛",
title: "副主任医师",
hospital: "南京鼓楼医院",
avatar: "https://via.placeholder.com/100x100/2196F3/ffffff?text=刘",
reason: "抗菌谱广,对多种革兰氏阴性菌和阳性菌有效,特别适用于泌尿系统感染的治疗。",
expertise: "泌尿外科",
years: 10,
recommendTime: "2024-01-11"
},
store: {
name: "金陵大药房",
address: "南京市鼓楼区中山路321号",
phone: "025-44444444",
businessHours: "8:00-21:00",
features: "专业处方药房,药师驻店咨询",
distance: "1.8",
latitude: 32.0603,
longitude: 118.7969,
rating: 4.5,
images: []
},
details: {
usage: "口服。一次1片,一日1次。",
precautions: "18岁以下患者禁用,孕妇及哺乳期妇女禁用。",
storage: "遮光,密封保存。",
validity: "24个月"
}
},
{
id: 6,
name: "板蓝根颗粒",
manufacturer: "广州白云山和记黄埔中药有限公司",
specification: "10g*20袋/盒",
category: "chinese",
categoryText: "中成药",
indication: "清热解毒,凉血利咽,用于肺胃热盛所致的咽喉肿痛",
price: 15.9,
originalPrice: 19.9,
isHot: true,
salesCount: 3200,
stock: 450,
image: "https://via.placeholder.com/300x300/FF5722/ffffff?text=板蓝根",
expert: {
name: "孙丽",
title: "主治医师",
hospital: "成都中医药大学附属医院",
avatar: "https://via.placeholder.com/100x100/FF5722/ffffff?text=孙",
reason: "传统经典方剂,清热解毒效果显著,特别适合预防和治疗感冒初期症状。",
expertise: "中医内科",
years: 6,
recommendTime: "2024-01-10"
},
store: {
name: "康恩贝大药房",
address: "成都市锦江区春熙路58号",
phone: "028-33333333",
businessHours: "9:00-22:00",
features: "连锁品牌,中药西药齐全",
distance: "0.5",
latitude: 30.6578,
longitude: 104.0657,
rating: 4.4,
images: []
},
details: {
usage: "开水冲服。一次1袋,一日3次。",
precautions: "风寒感冒者不适用,糖尿病患者慎用。",
storage: "密封,防潮。",
validity: "36个月"
}
},
{
id: 7,
name: "复方甘草片",
manufacturer: "北京双鹤药业股份有限公司",
specification: "100片/瓶",
category: "prescription",
categoryText: "处方药",
indication: "用于镇咳祛痰,适用于感冒咳嗽",
price: 12.5,
originalPrice: 16.0,
isHot: false,
salesCount: 780,
stock: 200,
image: "https://via.placeholder.com/300x300/673AB7/ffffff?text=甘草片",
expert: {
name: "赵国强",
title: "主任医师",
hospital: "天津医科大学总医院",
avatar: "https://via.placeholder.com/100x100/673AB7/ffffff?text=赵",
reason: "传统止咳良药,镇咳祛痰效果确切,价格实惠,适合普通感冒咳嗽。",
expertise: "呼吸内科",
years: 18,
recommendTime: "2024-01-09"
},
store: {
name: "天津医药大药房",
address: "天津市和平区南京路128号",
phone: "022-22222222",
businessHours: "8:00-21:30",
features: "国营药店,药品质量有保障",
distance: "2.0",
latitude: 39.1172,
longitude: 117.2056,
rating: 4.3,
images: []
},
details: {
usage: "口服。一次3-4片,一日3次。",
precautions: "不宜长期服用,孕妇及哺乳期妇女慎用。",
storage: "密封,在干燥处保存。",
validity: "36个月"
}
},
{
id: 8,
name: "葡萄糖酸钙口服液",
manufacturer: "哈药集团制药六厂",
specification: "10ml*12支/盒",
category: "otc",
categoryText: "非处方药",
indication: "用于预防和治疗钙缺乏症",
price: 35.0,
originalPrice: 42.0,
isHot: true,
salesCount: 1560,
stock: 180,
image: "https://via.placeholder.com/300x300/00BCD4/ffffff?text=葡萄糖酸钙",
expert: {
name: "周敏",
title: "副主任医师",
hospital: "西安交通大学第一附属医院",
avatar: "https://via.placeholder.com/100x100/00BCD4/ffffff?text=周",
reason: "钙吸收好,口感适宜,特别适合儿童、孕妇和老年人补钙。",
expertise: "儿科",
years: 14,
recommendTime: "2024-01-08"
},
store: {
name: "西安医药大药房",
address: "西安市碑林区南大街58号",
phone: "029-11111111",
businessHours: "8:30-21:00",
features: "专业儿科用药,儿童健康咨询",
distance: "1.5",
latitude: 34.2583,
longitude: 108.9426,
rating: 4.7,
images: []
},
details: {
usage: "口服。一次1-2支,一日3次。",
precautions: "肾功能不全者慎用,不宜与洋地黄类药物同时使用。",
storage: "密封,置阴凉处。",
validity: "24个月"
}
}
];
},
// 检查收藏状态
checkFavoriteStatus: function() {
const medicineData = this.data.medicineData;
if (!medicineData) return;
try {
const favorites = wx.getStorageSync('medicineFavorites') || [];
const isFavorite = favorites.some(item => item.id === medicineData.id);
this.setData({ isFavorite });
} catch (e) {
console.error('读取收藏失败', e);
}
},
// 切换收藏状态
toggleFavorite: function() {
const medicineData = this.data.medicineData;
if (!medicineData) return;
const newFavorite = !this.data.isFavorite;
this.setData({ isFavorite: newFavorite });
// 保存到本地缓存
this.saveFavorite(newFavorite);
wx.showToast({
title: newFavorite ? '已收藏' : '已取消收藏',
icon: 'success',
duration: 1500
});
},
// 保存收藏状态到本地缓存
saveFavorite: function(isFavorite) {
const medicineData = this.data.medicineData;
if (!medicineData) return;
try {
let favorites = wx.getStorageSync('medicineFavorites') || [];
if (isFavorite) {
// 添加收藏
if (!favorites.some(item => item.id === medicineData.id)) {
favorites.push({
id: medicineData.id,
name: medicineData.name,
price: medicineData.price,
image: medicineData.image,
expert: medicineData.expert.name,
store: medicineData.store.name,
time: new Date().getTime()
});
}
} else {
// 取消收藏
favorites = favorites.filter(item => item.id !== medicineData.id);
}
wx.setStorageSync('medicineFavorites', favorites);
} catch (e) {
console.error('保存收藏失败', e);
}
},
// 打开位置地图
openLocation: function() {
const { store } = this.data.medicineData;
if (store.latitude && store.longitude) {
wx.openLocation({
latitude: parseFloat(store.latitude),
longitude: parseFloat(store.longitude),
name: store.name,
address: store.address,
scale: 18
});
} else {
wx.showToast({
title: '位置信息不可用',
icon: 'none'
});
}
},
// 拨打电话
makePhoneCall: function() {
const phone = this.data.medicineData.store.phone;
if (phone) {
wx.makePhoneCall({
phoneNumber: phone
})
}
},
// 预览主图片
previewMainImage: function() {
const url = this.data.medicineData.image;
if (url) {
wx.previewImage({
current: url,
urls: [url]
});
}
},
// 预览轮播图片
previewImage: function(e) {
const index = parseInt(e.currentTarget.dataset.index);
const images = this.data.medicineData.store.images || [];
const urls = [this.data.medicineData.image, ...images];
wx.previewImage({
current: urls[index + 1], // +1 因为第一个是主图
urls: urls
});
},
// 预览店铺图片
previewStoreImage: function(e) {
const index = parseInt(e.currentTarget.dataset.index);
const images = this.data.medicineData.store.images || [];
wx.previewImage({
current: images[index],
urls: images
});
},
// 分享给朋友
onShareToFriend: function() {
wx.showShareMenu({
withShareTicket: true,
menus: ['shareAppMessage', 'shareTimeline']
});
}
});