lmw
2023-05-12 f67802a41f9e01444d1115f34ecc6e1beb05fc3b
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
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()
            }
    }
}