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.
134 lines
2.7 KiB
134 lines
2.7 KiB
import http from '../../../utils/api'
|
|
const baseUr = require('../../../utils/baseUrl')
|
|
Page({
|
|
data: {
|
|
// 药品数据
|
|
medicineData: null,
|
|
// 是否收藏
|
|
isFavorite: false,
|
|
baseUr: baseUr,
|
|
// 加载状态
|
|
loading: true,
|
|
imageUrl:''
|
|
},
|
|
|
|
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 () {
|
|
|
|
},
|
|
|
|
|
|
// 根据ID加载药品数据
|
|
loadMedicineData: function (id) {
|
|
this.setData({
|
|
loading: true
|
|
});
|
|
|
|
// 模拟网络请求,实际项目中应该从服务器获取
|
|
setTimeout(() => {
|
|
http.recommendationXq({
|
|
data: {
|
|
id: id
|
|
},
|
|
success: res => {
|
|
const mockData = res.data
|
|
const imageUrl = mockData.imageUrl.split(',')
|
|
|
|
this.setData({
|
|
medicineData: mockData,
|
|
imageUrl: imageUrl
|
|
});
|
|
}
|
|
})
|
|
|
|
}, 500);
|
|
},
|
|
|
|
|
|
|
|
// 打开位置地图
|
|
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.storePhone;
|
|
if (phone) {
|
|
wx.makePhoneCall({
|
|
phoneNumber: phone
|
|
})
|
|
}
|
|
},
|
|
|
|
// 预览主图片
|
|
previewMainImage: function () {
|
|
const url = this.data.imageUrl.split(',');
|
|
if (url) {
|
|
wx.previewImage({
|
|
current: url,
|
|
urls: [url]
|
|
});
|
|
}
|
|
},
|
|
|
|
// 预览轮播图片
|
|
previewImage: function (e) {
|
|
const imageUrl = this.data.imageUrl
|
|
const index = parseInt(e.currentTarget.dataset.index);
|
|
const images = imageUrl|| [];
|
|
const urls = [imageUrl, ...images];
|
|
|
|
wx.previewImage({
|
|
current: urls[index + 1], // +1 因为第一个是主图
|
|
urls: urls
|
|
});
|
|
},
|
|
|
|
// 预览店铺图片
|
|
previewStoreImage: function (e) {
|
|
const index = parseInt(e.currentTarget.dataset.index);
|
|
const images = this.data.imageUrl || [];
|
|
|
|
wx.previewImage({
|
|
current: images[index],
|
|
urls: images
|
|
});
|
|
},
|
|
|
|
|
|
});
|