18034727885
2026-07-09 f35664f0ad753df3dc4ca3b47c2f91263973af34
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
package com.igo.user.ui.trip
 
//import com.share.utils.ShareUtils
//import com.umeng.socialize.UMShareListener
//import com.umeng.socialize.bean.SHARE_MEDIA
import android.annotation.SuppressLint
import android.app.Activity
import android.graphics.Typeface
import android.util.Log
import android.view.View
import android.widget.CheckBox
import android.widget.LinearLayout
import android.widget.TextView
import androidx.core.os.bundleOf
import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import cn.sinata.xldutils.callPhone
import cn.sinata.xldutils.gone
import cn.sinata.xldutils.hide
import cn.sinata.xldutils.invisible
import cn.sinata.xldutils.toBrowser
import cn.sinata.xldutils.utils.LanguageUtil
import cn.sinata.xldutils.utils.SPUtils
import cn.sinata.xldutils.utils.SpanBuilder
import cn.sinata.xldutils.utils.myToast
import cn.sinata.xldutils.utils.optDouble
import cn.sinata.xldutils.utils.optInt
import cn.sinata.xldutils.utils.showAllowingStateLoss
import cn.sinata.xldutils.visible
import com.facebook.drawee.view.SimpleDraweeView
import com.igo.user.IGoApplication
import com.igo.user.R
import com.igo.user.dialog.ChooseCardDialog
import com.igo.user.dialog.PayDialog
import com.igo.user.dialog.ShareDialog
import com.igo.user.dialog.SpecialSuggestDialog
import com.igo.user.dialog.TipDialog
import com.igo.user.interfaces.OrderStateChangeListener
import com.igo.user.interfaces.StringCallback
import com.igo.user.network.Apis
import com.igo.user.network.HttpManager
import com.igo.user.network.entity.Order
import com.igo.user.network.entity.TrippingInfo
import com.igo.user.network.request
import com.igo.user.ui.ShowPictureActivity
import com.igo.user.ui.TransparentStatusBarActivity
import com.igo.user.ui.crosscity.PayCrossActivity
import com.igo.user.ui.crosscity.ShuttleBusActivity
import com.igo.user.ui.trip.adapter.ExpressPictureAdapter
import com.igo.user.utils.Const
import com.igo.user.utils.IGoShareUtils
import com.igo.user.utils.pay.PayListener
import com.igo.user.utils.pay.PayUtil
import com.igo.user.utils.showMoney
import com.igo.user.views.CenterFlowLayout
import com.igo.user.views.RatingBar
import org.jetbrains.anko.find
import org.jetbrains.anko.sdk27.coroutines.onClick
import org.jetbrains.anko.startActivity
 
