hejianhao
2025-09-12 34387905766d41cbca973488df03b9157ad297c6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<template>
    <div>
        <el-dialog title="订单详情" :visible.sync="dialogVisible" width="50%" :modal-append-to-body="false"
            :close-on-press-escape="false" :close-on-click-modal="false" @close="closeClick">
            <el-radio-group v-model="tabPosition" style="margin-bottom: 30px;">
                <el-radio-button label="order">订单信息</el-radio-button>
                <el-radio-button label="track">行程轨迹</el-radio-button>
                <!-- <el-radio-button label="monitoring">行程监控</el-radio-button> -->
            </el-radio-group>
            <!-- 订单信息 -->
            <div v-show="tabPosition == 'order'">
                <el-descriptions title="" :column="3">
                    <el-descriptions-item label="公司名称">{{ orderData.enterpriseName }}</el-descriptions-item>
                    <el-descriptions-item label="发起地区划">{{ orderData.drivingLicenseNumber }}</el-descriptions-item>
                    <el-descriptions-item label="订单编号">{{ orderData.code }}</el-descriptions-item>
                    <el-descriptions-item label="机动车驾驶证编号">{{ orderData.drivingLicenseNumber }}</el-descriptions-item>
                    <el-descriptions-item label="驾驶员手机号">{{ orderData.driverPhone }}</el-descriptions-item>
                    <el-descriptions-item label="车辆号牌">{{ orderData.vehicleNumber }}</el-descriptions-item>
                    <el-descriptions-item label="派单时间">{{ orderData.orderDeliveryTime }}</el-descriptions-item>
                    <el-descriptions-item label="订单发起时间">{{ orderData.orderTime }}</el-descriptions-item>
                    <el-descriptions-item label="乘客备注">{{ orderData.remark }}</el-descriptions-item>
                    <el-descriptions-item label="出发地点">{{ orderData.orderPlace }}</el-descriptions-item>
                    <el-descriptions-item label="下车地点">{{ orderData.dropOffPoint }}</el-descriptions-item>
                    <el-descriptions-item label="运价类型编号">{{ orderData.tariffType }}</el-descriptions-item>
                    <el-descriptions-item label="订单金额">¥{{ orderData.orderAmount }}</el-descriptions-item>
                    <el-descriptions-item label="实付价">¥{{ orderData.paymentAmount }}</el-descriptions-item>
                    <el-descriptions-item label="支付方式">{{ orderData.paymentMode }}</el-descriptions-item>
                </el-descriptions>
            </div>
            <!-- 行程轨迹 -->
            <div v-if="tabPosition == 'track'">
                <div class="mapContainer" id="mapContainer"></div>
            </div>
            <!-- 行程监控 -->
            <!-- <div v-if="tabPosition == 'monitoring'">
                <PlayLive :serverIp="monitoringData.serverIp" :serverPort="monitoringData.serverPort"
                    :urlLink="monitoringData.url" :carId="orderData.carId" />
            </div> -->
        </el-dialog>
    </div>
</template>
 
<script>
import AMapLoader from "@amap/amap-jsapi-loader";
export default {
    data() {
        return {
            dialogVisible: false,
            tabPosition: 'order',
            orderData: {},
            monitoringData: {},
            travelData: [],
        };
    },
    computed: {},
    watch: {
        tabPosition(val) {
            if (val == 'track') {
                this.$nextTick(() => {
                    this.initMap();
                })
                return
            }
        }
    },
    methods: {
        initData(orderData = {}, monitoringData = {}, travelData = []) {
            this.orderData = orderData
            // this.monitoringData = monitoringData
            this.travelData = travelData
            this.dialogVisible = true
        },
        initMap() {
            window._AMapSecurityConfig = {
                securityJsCode: this.$secretKey,
            };
            AMapLoader.load({
                key: this.$mapKey,
                version: "2.0",
                plugins: [
                    "AMap.ToolBar",
                ],
            })
                .then((AMap) => {
                    // 转换 travelData 中的坐标
                    const wgs84Path = this.travelData.map(item => [item.longitude, item.latitude]);
                    const batchSize = 40; // 每次转换 40 对坐标
                    const batches = [];
 
                    // 分批处理
                    for (let i = 0; i < wgs84Path.length; i += batchSize) {
                        batches.push(wgs84Path.slice(i, i + batchSize));
                    }
 
                    const gcj02Path = [];
                    const promises = batches.map(batch => {
                        return new Promise((resolve, reject) => {
                            AMap.convertFrom(batch, 'gps', (status, result) => {
                                if (status === 'complete' && result.locations) {
                                    resolve(result.locations);
                                } else {
                                    reject(result);
                                }
                            });
                        });
                    });
 
                    // 等待所有批次转换完成
                    Promise.all(promises)
                        .then(results => {
                            results.forEach(batchResult => {
                                gcj02Path.push(...batchResult);
                            });
 
                            // 开始绘制地图
                            this.map = new AMap.Map("mapContainer", {
                                center: gcj02Path[Math.floor(gcj02Path.length / 2)], // 使用转换后的中点坐标
                                zoom: 12,
                            });
                            this.map.addControl(new AMap.ToolBar());
 
                            // 添加起点和终点标记
                            const marker = [
                                new AMap.Marker({
                                    content: `<div class="custom-content-marker">起点</div>`,
                                    position: gcj02Path[0],
                                    offset: new AMap.Pixel(-35, -25),
                                }),
                                new AMap.Marker({
                                    content: `<div class="custom-content-marker-two">终点</div>`,
                                    position: gcj02Path[gcj02Path.length - 1],
                                    offset: new AMap.Pixel(-35, -25),
                                }),
                            ];
                            this.map.add(marker);
 
                            // 绘制路径
                            const polyline = new AMap.Polyline({
                                path: gcj02Path,
                                strokeWeight: 3,
                                strokeColor: "red",
                                lineJoin: "round",
                            });
                            this.map.add(polyline);
 
                            // 强制刷新地图
                            this.$nextTick(() => {
                                this.map.resize();
                            });
                        })
                        .catch(error => {
                            console.error('坐标转换失败', error);
                        });
                })
                .catch((e) => {
                    console.log(e);
                });
        },
        closeClick() {
            this.dialogVisible = false
            this.tabPosition = 'order'
            this.orderData = {}
            this.monitoringData = {}
            this.travelData = []
        },
    },
};
</script>
<style>
.custom-content-marker {
    width: 50px;
    height: 50px;
    background-color: blue;
    color: #fff;
    border-radius: 50%;
    line-height: 50px;
    text-align: center;
}
 
.custom-content-marker-two {
    width: 50px;
    height: 50px;
    background-color: orange;
    color: #fff;
    border-radius: 50%;
    line-height: 50px;
    text-align: center;
}
 
.custom-content-marker img {
    width: 100%;
    height: 100%;
}
</style>
<style scoped lang="less">
::v-deep .el-descriptions .el-descriptions-item__cell {
    padding-bottom: 25px;
}
 
#mapContainer {
    width: 100%;
    height: 500px;
}
</style>