Pu Zhibing
2 天以前 d0d6f8f40e5d9762d940b47c566da1876361020e
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
@layout("/common/_container.html"){
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>新建订单</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
    <style>
        /* 司机列表表格样式 */
        .driver-table {
            width: 100%;
            background: white;
            border-radius: 4px;
            overflow: hidden;
        }
 
        .driver-table-header {
            display: flex;
            background: #f7f7f7;
            font-weight: bold;
            border-bottom: 1px solid #e8e8e8;
        }
 
        .driver-table-body {
            max-height: 300px;
            overflow-y: auto;
        }
 
        .driver-row {
            display: flex;
            border-bottom: 1px solid #e8e8e8;
        }
 
        .driver-row:hover {
            background-color: #f5f5f5;
        }
 
        .driver-table-header > div,
        .driver-row > div {
            padding: 12px 8px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
 
        .col-checkbox {
            width: 40px;
            text-align: center;
        }
 
        .col-name {
            flex: 1;
            min-width: 100px;
        }
 
        .col-distance {
            width: 100px;
            text-align: right;
        }
 
        .col-phone {
            width: 120px;
        }
 
        /* 复选框样式 */
        .driver-table input[type="checkbox"] {
            width: 16px;
            height: 16px;
            cursor: pointer;
        }
 
        /* 滑块容器样式 */
        .radius-control {
            background: white;
            padding: 15px;
            margin-bottom: 10px;
            border-radius: 4px;
            box-shadow: 0 1px 4px rgba(0,0,0,0.1);
        }
 
        .radius-control span {
            display: block;
            margin-bottom: 10px;
            color: #333;
        }
 
        /* 滑块样式 */
        #radiusSlider {
            width: 100%;
            height: 4px;
            -webkit-appearance: none;
            background: #e1e1e1;
            border-radius: 2px;
            outline: none;
        }
 
        #radiusSlider::-webkit-slider-thumb {
            -webkit-appearance: none;
            width: 16px;
            height: 16px;
            background: #1890FF;
            border-radius: 50%;
            cursor: pointer;
        }
 
        #radiusSlider::-moz-range-thumb {
            width: 16px;
            height: 16px;
            background: #1890FF;
            border-radius: 50%;
            cursor: pointer;
            border: none;
        }
 
        /* 加载状态样式 */
        .loading-state {
            padding: 20px;
            text-align: center;
            color: #1890FF;
        }
 
        .empty-state {
            padding: 20px;
            text-align: center;
            color: #999;
        }
        /* 添加状态提示样式 */
        .loading-state,
        .empty-state,
        .error-state {
            padding: 20px;
            text-align: center;
            color: #666;
        }
 
        .loading-state {
            color: #1890FF;
        }
 
        .empty-state {
            color: #999;
        }
 
        .error-state {
            color: #ff4d4f;
        }
 
        /* 优化滑块样式 */
        .radius-control {
            margin-bottom: 15px;
            padding: 10px;
            background: white;
            border-radius: 4px;
            box-shadow: 0 2px 6px rgba(0,0,0,0.1);
        }
 
        .radius-control span {
            display: block;
            margin-bottom: 8px;
        }
 
        #radiusSlider {
            width: 100%;
            margin: 0;
        }
 
        /* 优化滑块外观 */
        #radiusSlider {
            -webkit-appearance: none;
            height: 4px;
            background: #e1e1e1;
            border-radius: 2px;
            outline: none;
        }
 
        #radiusSlider::-webkit-slider-thumb {
            -webkit-appearance: none;
            appearance: none;
            width: 16px;
            height: 16px;
            background: #1890FF;
            border-radius: 50%;
            cursor: pointer;
        }
 
        #radiusSlider::-moz-range-thumb {
            width: 16px;
            height: 16px;
            background: #1890FF;
            border-radius: 50%;
            cursor: pointer;
            border: none;
        }
        /* 司机列表样式 */
.driver-list {
    margin-top: 10px;
    background: white;
    border-radius: 4px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}
 
.driver-list-header {
    padding: 10px 15px;
    border-bottom: 1px solid #eee;
    font-weight: bold;
    color: #333;
}
 
