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

133 lines
2.7 KiB

1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
  1. import http from '../../../utils/api'
  2. const baseUr = require('../../../utils/baseUrl')
  3. Page({
  4. data: {
  5. // 药品数据
  6. medicineData: null,
  7. // 是否收藏
  8. isFavorite: false,
  9. baseUr: baseUr,
  10. // 加载状态
  11. loading: true,
  12. imageUrl:''
  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. // 根据ID加载药品数据
  36. loadMedicineData: function (id) {
  37. this.setData({
  38. loading: true
  39. });
  40. // 模拟网络请求,实际项目中应该从服务器获取
  41. setTimeout(() => {
  42. http.recommendationXq({
  43. data: {
  44. id: id
  45. },
  46. success: res => {
  47. const mockData = res.data
  48. const imageUrl = mockData.imageUrl.split(',')
  49. this.setData({
  50. medicineData: mockData,
  51. imageUrl: imageUrl
  52. });
  53. }
  54. })
  55. }, 500);
  56. },
  57. // 打开位置地图
  58. openLocation: function () {
  59. const store = this.data.medicineData;
  60. if (store.latitude && store.longitude) {
  61. wx.openLocation({
  62. latitude: parseFloat(store.latitude),
  63. longitude: parseFloat(store.longitude),
  64. name: store.name,
  65. address: store.address,
  66. scale: 18
  67. });
  68. } else {
  69. wx.showToast({
  70. title: '位置信息不可用',
  71. icon: 'none'
  72. });
  73. }
  74. },
  75. // 拨打电话
  76. makePhoneCall: function () {
  77. const phone = this.data.medicineData.storePhone;
  78. if (phone) {
  79. wx.makePhoneCall({
  80. phoneNumber: phone
  81. })
  82. }
  83. },
  84. // 预览主图片
  85. previewMainImage: function () {
  86. const url = this.data.imageUrl.split(',');
  87. if (url) {
  88. wx.previewImage({
  89. current: url,
  90. urls: [url]
  91. });
  92. }
  93. },
  94. // 预览轮播图片
  95. previewImage: function (e) {
  96. const imageUrl = this.data.imageUrl
  97. const index = parseInt(e.currentTarget.dataset.index);
  98. const images = imageUrl|| [];
  99. const urls = [imageUrl, ...images];
  100. wx.previewImage({
  101. current: urls[index + 1], // +1 因为第一个是主图
  102. urls: urls
  103. });
  104. },
  105. // 预览店铺图片
  106. previewStoreImage: function (e) {
  107. const index = parseInt(e.currentTarget.dataset.index);
  108. const images = this.data.imageUrl || [];
  109. wx.previewImage({
  110. current: images[index],
  111. urls: images
  112. });
  113. },
  114. });