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

604 lines
19 KiB

1 month ago
  1. Page({
  2. data: {
  3. // 药品数据
  4. medicineData: null,
  5. // 是否收藏
  6. isFavorite: false,
  7. // 加载状态
  8. loading: true,
  9. // 分享配置
  10. shareTitle: '',
  11. sharePath: '',
  12. shareImageUrl: ''
  13. },
  14. onLoad: function(options) {
  15. // 获取传递过来的药品ID
  16. const medicineId = options.id;
  17. if (medicineId) {
  18. // 根据ID加载药品数据
  19. this.loadMedicineData(medicineId);
  20. } else {
  21. wx.showToast({
  22. title: '药品信息不存在',
  23. icon: 'error',
  24. duration: 2000,
  25. complete: () => {
  26. setTimeout(() => {
  27. wx.navigateBack();
  28. }, 1500);
  29. }
  30. });
  31. }
  32. },
  33. onShow: function() {
  34. // 检查收藏状态
  35. this.checkFavoriteStatus();
  36. },
  37. onShareAppMessage: function() {
  38. // 分享配置
  39. return {
  40. title: this.data.shareTitle || '专家推荐药品',
  41. path: this.data.sharePath || '/pages/index/index',
  42. imageUrl: this.data.shareImageUrl || '/images/share-default.jpg'
  43. };
  44. },
  45. // 根据ID加载药品数据
  46. loadMedicineData: function(id) {
  47. this.setData({ loading: true });
  48. // 模拟网络请求,实际项目中应该从服务器获取
  49. setTimeout(() => {
  50. const mockData = this.getMockData();
  51. const medicine = mockData.find(item => item.id == id);
  52. if (medicine) {
  53. this.setData({
  54. medicineData: medicine,
  55. loading: false,
  56. shareTitle: `${medicine.name} - ${medicine.expert.name}专家推荐`,
  57. sharePath: `/pages/detail/detail?id=${medicine.id}`,
  58. shareImageUrl: medicine.image
  59. });
  60. // 更新页面标题
  61. wx.setNavigationBarTitle({
  62. title: medicine.name
  63. });
  64. } else {
  65. this.setData({ loading: false });
  66. wx.showToast({
  67. title: '药品信息加载失败',
  68. icon: 'error',
  69. duration: 2000,
  70. complete: () => {
  71. setTimeout(() => {
  72. wx.navigateBack();
  73. }, 1500);
  74. }
  75. });
  76. }
  77. }, 500);
  78. },
  79. // 获取模拟数据(应与列表页保持一致)
  80. getMockData: function() {
  81. return [
  82. {
  83. id: 1,
  84. name: "阿莫西林胶囊",
  85. manufacturer: "华北制药股份有限公司",
  86. specification: "0.25g*24粒/盒",
  87. category: "prescription",
  88. categoryText: "处方药",
  89. indication: "用于敏感菌所致的呼吸道感染、泌尿系统感染等",
  90. price: 25.8,
  91. originalPrice: 32.0,
  92. isHot: true,
  93. salesCount: 1280,
  94. stock: 150,
  95. image: "https://via.placeholder.com/300x300/3a7ff3/ffffff?text=阿莫西林",
  96. expert: {
  97. name: "张明华",
  98. title: "主任医师",
  99. hospital: "北京协和医院",
  100. avatar: "https://via.placeholder.com/100x100/3a7ff3/ffffff?text=张",
  101. reason: "本品为广谱抗生素,对多数革兰氏阳性菌和革兰氏阴性菌均有良好的抗菌作用,是临床常用的一线抗生素。",
  102. expertise: "呼吸内科",
  103. years: 15,
  104. recommendTime: "2024-01-15"
  105. },
  106. store: {
  107. name: "仁和堂大药房",
  108. address: "北京市朝阳区建国路88号",
  109. phone: "010-88888888",
  110. businessHours: "8:00-22:00",
  111. features: "24小时营业,专业药师咨询,医保定点药店",
  112. distance: "1.2",
  113. latitude: 39.9042,
  114. longitude: 116.4074,
  115. rating: 4.8,
  116. images: [
  117. "/pagesA/images/5.png",
  118. "/pagesA/images/6.jpg",
  119. "/pagesA/images/6.jpg"
  120. ]
  121. },
  122. details: {
  123. usage: "口服。成人一次0.5g,每6~8小时1次,一日剂量不超过4g。",
  124. precautions: "青霉素过敏者禁用,用药期间可能出现腹泻、恶心等胃肠道反应。",
  125. storage: "密封,在干燥处保存。",
  126. validity: "24个月"
  127. }
  128. },
  129. {
  130. id: 2,
  131. name: "连花清瘟胶囊",
  132. manufacturer: "石家庄以岭药业股份有限公司",
  133. specification: "0.35g*24粒/盒",
  134. category: "chinese",
  135. categoryText: "中成药",
  136. indication: "用于治疗流行性感冒属热毒袭肺证",
  137. price: 28.5,
  138. originalPrice: 35.0,
  139. isHot: true,
  140. salesCount: 2560,
  141. stock: 89,
  142. image: "https://via.placeholder.com/300x300/4CAF50/ffffff?text=连花清瘟",
  143. expert: {
  144. name: "李芳",
  145. title: "副主任医师",
  146. hospital: "上海瑞金医院",
  147. avatar: "https://via.placeholder.com/100x100/4CAF50/ffffff?text=李",
  148. reason: "在新冠肺炎疫情防控中显示出良好效果,具有清瘟解毒、宣肺泄热的功效,适用于流感治疗。",
  149. expertise: "中医科",
  150. years: 12,
  151. recommendTime: "2024-01-14"
  152. },
  153. store: {
  154. name: "同济堂药店",
  155. address: "上海市黄浦区南京东路100号",
  156. phone: "021-66666666",
  157. businessHours: "9:00-21:00",
  158. features: "中药配方齐全,提供代煎服务,老字号药店",
  159. distance: "2.5",
  160. latitude: 31.2304,
  161. longitude: 121.4737,
  162. rating: 4.7,
  163. images: [
  164. "https://via.placeholder.com/400x300/FF9800/ffffff?text=中药柜台"
  165. ]
  166. },
  167. details: {
  168. usage: "口服。一次4粒,一日3次。",
  169. precautions: "风寒感冒者不适用,高血压、心脏病患者慎用。",
  170. storage: "密封,置阴凉干燥处。",
  171. validity: "36个月"
  172. }
  173. },
  174. {
  175. id: 3,
  176. name: "维生素C片",
  177. manufacturer: "养生堂药业有限公司",
  178. specification: "100mg*60片/瓶",
  179. category: "health",
  180. categoryText: "保健品",
  181. indication: "用于预防和治疗维生素C缺乏症",
  182. price: 18.9,
  183. originalPrice: 24.0,
  184. isHot: false,
  185. salesCount: 890,
  186. stock: 320,
  187. image: "https://via.placeholder.com/300x300/FF9800/ffffff?text=维生素C",
  188. expert: {
  189. name: "王建国",
  190. title: "执业药师",
  191. hospital: "广州中医药大学附属医院",
  192. avatar: "https://via.placeholder.com/100x100/FF9800/ffffff?text=王",
  193. reason: "增强免疫力,促进铁吸收,抗氧化作用明显,适合日常保健和预防感冒。",
  194. expertise: "临床药学",
  195. years: 8,
  196. recommendTime: "2024-01-13"
  197. },
  198. store: {
  199. name: "老百姓大药房",
  200. address: "广州市天河区体育西路189号",
  201. phone: "020-77777777",
  202. businessHours: "7:30-23:00",
  203. features: "连锁品牌,价格实惠,会员优惠,支持医保",
  204. distance: "0.8",
  205. latitude: 23.1358,
  206. longitude: 113.3269,
  207. rating: 4.6,
  208. images: []
  209. },
  210. details: {
  211. usage: "口服。成人一次1片,一日1次。",
  212. precautions: "不宜长期过量服用,肾功能不全者慎用。",
  213. storage: "避光,密封保存。",
  214. validity: "24个月"
  215. }
  216. },
  217. {
  218. id: 4,
  219. name: "布洛芬缓释胶囊",
  220. manufacturer: "中美天津史克制药有限公司",
  221. specification: "0.3g*20粒/盒",
  222. category: "otc",
  223. categoryText: "非处方药",
  224. indication: "用于缓解轻至中度疼痛如头痛、关节痛、偏头痛等",
  225. price: 22.5,
  226. originalPrice: 28.0,
  227. isHot: true,
  228. salesCount: 1870,
  229. stock: 120,
  230. image: "https://via.placeholder.com/300x300/9C27B0/ffffff?text=布洛芬",
  231. expert: {
  232. name: "陈晓东",
  233. title: "主任医师",
  234. hospital: "武汉同济医院",
  235. avatar: "https://via.placeholder.com/100x100/9C27B0/ffffff?text=陈",
  236. reason: "解热镇痛效果确切,缓释剂型作用持久,胃肠道刺激小,适合各种疼痛的缓解。",
  237. expertise: "疼痛科",
  238. years: 20,
  239. recommendTime: "2024-01-12"
  240. },
  241. store: {
  242. name: "九州通大药房",
  243. address: "武汉市江汉区解放大道688号",
  244. phone: "027-55555555",
  245. businessHours: "8:30-21:30",
  246. features: "药品齐全,支持线上订购,送货上门",
  247. distance: "3.2",
  248. latitude: 30.5928,
  249. longitude: 114.3052,
  250. rating: 4.9,
  251. images: [
  252. "https://via.placeholder.com/400x300/3F51B5/ffffff?text=现代药店",
  253. "https://via.placeholder.com/400x300/E91E63/ffffff?text=专业服务"
  254. ]
  255. },
  256. details: {
  257. usage: "口服。成人一次1粒,一日2次。",
  258. precautions: "胃肠道溃疡患者禁用,不宜长期服用。",
  259. storage: "密封,在阴凉干燥处保存。",
  260. validity: "36个月"
  261. }
  262. },
  263. {
  264. id: 5,
  265. name: "盐酸左氧氟沙星片",
  266. manufacturer: "浙江医药股份有限公司",
  267. specification: "0.5g*6片/盒",
  268. category: "prescription",
  269. categoryText: "处方药",
  270. indication: "用于敏感细菌引起的呼吸系统、泌尿系统感染",
  271. price: 42.8,
  272. originalPrice: 56.0,
  273. isHot: false,
  274. salesCount: 560,
  275. stock: 75,
  276. image: "https://via.placeholder.com/300x300/2196F3/ffffff?text=左氧氟沙星",
  277. expert: {
  278. name: "刘涛",
  279. title: "副主任医师",
  280. hospital: "南京鼓楼医院",
  281. avatar: "https://via.placeholder.com/100x100/2196F3/ffffff?text=刘",
  282. reason: "抗菌谱广,对多种革兰氏阴性菌和阳性菌有效,特别适用于泌尿系统感染的治疗。",
  283. expertise: "泌尿外科",
  284. years: 10,
  285. recommendTime: "2024-01-11"
  286. },
  287. store: {
  288. name: "金陵大药房",
  289. address: "南京市鼓楼区中山路321号",
  290. phone: "025-44444444",
  291. businessHours: "8:00-21:00",
  292. features: "专业处方药房,药师驻店咨询",
  293. distance: "1.8",
  294. latitude: 32.0603,
  295. longitude: 118.7969,
  296. rating: 4.5,
  297. images: []
  298. },
  299. details: {
  300. usage: "口服。一次1片,一日1次。",
  301. precautions: "18岁以下患者禁用,孕妇及哺乳期妇女禁用。",
  302. storage: "遮光,密封保存。",
  303. validity: "24个月"
  304. }
  305. },
  306. {
  307. id: 6,
  308. name: "板蓝根颗粒",
  309. manufacturer: "广州白云山和记黄埔中药有限公司",
  310. specification: "10g*20袋/盒",
  311. category: "chinese",
  312. categoryText: "中成药",
  313. indication: "清热解毒,凉血利咽,用于肺胃热盛所致的咽喉肿痛",
  314. price: 15.9,
  315. originalPrice: 19.9,
  316. isHot: true,
  317. salesCount: 3200,
  318. stock: 450,
  319. image: "https://via.placeholder.com/300x300/FF5722/ffffff?text=板蓝根",
  320. expert: {
  321. name: "孙丽",
  322. title: "主治医师",
  323. hospital: "成都中医药大学附属医院",
  324. avatar: "https://via.placeholder.com/100x100/FF5722/ffffff?text=孙",
  325. reason: "传统经典方剂,清热解毒效果显著,特别适合预防和治疗感冒初期症状。",
  326. expertise: "中医内科",
  327. years: 6,
  328. recommendTime: "2024-01-10"
  329. },
  330. store: {
  331. name: "康恩贝大药房",
  332. address: "成都市锦江区春熙路58号",
  333. phone: "028-33333333",
  334. businessHours: "9:00-22:00",
  335. features: "连锁品牌,中药西药齐全",
  336. distance: "0.5",
  337. latitude: 30.6578,
  338. longitude: 104.0657,
  339. rating: 4.4,
  340. images: []
  341. },
  342. details: {
  343. usage: "开水冲服。一次1袋,一日3次。",
  344. precautions: "风寒感冒者不适用,糖尿病患者慎用。",
  345. storage: "密封,防潮。",
  346. validity: "36个月"
  347. }
  348. },
  349. {
  350. id: 7,
  351. name: "复方甘草片",
  352. manufacturer: "北京双鹤药业股份有限公司",
  353. specification: "100片/瓶",
  354. category: "prescription",
  355. categoryText: "处方药",
  356. indication: "用于镇咳祛痰,适用于感冒咳嗽",
  357. price: 12.5,
  358. originalPrice: 16.0,
  359. isHot: false,
  360. salesCount: 780,
  361. stock: 200,
  362. image: "https://via.placeholder.com/300x300/673AB7/ffffff?text=甘草片",
  363. expert: {
  364. name: "赵国强",
  365. title: "主任医师",
  366. hospital: "天津医科大学总医院",
  367. avatar: "https://via.placeholder.com/100x100/673AB7/ffffff?text=赵",
  368. reason: "传统止咳良药,镇咳祛痰效果确切,价格实惠,适合普通感冒咳嗽。",
  369. expertise: "呼吸内科",
  370. years: 18,
  371. recommendTime: "2024-01-09"
  372. },
  373. store: {
  374. name: "天津医药大药房",
  375. address: "天津市和平区南京路128号",
  376. phone: "022-22222222",
  377. businessHours: "8:00-21:30",
  378. features: "国营药店,药品质量有保障",
  379. distance: "2.0",
  380. latitude: 39.1172,
  381. longitude: 117.2056,
  382. rating: 4.3,
  383. images: []
  384. },
  385. details: {
  386. usage: "口服。一次3-4片,一日3次。",
  387. precautions: "不宜长期服用,孕妇及哺乳期妇女慎用。",
  388. storage: "密封,在干燥处保存。",
  389. validity: "36个月"
  390. }
  391. },
  392. {
  393. id: 8,
  394. name: "葡萄糖酸钙口服液",
  395. manufacturer: "哈药集团制药六厂",
  396. specification: "10ml*12支/盒",
  397. category: "otc",
  398. categoryText: "非处方药",
  399. indication: "用于预防和治疗钙缺乏症",
  400. price: 35.0,
  401. originalPrice: 42.0,
  402. isHot: true,
  403. salesCount: 1560,
  404. stock: 180,
  405. image: "https://via.placeholder.com/300x300/00BCD4/ffffff?text=葡萄糖酸钙",
  406. expert: {
  407. name: "周敏",
  408. title: "副主任医师",
  409. hospital: "西安交通大学第一附属医院",
  410. avatar: "https://via.placeholder.com/100x100/00BCD4/ffffff?text=周",
  411. reason: "钙吸收好,口感适宜,特别适合儿童、孕妇和老年人补钙。",
  412. expertise: "儿科",
  413. years: 14,
  414. recommendTime: "2024-01-08"
  415. },
  416. store: {
  417. name: "西安医药大药房",
  418. address: "西安市碑林区南大街58号",
  419. phone: "029-11111111",
  420. businessHours: "8:30-21:00",
  421. features: "专业儿科用药,儿童健康咨询",
  422. distance: "1.5",
  423. latitude: 34.2583,
  424. longitude: 108.9426,
  425. rating: 4.7,
  426. images: []
  427. },
  428. details: {
  429. usage: "口服。一次1-2支,一日3次。",
  430. precautions: "肾功能不全者慎用,不宜与洋地黄类药物同时使用。",
  431. storage: "密封,置阴凉处。",
  432. validity: "24个月"
  433. }
  434. }
  435. ];
  436. },
  437. // 检查收藏状态
  438. checkFavoriteStatus: function() {
  439. const medicineData = this.data.medicineData;
  440. if (!medicineData) return;
  441. try {
  442. const favorites = wx.getStorageSync('medicineFavorites') || [];
  443. const isFavorite = favorites.some(item => item.id === medicineData.id);
  444. this.setData({ isFavorite });
  445. } catch (e) {
  446. console.error('读取收藏失败', e);
  447. }
  448. },
  449. // 切换收藏状态
  450. toggleFavorite: function() {
  451. const medicineData = this.data.medicineData;
  452. if (!medicineData) return;
  453. const newFavorite = !this.data.isFavorite;
  454. this.setData({ isFavorite: newFavorite });
  455. // 保存到本地缓存
  456. this.saveFavorite(newFavorite);
  457. wx.showToast({
  458. title: newFavorite ? '已收藏' : '已取消收藏',
  459. icon: 'success',
  460. duration: 1500
  461. });
  462. },
  463. // 保存收藏状态到本地缓存
  464. saveFavorite: function(isFavorite) {
  465. const medicineData = this.data.medicineData;
  466. if (!medicineData) return;
  467. try {
  468. let favorites = wx.getStorageSync('medicineFavorites') || [];
  469. if (isFavorite) {
  470. // 添加收藏
  471. if (!favorites.some(item => item.id === medicineData.id)) {
  472. favorites.push({
  473. id: medicineData.id,
  474. name: medicineData.name,
  475. price: medicineData.price,
  476. image: medicineData.image,
  477. expert: medicineData.expert.name,
  478. store: medicineData.store.name,
  479. time: new Date().getTime()
  480. });
  481. }
  482. } else {
  483. // 取消收藏
  484. favorites = favorites.filter(item => item.id !== medicineData.id);
  485. }
  486. wx.setStorageSync('medicineFavorites', favorites);
  487. } catch (e) {
  488. console.error('保存收藏失败', e);
  489. }
  490. },
  491. // 打开位置地图
  492. openLocation: function() {
  493. const { store } = this.data.medicineData;
  494. if (store.latitude && store.longitude) {
  495. wx.openLocation({
  496. latitude: parseFloat(store.latitude),
  497. longitude: parseFloat(store.longitude),
  498. name: store.name,
  499. address: store.address,
  500. scale: 18
  501. });
  502. } else {
  503. wx.showToast({
  504. title: '位置信息不可用',
  505. icon: 'none'
  506. });
  507. }
  508. },
  509. // 拨打电话
  510. makePhoneCall: function() {
  511. const phone = this.data.medicineData.store.phone;
  512. if (phone) {
  513. wx.makePhoneCall({
  514. phoneNumber: phone
  515. })
  516. }
  517. },
  518. // 预览主图片
  519. previewMainImage: function() {
  520. const url = this.data.medicineData.image;
  521. if (url) {
  522. wx.previewImage({
  523. current: url,
  524. urls: [url]
  525. });
  526. }
  527. },
  528. // 预览轮播图片
  529. previewImage: function(e) {
  530. const index = parseInt(e.currentTarget.dataset.index);
  531. const images = this.data.medicineData.store.images || [];
  532. const urls = [this.data.medicineData.image, ...images];
  533. wx.previewImage({
  534. current: urls[index + 1], // +1 因为第一个是主图
  535. urls: urls
  536. });
  537. },
  538. // 预览店铺图片
  539. previewStoreImage: function(e) {
  540. const index = parseInt(e.currentTarget.dataset.index);
  541. const images = this.data.medicineData.store.images || [];
  542. wx.previewImage({
  543. current: images[index],
  544. urls: images
  545. });
  546. },
  547. // 分享给朋友
  548. onShareToFriend: function() {
  549. wx.showShareMenu({
  550. withShareTicket: true,
  551. menus: ['shareAppMessage', 'shareTimeline']
  552. });
  553. }
  554. });