package com.okgoincar.slab
|
|
import android.os.CountDownTimer
|
import android.os.Handler
|
import android.os.Looper
|
import android.view.View
|
import cn.sinata.xldutils.utils.*
|
import com.okgoincar.netUtls.callNet
|
import com.okgoincar.netUtls.getMapByAny
|
import com.google.gson.Gson
|
import com.okgoincar.R
|
import com.okgoincar.base.MyApplication
|
import com.okgoincar.bean.OrderBean
|
import com.okgoincar.bean.OrderSimpleData
|
import com.okgoincar.bean.OrderStatueBean
|
import com.okgoincar.netUtls.Api
|
import com.okgoincar.netUtls.timeOver
|
import com.okgoincar.slab.util.DialogUtil
|
import com.okgoincar.utils.MyUtils
|
import kotlinx.android.synthetic.main.activity_order_over.*
|
import kotlinx.android.synthetic.main.dialog_sure_and_del_slab.view.*
|
import java.lang.Exception
|
|
class SlabOrderOverActivity : MySlabBaseActivity() {
|
|
val orderType by lazy {
|
intent.getStringExtra("orderType")
|
}
|
|
val orderId by lazy {
|
intent.getStringExtra("orderId")
|
}
|
|
var time: CountDownTimer? = null
|
|
lateinit var orderBean: OrderBean
|
|
override fun setContentView() {
|
setContentView(R.layout.activity_order_over)
|
MyApplication.currentOrderType = ""
|
MyApplication.currentOrderId = ""
|
showHeader(false)
|
showTitle(false)
|
|
}
|
|
override fun onPause() {
|
super.onPause()
|
if (time != null) {
|
time!!.cancel()
|
}
|
}
|
|
override fun setBlackMode(b: Boolean?) {
|
super.setBlackMode(b)
|
if (b!!) { //晚上
|
rl_main_bg.setBackgroundResource(R.color.black)
|
ll_content_web.setBackgroundResource(R.drawable.bg_slab_main_8_black)
|
ll_order_top.setBackgroundResource(R.drawable.bg_slab_main_8_black_bottom)
|
// ll_pay_result.setBackgroundResource(R.drawable.bg_slab_main_8_shen_black)
|
iv_back_slab.setImageResource(R.mipmap.icon_back_slab)
|
tv_title_slab.textColor(this, R.color.write)
|
tv_name.textColor(this, R.color.write)
|
tv_car_num.textColor(this, R.color.write)
|
tv_phone.textColor(this, R.color.write)
|
tv_time.textColor(this, R.color.write)
|
tv_time.setDrawableLeft(R.mipmap.icon_time_gray)
|
tv_start_address.textColor(this, R.color.write)
|
tv_end_address.textColor(this, R.color.write)
|
tv_red_money.textColor(this, R.color.write)
|
tv_pay_result_title.textColor(this, R.color.write)
|
tv_order_type.textColor(this, R.color.write)
|
tv_hive_small_money.textColor(this, R.color.write)
|
tv_phone.setDrawableLeft(R.mipmap.icon_dial_slab)
|
} else {
|
rl_main_bg.setBackgroundResource(R.color.write)
|
ll_content_web.setBackgroundResource(R.drawable.write_top_10)
|
ll_order_top.setBackgroundResource(R.drawable.write_bottom_10)
|
// ll_pay_result.setBackgroundResource(R.drawable.bg_white_round5)
|
iv_back_slab.setImageResource(R.mipmap.icon_back_black)
|
tv_title_slab.textColor(this, R.color.black)
|
tv_name.textColor(this, R.color.black)
|
tv_car_num.textColor(this, R.color.black)
|
tv_phone.textColor(this, R.color.black)
|
tv_time.textColor(this, R.color.black)
|
tv_time.setDrawableLeft(R.mipmap.icon_time_xiao)
|
tv_start_address.textColor(this, R.color.black)
|
tv_end_address.textColor(this, R.color.black)
|
tv_red_money.textColor(this, R.color.black)
|
tv_pay_result_title.textColor(this, R.color.black)
|
tv_order_type.textColor(this, R.color.black)
|
tv_hive_small_money.textColor(this, R.color.black)
|
tv_phone.setDrawableLeft(R.mipmap.icon_dial)
|
}
|
}
|
|
override fun initView() {
|
var map = getMapByAny()
|
map["orderId"] = orderId
|
map["orderType"] = orderType
|
callNet(this, Api.queryOrderInfo, map) {
|
orderBean = gson.fromJson(it, OrderBean::class.java)
|
showUi(orderBean)
|
// addSocketLisener(orderBean)
|
checkOrderStatue()
|
}
|
}
|
|
|
|
private fun showUi(orderBean: OrderBean?) {
|
orderBean?.let {
|
MyApplication.getTTsManager()
|
.setVideoText("请确认乘客车内付款后,再点击返回首页")
|
time = timeOver(60000 * 6) {
|
tv_title_slab.text = "待支付($it)"
|
if (it == 0) {
|
if (time != null) {
|
time!!.cancel()
|
}
|
try {
|
finish()
|
} catch (e: Exception) {
|
}
|
}
|
}
|
tv_title_slab.text = "待支付"
|
tv_name.text = it.data.nickName
|
tv_car_num.text = it.data.historyNum.toString() + "次乘车"
|
tv_phone.text = it.data.phone
|
|
tv_phone.clickDelay {
|
MyUtils.getInstans().CallPhone(this, it.data.phone.toString())
|
}
|
tv_pay_result_money.text = "¥" + it.data.orderMoney.toString()
|
tv_pay_result_small_money.text = "¥" + it.data.tipMoney.toString()
|
tv_time.text = it.data.travelTime
|
tv_start_address.text = it.data.startAddress
|
tv_end_address.text = it.data.endAddress
|
tv_end_address.visibility = if (it.data.endAddress.isNullOrEmpty()) View.GONE else View.VISIBLE
|
tv_red_money.text = it.data.tipMoney.toString() + "元小费"
|
// when (orderBean.data.orderState) {
|
// 10, 11 -> {
|
// ll_pay_result.gone()
|
// setTitleText("已取消")
|
// }
|
// 6, 7 -> {
|
// if (it.data.payManner == 2) {
|
// ll_pay_result.gone()
|
// setTitleText("已完成")
|
// } else {
|
// addSocketLisener()
|
// showPayResultText(it, it.data.orderState)
|
// }
|
// }
|
// 8, 9 -> {
|
// if (it.data.payManner == 2) {
|
// ll_pay_result.gone()
|
// setTitleText("已完成")
|
// } else {
|
// showPayResultText(it, it.data.orderState)
|
// }
|
// }
|
// }
|
}
|
}
|
|
fun overOrder(){
|
callComplete() {
|
Handler(Looper.getMainLooper()).post {
|
time?.cancel()
|
time?.onFinish()
|
finish()
|
}
|
}
|
}
|
|
var handler: Handler? = null
|
var isPlay = false
|
|
fun checkOrderStatue() {
|
if (handler == null) {
|
handler = Handler(mainLooper)
|
}
|
handler!!.postDelayed({
|
checkOrderStatue()
|
}, 3000)
|
var map = getMapByAny()
|
// map["orderId"] = orderId
|
// map["orderType"] = orderType
|
callNet(false, Api.orderStateSocket, map) {
|
val orderSimpleData =
|
Gson().fromJson(
|
it,
|
OrderStatueBean::class.java
|
)
|
orderSimpleData?.data?.let {
|
var currentBean: OrderStatueBean.DataBean? = null
|
for (item in it) {
|
if (item.orderId == orderBean.data?.orderId) {
|
currentBean = item
|
}
|
}
|
if (it.size == 0 || currentBean == null) {
|
return@callNet
|
}
|
if (currentBean.state == 8) {
|
tv_pay_result_money.textColor(
|
this@SlabOrderOverActivity,
|
R.color.slab_green_over
|
)
|
Handler(Looper.getMainLooper()).post {
|
if (isPlay) {
|
return@post
|
}
|
isPlay = true
|
tv_complete.gone()
|
tv_to_main.visible()
|
MyApplication.getTTsManager()
|
.setVideoText("乘客已支付" + orderBean.data?.orderMoney.toString() + "元")
|
time?.cancel()
|
time = timeOver(20000) {
|
tv_title_slab.text = "已完成($it)"
|
if (it == 0) {
|
if (time != null) {
|
time!!.cancel()
|
}
|
try {
|
finish()
|
} catch (e: Exception) {
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
|
override fun onDestroy() {
|
super.onDestroy()
|
handler?.removeCallbacksAndMessages(null)
|
}
|
|
fun showPayResultText(it: OrderBean, statue: Int) {
|
ll_pay_result.visible()
|
if (statue in 6..7) {
|
tv_pay_result_title.text = "待乘客支付"
|
setTitleText("待支付")
|
} else {
|
tv_pay_result_title.text = "乘客已支付"
|
setTitleText("已完成")
|
}
|
|
tv_pay_result_money.text = "¥" + it.data.orderMoney.toString()
|
tv_pay_result_small_money.text = "¥" + it.data.tipMoney.toString()
|
}
|
|
override fun setTitleText(title: String?) {
|
tv_title_slab.text = title
|
}
|
|
|
override fun setOnclick() {
|
iv_back_slab.clickDelay {
|
onBackPressed()
|
}
|
|
tv_to_main.clickDelay {
|
onBackPressed()
|
}
|
|
tv_complete.clickDelay {
|
var pop = DialogUtil.getSlabDelAndSurePopWindow(this,"请确认是否收到乘客线下付款",{}){
|
overOrder()
|
}
|
pop.contentView.tv_close_base.text = "未收款"
|
pop.contentView.tv_sure_base.text = "已收款"
|
pop.showCenter(window.decorView)
|
|
}
|
}
|
|
override fun onBackPressed() {
|
overOrder()
|
}
|
|
private fun callComplete(function: () -> Unit) {
|
var map = getMapByAny()
|
map["orderId"] = orderId
|
map["orderType"] = orderType
|
callNet(Api.completeOrder,map,{
|
function()
|
}){
|
function()
|
}
|
}
|
|
|
|
private fun addSocketLisener(orderBean: OrderBean?) {
|
MyApplication.addOrderView(object : MyApplication.OrderStatueView {
|
override fun orderInfo(data: OrderSimpleData?) {
|
data?.let {
|
if (it.status == 8 || it.status == 7) {
|
tv_pay_result_money.textColor(
|
this@SlabOrderOverActivity,
|
R.color.slab_green_over
|
)
|
Handler(Looper.getMainLooper()).post {
|
if (isPlay) {
|
return@post
|
}
|
isPlay = true
|
MyApplication.getTTsManager()
|
.setVideoText("乘客已支付" + orderBean?.data?.orderMoney.toString() + "元")
|
time = timeOver(20000) {
|
tv_title_slab.text = "已完成($it)"
|
if (it == 0) {
|
if (time != null) {
|
time!!.cancel()
|
}
|
try {
|
finish()
|
} catch (e: Exception) {
|
}
|
}
|
}
|
}
|
|
// android.os.Handler(Looper.getMainLooper()).post {
|
// orderBean.data.orderState = 8
|
// showUi(orderBean)
|
// }
|
}
|
}
|
}
|
})
|
|
|
// if (handler == null) {
|
// handler = android.os.Handler(mainLooper)
|
// handler!!.postDelayed({
|
// checkOrderStatue()
|
// }, 3000)
|
// }
|
}
|
|
}
|