lmw
2023-03-11 4df5bb59e5fe9f9d140e5610f7772dd8a05a28d4
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
package com.fuban.driver.ui.main.small_cargo
 
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.view.View
import cn.sinata.xldutils.utils.*
import com.amap.api.location.AMapLocationListener
import com.amap.api.maps.AMap
import com.amap.api.maps.model.LatLng
import com.amap.api.maps.model.Marker
import com.amap.api.maps.model.Polyline
import com.fuban.driver.R
import com.fuban.driver.base.BaseEvent
import com.fuban.driver.base.MyApplication
import com.fuban.driver.base.MyBaseActivity
import com.fuban.driver.base.gaode.AMapKit
import com.fuban.driver.base.gaode.AMapKit.addMarker
import com.fuban.driver.base.gaode.AMapKit.getIcon
import com.fuban.driver.base.gaode.AMapKit.getTimeType
import com.fuban.driver.base.gaode.AMapKit.initMap
import com.fuban.driver.base.gaode.AMapKit.moveCamera
import com.fuban.driver.base.gaode.gpsnav.GPSNaviActivity
import com.fuban.driver.bean.OrderBean
import com.fuban.driver.bean.OrderSimpleData
import com.fuban.driver.bean.RessignBean
import com.fuban.driver.netUtls.*
import com.fuban.driver.ui.DialogUtil
import com.fuban.driver.ui.main.FillOutActivity
import com.fuban.driver.ui.main.OrderOverActivity
import com.fuban.driver.ui.main.ReassignActivity
import com.fuban.driver.utils.DateUtil
import com.fuban.driver.utils.MyUtils
import com.google.gson.Gson
import com.trello.rxlifecycle3.android.ActivityEvent
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import kotlinx.android.synthetic.main.activity_trip.*
import kotlinx.android.synthetic.main.activity_trip.iv_move
import kotlinx.android.synthetic.main.activity_trip.iv_police
import kotlinx.android.synthetic.main.activity_trip.iv_to_gd
import kotlinx.android.synthetic.main.activity_trip.map_view
import kotlinx.android.synthetic.main.activity_trip.slide_btn
import kotlinx.android.synthetic.main.activity_trip_cargo.*
import kotlinx.android.synthetic.main.dialog_select_pay_type.view.*
import kotlinx.android.synthetic.main.dialog_show_cargo_money.view.*
import kotlinx.android.synthetic.main.dialog_show_cha_money.view.*
import kotlinx.android.synthetic.main.include_order_top_cargo.*
import kotlinx.android.synthetic.main.item_map_market.view.*
import org.greenrobot.eventbus.EventBus
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.toast
import java.util.*
import java.util.concurrent.TimeUnit
 
 
class SmallCargoActivity : MyBaseActivity() {
    /***
     *     1=待接单,2=待出发,3=待到达预约地点,4=待取货,5=送货中,6=已送达,7=待支付,8=需补差价,9=已取货,10=已取消,11=改派中,12=已支付差价
 
    integer($int32)
    订单状态(1=待接单,2=待出发,3=待到达预约地点,4=待乘客上车,5=服务中,6=完成服务,7=待支付,8=待评价,9=已完成,10=已取消,11=改派中,12=取消待支付)
     */
 
    /***
     * //    流程操作状态(3=开始出发预约点,4=到达预约点,5=开始服务,6=服务结束)
     * 页面一共4个marker 1:预约地点 2:起点 3终点 4:司机点
     */
    val orderType by lazy {
        intent.getStringExtra("orderType")
    }
 
    val orderId by lazy {
        intent.getStringExtra("orderId")
    }
    var isTimeStart = false //限制计时器
 
 
    var makeMarker: Marker? = null
    var startMarker: Marker? = null
    var endMarker: Marker? = null
    var carMarker: Marker? = null
    var markerLine: Polyline? = null
    lateinit var aMap: AMap
    lateinit var orderBean: OrderBean
 
 
    override fun setContentView() {
        setContentView(R.layout.activity_trip_cargo)
    }
 
