18034727885
2026-08-07 bbc64160643c4ed818eb574831dc303b0a979089
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
package com.driver.igotrip.ui.main
 
import android.app.Dialog
import android.content.Intent
import android.net.Uri
import android.os.Handler
import android.os.Looper
import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.core.view.isVisible
import cn.sinata.rxnetty.LogHelper
import cn.sinata.xldutils.utils.clickDelay
import cn.sinata.xldutils.utils.doubleOne
import cn.sinata.xldutils.utils.gone
import cn.sinata.xldutils.utils.visible
import com.driver.igotrip.R
import com.driver.igotrip.base.BaseEvent
import com.driver.igotrip.base.MyApplication
import com.driver.igotrip.base.MyApplication.Companion.getTTsManager
import com.driver.igotrip.base.MyBaseActivity
import com.driver.igotrip.bean.OrderBean
import com.driver.igotrip.bean.OrderSimpleData
import com.driver.igotrip.bean.StringBean
import com.driver.igotrip.extension.extClearInvalidZero
import com.driver.igotrip.netUtls.Api
import com.driver.igotrip.netUtls.callNet
import com.driver.igotrip.netUtls.getMapByAny
import com.driver.igotrip.ui.DialogUtil
import com.driver.igotrip.ui.UiUtil
import com.driver.igotrip.ui.main.major.MajorMoneyDetailActivity
import com.driver.igotrip.utils.MyUtils
import com.driver.igotrip.utils.StringCallback
import com.google.gson.Gson
import org.greenrobot.eventbus.EventBus
import org.jetbrains.anko.find
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.toast
 
class OrderOverActivity : MyBaseActivity() {
    val orderType by lazy {
        intent.getStringExtra("orderType")
    }
 
    val orderId by lazy {
        intent.getStringExtra("orderId")
    }
 
    lateinit var orderBean: OrderBean.DataBean
    private var toPay = false
 
    private val ll_order_cancel by lazy { find<LinearLayout>(R.id.ll_order_cancel) }
    private val ll_pay_result by lazy { find<LinearLayout>(R.id.ll_pay_result) }
    private val tv_show_pay_over by lazy { find<TextView>(R.id.tv_show_pay_over) }
    private val tv_name by lazy { find<TextView>(R.id.tv_name) }
    private val tv_car_num by lazy { find<TextView>(R.id.tv_car_num) }
    private val iv_phone by lazy { find<View>(R.id.iv_phone) }
    private val tv_time by lazy { find<TextView>(R.id.tv_time) }
    private val tv_start_address by lazy { find<TextView>(R.id.tv_start_address) }
    private val tv_end_address by lazy { find<TextView>(R.id.tv_end_address) }
    private val tv_red_money by lazy { find<TextView>(R.id.tv_red_money) }
    private val remark by lazy { find<TextView>(R.id.remark) }
    private val ll_order_money by lazy { find<LinearLayout>(R.id.ll_order_money) }
    private val tv_order_money by lazy { find<TextView>(R.id.tv_order_money) }
    private val ll_service_money by lazy { find<LinearLayout>(R.id.ll_service_money) }
    private val tv_service_money by lazy { find<TextView>(R.id.tv_service_money) }
    private val ll_real_income by lazy { find<LinearLayout>(R.id.ll_real_income) }
    private val tv_coupon_price by lazy { find<TextView>(R.id.tv_coupon_price) }
    private val ll_coupon_price by lazy { find<LinearLayout>(R.id.ll_coupon_price) }
    private val tv_real_income by lazy { find<TextView>(R.id.tv_real_income) }
    private val tv_cancel_to by lazy { find<TextView>(R.id.tv_cancel_to) }
    private val tv_cancel_money by lazy { find<TextView>(R.id.tv_cancel_money) }
    private val tv_cancel_result by lazy { find<TextView>(R.id.tv_cancel_result) }
    private val tv_cancel_s by lazy { find<TextView>(R.id.tv_cancel_s) }
    private val tv_pay_result_title by lazy { find<TextView>(R.id.tv_pay_result_title) }
    private val ll_pay_bottom by lazy { find<LinearLayout>(R.id.ll_pay_bottom) }
    private val ll_card_select by lazy { find<LinearLayout>(R.id.ll_card_select) }
    private val ll_money_select by lazy { find<LinearLayout>(R.id.ll_money_select) }
    private val iv_card_select by lazy { find<ImageView>(R.id.iv_card_select) }
    private val iv_money_select by lazy { find<ImageView>(R.id.iv_money_select) }
    private val ll_phone_select by lazy { find<LinearLayout>(R.id.ll_phone_select) }
    private val iv_phone_select by lazy { find<ImageView>(R.id.iv_phone_select) }
    private val tv_pay_result_money by lazy { find<TextView>(R.id.tv_pay_result_money) }
    private val tv_pay_result_small_money by lazy { find<TextView>(R.id.tv_pay_result_small_money) }
    private val tv_sure_dan by lazy { find<View>(R.id.tv_sure_dan) }
    private val view_line_money_detail by lazy { find<View>(R.id.view_line_money_detail) }
    private val tv_frozen by lazy { find<TextView>(R.id.tv_frozen) }
 
