liugl
2021-01-28 4873e23bebf15d2093ee99012d92794faeac474c
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
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)
//        }
    }
 
}