class OrderDetailActivity : TransparentStatusBarActivity(), OrderStateChangeListener,
    PayListener/*, UMShareListener*/ {
    override fun setContentView() = R.layout.activity_order_detail
 
    private val id by lazy {
        intent.getIntExtra("id", 0)
    }
    private val type by lazy {
        intent.getIntExtra("type", 0)
    }
    private val doPay by lazy { intent.getBooleanExtra("doPay", false) }
 
    private var order: Order? = null
    private var payMoney = 0.0//支付费用
    private var isGotoWx = false //是否跳转到微信小程序支付 true:回来时需要查询是否支付成功
 
    private var score = 0
    private val pickupAdapter by lazy { ExpressPictureAdapter(ArrayList<String>()) }
    private val deliveryAdapter by lazy { ExpressPictureAdapter(ArrayList<String>()) }
    private val iv_call by lazy { find<View>(R.id.iv_call) }
    private val tv_title1 by lazy { find<TextView>(R.id.tv_title1) }
    private val tv_detail by lazy { find<TextView>(R.id.tv_detail) }
    private val tv_pay_offline by lazy { find<TextView>(R.id.tv_pay_offline) }
    private val rating by lazy { find<RatingBar>(R.id.rating) }
    private val iv_header_home by lazy { find<SimpleDraweeView>(R.id.iv_header_home) }
    private val tv_start by lazy { find<TextView>(R.id.tv_start) }
    private val tv_end by lazy { find<TextView>(R.id.tv_end) }
    private val tv_time by lazy { find<TextView>(R.id.tv_time) }
    private val tv_name by lazy { find<TextView>(R.id.tv_name) }
    private val tv_car by lazy { find<TextView>(R.id.tv_car) }
    private val tv_car_info by lazy { find<TextView>(R.id.tv_car_info) }
    private val tv_score by lazy { find<TextView>(R.id.tv_score) }
    private val tv_count by lazy { find<TextView>(R.id.tv_count) }
    private val tv_passenger_num by lazy { find<TextView>(R.id.tv_passenger_num) }
    private val tv_remark by lazy { find<TextView>(R.id.tv_remark) }
    private val ll_pickup_picture by lazy { find<LinearLayout>(R.id.ll_pickup_picture) }
    private val rv_pickup by lazy { find<RecyclerView>(R.id.rv_pickup) }
    private val ll_delivery_picture by lazy { find<LinearLayout>(R.id.ll_delivery_picture) }
    private val rv_delivery by lazy { find<RecyclerView>(R.id.rv_delivery) }
    private val tv_tip by lazy { find<TextView>(R.id.tv_tip) }
    private val tv_title by lazy { find<TextView>(R.id.tv_title) }
    private val tv_money by lazy { find<TextView>(R.id.tv_money) }
    private val tv_frozen by lazy { find<TextView>(R.id.tv_frozen) }
    private val tv_action by lazy { find<TextView>(R.id.tv_action) }
    private val cl_evaluate by lazy { find<View>(R.id.cl_evaluate) }
    private val fl_label by lazy { find<CenterFlowLayout>(R.id.fl_label) }
    private val tv_confirm_fee by lazy { find<View>(R.id.tv_confirm_fee) }
 
 
    private val cl_driver by lazy { find<View>(R.id.cl_driver) }
 
 
    private var isCancel = false
    private var balance = -1.0
    private var coupon = 0
    private var redTotal = 0.0
    private var deductionAmount = 0.0
 
    private val app by lazy {
        application as IGoApplication
    }
 
    //订单状态(1=待接单,2=待出发,3=待到达预约地点,4=待乘客上车,5=服务中,6=完成服务,7=待支付,8=待评价,9=已完成,10=已取消,11=改派中,12=取消待支付)加个15作为改派成功
    override fun initClick() {
        iv_call.setOnClickListener {
            callPhone(order?.driverPhone)
        }
        tv_action.setOnClickListener {
            if ((balance >= 0 && order?.state == 7) || order?.state == 12 || (balance >= 0 && order?.state == 13)) {
                val payDialog = PayDialog()
                payDialog.arguments = bundleOf(
                    "isCancel" to (order?.state == 12),
                    "balance" to balance,
                    "coupon" to coupon,
                    "money" to payMoney,
                    "id" to id,
                    "type" to type,
                    "isFrozen" to (order?.isDispute == 1),
                    "discount" to order?.discountMoney,
                    "redTotal" to redTotal,
                    "deductionAmount" to deductionAmount,
                    "isLogistics" to (order?.state == 13),
                )
                payDialog.setCallback(object : PayDialog.Callback {
                    override fun onOk(way: Int, couponId: Int, useRed: Boolean) {
                        if (way == 2) {
                            val dialog = ChooseCardDialog()
                            dialog.setCallback(object : StringCallback {
                                override fun onRlt(rlt: String) {
                                    pay(way, couponId, rlt, useRed)
                                }
                            })
                            dialog.show(supportFragmentManager, "card")
                        } else
                            pay(way, couponId, null, useRed)
                        payDialog.dismiss()
                    }
 
                    override fun onClose() {
                    }
                })
                payDialog.show(supportFragmentManager, "pay")
            } else if (order?.state == 8) {
                HttpManager.orderEvaluate(id, score, type, checkList.joinToString(",") { it })
                    .request(this) { _, _ ->
                        setResult(Activity.RESULT_OK)
                        myToast(getString(R.string.评价成功))
                        tv_action.gone()
                        tv_title1.text = getString(R.string.评价详情)
                        getData()
                        getRedMoney()
                    }
            }
        }
        rating.setOnRatingChangeListener {
            if (!rating.clickable)
                return@setOnRatingChangeListener
            tv_action.visible()
            if (it.toInt() != score)
                inputLabel(it.toInt())
            score = it.toInt()
        }
        iv_header_home.setOnClickListener {
            if (order != null)
                startActivity<DriverDetailActivity>("id" to order!!.driverId)
        }
        tv_detail.onClick {
            startActivity<PriceDetailActivity>("order" to order)
        }
        tv_pay_offline.onClick {
//            val tipDialog = TipDialog()
//            tipDialog.arguments = bundleOf("msg" to "是否确认已线下支付费用?","ok" to "确认","cancle" to "取消")
//            tipDialog.setCallback(object :TipDialog.OnClickCallback{
//                override fun onOk() {
//                    HttpManager.completeOrder(id,type).request(this@OrderDetailActivity){_,_->
//                        onPaySuccess()
//                    }
//                }
//
//                override fun onCancel() {
//                }
//            })
//            tipDialog.show(supportFragmentManager,"offline")
        }
 
        pickupAdapter.setOnItemClickListener { _, position ->
            startActivity(
                ShowPictureActivity.getIntent(
                    this,
                    "",
                    ArrayList<String>().apply { addAll(pickupAdapter.mData) },
                    position
                )
            )
        }
        deliveryAdapter.setOnItemClickListener { _, position ->
            startActivity(
                ShowPictureActivity.getIntent(
                    this,
                    "",
                    ArrayList<String>().apply { addAll(deliveryAdapter.mData) },
                    position
                )
            )
        }
    }
 
    override fun initView() {
        titleBar.addRightButton(
            getString(R.string.投诉司机),
            onClickListener = View.OnClickListener {
                order?.driverId?.let {
                    startActivity<ComplainActivity>("id" to it)
                }
            })
        showDialog()
        getData()
        PayUtil.addPayListener(this)
        app.addTripStateListener(this)
        rv_pickup.adapter = pickupAdapter
        rv_pickup.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)
        rv_delivery.adapter = deliveryAdapter
        rv_delivery.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)
    }
 
    private fun getData() {
        HttpManager.queryOrderInfo(id, type).request(this) { _, data ->
            order = data
            data?.run {
                tv_start.text = startAddress
                tv_end.text = endAddress
                tv_time.text = travelTime
                iv_header_home.setImageURI(driverAvatar)
                tv_name.text = driverName
                tv_car.text = licensePlate
                tv_car_info.text = "$brand·$carColor"
                tv_score.text = String.format("%.1f", score)
                tv_count.text = getString(R.string.单数, orderNum)
                if (type == Const.OrderType.TYPE_CROSS_CITY) {
                    tv_passenger_num.visible()
                    tv_passenger_num.text =
                        String.format("%d人乘车:%s号座位", peopleNumber, seatNumber)
                            .replace(",", "号,")
                    tv_remark.visibility = if (!remark.isNullOrEmpty()) View.VISIBLE else View.GONE
                    tv_remark.text = remark
                }
 
                if (type == Const.OrderType.TYPE_SAME_CITY) {
                    tv_remark.visible()
                    tv_remark.text = if (remark.isNullOrEmpty()) "——" else remark
                }
                ll_pickup_picture.isVisible = !imgOne.isNullOrEmpty()
                pickupAdapter.mData = ArrayList<String>().apply { addAll(getPickupPictures()) }
                ll_delivery_picture.isVisible = !imgTwo.isNullOrEmpty()
                deliveryAdapter.mData = ArrayList<String>().apply { addAll(getDeliveryPictures()) }
                setStateUI()
                if (state == 10 || state == 12)
                    tv_tip.text = getString(R.string.乘客在司机到达上车点后取消了行程)
                else if (tipMoney == 0.0) {
                    tv_tip.invisible()
                } else {
                    tv_tip.typeface = Typeface.DEFAULT_BOLD
                    val content = getString(R.string.tips_is, tipMoney)
                    tv_tip.text = SpanBuilder(content).color(
                        this@OrderDetailActivity,
                        6,
                        content.length,
                        R.color.colorPrimary
                    ).build()
                }
                if (order!!.isFree == "2") {//首单免费订单
                    tv_title.visible()
                    tv_money.visible()
                    tv_title.text = "此次行程免费,无需支付"
                    tv_money.text = order!!.orderMoney.showMoney(this@OrderDetailActivity)
                }
                if (order!!.isFrozen == 2) {
                    tv_frozen.visible()
                    val language = LanguageUtil.getLanguage()
                    val ic = when (language) {
                        Const.Language.ENGLISH -> R.mipmap.yidongjie_e
                        Const.Language.CHINESE -> R.mipmap.yidongjie
                        else -> R.mipmap.yidongjie_f
                    }
                    tv_frozen.setCompoundDrawablesRelativeWithIntrinsicBounds(0, ic, 0, 0)
                }
            }
        }
    }
 
    /**
     * 评价成功以后需要查询是否可以获得分享红包
     */
    private var hasGetRed = false //防止多次触发红包获取
 
    @SuppressLint("StringFormatMatches")
    private fun getRedMoney() {
        HttpManager.queryRedMoney(id, type).request(this) { _, data ->
            data?.let {
                val money = it.optDouble("amount")
                if (money > 0) {
                    val tipDialog = TipDialog()
                    tipDialog.arguments = bundleOf(
                        "msg" to String.format(
                            getString(
                                R.string.分享APP给好友可以获得红包,
                                money.showMoney(this)
                            )
                        ),
                        "ok" to getString(R.string.去分享), "cancel" to getString(R.string.不分享)
                    )
                    tipDialog.setCallback(object : TipDialog.OnClickCallback {
                        override fun onOk() {
                            val shareDialog = ShareDialog()
                            shareDialog.setCallback(object : ShareDialog.Callback {
                                override fun onOk(way: Int) { //0:wx 1:qq 2:msg
                                    val language = LanguageUtil.getLanguage()
                                    val languageP =
                                        if (language == Const.Language.CHINESE) 1 else if (language == Const.Language.ENGLISH) 2 else 3
                                    val url = String.format(
                                        Apis.SHARE_URL,
                                        languageP,
                                        languageP,
                                        SPUtils.instance().getInt(Const.User.USER_ID)
                                    )
                                    if (way == 3) {
                                        IGoShareUtils.shareWA(
                                            this@OrderDetailActivity,
                                            getString(R.string.下载注册即送打车券),
                                            url
                                        )
                                    } else
                                        if (way == 4) {
                                            IGoShareUtils.shareFB(
                                                this@OrderDetailActivity,
                                                url,
                                                getString(R.string.下载注册即送打车券),
                                                null
                                            )
                                        } else if (way == 5) {
                                            IGoShareUtils.shareTweet(
                                                this@OrderDetailActivity,
                                                getString(R.string.下载注册即送打车券),
                                                url
                                            )
                                        } else {
//                                            ShareUtils.share(
//                                                this@OrderDetailActivity,
//                                                if (way == 0) SHARE_MEDIA.WEIXIN else if (way == 1) SHARE_MEDIA.QQ else
//                                                    SHARE_MEDIA.MORE,
//                                                getString(R.string.下载注册即送打车券),
//                                                Const.Share.TITLE,
//                                                url,
//                                                this@OrderDetailActivity,
//                                                ""
//                                            )
                                        }
                                    shareDialog.dismiss()
                                    if (!hasGetRed) {
                                        hasGetRed = true
                                        getRed(money)
                                    }
                                }
                            })
                            shareDialog.showAllowingStateLoss(supportFragmentManager, "share")
                        }
 
                        override fun onCancel() {}
                    })
                    tipDialog.showAllowingStateLoss(supportFragmentManager, "red")
                }
            }
 
        }
    }
 
    private fun setStateUI() {
        tv_pay_offline.gone()
        tv_confirm_fee.gone()
        cl_driver.visible()
        when (order?.state) {
            in (1..5) -> {
                startActivity<TripActivity>(
                    "id" to order?.orderId,
                    "type" to order?.orderType
                )
                finish()
            }
 
            6 -> { //已送达
                title = getString(R.string.待确认费用)
                tv_action.gone()
                tv_money.text = ""
                tv_confirm_fee.visible()
            }
 
            7 -> { //待支付
                cl_driver.gone()
                payMoney = order!!.orderMoney!!
                tv_money.text = payMoney.showMoney(this)
                title = getString(R.string.支付费用)
                if (order?.isFrozen != 2) {
                    tv_pay_offline.visible() //新增提示文字
                    tv_action.visible()
                }
                tv_title.visible()
                tv_action.text = getString(R.string.立即支付)
                queryBalance()
                if (order!!.device == 2) {//车载端,显示线下付款按钮 2.0客户反馈,不要该按钮
//                    tv_pay_offline.visible()
                }
                if (type == Const.OrderType.TYPE_SPECIAL || type == Const.OrderType.TYPE_SAME_CITY) //专车有查看明细 ,物流也有
                    tv_detail.visible()
            }
 
            8 -> { //待评价
                title =
                    if (type == Const.OrderType.TYPE_CROSS_CITY) getString(R.string.已完成) else getString(
                        R.string.evaluate
                    )
                tv_money.text = order!!.payMoney.showMoney(this)
                if (0.0 == order!!.payMoney && order!!.tipMoney == 0.0) { //其他方式收费
                    tv_money.invisible()
                    tv_tip.invisible()
                }
                tv_title.hide()
                tv_action.text = getString(R.string.匿名评价)
                titleBar.getRightButton(0)?.visible()
                if (order?.isFrozen != 2) {
                    cl_evaluate.visible()
                }
                tv_detail.visible()
                if (type == Const.OrderType.TYPE_SPECIAL) //专车有查看明细
                    tv_detail.visible()
                if (type == Const.OrderType.TYPE_CROSS_CITY) {//跨城要提示摆渡车
                    val specialSuggestDialog = SpecialSuggestDialog()
                    specialSuggestDialog.setCallback(object : StringCallback {
                        override fun onRlt(rlt: String) {
                            if (rlt == "ok")
                                startActivity<ShuttleBusActivity>(
                                    "order" to order,
                                    "isStart" to false
                                )
                        }
                    })
                    specialSuggestDialog.show(supportFragmentManager, "suggest")
                }
            }
 
            9 -> { //已完成
                title = getString(R.string.行程结束)
                tv_money.text = order!!.payMoney.showMoney(this)
                if (0.0 == order!!.payMoney && order!!.tipMoney == 0.0) { //其他方式收费
                    tv_money.invisible()
                    tv_tip.invisible()
                }
                tv_action.gone()
                titleBar.getRightButton(0)?.visible()
                if (order?.isFrozen != 2) {
                    cl_evaluate.visible()
                }
                rating.isClickable = false
                order?.orderScore?.let {
                    rating.setStar(order!!.orderScore!!.toFloat())
                }
 
                fl_label.removeAllViews()
                val list = arrayListOf<String>()
                order?.orderScore?.let {
                    list.addAll(getLabelList(order!!.orderScore!!))
                }
 
                val split = order!!.evaluate!!.split(",")
                list.forEach {
                    val view = layoutInflater.inflate(R.layout.item_score_label, null) as CheckBox
                    view.text = it
                    view.isEnabled = false
                    if (it in split)
                        view.isChecked = true
                    fl_label.addView(view)
                }
                tv_detail.visible()
            }
 
            10 -> {
                title = getString(R.string.已取消)
                tv_money.text = order!!.cancelPayMoney.showMoney(this)
                titleBar.getRightButton(0)?.gone() //刘矩:已取消没有投诉
                if (type == Const.OrderType.TYPE_CROSS_CITY) { //跨城取消没有扣钱
                    tv_money.gone()
                    tv_tip.gone()
                }
            }
 
            12 -> { //取消待支付
                title = getString(R.string.支付费用)
                titleBar.getRightButton(0)?.gone()
                order?.cancelPayMoney?.let {
                    payMoney = order!!.cancelPayMoney!!
                }
 
                tv_money.text = payMoney.showMoney(this)
                if (order?.isFrozen != 2) {
                    tv_action.visible()
                }
                tv_title.visible()
                tv_action.text = getString(R.string.立即支付)
            }
 
            13 -> { // 支付差价
                title = getString(R.string.需补差价)
                titleBar.getRightButton(0)?.gone()
                cl_driver.gone()
                payMoney = order!!.priceDifference
                tv_money.text = payMoney.showMoney(this)
                tv_title.visible()
                tv_action.visible()
                tv_action.text = getString(R.string.立即支付)
                queryBalance()
                tv_detail.visible()
            }
        }
    }
 
    //一至五星评价内容
    private val list1 by lazy {
        arrayListOf(
            getString(R.string.车辆不符),
            getString(R.string.司机不符),
            getString(R.string.态度恶劣),
            getString(R.string.行为不端),
            getString(R.string.违反交通),
            getString(R.string.额外收费)
        )
    }
    private val list2 by lazy {
        arrayListOf(
            getString(R.string.故意绕路),
            getString(R.string.额外加人),
            getString(R.string.送错地点),
            getString(R.string.车辆肮脏),
            getString(R.string.司机迟到),
            getString(R.string.中途换车)
        )
    }
    private val list3 by lazy {
        arrayListOf(
            getString(R.string.车内异味),
            getString(R.string.开车不稳),
            getString(R.string.道路不熟),
            getString(R.string.接打电话),
            getString(R.string.索要好评),
            getString(R.string.索要小费)
        )
    }
    private val list4 by lazy {
        arrayListOf(
            getString(R.string.基本整洁),
            getString(R.string.基本礼貌),
            getString(R.string.基本平稳),
            getString(R.string.基本准时),
            getString(R.string.基本友好),
            getString(R.string.基本合理)
        )
    }
    private val list5 by lazy {
        arrayListOf(
            getString(R.string.车辆美观),
            getString(R.string.内部整洁),
            getString(R.string.路线优化),
            getString(R.string.接待礼貌),
            getString(R.string.驾驶平稳),
            getString(R.string.服务卓越)
        )
    }
 
    private fun getLabelList(star: Int): List<String> {
        return when (star) {
            5 -> list5
            4 -> list4
            3 -> list3
            2 -> list2
            else -> list1
        }
    }
 
    private val checkList = arrayListOf<String>()
    private fun inputLabel(start: Int) {
        fl_label.removeAllViews()
        checkList.clear()
        val list = arrayListOf<String>()
        list.addAll(getLabelList(start))
        list.forEach {
            val view = layoutInflater.inflate(R.layout.item_score_label, null) as CheckBox
            view.text = it
            view.setOnCheckedChangeListener { _, isChecked ->
                if (isChecked)
                    checkList.add(view.text.toString())
                else
                    checkList.remove(view.text.toString())
            }
            fl_label.addView(view)
        }
    }
 
    /**
     * 查询余额和优惠券以供支付
     */
    private fun queryBalance() {
        HttpManager.queryBalance(id, type).request(this) { _, data ->
            data?.let {
                isCancel = order?.state == 12
                balance = it.optDouble("balance")
                coupon = it.optInt("coupon")
                redTotal = it.optDouble("redTotal")
                deductionAmount = it.optDouble("deductionAmount")
                if (doPay)
                    tv_action.callOnClick()
            }
        }
    }
 
    /**
     * @param way 1=微信,2=支付宝,3=余额,4=现金
     */
    private fun pay(way: Int, couponId: Int, cardId: String?, useRed: Boolean) {
        tv_action.isEnabled = false
        when (order!!.state) {
            7 -> { // 待支付
                Log.e("当前订单详情: ", "开始支付${type} ")
                HttpManager.payTaxiOrder(
                    id,
                    way,
                    type,
                    if (couponId == 0) null else couponId,
                    cardId,
                    if (useRed) 1 else 0
                ).request(this, success = { _, data ->
                    tv_action.isEnabled = true
                    if (way in 3..4) {
                        if (type == 4) {
                            Log.e("当前订单详情: ", "小件物流支付成功进入下个流程 ")
                            queryTripping()
                        }
                        onPaySuccess()
                    } else {
                        isGotoWx = true
                        toBrowser(data.toString())
                    }
                }) { _, _ ->
                    tv_action.isEnabled = true
                }
            }
 
            12 -> { // 取消支付
                HttpManager.cancleOrderTaxi(id, way, order!!.cancelId!!, type, cardId)
                    .request(this, success = { _, data ->
                        tv_action.isEnabled = true
                        if (way == 3)
                            onPaySuccess()
                        else {
                            isGotoWx = true
                            toBrowser(data ?: "")
                        }
                    }) { _, _ ->
                        tv_action.isEnabled = true
                    }
            }
 
            13 -> { // 补差价
                HttpManager.payOrderLogisticsSpread(id, way)
                    .request(this, showDialog = true) { _, data ->
                        onPaySuccess()
                    }
            }
        }
    }
 
    /**
     * 查询是否有进行中的订单
     */
    fun queryTripping() {
        HttpManager.queryServingOrder().request(this, false) { _, data ->
            data?.let {
                if (!it.isNullOrEmpty()) {
 
                    val order = data[0]
 
                    Log.e("当前订单详情: ", "order.state ${order.state}")
                    Log.e("当前订单详情: ", "order.orderType ${order.orderType}")
                    if (order.state in (1..5) || order.state == 11)
                        startActivity<TripActivity>(
                            "id" to order.orderId,
                            "type" to order.orderType
                        )
                    else if (order.state == 7 && order.orderType == Const.OrderType.TYPE_CROSS_CITY) {
                        startActivity<PayCrossActivity>("id" to order.orderId)
                    } else
                        startActivity<OrderDetailActivity>(
                            "id" to order.orderId,
                            "type" to order.orderType
                        )
                    if (!IGoApplication.hasAutoGoTripping) {
                        tv_tip.callOnClick()
                        IGoApplication.hasAutoGoTripping = true
                    }
 
                    finish()
                }
            }
        }
    }
 
 
    /**
     * 分享后获得红包
     */
    private fun getRed(money: Double) {
        HttpManager.shareRedEnvelope(id, type).request(this) { _, _ ->
            val tipDialog = TipDialog()
            tipDialog.arguments = bundleOf(
                "msg" to String.format(
                    getString(R.string.您收到一个打车红包下次打车可抵扣金额),
                    money.showMoney(this)
                ),
                "ok" to getString(R.string.确定), "isAlert" to true
            )
            tipDialog.showAllowingStateLoss(supportFragmentManager, "red")
        }
    }
 
    override fun onPaySuccess() {
        myToast(getString(R.string.支付成功))
        setResult(Activity.RESULT_OK)
        tv_title.hide()
        tv_action.gone()
        if (order?.state == 12) {
            title = getString(R.string.已取消)
            titleBar.getRightButton(0).gone()
        } else {
            showDialog()
            getData()
        }
    }
 
    override fun onPayCancel() {
 
    }
 
    override fun onResume() {
        super.onResume()
        if (isGotoWx) {
            isGotoWx = false
            HttpManager.queryOrderInfo(id, type).request(this) { _, data ->
                if (data?.state == order?.state) {
                    myToast(getString(R.string.支付失败))
                } else {
                    onPaySuccess()
                }
            }
        }
    }
 
 
    override fun onDestroy() {
        super.onDestroy()
        PayUtil.removePayListener(this)
        app.removeTripStateListener(this)
    }
 
//    override fun onResult(p0: SHARE_MEDIA?) {
//    }
//
//    override fun onCancel(p0: SHARE_MEDIA?) {
//    }
//
//    override fun onError(p0: SHARE_MEDIA?, p1: Throwable?) {
//    }
//
//    override fun onStart(p0: SHARE_MEDIA?) {
//
//    }
 
    override fun onStateChanged(id: Int, state: Int) {
        if (id == this.id && order?.state == 6) { //当前是待司机确认费用,需要重新获取订单信息
            getData()
        }
    }
 
    override fun onTrippingChanged(info: TrippingInfo) {
    }
 
    override fun onAddressChanged(info: TrippingInfo) {
    }
 
    override fun onShuttleConfirm(id: Int, type: Int) {
    }
 
}