.driver-items {
    max-height: 300px;
    overflow-y: auto;
}
 
.driver-item {
    display: flex;
    align-items: center;
    padding: 10px 15px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
}
 
.driver-item:hover {
    background-color: #f5f5f5;
}
 
.driver-icon {
    width: 30px;
    height: 30px;
    margin-right: 10px;
}
 
.driver-info {
    flex: 1;
}
 
.driver-name {
    font-weight: 500;
    color: #333;
}
 
.driver-phone {
    font-size: 12px;
    color: #666;
    margin-top: 2px;
}
 
/* 标记样式 */
.driver-marker {
    background: white;
    border-radius: 50%;
    padding: 5px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
    border: 2px solid #1890FF;
}
 
.driver-marker img {
    display: block;
}
        body, html {
            margin: 0;
            padding: 0;
            height: 100%;
        }
 
        .container {
            position: relative;
            width: 100%;
            height: 100vh;
        }
 
        #map-container {
            width: 100%;
            height: 100%;
        }
 
        .floating-box {
            position: absolute;
            background: white;
            border-radius: 8px;
            box-shadow: 0 2px 12px rgba(0,0,0,0.1);
            padding: 15px;
            z-index: 1000;
        }
        /* 调整其他浮动框的z-index,确保不会遮挡联想列表 */
        .floating-box.driver-info {
            z-index: 1000;
        }
 
        .floating-box.customer-info {
            z-index: 1000;
        }
        .location-inputs {
            position: absolute;
            top: 20px;
            left: 20px;
            width: 400px;
            z-index: 1001; /* 确保在最上层 */
        }
 
        .customer-info {
            top: 20px;
            right: 20px;
            width: 400px;
        }
 
        .driver-info {
            top: 180px;
            left: 20px;
            width: 400px;
        }
 
        .input-group {
            position: relative;
 
            margin-bottom: 15px;
        }
 
        .input-group input{
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-shadow: 0 2px 6px rgba(0,0,0,0.1);
            background: white;
        }
        .input-group textarea {
            width: calc(100% - 80px);
            padding: 8px;
            margin-top: 5px;
            border: 1px solid #ddd;
            border-radius: 4px;
        }
 
        .radius-control {
            margin: 15px 0;
        }
 
        #radiusSlider {
            width: 100%;
        }
 
        .driver-list {
            max-height: 200px;
            overflow-y: auto;
            margin-top: 10px;
        }
 
        .driver-item {
            display: flex;
            align-items: center;
            padding: 8px 0;
            border-bottom: 1px solid #eee;
        }
 
        .driver-item:last-child {
            border-bottom: none;
        }
 
        .driver-item label {
            margin: 0 10px;
        }
 
        .driver-item .distance,
        .driver-item .phone {
            margin-left: 10px;
            color: #666;
            font-size: 14px;
        }
 
        .sug-result {
            position: absolute;
            top: 100%;
            left: 0;
            right: 0;
            background: white;
            border: 1px solid #ddd;
            border-radius: 0 0 4px 4px;
            box-shadow: 0 2px 6px rgba(0,0,0,0.1);
            max-height: 300px;
            overflow-y: auto;
            z-index: 1002; /* 确保联想列表在输入框之上 */
        }
 
        .sug-item {
            padding: 8px 12px;
            cursor: pointer;
            border-bottom: 1px solid #f0f0f0;
        }
 
        .sug-item:hover {
            background: #f5f5f5;
        }
 
        .marker-content {
            padding: 10px;
        }
        .submit-btn {
            background: #1890ff;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 4px;
            cursor: pointer;
            width: 100%;
        }
 
        .submit-btn:hover {
            background: #40a9ff;
        }
    </style>
        <!-- 其他代码 -->
        
        <!-- 引入 flatpickr 的 CSS -->
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
        <!-- 引入 flatpickr 的中文语言包 CSS -->
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/themes/light.css">
        
        <!-- 引入 flatpickr 的 JavaScript -->
        <script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
        <!-- 引入 flatpickr 的中文语言包 -->
        <script src="https://cdn.jsdelivr.net/npm/flatpickr/dist/l10n/zh.js"></script>
        
        <!-- 其他代码 -->
