|
@@ -9,12 +9,15 @@ Page({
|
|
|
hospitals: mockData.hospitals,
|
|
hospitals: mockData.hospitals,
|
|
|
filteredHospitals: mockData.hospitals,
|
|
filteredHospitals: mockData.hospitals,
|
|
|
priceResults: [],
|
|
priceResults: [],
|
|
|
|
|
+ selectedMedicine: null,
|
|
|
hotMedicines: [
|
|
hotMedicines: [
|
|
|
{ name: '阿莫西林胶囊', minPrice: 24.8 },
|
|
{ name: '阿莫西林胶囊', minPrice: 24.8 },
|
|
|
{ name: '布洛芬缓释胶囊', minPrice: 17.5 },
|
|
{ name: '布洛芬缓释胶囊', minPrice: 17.5 },
|
|
|
{ name: '氯雷他定片', minPrice: 30.5 },
|
|
{ name: '氯雷他定片', minPrice: 30.5 },
|
|
|
{ name: '奥美拉唑肠溶胶囊', minPrice: 45.0 }
|
|
{ name: '奥美拉唑肠溶胶囊', minPrice: 45.0 }
|
|
|
],
|
|
],
|
|
|
|
|
+ otherMedicines: [],
|
|
|
|
|
+ selectedMedicineQuantity: {},
|
|
|
showCaseModal: false,
|
|
showCaseModal: false,
|
|
|
showMedicineModal: false,
|
|
showMedicineModal: false,
|
|
|
showPriceConfirmModal: false,
|
|
showPriceConfirmModal: false,
|
|
@@ -28,6 +31,27 @@ Page({
|
|
|
|
|
|
|
|
onLoad() {
|
|
onLoad() {
|
|
|
console.log('下单页面加载完成')
|
|
console.log('下单页面加载完成')
|
|
|
|
|
+ this.loadOtherMedicines()
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ loadOtherMedicines() {
|
|
|
|
|
+ const hotMedicineNames = this.data.hotMedicines.map(m => m.name)
|
|
|
|
|
+ const otherMedicines = []
|
|
|
|
|
+
|
|
|
|
|
+ for (const medicineName in mockData.medicinePrices) {
|
|
|
|
|
+ if (!hotMedicineNames.includes(medicineName)) {
|
|
|
|
|
+ const prices = mockData.medicinePrices[medicineName]
|
|
|
|
|
+ const minPrice = Math.min(...prices.map(p => p.price))
|
|
|
|
|
+ otherMedicines.push({
|
|
|
|
|
+ name: medicineName,
|
|
|
|
|
+ minPrice: minPrice
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ this.setData({
|
|
|
|
|
+ otherMedicines: otherMedicines
|
|
|
|
|
+ })
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
// 切换选项卡
|
|
// 切换选项卡
|
|
@@ -52,20 +76,36 @@ Page({
|
|
|
|
|
|
|
|
// 药品搜索
|
|
// 药品搜索
|
|
|
onMedicineSearch(e) {
|
|
onMedicineSearch(e) {
|
|
|
- const keyword = e.detail.value
|
|
|
|
|
|
|
+ const keyword = e.detail.value.trim()
|
|
|
this.setData({
|
|
this.setData({
|
|
|
- medicineKeyword: keyword
|
|
|
|
|
|
|
+ medicineKeyword: keyword,
|
|
|
|
|
+ selectedMedicine: null,
|
|
|
|
|
+ priceResults: []
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- if (keyword && mockData.medicinePrices[keyword]) {
|
|
|
|
|
- this.setData({
|
|
|
|
|
- priceResults: mockData.medicinePrices[keyword]
|
|
|
|
|
- })
|
|
|
|
|
- } else {
|
|
|
|
|
- this.setData({
|
|
|
|
|
- priceResults: []
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ if (!keyword) {
|
|
|
|
|
+ // 清空搜索时,重新加载所有药品信息
|
|
|
|
|
+ this.loadOtherMedicines()
|
|
|
|
|
+ return
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // 模糊搜索:查找包含关键词的药品
|
|
|
|
|
+ const matchedMedicines = []
|
|
|
|
|
+ for (const medicineName in mockData.medicinePrices) {
|
|
|
|
|
+ if (medicineName.includes(keyword)) {
|
|
|
|
|
+ const prices = mockData.medicinePrices[medicineName]
|
|
|
|
|
+ const minPrice = Math.min(...prices.map(p => p.price))
|
|
|
|
|
+ matchedMedicines.push({
|
|
|
|
|
+ name: medicineName,
|
|
|
|
|
+ minPrice: minPrice
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 将搜索结果显示在药品信息模块中
|
|
|
|
|
+ this.setData({
|
|
|
|
|
+ otherMedicines: matchedMedicines
|
|
|
|
|
+ })
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
// 选择医院
|
|
// 选择医院
|
|
@@ -246,12 +286,50 @@ Page({
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
|
|
+ // 选择药品
|
|
|
|
|
+ selectMedicine(e) {
|
|
|
|
|
+ const medicineName = e.currentTarget.dataset.medicine
|
|
|
|
|
+ this.setData({
|
|
|
|
|
+ selectedMedicine: medicineName
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ if (mockData.medicinePrices[medicineName]) {
|
|
|
|
|
+ const priceResults = mockData.medicinePrices[medicineName].map(item => {
|
|
|
|
|
+ const hospital = this.data.hospitals.find(h => h.name === item.hospital)
|
|
|
|
|
+ return {
|
|
|
|
|
+ ...item,
|
|
|
|
|
+ distance: hospital ? hospital.distance : '未知'
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ this.setData({
|
|
|
|
|
+ priceResults: priceResults
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
// 获取医院位置
|
|
// 获取医院位置
|
|
|
getHospitalLocation(hospitalName) {
|
|
getHospitalLocation(hospitalName) {
|
|
|
const locations = {
|
|
const locations = {
|
|
|
'北京协和医院': { latitude: 39.9139, longitude: 116.3917 },
|
|
'北京协和医院': { latitude: 39.9139, longitude: 116.3917 },
|
|
|
'上海瑞金医院': { latitude: 31.2304, longitude: 121.4737 },
|
|
'上海瑞金医院': { latitude: 31.2304, longitude: 121.4737 },
|
|
|
- '广州中山医院': { latitude: 23.1291, longitude: 113.2644 }
|
|
|
|
|
|
|
+ '广州中山医院': { latitude: 23.1291, longitude: 113.2644 },
|
|
|
|
|
+ '北京大学第一医院': { latitude: 39.9289, longitude: 116.3883 },
|
|
|
|
|
+ '上海华山医院': { latitude: 31.2165, longitude: 121.4449 },
|
|
|
|
|
+ '广东省人民医院': { latitude: 23.1256, longitude: 113.2732 },
|
|
|
|
|
+ '北京301医院': { latitude: 39.9135, longitude: 116.2766 },
|
|
|
|
|
+ '上海仁济医院': { latitude: 31.2269, longitude: 121.4997 },
|
|
|
|
|
+ '广州南方医院': { latitude: 23.1825, longitude: 113.2767 },
|
|
|
|
|
+ '北京中日友好医院': { latitude: 39.9792, longitude: 116.4472 },
|
|
|
|
|
+ '上海长征医院': { latitude: 31.2317, longitude: 121.4708 },
|
|
|
|
|
+ '广东省中医院': { latitude: 23.1215, longitude: 113.2665 },
|
|
|
|
|
+ '北京天坛医院': { latitude: 39.8726, longitude: 116.4168 },
|
|
|
|
|
+ '上海第九人民医院': { latitude: 31.2304, longitude: 121.4851 },
|
|
|
|
|
+ '广州华侨医院': { latitude: 23.1358, longitude: 113.3245 },
|
|
|
|
|
+ '北京安贞医院': { latitude: 39.9432, longitude: 116.4134 },
|
|
|
|
|
+ '上海新华医院': { latitude: 31.2576, longitude: 121.5119 },
|
|
|
|
|
+ '广州医科大学附属第一医院': { latitude: 23.1258, longitude: 113.2587 },
|
|
|
|
|
+ '北京朝阳医院': { latitude: 39.9299, longitude: 116.4443 },
|
|
|
|
|
+ '上海第六人民医院': { latitude: 31.1884, longitude: 121.4367 }
|
|
|
}
|
|
}
|
|
|
return locations[hospitalName] || { latitude: 39.9042, longitude: 116.4074 }
|
|
return locations[hospitalName] || { latitude: 39.9042, longitude: 116.4074 }
|
|
|
},
|
|
},
|
|
@@ -302,24 +380,18 @@ Page({
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
- // 选择热门药品
|
|
|
|
|
- selectHotMedicine(e) {
|
|
|
|
|
- const medicineName = e.currentTarget.dataset.medicine
|
|
|
|
|
|
|
+ // 返回药品列表
|
|
|
|
|
+ backToMedicines() {
|
|
|
this.setData({
|
|
this.setData({
|
|
|
- medicineKeyword: medicineName
|
|
|
|
|
|
|
+ selectedMedicine: null,
|
|
|
|
|
+ priceResults: []
|
|
|
})
|
|
})
|
|
|
-
|
|
|
|
|
- if (mockData.medicinePrices[medicineName]) {
|
|
|
|
|
- this.setData({
|
|
|
|
|
- priceResults: mockData.medicinePrices[medicineName]
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
// 通过价格选择医院
|
|
// 通过价格选择医院
|
|
|
selectByPrice(e) {
|
|
selectByPrice(e) {
|
|
|
const priceInfo = e.currentTarget.dataset.price
|
|
const priceInfo = e.currentTarget.dataset.price
|
|
|
- const medicineName = this.data.medicineKeyword
|
|
|
|
|
|
|
+ const medicineName = this.data.selectedMedicine
|
|
|
|
|
|
|
|
// 显示确认模态框
|
|
// 显示确认模态框
|
|
|
this.setData({
|
|
this.setData({
|
|
@@ -327,12 +399,37 @@ Page({
|
|
|
selectedPriceItem: {
|
|
selectedPriceItem: {
|
|
|
medicine: medicineName,
|
|
medicine: medicineName,
|
|
|
hospital: priceInfo.hospital,
|
|
hospital: priceInfo.hospital,
|
|
|
- price: priceInfo.price
|
|
|
|
|
|
|
+ price: priceInfo.price,
|
|
|
|
|
+ distance: priceInfo.distance
|
|
|
},
|
|
},
|
|
|
deliveryAddress: ''
|
|
deliveryAddress: ''
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
|
|
+ // 增加比价药品数量
|
|
|
|
|
+ increasePriceQuantity(e) {
|
|
|
|
|
+ const hospital = e.currentTarget.dataset.hospital
|
|
|
|
|
+ const selectedMedicineQuantity = { ...this.data.selectedMedicineQuantity }
|
|
|
|
|
+ selectedMedicineQuantity[hospital] = (selectedMedicineQuantity[hospital] || 0) + 1
|
|
|
|
|
+
|
|
|
|
|
+ this.setData({
|
|
|
|
|
+ selectedMedicineQuantity
|
|
|
|
|
+ })
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ // 减少比价药品数量
|
|
|
|
|
+ decreasePriceQuantity(e) {
|
|
|
|
|
+ const hospital = e.currentTarget.dataset.hospital
|
|
|
|
|
+ const selectedMedicineQuantity = { ...this.data.selectedMedicineQuantity }
|
|
|
|
|
+ if ((selectedMedicineQuantity[hospital] || 0) > 0) {
|
|
|
|
|
+ selectedMedicineQuantity[hospital] = selectedMedicineQuantity[hospital] - 1
|
|
|
|
|
+
|
|
|
|
|
+ this.setData({
|
|
|
|
|
+ selectedMedicineQuantity
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
// 关闭比价确认模态框
|
|
// 关闭比价确认模态框
|
|
|
closePriceConfirmModal() {
|
|
closePriceConfirmModal() {
|
|
|
this.setData({
|
|
this.setData({
|
|
@@ -354,6 +451,7 @@ Page({
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const selectedPriceItem = this.data.selectedPriceItem
|
|
const selectedPriceItem = this.data.selectedPriceItem
|
|
|
|
|
+ const quantity = this.data.selectedMedicineQuantity[selectedPriceItem.hospital] || 1
|
|
|
|
|
|
|
|
// 根据医院生成地图轨迹数据
|
|
// 根据医院生成地图轨迹数据
|
|
|
const hospitalLocation = this.getHospitalLocation(selectedPriceItem.hospital)
|
|
const hospitalLocation = this.getHospitalLocation(selectedPriceItem.hospital)
|
|
@@ -364,7 +462,8 @@ Page({
|
|
|
id: Date.now(),
|
|
id: Date.now(),
|
|
|
hospital: selectedPriceItem.hospital,
|
|
hospital: selectedPriceItem.hospital,
|
|
|
medicines: [selectedPriceItem.medicine],
|
|
medicines: [selectedPriceItem.medicine],
|
|
|
- totalPrice: selectedPriceItem.price,
|
|
|
|
|
|
|
+ totalPrice: selectedPriceItem.price * quantity,
|
|
|
|
|
+ quantity: quantity,
|
|
|
status: '配送中',
|
|
status: '配送中',
|
|
|
date: new Date().toISOString().split('T')[0],
|
|
date: new Date().toISOString().split('T')[0],
|
|
|
deliveryAddress: this.data.deliveryAddress,
|
|
deliveryAddress: this.data.deliveryAddress,
|
|
@@ -386,12 +485,13 @@ Page({
|
|
|
this.setData({
|
|
this.setData({
|
|
|
showPriceConfirmModal: false,
|
|
showPriceConfirmModal: false,
|
|
|
selectedPriceItem: null,
|
|
selectedPriceItem: null,
|
|
|
- deliveryAddress: ''
|
|
|
|
|
|
|
+ deliveryAddress: '',
|
|
|
|
|
+ selectedMedicineQuantity: {}
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
wx.showModal({
|
|
wx.showModal({
|
|
|
title: '下单成功',
|
|
title: '下单成功',
|
|
|
- content: `订单总价:¥${selectedPriceItem.price}\n送货地址:${savedAddress}\n药品将尽快通过无人机配送`,
|
|
|
|
|
|
|
+ content: `订单总价:¥${selectedPriceItem.price * quantity}\n药品数量:${quantity}\n送货地址:${savedAddress}\n药品将尽快通过无人机配送`,
|
|
|
showCancel: false,
|
|
showCancel: false,
|
|
|
success: () => {
|
|
success: () => {
|
|
|
// 跳转到我的页面查看订单
|
|
// 跳转到我的页面查看订单
|