18034727885
2026-07-24 6180e2986ca3c39262486458cee97e54d5f67450
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
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()
            }
    }
}