    override fun initView() {
        setTitleText("准备出发-去接客户-等待客户-服务中")
        tv_Right.text = "申请改派"
        callOrder()
        initMineLocation()
        onclick()
        addSockectCancel()
        MyApplication.getInstance()!!.initUpPoint()
    }
 
    private fun addSockectCancel() {
        checkOrderStatue()
        MyApplication.addOrderView(viewOrder)
    }
 
    var viewOrder = object : MyApplication.OrderStatueView {
        override fun orderInfo(data: OrderSimpleData?) {
            data?.let {
                if (it.orderType == 4 || it.orderType == 5){
                    if (it.status == 10 || it.status == 11) {
                        Handler(Looper.getMainLooper()).post {
                            if (it.status == 10) {
                                MyApplication.getTTsManager().setVideoText("用户已取消订单")
                            } else {
                                MyApplication.getTTsManager().setVideoText("用户已改派订单")
                            }
                            finish()
                        }
                    }
                    if (it.orderId.toString() == orderId && (it.status != 10 && it.status != 11)) {
                        Handler(Looper.getMainLooper()).post {
                            callOrder()
                        }
                    }
                }
            }
        }
    }
 
 
    var handler: Handler? = null
    fun checkOrderStatue() {
        var map = getMapByAny()
        map["orderId"] = orderId
        map["orderType"] = orderType
        callNet(false, Api.orderStateSocket, map) {
            val orderSimpleData =
                Gson().fromJson(
                    it,
                    OrderSimpleData::class.java
                )
            orderSimpleData?.let {
                if (it.status == 10 || it.status == 12) {
                    Handler(Looper.getMainLooper()).post {
                        MyApplication.getTTsManager().setVideoText("用户已取消订单")
                        finish()
                    }
                }
            }
 
        }
        handler?.postDelayed({ checkOrderStatue() }, 3000)
    }
 
 
    override fun onBackPressed() {
        EventBus.getDefault().post(BaseEvent(BaseEvent.UPDATA_MAIN_CAR))
        super.onBackPressed()
    }
 
    override fun finish() {
        EventBus.getDefault().post(BaseEvent(BaseEvent.UPDATA_MAIN_CAR))
        super.finish()
    }
 
