package com.igo.user.ui.trip
|
|
|
import android.app.Activity
|
import android.view.View
|
import android.widget.EditText
|
import android.widget.TextView
|
import androidx.core.os.bundleOf
|
import cn.sinata.xldutils.utils.myToast
|
import cn.sinata.xldutils.utils.optDouble
|
import cn.sinata.xldutils.utils.optString
|
import com.igo.user.IGoApplication
|
import com.igo.user.R
|
import com.igo.user.dialog.TipDialog
|
import com.igo.user.network.HttpManager
|
import com.igo.user.network.request
|
import com.igo.user.ui.H5Activity
|
import com.igo.user.ui.TransparentStatusBarActivity
|
import org.jetbrains.anko.find
|
import org.jetbrains.anko.startActivity
|
|
/**
|
* 取消订单
|
*/
|
class CancelOrderActivity : TransparentStatusBarActivity() {
|
|
private val tv_1 by lazy { find<TextView>(R.id.tv_1) }
|
private val tv_2 by lazy { find<TextView>(R.id.tv_2) }
|
private val tv_3 by lazy { find<TextView>(R.id.tv_3) }
|
private val tv_4 by lazy { find<TextView>(R.id.tv_4) }
|
private val tv_5 by lazy { find<TextView>(R.id.tv_5) }
|
private val tv_6 by lazy { find<TextView>(R.id.tv_6) }
|
private val tv_7 by lazy { find<TextView>(R.id.tv_7) }
|
private val tv_8 by lazy { find<TextView>(R.id.tv_8) }
|
private val tv_9 by lazy { find<TextView>(R.id.tv_9) }
|
private val tv_10 by lazy { find<TextView>(R.id.tv_10) }
|
private val tv_11 by lazy { find<TextView>(R.id.tv_11) }
|
private val tv_action by lazy { find<TextView>(R.id.tv_action) }
|
private val tv_driver by lazy { find<TextView>(R.id.tv_driver) }
|
private val et_content by lazy { find<EditText>(R.id.et_content) }
|
private val tv_me by lazy { find<TextView>(R.id.tv_me) }
|
private val ll_me by lazy { find<View>(R.id.ll_me) }
|
private val tv_platform by lazy { find<View>(R.id.tv_platform) }
|
private val ll_plat by lazy { find<View>(R.id.ll_plat) }
|
private val ll_driver by lazy { find<View>(R.id.ll_driver) }
|
private val tv_other by lazy { find<View>(R.id.tv_other) }
|
private val ll_other by lazy { find<View>(R.id.ll_other) }
|
|
private val tvList by lazy { arrayListOf(tv_1,tv_2,tv_3,tv_4,tv_5,tv_6,tv_7,tv_8,tv_9,tv_10,tv_11) }
|
|
private val state by lazy { intent.getIntExtra("state",0) }
|
|
override fun setContentView(): Int = R.layout.activity_cancel_order
|
|
override fun initClick() {
|
tvList.forEach {
|
it.setOnClickListener { _ ->
|
tvList.forEach { it.isSelected = false }
|
it.isSelected = true
|
reason = when (it.id) {
|
R.id.tv_1 -> getString(R.string.等太久)
|
R.id.tv_2 -> getString(R.string.不需要用车了)
|
R.id.tv_3 -> getString(R.string.发错单)
|
R.id.tv_4 -> getString(R.string.在其他平台打到了车)
|
R.id.tv_5 -> getString(R.string.定位不准)
|
R.id.tv_6 -> getString(R.string.司机不愿意来接我)
|
R.id.tv_7 -> getString(R.string.无法与司机碰面)
|
R.id.tv_8 -> getString(R.string.司机迟到)
|
R.id.tv_9 -> getString(R.string.司机要求加价)
|
R.id.tv_10 -> getString(R.string.交通原因)
|
else -> getString(R.string.其他)
|
}
|
}
|
}
|
|
tv_action.setOnClickListener {
|
if (reason.isEmpty()) {
|
myToast(getString(R.string.请选择取消原因))
|
return@setOnClickListener
|
}
|
if (reason == tv_11.text.toString()) {
|
val content = et_content.text.toString()
|
if (content.isEmpty()) {
|
myToast(getString(R.string.请输入详细描述))
|
return@setOnClickListener
|
}
|
}
|
submit()
|
}
|
tv_me.setOnClickListener {
|
tv_me.isSelected = !tv_me.isSelected
|
ll_me.visibility = if (tv_me.isSelected) View.GONE else View.VISIBLE
|
}
|
tv_platform.setOnClickListener {
|
tv_platform.isSelected = !tv_platform.isSelected
|
ll_plat.visibility = if (tv_platform.isSelected) View.GONE else View.VISIBLE
|
}
|
tv_driver.setOnClickListener {
|
tv_driver.isSelected = !tv_driver.isSelected
|
ll_driver.visibility = if (tv_driver.isSelected) View.GONE else View.VISIBLE
|
}
|
tv_other.setOnClickListener {
|
tv_other.isSelected = !tv_other.isSelected
|
ll_other.visibility = if (tv_other.isSelected) View.GONE else View.VISIBLE
|
}
|
}
|
|
override fun initView() {
|
title = getString(R.string.取消订单)
|
getRule()
|
}
|
|
private val id by lazy {
|
intent.getIntExtra("id", 0)
|
}
|
private val type by lazy {
|
intent.getIntExtra("type", 0)
|
}
|
|
private var reason = ""
|
|
|
private fun submit() {
|
if (state == 5){
|
val tipDialog = TipDialog()
|
tipDialog.arguments = bundleOf("msg" to getString(R.string.取消订单吗),
|
"ok" to getString(R.string.确定取消), "cancel" to getString(R.string.不取消))
|
tipDialog.setCallback(object : TipDialog.OnClickCallback {
|
override fun onOk() {
|
cancel(1.0)
|
}
|
|
override fun onCancel() {
|
}
|
})
|
tipDialog.show(supportFragmentManager,"cancel")
|
}else{
|
showDialog()
|
HttpManager.cancelMoney(id,type).request(this) { _, data ->
|
val money = data?.optDouble("amount")?:0.0
|
val tipDialog = TipDialog()
|
if (money!=0.0){ //有取消费用
|
tipDialog.arguments = bundleOf("msg" to getString(R.string.取消要收费提示).format(money).replace(",","."),
|
"ok" to getString(R.string.确定取消), "cancel" to getString(R.string.不取消))
|
tipDialog.setCallback(object : TipDialog.OnClickCallback {
|
override fun onOk() {
|
cancel(money)
|
}
|
|
override fun onCancel() {
|
}
|
})
|
tipDialog.show(supportFragmentManager, "money")
|
}else{ //免费取消,判断是否因为司机超时
|
HttpManager.queryOrderInfo(id, type).request(this){_,_data->
|
if (_data?.driverTimeOut == "1"){ //司机超时了
|
tipDialog.arguments = bundleOf("msg" to getString(R.string.超时取消订单).format(_data?.driverTimeOutTime?:0),
|
"ok" to getString(R.string.继续等待2), "cancel" to getString(R.string.取消订单2))
|
tipDialog.setCallback(object : TipDialog.OnClickCallback {
|
override fun onOk() {
|
}
|
|
override fun onCancel() {
|
cancel(money)
|
}
|
})
|
}else{
|
tipDialog.arguments = bundleOf("msg" to getString(R.string.取消订单吗),
|
"ok" to getString(R.string.确定取消), "cancel" to getString(R.string.不取消))
|
tipDialog.setCallback(object : TipDialog.OnClickCallback {
|
override fun onOk() {
|
cancel(money)
|
}
|
|
override fun onCancel() {
|
}
|
})
|
}
|
tipDialog.show(supportFragmentManager, "money")
|
}
|
}
|
}
|
}
|
}
|
|
private fun getRule(){
|
HttpManager.getH5(7).request(this){_,data->
|
data?.let {
|
titleBar.addRightButton(getString(R.string.取消订单说明), onClickListener = View.OnClickListener { _->
|
startActivity<H5Activity>("title" to getString(R.string.取消订单说明), "url" to it.optString("content"))
|
})
|
}
|
}
|
}
|
|
private fun cancel(money:Double) {
|
val content = et_content.text.toString()
|
val currentLocation = IGoApplication.getCurrentLocation()
|
HttpManager.cancelOrder(
|
currentLocation.latitude,
|
currentLocation.longitude,
|
id,
|
type,
|
reason,
|
content
|
)
|
.request(this@CancelOrderActivity) { _, _ ->
|
setResult(Activity.RESULT_OK, intent.putExtra("money", money))
|
finish()
|
}
|
}
|
}
|