</head>
<body>
    <div class="container">
        <!-- 地址输入框 -->
 
        <div class="location-inputs">
            <div class="input-group">
                <input style="width: 350px" type="text" id="appointmentAddress" placeholder="预约地">
                <div id="appointmentSug" class="sug-result"></div>
            </div>
            <div class="input-group">
                <input style="width: 350px" type="text" id="destinationAddress" placeholder="目的地">
                <div id="destinationSug" class="sug-result"></div>
            </div>
        </div>
        <!-- 客户信息 -->
        <div class="floating-box driver-info">
            <div class="input-group" style="display: flex">
                <span style="margin-top: 10px;margin-right: 5px">客户电话</span><input style="width: 200px" type="text" id="customerPhone" placeholder="客户电话">
            </div>
            <div class="input-group"style="display: flex">
                <span style="margin-top: 10px;margin-right: 5px">客户姓名</span><input style="width: 200px"type="text" id="customerName" placeholder="客户姓名">
            </div>
            <div class="input-group"style="display: flex">
                <span style="margin-top: 10px;margin-right: 5px">司机人数</span><input style="width: 200px"type="number" id="peopleCount" placeholder="司机人数" min="1" value="1">
            </div>
            <div class="input-group"style="display: flex">
                <span style="margin-top: 10px;margin-right: 5px">预约时间</span><input style="width: 200px"type="text" id="appointmentTime" placeholder="预约时间">
            </div>
            <div class="input-group"style="display: flex">
                <span style="margin-top: 10px;margin-right: 5px">备注</span><textarea id="remarks" placeholder="备注" rows="3"></textarea>
            </div>
            <button class="submit-btn" onclick="createOrder()">创建订单</button>
        </div>
 
        <!-- 司机信息 -->
        <div class="floating-box customer-info">
            <div class="radius-control">
                <span>搜索范围: <span id="radiusValue">1</span>km</span>
                <input type="range" id="radiusSlider" min="0" max="25" step="0.1" value="0.5">
            </div>
            <div id="driverList"></div>
        </div>
 
        <!-- 地图容器 -->
        <div id="map-container"></div>
    </div>
 
    <!-- 引入必要的脚本 -->
    <script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
    <script src="https://cdn.jsdelivr.net/npm/flatpickr/dist/l10n/zh.js"></script>
    <script type="text/javascript">
        window._AMapSecurityConfig = {
            securityJsCode: '0cd5c54ea05e8eae8f4ff513c2aa078b',
        }
    </script>
    <script type="text/javascript" src="https://webapi.amap.com/maps?v=2.0&key=825b92eb08c887698726c99c27accf3a&plugin=AMap.AutoComplete,AMap.PlaceSearch,AMap.Geocoder,AMap.CitySearch"></script>
    