    private fun onclick() {
        tv_Right.clickDelay {
            var map = getMapByAny()
            map["orderId"] = orderId
            map["orderType"] = orderType
            callNet(Api.queryReassignMoney, map) {
                val data = gson.fromJson<RessignBean>(it, RessignBean::class.java)
                if (data.data.amount.isNullOrEmpty()) {
                    startActivity<ReassignActivity>(
                        "orderId" to orderId,
                        "orderType" to orderType
                    )
                } else {
                    DialogUtil.getDelAndSureDialog(
                        this,
                        "现在改派将收取" + data.data.amount + "元改派费,您是否要进行改派?",
                        {},
                        {
                            //跳转改派页面
                            startActivity<ReassignActivity>(
                                "orderId" to orderId,
                                "orderType" to orderType,
                                "money" to data.data.amount.toString()
                            )
                        })
                }
 
 
            }
        }
 
        tv_gap_money.clickDelay {
            if (orderBean.data.orderState == 12) {
                toast("用户已支付差价,不能修改")
                return@clickDelay
            }
            var dialog = DialogUtil.getDialog(this, R.layout.dialog_show_cha_money)
            var viewContent = DialogUtil.getView(dialog)
            viewContent.view_hint_close_car_cha.setOnClickListener {
                dialog.dismiss()
            }
            viewContent.tv_car_num_close_cha.setOnClickListener {
                dialog.dismiss()
            }
            viewContent.tv_sure_car_num_cha.setOnClickListener {
                var num = viewContent.et_num_zg_cha.getContent()
                if (num.isEmpty()) {
                    toast("请输入金额")
                    return@setOnClickListener
                }
                if (num.toDouble() > 9999) {
                    toast("金额不能大于9999元")
                    return@setOnClickListener
                }
                if (num.toDouble() <= 0) {
                    toast("金额不能小于0元")
                    return@setOnClickListener
                }
                callseatmoney(num) {
                    dialog.dismiss()
                    tv_gap_money.text = "¥" + doubleTwo(num.toDouble()) + " 差价"
                    tv_gap_money.setDrawableNull()
                    tv_gap_money.setDrawableRight(R.mipmap.fill_cj)
                    orderBean.let {
                        it.data.orderState = 8
                    }
                    toast("设置成功")
                }
            }
        }
        iv_move.setOnClickListener {
            orderBean.let {
                when (it.data.orderState) {
                    2, 3 -> {
                        moveCamera(aMap, makeMarker!!.position, carMarker!!.position)
                    }
                    4 -> {
                        moveCamera(aMap, carMarker!!.position)
                    }
                    5, 6 -> {
                        moveCamera(aMap, carMarker!!.position, endMarker!!.position)
                    }
                }
            }
        }
 
        iv_police.clickDelay {
            orderBean.let {
                MyUtils.getInstans().CallPhone(this, it.data.emergencyCall)
            }
        }
 
 
        iv_to_gd.clickDelay {
            orderBean.let {
                when (it.data.orderState) {
                    2, 3 -> {
//                        startAMapNavi(makeMarker!!)
                        startActivity<GPSNaviActivity>(
                            "start" to carMarker!!.position,
                            "end" to makeMarker!!.position
                        )
 
                    }
 
                    4 -> {
                        showToast("没有终点,无法导航")
                    }
 
                    5, 6 -> {
//                        startAMapNavi(endMarker!!)
                        startActivity<GPSNaviActivity>(
                            "start" to carMarker!!.position,
                            "end" to endMarker!!.position
                        )
                    }
                }
            }
        }
 
        //        *     1=待接单,2=待出发,3=待到达预约地点,4=待取货,5=送货中,6=已送达,7=待支付,8=需补差价,9=已取货,10=已取消,11=改派中,12=已支付差价
        slide_btn.onSwipeListener = {
            orderBean.let {
                when (it.data.orderState) {
                    2, 3, 4 -> {
                        it.data.orderState++
                        callStatue(it.data.orderState) {}
                        showStatueMapUI(it)
                    }
 
                    5, 6 -> {
                        sendCode() {
                            it.data.orderState = 6
                            var dialog =
                                DialogUtil.getDialog(this, R.layout.dialog_show_cargo_money)
                            var viewContent = DialogUtil.getView(dialog)
                            viewContent.view_hint_close_car.setOnClickListener {
                                dialog.dismiss()
                            }
                            viewContent.tv_car_num_close.setOnClickListener {
                                dialog.dismiss()
                            }
                            viewContent.tv_sure_car_num.setOnClickListener {
                                var num = viewContent.et_num_zg.getContent()
                                if (num.isEmpty()) {
                                    toast("请输入验证码")
                                    return@setOnClickListener
                                }
                                callNumberCargo(num) {
                                    dialog.dismiss()
                                    callStatue(orderBean.data.orderState) {
                                        startActivity<SmallOverActivity>(
                                            "orderId" to orderId,
                                            "orderType" to orderType
                                        )
                                        finish()
                                    }
 
                                }
                            }
                        }
                    }
                    12 -> {
                        it.data.orderState = 5
                        callStatue(it.data.orderState) {}
                        showStatueMapUI(it)
                    }
 
                    8 -> {
                        toast("等待用户支付差价")
                    }
                    else -> {
 
                    }
                }
            }
        }
 
        iv_phone.clickDelay {
            orderBean.let {
                Utils.callPhone(this, it.data.phone)
            }
        }
    }
 
    private fun sendCode(function: () -> Unit) {
        var map = getMapByAny()
        map["orderId"] = orderId
        callNet(Api.sendVerificationCode, map) {
            function()
        }
    }
 
