| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- // order-detail.js
- Page({
- data: {
- order: null,
- mapCenter: {
- latitude: 39.9042,
- longitude: 116.4074
- },
- mapScale: 14
- },
- onLoad(options) {
- const orderId = parseInt(options.id)
- const app = getApp()
- const orders = app.getOrders()
- const order = orders.find(o => o.id === orderId)
-
- if (order) {
- this.setData({
- order: order
- })
- // 如果订单有地图数据,设置地图中心点和缩放级别
- if (order.mapTracking && order.mapTracking.markers) {
- this.setupMap(order.mapTracking.markers)
- }
- } else {
- wx.showToast({
- title: '订单不存在',
- icon: 'none'
- })
- setTimeout(() => {
- wx.navigateBack()
- }, 1500)
- }
- },
- // 设置地图中心点和缩放级别
- setupMap(markers) {
- if (markers.length === 0) return
- // 计算所有标记点的中心点
- let totalLat = 0
- let totalLng = 0
- markers.forEach(marker => {
- totalLat += marker.latitude
- totalLng += marker.longitude
- })
- const centerLat = totalLat / markers.length
- const centerLng = totalLng / markers.length
- // 计算合适的缩放级别(基于标记点之间的距离)
- let minLat = Infinity
- let maxLat = -Infinity
- let minLng = Infinity
- let maxLng = -Infinity
- markers.forEach(marker => {
- minLat = Math.min(minLat, marker.latitude)
- maxLat = Math.max(maxLat, marker.latitude)
- minLng = Math.min(minLng, marker.longitude)
- maxLng = Math.max(maxLng, marker.longitude)
- })
- const latDiff = maxLat - minLat
- const lngDiff = maxLng - minLng
- const maxDiff = Math.max(latDiff, lngDiff)
- // 根据距离设置缩放级别
- let scale = 14
- if (maxDiff > 0.01) {
- scale = 12
- } else if (maxDiff > 0.005) {
- scale = 13
- } else if (maxDiff > 0.002) {
- scale = 14
- } else {
- scale = 15
- }
- this.setData({
- mapCenter: {
- latitude: centerLat,
- longitude: centerLng
- },
- mapScale: scale
- })
- },
- // 返回上一页
- goBack() {
- wx.navigateBack({
- delta: 1
- })
- },
- // 联系客服
- contactSupport() {
- wx.showModal({
- title: '联系客服',
- content: '客服电话:400-123-4567\n工作时间:9:00-18:00',
- showCancel: false
- })
- },
- // 再次购买
- reorder() {
- const order = this.data.order
- wx.showModal({
- title: '再次购买',
- content: `确认再次购买${order.hospital}的药品吗?`,
- success: (res) => {
- if (res.confirm) {
- // 跳转到下单页面
- wx.switchTab({
- url: '/pages/order/order'
- })
-
- // 延迟设置搜索关键词
- setTimeout(() => {
- const pages = getCurrentPages()
- const orderPage = pages.find(page => page.route === 'pages/order/order')
- if (orderPage) {
- orderPage.setData({
- currentTab: 0,
- hospitalKeyword: order.hospital
- })
- }
- }, 500)
- }
- }
- })
- },
- // 删除订单
- deleteOrder() {
- const order = this.data.order
- wx.showModal({
- title: '确认删除',
- content: '确定要删除这个订单吗?删除后无法恢复。',
- success: (res) => {
- if (res.confirm) {
- const app = getApp()
- app.deleteOrder(order.id)
-
- wx.showToast({
- title: '订单已删除',
- icon: 'success',
- success: () => {
- setTimeout(() => {
- wx.navigateBack()
- }, 1500)
- }
- })
- }
- }
- }
- )
- }
- })
|