</body>
</html>
<script>
// 定义获取司机列表的函数
// 修改 fetchDrivers 函数,添加加载状态
function fetchDrivers(center, radius) {
    // 显示加载中状态
    var driverList = document.getElementById('driverList');
    driverList.innerHTML = '<div class="loading-state">正在搜索附近司机...</div>';
 
    var ajax = new $ax(Feng.ctxPath + "/tOrder/getDriversByScope", function (data) {
        console.log("司机数据", data);
        if (data && data.length > 0) {
            displayDrivers(data);
        } else {
            // 没有找到司机时显示提示
            driverList.innerHTML = '<div class="empty-state">该范围内暂无可用司机</div>';
        }
    }, function (data) {
        Feng.error("获取司机失败!" + data.responseJSON.message + "!");
        // 请求失败时显示错误提示
        driverList.innerHTML = '<div class="error-state">获取司机列表失败,请重试</div>';
    });
    ajax.set('startLng', center[1]);
    ajax.set('startLat', center[0]);
    ajax.set('radiusValue', radius);
    ajax.start();
}
// 获取选中的司机ID数组
function getSelectedDriverIds() {
    var selectedIds = [];
    var checkboxes = document.getElementsByClassName('driver-checkbox');
 
    for (var i = 0; i < checkboxes.length; i++) {
        if (checkboxes[i].checked) {
            var driverId = checkboxes[i].getAttribute('data-id');
            if (driverId) {
                selectedIds.push(driverId);
            }
        }
    }
 
    return selectedIds;
}
function createOrder() {
    console.log("创建订单")
    if ($("#appointmentAddress").val()==''|| $("#destinationAddress").val()==null){
        Feng.info("请输入起点");
        return;
    }
    // if ($("#destinationAddress").val()==''|| $("#destinationAddress").val()==null){
    //     Feng.info("请输入终点");
    //     return;
    // }
    // var selectedDrivers = getSelectedDriversList();
    // if (selectedDrivers.length === 0){
    //     Feng.info("请选择司机");
    //     return ;
    // }
    if ($("#customerPhone").val()==''|| $("#customerPhone").val()==null){
        Feng.info("请输入客户电话");
        return;
    }
    if ($("#customerName").val()==''|| $("#customerName").val()==null){
        Feng.info("请输入客户姓名");
        return;
    }
 
 
    // 逗号拼接
    // 显示加载中状态
    var radiusValue = document.getElementById('radiusValue');
 
    var ajax = new $ax(Feng.ctxPath + "/tOrder/pushOrder", function (data) {
        if(data == 501){
            Feng.info("当前用户已存在进行中订单!");
            return;
        }else{
            Feng.success("创建订单成功!");
        }
    }, function (data) {
        if(data == 501){
            Feng.info("当前用户已存在进行中订单!");
            return;
        }
    });
    ajax.set('startLng', currentCenter[1]);
    ajax.set('startLat', currentCenter[0]);
    ajax.set('startAddress', $("#appointmentAddress").val());
    ajax.set('endLng', currentDe[1]);
    ajax.set('endLat', currentDe[0]);
    ajax.set('endAddress', $("#destinationAddress").val());
    ajax.set('radiusValue', radiusValue.value);
    ajax.set('phone', $("#customerPhone").val());
    ajax.set('nickName', $("#customerName").val());
    var selectedDrivers = getSelectedDriversList();
    if (selectedDrivers.length != 0){
        var selectedDriversStr = selectedDrivers.join(',');
        ajax.set("driverIds", selectedDriversStr);
    }else{
        ajax.set("driverIds", "");
    }
    ajax.set("remarks", $("#remarks").val());
    ajax.start();
}
 
    // 添加CSS样式
const style = document.createElement('style');
style.textContent = `
    .sug-result {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: white;
        border: 1px solid #ddd;
        border-radius: 0 0 4px 4px;
        max-height: 200px;
        overflow-y: auto;
        z-index: 1001;
        box-shadow: 0 2px 6px rgba(0,0,0,0.1);
    }
 
    .sug-item {
        padding: 8px 12px;
        cursor: pointer;
        border-bottom: 1px solid #eee;
    }
 
    .sug-item:last-child {
        border-bottom: none;
    }
 
    .sug-item:hover {
        background-color: #f5f5f5;
    }
 
    .input-group {
        position: relative;
        margin-bottom: 10px;
    }
`;
document.head.appendChild(style);
    // 添加 initDateTimePicker 函数的定义
function initDateTimePicker() {
    // 确保已经引入了 flatpickr
    if (typeof flatpickr !== 'undefined') {
        // 初始化中文语言包
        flatpickr.localize(flatpickr.l10ns.zh);
 
        // 初始化日期时间选择器
        flatpickr("#appointmentTime", {
            enableTime: true, // 启用时间选择
            dateFormat: "Y-m-d H:i:S", // 日期格式
            time_24hr: true, // 24小时制
            minuteIncrement: 1, // 分钟增量
            defaultDate: new Date(), // 默认当前时间
            locale: "zh", // 使用中文
            minDate: "today", // 最小日期为今天
            // 可以自定义时间范围
            minTime: "00:00:00",
            maxTime: "23:59:59"
        });
    } else {
        console.error('Flatpickr is not loaded. Please include the flatpickr library.');
    }
}
    // 修改后的完整 script.js