    override fun setContentView() {
        setContentView(R.layout.activity_order_over)
        ll_order_cancel.gone()
        MyApplication.currentOrderType = ""
        MyApplication.currentOrderId = ""
        ll_pay_result.gone()
        tv_show_pay_over.gone()
        LogHelper.logRecord("订单已结束orderId:${orderId} orderType:${orderType}")
    }
 
    override fun initView() {
        orderBean = intent.getSerializableExtra("orderBean") as OrderBean.DataBean
        showUi(orderBean)
 
    }
 
    private fun showUi(orderBean: OrderBean.DataBean) {
        orderBean?.let {
            tv_name.text = it.nickName
            tv_car_num.text = getString(R.string.次乘车, it.historyNum.toString())
            iv_phone.visible()
            iv_phone.clickDelay {
                MyUtils.getInstans().CallPhone(this, it.phone.toString())
            }
            tv_time.text = it.travelTime_
            tv_start_address.text = it.startAddress
            tv_end_address.text = it.endAddress
            tv_red_money.text =
                getString(R.string.元红包, it.tipMoney.toString().extClearInvalidZero())
            remark.text = it.remark
            remark.gone()
            if (orderType == "1") {
                tv_red_money.gone()
            }
            tv_order_money.text =
                getString(R.string.money) + " " + it.orderMoney.toString().extClearInvalidZero()
            tv_service_money.text =
                getString(R.string.money) + " " + it.platformServerMoney.extClearInvalidZero()
            tv_coupon_price.text =
                "-" + getString(R.string.money) + " " + it.couponMoney.extClearInvalidZero()
            ll_coupon_price.isVisible = (it.couponMoney?.toDoubleOrNull() ?: 0.0) > 0
            tv_real_income.text =
                getString(R.string.money) + " " + it.driverServerMoney.extClearInvalidZero()
            when (orderBean.orderState) {
                10, 12 -> {
                    ll_order_cancel.visible()
                    setTitleText(getString(if (orderBean.orderState == 10) R.string.已取消 else R.string.取消待支付))
                    iv_phone.gone()
                    tv_cancel_to.text = it.cancelUser
                    tv_cancel_money.text =
                        (getString(R.string.money) + " " + doubleOne(it.cancelPayMoney)).extClearInvalidZero()
                    tv_cancel_result.text = it.cancelReason
                    tv_cancel_s.text = it.cancelRemark
                    if (it.cancelRemark.isNullOrEmpty()) {
                        tv_cancel_s.text = ""
                    }
                }
 
                6, 7 -> {
                    if (it.payManner == 2) {
                        tv_show_pay_over.visible()
                        setTitleText(getString(R.string.已完成))
                    } else {
                        addSocketLisener()
                        showPayResultText(it, it.orderState)
                    }
                }
 
                8, 9 -> {
                    if (it.payManner == 2) {
                        tv_show_pay_over.visible()
                        setTitleText(getString(if (orderBean.orderState == 8) R.string.待评价 else R.string.已完成))
                    } else {
                        showPayResultText(it, it.orderState)
                    }
                }
            }
            if (orderBean.orderState in 6..9 && it.driverPay == "1") {
                var paytype = 3
                tv_pay_result_title.text = getString(R.string.乘客已现金支付)
                ll_pay_bottom.visible()
                ll_card_select.clickDelay {
                    paytype = 2
                    selectItem(iv_card_select)
                }
                ll_money_select.clickDelay {
                    paytype = 3
                    selectItem(iv_money_select)
                }
                ll_phone_select.clickDelay {
                    paytype = 1
                    selectItem(iv_phone_select)
                }
                tv_sure_dan.clickDelay {
                    if (paytype == 2) {
                        val dialog = ChooseCardDialog()
                        dialog.setCallback(object : StringCallback {
                            override fun onRlt(rlt: String) {
                                payOrder(paytype, rlt)
                            }
                        })
                        dialog.show(supportFragmentManager, "card")
                    } else
                        payOrder(paytype)
                }
            }
            if (it.isFrozen == 2) {
                tv_frozen.visible()
                tv_frozen.setCompoundDrawablesRelativeWithIntrinsicBounds(
                    0,
                    UiUtil.getFrozenBitmap(), 0, 0
                )
            }
        }
    }
 
    /**
     * @param paytype 支付方式1=线上,2=余额
     */
    private fun payOrder(paytype: Int, bank: String? = null) {
        var map = getMapByAny()
        map["orderId"] = orderId
        map["orderType"] = orderType
        map["payType"] = paytype
        if (paytype == 2 && bank != null)
            map["bankCardId"] = bank
        callNet(Api.payOrder, map) {
            when (paytype) {
                3 -> { //现金支付成功
                    showToast(getString(R.string.支付成功))
                    ll_pay_bottom.gone()
                }
 
                else -> {
                    val data = gson.fromJson(it, StringBean::class.java).data
                    toBrowser(data ?: "")
                }
            }
        }
    }
 
