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

616 lines
19 KiB

Page({
data: {
// 原始药品列表数据
medicineList: [],
// 筛选后的列表
filteredList: [],
// 搜索相关
searchKeyword: '',
// 筛选相关
currentCategory: 'all',
// 分页相关
page: 1,
pageSize: 12,
hasMore: true,
loading: false,
// 弹窗控制
showDetailModal: false,
currentMedicine: null,
// 滚动相关
showBackToTop: false,
scrollTop: 0
},
onLoad: function() {
this.initData();
},
onShow: function() {
// 页面显示时刷新数据
this.refreshList();
},
onPullDownRefresh: function() {
// 下拉刷新
this.refreshList();
},
onReachBottom: function() {
// 上拉加载更多
if (this.data.hasMore && !this.data.loading) {
this.loadMore();
}
},
onPageScroll: function(e) {
// 显示/隐藏返回顶部按钮
if (e.scrollTop > 300 && !this.data.showBackToTop) {
this.setData({ showBackToTop: true });
} else if (e.scrollTop <= 300 && this.data.showBackToTop) {
this.setData({ showBackToTop: false });
}
this.setData({ scrollTop: e.scrollTop });
},
// 初始化数据
initData: function() {
const mockData = this.getMockData();
this.setData({
medicineList: mockData,
filteredList: mockData
});
},
// 获取模拟数据
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: [
"https://via.placeholder.com/400x300/4CAF50/ffffff?text=药店外观",
"https://via.placeholder.com/400x300/2196F3/ffffff?text=店内环境"
]
},
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个月"
}
}
];
},
// 获取简短文本(修复undefined问题)
getShortText: function(text, maxLength) {
if (!text || typeof text !== 'string') {
return '';
}
if (text.length <= maxLength) {
return text;
}
return text.substring(0, maxLength) + '...';
},
// 搜索输入处理(输入时自动搜索)
onSearchInput: function(e) {
const keyword = e.detail.value;
this.setData({
searchKeyword: keyword
}, () => {
// 输入后立即执行筛选
this.filterList();
});
},
// 清除搜索
clearSearch: function() {
this.setData({
searchKeyword: ''
}, () => {
this.filterList();
});
},
// 分类筛选切换
onCategoryChange: function(e) {
const category = e.currentTarget.dataset.category;
this.setData({
currentCategory: category
}, () => {
this.filterList();
});
},
// 筛选列表
filterList: function() {
const { searchKeyword, currentCategory, medicineList } = this.data;
let filteredList = [...medicineList];
// 搜索筛选
if (searchKeyword && searchKeyword.trim()) {
const keyword = searchKeyword.trim().toLowerCase();
filteredList = filteredList.filter(item => {
// 搜索药品名称
if (item.name && item.name.toLowerCase().includes(keyword)) {
return true;
}
// 搜索专家姓名
if (item.expert && item.expert.name && item.expert.name.toLowerCase().includes(keyword)) {
return true;
}
// 搜索适用症状
if (item.indication && item.indication.toLowerCase().includes(keyword)) {
return true;
}
// 搜索生产厂家
if (item.manufacturer && item.manufacturer.toLowerCase().includes(keyword)) {
return true;
}
return false;
});
}
// 分类筛选
if (currentCategory !== 'all') {
filteredList = filteredList.filter(item => item.category === currentCategory);
}
this.setData({
filteredList: filteredList,
page: 1,
hasMore: filteredList.length > this.data.pageSize
});
},
// 刷新列表
refreshList: function() {
wx.showLoading({
title: '刷新中...',
});
// 模拟网络请求
setTimeout(() => {
const mockData = this.getMockData();
this.setData({
medicineList: mockData
}, () => {
// 刷新后重新筛选
this.filterList();
});
wx.hideLoading();
wx.stopPullDownRefresh();
}, 800);
},
// 加载更多
loadMore: function() {
if (!this.data.hasMore) return;
this.setData({ loading: true });
// 模拟网络请求
setTimeout(() => {
const currentList = this.data.filteredList;
// 这里简化为直接追加数据(实际项目中应该从服务器获取新数据)
if (currentList.length < this.data.medicineList.length) {
const allData = this.data.medicineList;
const startIndex = currentList.length;
const endIndex = Math.min(startIndex + 4, allData.length);
const newData = allData.slice(startIndex, endIndex);
const updatedList = [...currentList, ...newData];
this.setData({
filteredList: updatedList,
hasMore: updatedList.length < allData.length,
loading: false
});
} else {
this.setData({
hasMore: false,
loading: false
});
}
}, 1000);
},
// 显示药品详情
showMedicineDetail: function(e) {
const medId = e.currentTarget.dataset.id;
// const medicine = this.data.filteredList[index];
// this.setData({
// showDetailModal: true,
// currentMedicine: medicine
// });
wx.navigateTo({
url: `/pagesA/pages/medicineDetails/medicineDetails?id=${medId}`,
})
},
// 详情弹窗关闭
onDetailModalClose: function() {
this.setData({
showDetailModal: false
});
},
// 返回顶部
scrollToTop: function() {
wx.pageScrollTo({
scrollTop: 0,
duration: 300
});
}
});