let map, circle, appointmentMarker, destinationMarker;
let driverMarkers = [];
let currentCenter = null;
let currentDe = [];
 
function initMap() {
    map = new AMap.Map('map-container', {
        zoom: 11,
        center: ["${lon}", "${lat}"], // 成都市中心坐标
        resizeEnable: true
    });
    window.driverMarkers = [];
 
    // 先初始化日期选择器,因为它不依赖地图插件
    initDateTimePicker();
 
    // 加载地图插件
    AMap.plugin(['AMap.PlaceSearch', 'AMap.AutoComplete', 'AMap.Geocoder'], function(){
        // 初始化地址输入框的自动完成功能
        initAutoComplete('appointmentAddress', 'appointmentSug', true);
        initAutoComplete('destinationAddress', 'destinationSug', false);
        initRadiusControl();
    });
    // 添加地图加载完成的回调
    map.on('complete', function() {
        console.log('地图加载完成');
    });
}
 
// 修改后的关键函数
function initAutoComplete(inputId, sugId, isAppointment) {
    var input = document.getElementById(inputId);
    var sugDiv = document.getElementById(sugId);
 
    // 创建自动完成实例,移除城市限制
    var autoComplete = new AMap.AutoComplete({
        input: null,  // 不直接绑定输入框
        citylimit: false,  // 关闭城市限制
        datatype: 'all'    // 返回所有数据类型
    });
 
    // 监听输入变化
    input.addEventListener('input', function() {
        var keyword = this.value.trim();
        if (keyword.length > 0) {
            autoComplete.search(keyword, function(status, result) {
                if (status === 'complete' && result.tips) {
                    // 显示搜索建议
                    var html = '';
                    for (var i = 0; i < result.tips.length; i++) {
                        var tip = result.tips[i];
                        if (tip.name || tip.district) {
                            html += '<div class="sug-item" data-name="' + tip.name + '" data-district="' +
                                (tip.district || '') + '" data-location="' +
                                (tip.location ? [tip.location.lng, tip.location.lat].join(',') : '') + '">' +
                                tip.name +
                                (tip.district ? ' <span style="color: #666;">(' + tip.district + ')</span>' : '') +
                                '</div>';
                        }
                    }
                    sugDiv.innerHTML = html;
                    sugDiv.style.display = 'block';
                }
            });
        } else {
            sugDiv.style.display = 'none';
        }
    });
 
    // 点击其他地方时隐藏联想列表
    document.addEventListener('click', function(e) {
        if (!input.contains(e.target) && !sugDiv.contains(e.target)) {
            sugDiv.style.display = 'none';
        }
    });
 
    // 点击选择地址
    sugDiv.addEventListener('click', function(e) {
        var target = e.target.closest('.sug-item');
        if (target) {
            var name = target.getAttribute('data-name');
            var district = target.getAttribute('data-district');
            var locationStr = target.getAttribute('data-location');
            input.value = name + (district ? ' ' + district : '');
            sugDiv.style.display = 'none';
 
            // 如果有位置信息,直接使用
            if (locationStr) {
                var location = locationStr.split(',').map(Number);
                if (isAppointment) {
                    setAppointmentLocation(location);
                } else {
                    setDestinationLocation(location);
                }
            } else {
                // 如果没有位置信息,使用地理编码服务
                var geocoder = new AMap.Geocoder();
                geocoder.getLocation(input.value, function(status, result) {
                    if (status === 'complete' && result.geocodes.length) {
                        var location = result.geocodes[0].location;
                        var lnglat = [location.lng, location.lat];
                        if (isAppointment) {
                            setAppointmentLocation(lnglat);
                        } else {
                            setDestinationLocation(lnglat);
                        }
                    }
                });
            }
        }
    });
}
// 修改设置预约地点的函数
function setAppointmentLocation(lnglat) {
    if (!lnglat || !Array.isArray(lnglat) || lnglat.length !== 2) {
        console.error('Invalid location coordinates');
        return;
    }
 
    if (appointmentMarker) {
        appointmentMarker.setMap(null);
    }
 
    appointmentMarker = new AMap.Marker({
        position: lnglat,
        map: map,
        animation: 'AMAP_ANIMATION_DROP'
    });
 
    currentCenter = lnglat;
    map.setCenter(lnglat);
    updateSearchCircle(lnglat);
    searchNearbyDrivers(lnglat);
}
function setDestinationLocation(lnglat) {
    console.log('设置目的地点:', lnglat); // 调试日志
    currentDe = lnglat;
    console.log("常量")
    console.log(currentDe)
    if (!lnglat || !Array.isArray(lnglat) || lnglat.length !== 2) {
        console.error('Invalid location coordinates');
        return;
    }
    // 更新目的地
}
// 修改更新搜索范围的函数
// 修改 updateSearchCircle 函数
function updateSearchCircle(center) {
    if (!center) return;
 
    // 清除旧的圆形区域
    if (circle) {
        circle.setMap(null);
    }
 
    // 获取当前搜索范围值
    var radius = parseFloat(document.getElementById('radiusSlider').value) * 1000; // 转换为米
 
    // 创建新的圆形区域
    circle = new AMap.Circle({
        center: center,
        radius: radius,
        strokeColor: "#1890FF",
        strokeWeight: 2,
        strokeOpacity: 0.6,
        fillColor: "#1890FF",
        fillOpacity: 0.1,
        zIndex: 50
    });
 
    circle.setMap(map);
    // 调整地图视野以包含整个圆形区域
    map.setFitView([circle]);
}
 
