package com.fuban.user.ui.trip
|
|
import android.app.Activity
|
import android.view.View
|
import android.widget.RadioButton
|
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.fuban.user.R
|
import com.fuban.user.network.HttpManager
|
import com.fuban.user.network.request
|
import com.fuban.user.ui.H5Activity
|
import com.fuban.user.ui.TransparentStatusBarActivity
|
import com.fuban.user.dialog.TipDialog
|
import com.fuban.user.utils.Const
|
import kotlinx.android.synthetic.main.activity_cancel_order.*
|
|
|
import org.jetbrains.anko.find
|
import org.jetbrains.anko.startActivity
|
|
/**
|
* 取消订单
|
*/
|
class CancelOrderActivity : TransparentStatusBarActivity() {
|
|
override fun setContentView(): Int = R.layout.activity_cancel_order
|
|
override fun initClick() {
|
rg.setOnCheckedChangeListener { group, checkedId ->
|
reason = find<RadioButton>(checkedId).text.toString()
|
if (checkedId == R.id.rb_8) {//其他理由
|
reason = "其他"
|
}
|
}
|
|
tv_action.setOnClickListener {
|
if (reason.isEmpty()) {
|
myToast("请选择取消原因")
|
return@setOnClickListener
|
}
|
if (rg.checkedRadioButtonId == R.id.rb_8) {
|
val content = et_content.text.toString()
|
if (content.isEmpty()) {
|
myToast("请输入详细描述")
|
return@setOnClickListener
|
}
|
}
|
submit()
|
}
|
}
|
|
override fun initView() {
|
title = "取消订单"
|
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 (type == Const.OrderType.TYPE_CROSS_CITY){//跨城直接取消
|
val tipDialog = TipDialog()
|
tipDialog.arguments =
|
bundleOf("msg" to "您确定要取消该订单吗?", "ok" to "确定取消", "cancel" to "不取消")
|
tipDialog.setCallback(object : TipDialog.OnClickCallback {
|
override fun onOk() {
|
cancel(0.0)
|
}
|
|
override fun onCancel() {
|
}
|
})
|
tipDialog.show(supportFragmentManager, "money")
|
}else{
|
showDialog()
|
HttpManager.cancelMoney(id,type).request(this) { _, data ->
|
val money = data?.optDouble("amount")?:0.0
|
val tipDialog = TipDialog()
|
tipDialog.arguments =
|
bundleOf("msg" to if (money == 0.0)"您确定要取消该订单吗?" else "司机接单以后取消订单\n将收取您${money}元服务费", "ok" to "确定取消", "cancel" to "不取消")
|
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("取消订单说明", onClickListener = View.OnClickListener {_->
|
startActivity<H5Activity>("title" to "取消订单说明", "url" to it.optString("content"))
|
})
|
|
}
|
}
|
}
|
|
private fun cancel(money:Double) {
|
val content = et_content.text.toString()
|
HttpManager.cancelOrder(id, type,reason, content)
|
.request(this@CancelOrderActivity) { _, _ ->
|
setResult(Activity.RESULT_OK, intent.putExtra("money", money))
|
finish()
|
}
|
}
|
}
|