    fun toBrowser(url: String) {
        toPay = true
        MyApplication.isPlayVoice = false
        val intent = Intent()
        intent.action = "android.intent.action.VIEW"
        intent.data = Uri.parse(url)
        startActivity(intent)
    }
 
    override fun onResume() {
        super.onResume()
        if (toPay) {
            var map = getMapByAny()
            map["orderId"] = orderId
            map["orderType"] = orderType
            callNet(Api.queryOrderInfo, map) {
                val orderBean1 = gson.fromJson(it, OrderBean::class.java)
                if (orderBean1.data.driverPay == "2") {
                    showUi(orderBean1.data)
                    toast(getString(R.string.支付成功))
                } else {
                    toast(getString(R.string.支付失败))
                }
            }
            toPay = false
        }
    }
 
    private fun selectItem(ivCardSelect: ImageView?) {
        iv_card_select.setImageResource(R.mipmap.icon_raidobutton)
        iv_money_select.setImageResource(R.mipmap.icon_raidobutton)
        iv_phone_select.setImageResource(R.mipmap.icon_raidobutton)
        ivCardSelect?.setImageResource(R.mipmap.icon_raidobutton_selected)
    }
 
    /**
     * 提示乘客现金支付
     */
    override fun showDriverPayDialog(
        audioUrl: String,
        orderId: String,
        orderType: String,
        money: Double
    ) {
        getTTsManager().setVideoText(audioUrl)
        if (orderId == this.orderId && orderType == this.orderType) {
            var map = getMapByAny()
            map["orderId"] = orderId
            map["orderType"] = orderType
            callNet(Api.queryOrderInfo, map) {
                orderBean = gson.fromJson(it, OrderBean::class.java).data
                showUi(orderBean)
                var dialog: Dialog = DialogUtil.getDialog(this, R.layout.dialog_sure_cash)
                dialog.setCanceledOnTouchOutside(false)
                dialog.setCancelable(false)
                val view = DialogUtil.getView(dialog)
                view.find<TextView>(R.id.tv_price).text =
                    getString(R.string.确认现金金额).format(if (money == 0.0) orderBean.orderMoney else money)
                        .replace(",", ".").extClearInvalidZero()
                view.find<TextView>(R.id.tv_close_base).setOnClickListener { dialog.dismiss() }
                view.find<TextView>(R.id.tv_sure_base).setOnClickListener { dialog.dismiss() }
            }
        }
    }
 
    private fun addSocketLisener() {
        MyApplication.addOrderView(listener)
    }
 
    private val listener = object : MyApplication.OrderStatueView {
        override fun orderInfo(data: OrderSimpleData?) {
            data?.let {
                if (it.status == 8 || it.status == 9) {
                    Handler(Looper.getMainLooper()).post {
                        orderBean.orderState = 8
                        showUi(orderBean)
                    }
                }
            }
        }
    }
    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 (orderSimpleData.status == 8) {
                    orderBean.orderState = 8
                    showUi(orderBean)
                }
            }
        }
        handler?.postDelayed({ checkOrderStatue() }, 3000)
    }
 
    override fun onDestroy() {
        super.onDestroy()
        MyApplication.removeOrderView(listener)
        handler?.removeCallbacksAndMessages(null)
    }
 
    fun showPayResultText(it: OrderBean.DataBean, statue: Int) {
        ll_pay_result.visible()
        if (statue in 6..7) {
            tv_pay_result_title.text = getString(R.string.待乘客支付)
            setTitleText(getString(R.string.待支付))
        } else {
            tv_pay_result_title.text = getString(R.string.乘客已支付)
            setTitleText(if (orderBean.orderState == 8) R.string.待评价 else R.string.已完成)
        }
        tv_pay_result_money.text =
            getString(R.string.money) + " " + (if (it.payMoney == 0.0) it.orderMoney.toString() else it.payMoney.toString()).extClearInvalidZero()
        when (orderType) {
            "2" -> {
                tv_pay_result_small_money.text =
                    getString(R.string.其中含红包费用) + " " + it.tipMoney.toString()
                        .extClearInvalidZero()
            }
 
            "1" -> {
                tv_pay_result_small_money.text = getString(R.string.查看收费明细)
                view_line_money_detail.visible()
                tv_pay_result_small_money.clickDelay {
                    startActivity<MajorMoneyDetailActivity>(
                        "orderId" to orderId,
                        "orderType" to orderType
                    )
                }
            }
        }
    }
 
    override fun onBackPressed() {
        super.onBackPressed()
        EventBus.getDefault().post(BaseEvent(BaseEvent.CALL_NUM_MAIN))
        EventBus.getDefault().post(BaseEvent(BaseEvent.BACK_CAR_OVER))
    }
 
    override fun setOnclick() {
 
    }
}