// 初始化范围滑块控制
// 修改范围滑块控制函数
function initRadiusControl() {
    var slider = document.getElementById('radiusSlider');
    var radiusValue = document.getElementById('radiusValue');
 
    // 使用定时器来控制请求频率
    var timer = null;
 
    // 监听滑块值变化
    slider.addEventListener('input', function() {
        // 更新显示的数值
        radiusValue.textContent = this.value;
 
        if (currentCenter) {
            // 更新搜索圈
            updateSearchCircle(currentCenter);
        }
    });
 
    // 监听滑块释放事件
    slider.addEventListener('change', function() {
        if (currentCenter) {
            // 重新查询司机
            fetchDrivers(currentCenter, this.value);
        }
    });
}
 
// 修改搜索附近司机的函数
function searchNearbyDrivers(center) {
    if (!center) return;
    var radius = parseFloat(document.getElementById('radiusSlider').value);
    fetchDrivers(center, radius);
}
// 清除司机标记
// 清除现有的司机标记
function clearDriverMarkers() {
    for (var i = 0; i < driverMarkers.length; i++) {
        if (driverMarkers[i]) {
            driverMarkers[i].setMap(null);
        }
    }
    driverMarkers = [];
}
function displayDrivers(data) {
    // 更新司机列表
    updateDriverList(data);
 
    // 在地图上添加标记
    for (var i = 0; i < data.length; i++) {
        addDriverMarker(data[i]);
    }
}
// 创建司机标记的HTML内容
function createDriverMarkerContent() {
    return '<div class="driver-marker" style="background: white; border-radius: 50%; padding: 5px; box-shadow: 0 2px 6px rgba(0,0,0,0.2); border: 2px solid #1890FF;">' +
        '<img src="https://webapi.amap.com/images/car.png" ' +
        'style="width: 15px; height: 15px; display: block;">' +
        '</div>';
}
// 添加单个司机标记
function addDriverMarker(driver) {
    // 创建标记
    var marker = new AMap.Marker({
        position: [driver.latitude, driver.longitude], // 注意经纬度顺序
        map: map,
        content: createDriverMarkerContent(),
        offset: new AMap.Pixel(-15, -15)
    });
 
    // 创建信息窗体
    var infoWindow = new AMap.InfoWindow({
        content: createDriverInfoWindowContent(driver),
        offset: new AMap.Pixel(0, -20)
    });
 
    // 绑定点击事件
    marker.on('click', function() {
        infoWindow.open(map, marker.getPosition());
    });
 
    // 保存标记引用
    driverMarkers.push(marker);
}
// 创建信息窗体的HTML内容
function createDriverInfoWindowContent(driver) {
    return '<div class="driver-info-window" style="padding: 10px; min-width: 200px;">' +
        '<div class="info-item"><label>司机:</label>' + driver.name + '</div>' +
        '<div class="info-item"><label>距离:</label>' + driver.distance + 'km</div>' +
        '<div class="info-item"><label>电话:</label>' + driver.phone + '</div>' +
        '</div>';
}
// 更新司机列表显示
// 更新司机列表显示函数
function updateDriverList(drivers) {
    var driverList = document.getElementById('driverList');
    var html = '<div class="driver-table">' +
        '<div class="driver-table-header">' +
        '<div class="col-checkbox"><input type="checkbox" id="checkAll"></div>' +
        '<div class="col-name">司机名称</div>' +
        '<div class="col-distance">距离(km)</div>' +
        '<div class="col-phone">手机号</div>' +
        '</div>' +
        '<div class="driver-table-body">';
 
    for (var i = 0; i < drivers.length; i++) {
        var driver = drivers[i];
        html += '<div class="driver-row">' +
            '<div class="col-checkbox">' +
            '<input type="checkbox" class="driver-checkbox" value="' + driver.id + '">' +
            '</div>' +
            '<div class="col-name">' + driver.name + '</div>' +
            '<div class="col-distance">' + driver.distance + '</div>' +
            '<div class="col-phone">' + driver.phone + '</div>' +
            '</div>';
    }
 
    html += '</div></div>';
    driverList.innerHTML = html;
 
    // 获取所有复选框
    var checkAll = document.getElementById('checkAll');
    var checkboxes = document.getElementsByClassName('driver-checkbox');
 
    // 全选框事件
    checkAll.onclick = function() {
        var isChecked = this.checked;
        for (var i = 0; i < checkboxes.length; i++) {
            checkboxes[i].checked = isChecked;
        }
    };
 
    // 单个复选框事件
    for (var i = 0; i < checkboxes.length; i++) {
        checkboxes[i].onclick = function() {
            // 检查是否全部选中
            var allChecked = true;
            for (var j = 0; j < checkboxes.length; j++) {
                if (!checkboxes[j].checked) {
                    allChecked = false;
                    break;
                }
            }
            checkAll.checked = allChecked;
        };
    }
}
// 更新选中的司机(每次选择变化时调用)
function updateSelectedDrivers() {
    var selectedIds = getSelectedDriverIds();
    console.log('选中的司机ID:', selectedIds);
    // 存储到全局变量
    window.selectedDriverIds = selectedIds;
}
 