    private fun callNumberCargo(num: String, click: () -> Unit) {
        var map = getMapByAny()
        map["orderId"] = orderId
        map["pickUpCode"] = num
        callNet(Api.fillInPickUpCode, map) {
            click()
        }
    }
 
 
    private fun callseatmoney(num: String, click: () -> Unit) {
        var map = getMapByAny()
        map["orderId"] = orderId
        map["difference"] = doubleTwo(num.toDouble())
        callNet(Api.makeUpTheDifference, map) {
            click()
        }
    }
 
    private fun callStatue(i: Int, click: () -> Unit) {
        var map = getMapByAny()
        map["orderId"] = orderId
        map["orderType"] = orderType
        map["state"] = i
        map["lat"] = MyApplication.getLocation().latitude
        map["lon"] = MyApplication.getLocation().longitude
        callNet(Api.process, map) {
            click()
        }
    }
 
 
    private fun showMoneyTypeDialog() {
        var pop = DialogUtil.getPopupwindow(this, R.layout.dialog_select_pay_type)
        var payType = 1 //支付方式(1=快运平台收款,2=其他方式收款)
        pop.showDown(window.decorView)
        pop.contentView.tv_cancel.setOnClickListener {
            pop.dismiss()
        }
        pop.contentView.tv_ok.setOnClickListener {
            pop.dismiss()
            if (payType == 1) {
                callStatue(6) {
                    startActivity<FillOutActivity>("orderId" to orderId, "orderType" to orderType)
                    finish()
                }
            } else {
                DialogUtil.getDelAndSureDialog(this, "请确定是否收款?", {}, {
                    pop.dismiss()
                    val map = getMapByAny()
                    map["orderId"] = orderId
                    map["orderType"] = orderType
                    map["type"] = payType
                    callStatue(6) {
                        callNet(Api.confirmFees, map) {
                            finish()
                            startActivity<OrderOverActivity>(
                                "orderId" to orderId,
                                "orderType" to orderType
                            )
                        }
                    }
                })
            }
        }
        pop.contentView.tv_select_ok.setOnClickListener {
            pop.contentView.tv_select_ok.alpha = 1f
            pop.contentView.tv_select_ok.textSize = 16f
            pop.contentView.tv_select_or.alpha = 0.6f
            pop.contentView.tv_select_or.textSize = 14f
            payType = 1
        }
        pop.contentView.tv_select_or.setOnClickListener {
            pop.contentView.tv_select_ok.alpha = 0.6f
            pop.contentView.tv_select_ok.textSize = 14f
            pop.contentView.tv_select_or.alpha = 1f
            pop.contentView.tv_select_or.textSize = 16f
            payType = 2
        }
    }
 
 
    /***
     * 定位时司机与线路的改变
     */
    private fun initMineLocation() {
        AMapKit.initLocation(this, AMapLocationListener {
            it?.let {
                MyApplication.aMapLocation = it
                carMarker!!.position = LatLng(it.latitude, it.longitude)
            }
            orderBean.let {
                when (it.data.orderState) {
                    2, 3 -> {
                        changeCarThree(false)
                    }
                    5, 6 -> {
                        changeCarFive(false)
                    }
                }
            }
        })
    }
 
    private fun changeCarThree(isMove: Boolean) {
        if (makeMarker != null && carMarker != null) {
            AMapKit.initRouteLine(
                this,
                makeMarker!!.position,
                carMarker!!.position,
                object : (MutableList<LatLng>, Float, Long) -> Unit {
                    override fun invoke(p1: MutableList<LatLng>, p2: Float, p3: Long) {
                        var view = creatCarView("距预约点" + AMapKit.getTance(p2))
                        carMarker!!.setIcon(getIcon(view))
                        addline(p1)
                        if (isMove)
                            moveCamera(aMap, makeMarker!!.position, carMarker!!.position)
                    }
                })
        }
    }
 
    private fun changeCarFive(isMove: Boolean) {
        if (carMarker != null && endMarker != null) {
            AMapKit.initRouteLine(
                this,
                carMarker!!.position,
                endMarker!!.position,
                object : (MutableList<LatLng>, Float, Long) -> Unit {
                    override fun invoke(p1: MutableList<LatLng>, p2: Float, p3: Long) {
                        addline(p1)
                        var view =
                            creatCarView("剩余" + AMapKit.getTance(p2) + "\n" + "预计还需" + p3.toInt() + "分钟")
                        carMarker!!.setIcon(getIcon(view))
                        if (isMove) {
                            moveCamera(aMap, carMarker!!.position, endMarker!!.position)
                        }
                    }
                })
        }
    }
 
