|
|
@@ -17,10 +17,13 @@ Page({
|
|
|
],
|
|
|
showCaseModal: false,
|
|
|
showMedicineModal: false,
|
|
|
+ showPriceConfirmModal: false,
|
|
|
selectedHospital: null,
|
|
|
selectedCase: null,
|
|
|
selectedMedicines: [],
|
|
|
- totalPrice: 0
|
|
|
+ selectedPriceItem: null,
|
|
|
+ totalPrice: 0,
|
|
|
+ deliveryAddress: ''
|
|
|
},
|
|
|
|
|
|
onLoad() {
|
|
|
@@ -104,7 +107,8 @@ Page({
|
|
|
showMedicineModal: false,
|
|
|
selectedCase: null,
|
|
|
selectedMedicines: [],
|
|
|
- totalPrice: 0
|
|
|
+ totalPrice: 0,
|
|
|
+ deliveryAddress: ''
|
|
|
})
|
|
|
},
|
|
|
|
|
|
@@ -146,6 +150,34 @@ Page({
|
|
|
})
|
|
|
},
|
|
|
|
|
|
+ // 地址输入处理
|
|
|
+ onAddressInput(e) {
|
|
|
+ this.setData({
|
|
|
+ deliveryAddress: e.detail.value
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ // 使用默认地址
|
|
|
+ useDefaultAddress() {
|
|
|
+ const app = getApp()
|
|
|
+ const userInfo = app.globalData.userInfo || mockData.userInfo
|
|
|
+
|
|
|
+ if (userInfo && userInfo.defaultAddress) {
|
|
|
+ this.setData({
|
|
|
+ deliveryAddress: userInfo.defaultAddress
|
|
|
+ })
|
|
|
+ wx.showToast({
|
|
|
+ title: '已使用默认地址',
|
|
|
+ icon: 'success'
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ wx.showToast({
|
|
|
+ title: '暂无默认地址',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
// 确认下单
|
|
|
confirmOrder() {
|
|
|
const selectedMedicines = this.data.selectedCase.medicines
|
|
|
@@ -164,6 +196,15 @@ Page({
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ // 验证送货地址
|
|
|
+ if (!this.data.deliveryAddress || this.data.deliveryAddress.trim() === '') {
|
|
|
+ wx.showToast({
|
|
|
+ title: '请输入送货地址',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
// 根据医院生成地图轨迹数据
|
|
|
const hospitalLocation = this.getHospitalLocation(this.data.selectedHospital.name)
|
|
|
const mapTracking = this.generateMapTracking(hospitalLocation)
|
|
|
@@ -176,6 +217,7 @@ Page({
|
|
|
totalPrice: this.data.totalPrice,
|
|
|
status: '配送中',
|
|
|
date: new Date().toISOString().split('T')[0],
|
|
|
+ deliveryAddress: this.data.deliveryAddress,
|
|
|
droneTracking: {
|
|
|
status: '配送中',
|
|
|
steps: ['订单确认', '药品准备', '无人机起飞', '配送中', '待送达']
|
|
|
@@ -190,7 +232,7 @@ Page({
|
|
|
// 模拟下单成功
|
|
|
wx.showModal({
|
|
|
title: '下单成功',
|
|
|
- content: `订单总价:¥${this.data.totalPrice}\n药品将尽快通过无人机配送`,
|
|
|
+ content: `订单总价:¥${this.data.totalPrice}\n送货地址:${this.data.deliveryAddress}\n药品将尽快通过无人机配送`,
|
|
|
showCancel: false,
|
|
|
success: () => {
|
|
|
this.closeMedicineModal()
|
|
|
@@ -279,47 +321,85 @@ Page({
|
|
|
const priceInfo = e.currentTarget.dataset.price
|
|
|
const medicineName = this.data.medicineKeyword
|
|
|
|
|
|
+ // 显示确认模态框
|
|
|
+ this.setData({
|
|
|
+ showPriceConfirmModal: true,
|
|
|
+ selectedPriceItem: {
|
|
|
+ medicine: medicineName,
|
|
|
+ hospital: priceInfo.hospital,
|
|
|
+ price: priceInfo.price
|
|
|
+ },
|
|
|
+ deliveryAddress: ''
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ // 关闭比价确认模态框
|
|
|
+ closePriceConfirmModal() {
|
|
|
+ this.setData({
|
|
|
+ showPriceConfirmModal: false,
|
|
|
+ selectedPriceItem: null,
|
|
|
+ deliveryAddress: ''
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ // 确认比价下单
|
|
|
+ confirmPriceOrder() {
|
|
|
+ // 验证送货地址
|
|
|
+ if (!this.data.deliveryAddress || this.data.deliveryAddress.trim() === '') {
|
|
|
+ wx.showToast({
|
|
|
+ title: '请输入送货地址',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ const selectedPriceItem = this.data.selectedPriceItem
|
|
|
+
|
|
|
+ // 根据医院生成地图轨迹数据
|
|
|
+ const hospitalLocation = this.getHospitalLocation(selectedPriceItem.hospital)
|
|
|
+ const mapTracking = this.generateMapTracking(hospitalLocation)
|
|
|
+
|
|
|
+ // 创建订单数据
|
|
|
+ const order = {
|
|
|
+ id: Date.now(),
|
|
|
+ hospital: selectedPriceItem.hospital,
|
|
|
+ medicines: [selectedPriceItem.medicine],
|
|
|
+ totalPrice: selectedPriceItem.price,
|
|
|
+ status: '配送中',
|
|
|
+ date: new Date().toISOString().split('T')[0],
|
|
|
+ deliveryAddress: this.data.deliveryAddress,
|
|
|
+ droneTracking: {
|
|
|
+ status: '配送中',
|
|
|
+ steps: ['订单确认', '药品准备', '无人机起飞', '配送中', '待送达']
|
|
|
+ },
|
|
|
+ mapTracking: mapTracking
|
|
|
+ }
|
|
|
+
|
|
|
+ // 保存订单到全局变量和本地存储
|
|
|
+ const app = getApp()
|
|
|
+ app.addOrder(order)
|
|
|
+
|
|
|
+ // 保存地址用于显示
|
|
|
+ const savedAddress = this.data.deliveryAddress
|
|
|
+
|
|
|
+ // 关闭模态框
|
|
|
+ this.setData({
|
|
|
+ showPriceConfirmModal: false,
|
|
|
+ selectedPriceItem: null,
|
|
|
+ deliveryAddress: ''
|
|
|
+ })
|
|
|
+
|
|
|
wx.showModal({
|
|
|
- title: '确认下单',
|
|
|
- content: `确认在${priceInfo.hospital}购买${medicineName},价格:¥${priceInfo.price}`,
|
|
|
- success: (res) => {
|
|
|
- if (res.confirm) {
|
|
|
- // 根据医院生成地图轨迹数据
|
|
|
- const hospitalLocation = this.getHospitalLocation(priceInfo.hospital)
|
|
|
- const mapTracking = this.generateMapTracking(hospitalLocation)
|
|
|
-
|
|
|
- // 创建订单数据
|
|
|
- const order = {
|
|
|
- id: Date.now(),
|
|
|
- hospital: priceInfo.hospital,
|
|
|
- medicines: [medicineName],
|
|
|
- totalPrice: priceInfo.price,
|
|
|
- status: '配送中',
|
|
|
- date: new Date().toISOString().split('T')[0],
|
|
|
- droneTracking: {
|
|
|
- status: '配送中',
|
|
|
- steps: ['订单确认', '药品准备', '无人机起飞', '配送中', '待送达']
|
|
|
- },
|
|
|
- mapTracking: mapTracking
|
|
|
- }
|
|
|
-
|
|
|
- // 保存订单到全局变量和本地存储
|
|
|
- const app = getApp()
|
|
|
- app.addOrder(order)
|
|
|
-
|
|
|
- wx.showToast({
|
|
|
- title: '下单成功',
|
|
|
- icon: 'success',
|
|
|
- success: () => {
|
|
|
- // 跳转到我的页面查看订单
|
|
|
- setTimeout(() => {
|
|
|
- wx.switchTab({
|
|
|
- url: '/pages/profile/profile'
|
|
|
- })
|
|
|
- }, 500)
|
|
|
- }
|
|
|
+ title: '下单成功',
|
|
|
+ content: `订单总价:¥${selectedPriceItem.price}\n送货地址:${savedAddress}\n药品将尽快通过无人机配送`,
|
|
|
+ showCancel: false,
|
|
|
+ success: () => {
|
|
|
+ // 跳转到我的页面查看订单
|
|
|
+ setTimeout(() => {
|
|
|
+ wx.switchTab({
|
|
|
+ url: '/pages/profile/profile'
|
|
|
})
|
|
|
- }
|
|
|
+ }, 500)
|
|
|
}
|
|
|
})
|
|
|
}
|