// 获取选中的司机ID数组
function getSelectedDrivers() {
    var selectedIds = [];
    var checkboxes = document.getElementsByClassName('driver-checkbox');
 
    for (var i = 0; i < checkboxes.length; i++) {
        if (checkboxes[i].checked) {
            selectedIds.push(checkboxes[i].value);
        }
    }
 
    return selectedIds;
}
function getSelectedDriversList() {
    var selectedDrivers = getSelectedDrivers();
    if (selectedDrivers && selectedDrivers.length > 0) {
        console.log('当前选中的司机ID:', selectedDrivers);
        return selectedDrivers;
    } else {
 
        return [];
    }
}
// 高亮选中的司机
function highlightSelectedDriver(driverId) {
    // 移除所有司机项的高亮
    var items = document.getElementsByClassName('driver-item');
    for (var i = 0; i < items.length; i++) {
        items[i].classList.remove('selected');
    }
 
    // 添加选中项的高亮
    var selectedItem = document.getElementById('driver_' + driverId).closest('.driver-item');
    if (selectedItem) {
        selectedItem.classList.add('selected');
    }
}
// 清除司机标记
function clearDriverMarkers() {
    for (var i = 0; i < driverMarkers.length; i++) {
        if (driverMarkers[i] && driverMarkers[i].getMap()) {
            driverMarkers[i].setMap(null);
        }
    }
    driverMarkers = [];
}
// 创建司机标记的HTML内容
 
// 更新司机列表显示
 
// 页面加载完成后初始化
document.addEventListener('DOMContentLoaded', initMap);
</script>
@}