    private fun callOrder() {
        var map = getMapByAny()
        map["orderId"] = orderId
        map["orderType"] = orderType
        callNet(Api.queryOrderInfo, map) {
            orderBean = gson.fromJson(it, OrderBean::class.java)
            showUi(orderBean)
        }
    }
 
    private fun showUi(orderBean: OrderBean?) {
        orderBean?.let {
            tv_name.text = orderBean.data.nickName
            tv_car_num.text = it.data.historyNum.toString() + "次寄物"
            tv_time.text = it.data.travelTime_
            tv_start_address.text = it.data.startAddress
            tv_end_address.text = it.data.endAddress
            showStatueMapUI(it)
            var cargoStrType = if (orderBean.data.cargoType == "1") "普通小件X" else "普通大件X"
            tv_tv_num_cargo.text = cargoStrType + orderBean.data.peopleNumber
            tv_people_cargo.text = orderBean.data.nickName + "-" + orderBean.data.phone
            if (orderBean.data.tipMoney != null && orderBean.data.tipMoney > 0.0) {
                tv_money_cargo.text = doubleTwo(orderBean.data.tipMoney) + "元加急费"
            } else {
                tv_money_cargo.gone()
            }
            if (!it.data.differenceMoney.isNullOrEmpty() && it.data.differenceMoney.toDouble() > 0) {
                tv_gap_money.text = "¥" + doubleTwo(it.data.differenceMoney.toDouble()) + " 差价"
                tv_gap_money.setDrawableNull()
                tv_gap_money.setDrawableRight(R.mipmap.fill_cj)
            }
        }
    }
 
    private fun getAllMark(it: OrderBean) {
        if (makeMarker == null) {
            val view = createView(R.layout.item_map_market_make, this)
            view.iv_img.setImageResource(R.mipmap.trip_yuyue)
            makeMarker = addMarker(aMap, it.data.startLat, it.data.startLon, view, "")
        }
        makeMarker!!.isVisible = false
        if (startMarker == null) {
            val view = createView(R.layout.item_map_market, this)
            view.iv_img.setImageResource(R.mipmap.starting_point)
            startMarker = addMarker(aMap, it.data.startLat, it.data.startLon, view, "")
        }
        startMarker!!.isVisible = false
        if (endMarker == null) {
            val view = createView(R.layout.item_map_market, this)
            view.iv_img.setImageResource(R.mipmap.end_point)
            endMarker = addMarker(aMap, it.data.endLat, it.data.endLon, view, "")
        }
        endMarker!!.isVisible = false
        if (carMarker == null) {
            val carView = creatCarView("")
            carMarker = addMarker(
                aMap,
                MyApplication.getLocation().latitude,
                MyApplication.getLocation().longitude,
                carView,
                ""
            )
        }
        carMarker!!.isVisible = false
        if (markerLine != null) {
            markerLine!!.isVisible = false
        }
    }
 
    fun creatCarView(content: String): View {
        val carView = createView(R.layout.item_map_market, this)
        carView.iv_img.setImageResource(R.mipmap.car_trip)
        carView.tv_hint.visible()
        carView.tv_hint.text = content
        return carView
    }
 
    fun creatCarViewHint(content: String): View {
        val carView = createView(R.layout.item_map_market, this)
        carView.iv_img.setImageResource(R.mipmap.car_trip)
        carView.tv_hint.visible()
        carView.tv_hint.setColorBuild(this, content, R.color.main_yellow, 4, content.length)
        return carView
    }
 
