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() {
|
|
}
|
}
|