    //    流程操作状态(3=开始出发预约点,4=到达预约点,5=开始服务,6=服务结束)
    private fun showStatueMapUI(it: OrderBean) {
        getAllMark(it)
        tv_gap_money.gone()
        if (it.data.orderState == 4 || it.data.orderState == 8 || it.data.orderState == 12) {
            tv_gap_money.visible()
        }
        tv_Right.visible()
        when (it.data.orderState) {
            2, 3 -> {
                if (it.data.reassign == 1) {
                    tv_Right.gone()
                }
                iv_to_gd.visible()
                makeMarker?.isVisible = true
                carMarker?.isVisible = true
                changeCarThree(true)
                closeTimeStart()
                if (it.data.orderState == 2) {
                    slide_btn.changeButtonText("出发前往预约地点")
                    setTitleText("准备出发")
                } else {
                    slide_btn.changeButtonText("到达预约地点")
                    setTitleText("去领取货物")
                }
            }
            4, 8, 12 -> {
                iv_to_gd.gone()
                if (it.data.reassign == 1) {
                    tv_Right.gone()
                }
                closeLine()
                carMarker?.isVisible = true
                startTimeStart(
                    ((System.currentTimeMillis() - DateUtil.dateToStamp(
                        DateUtil.TYPE0,
                        it.data.waitTime
                    )) / 1000).toInt()
                )
                moveCamera(aMap, carMarker!!.position)
                setTitleText("等待取货")
                slide_btn.changeButtonText("确认收货")
            }
            5, 6 -> {
                closeTimeStart()
                iv_to_gd.visible()
                tv_Right.gone()
                startMarker?.isVisible = true
                endMarker?.isVisible = true
                carMarker?.isVisible = true
                changeCarFive(true)
                setTitleText("送货中")
                slide_btn.changeButtonText("确认送达")
            }
        }
    }
 
 
    private fun startTimeStart(waitTime: Int) {
        if (!isTimeStart) {
            isTimeStart = true
            refreshTime(waitTime) {
                var view = creatCarViewHint("您已等待" + getTimeType(it))
                carMarker!!.setIcon(getIcon(view))
            }
        }
    }
 
    private var timeDisposable: Disposable? = null
 
    private fun refreshTime(waitTime: Int, click: (num: Int) -> Unit) {
        if (null != timeDisposable && !timeDisposable!!.isDisposed) {
            timeDisposable!!.dispose()
        }
        timeDisposable = Observable
            .interval(1, TimeUnit.SECONDS)
            .take(100000000)
            .subscribeOn(Schedulers.computation())
            .observeOn(AndroidSchedulers.mainThread())
            .compose(bindUntilEvent(ActivityEvent.DESTROY))
            .subscribe { aLong ->
                var num = waitTime + aLong
                click(num.toInt())
            }
    }
 
    private fun closeTimeStart() {
        if (timeDisposable != null) {
            timeDisposable!!.dispose()
        }
    }
 
    override fun onDestroy() {
        super.onDestroy()
        if (handler != null) {
            handler?.removeCallbacksAndMessages(null)
        }
        MyApplication.removeOrderView(viewOrder)
        closeTimeStart()
    }
 
 
    private fun addline(allLine: MutableList<LatLng>) {
        closeLine()
        markerLine = AMapKit.drawLine(this, aMap, allLine)
    }
 
    fun closeLine() {
        if (markerLine != null) {
            markerLine!!.remove()
        }
    }
 
    fun getTance(startLatLng: LatLng, endLatLng: LatLng, onclick: (tance: Float) -> Unit) {
        AMapKit.initRouteLine(
            this,
            startLatLng,
            endLatLng,
            object : (MutableList<LatLng>, Float, Long) -> Unit {
                override fun invoke(p1: MutableList<LatLng>, p2: Float, p3: Long) {
                    onclick(p2)
                }
            })
    }
 
    override fun setOnclick() {
 
    }
 
 
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        aMap = initMap(savedInstanceState, map_view)
    }
 
    override fun onEventMainThread(event: BaseEvent?) {
        super.onEventMainThread(event)
        when (event!!.code) {
            BaseEvent.REAGASSIGN_SUCCESS -> {
                finish()
            }
            BaseEvent.BACK_CAR_OVER -> {
                finish()
            }
        }
    }
}