lmw
2024-05-27 c00669a852702e1aa1326872bb916f9a079b57e2
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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
package com.future.driver.ui.main.add_order
 
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import cn.sinata.xldutils.utils.clickDelay
import cn.sinata.xldutils.utils.getContent
import cn.sinata.xldutils.utils.gone
import cn.sinata.xldutils.utils.visible
import com.amap.api.location.AMapLocationListener
import com.future.driver.R
import com.future.driver.base.BaseAlipayActivity
import com.future.driver.base.BaseEvent
import com.future.driver.base.gaode.AMapKit
import com.future.driver.bean.*
import com.future.driver.netUtls.Api
import com.future.driver.netUtls.callNet
import com.future.driver.netUtls.getMapByAny
import com.future.driver.netUtls.getUserId
import com.future.driver.ui.DialogUtil
import com.future.driver.ui.adapter.PopPeopleNUmAdapter
import com.future.driver.ui.adapter.SelectNumberAdapter
import com.future.driver.utils.PhoneCheckUtil
 
import kotlinx.android.synthetic.main.activity_add_city_order.*
import kotlinx.android.synthetic.main.pop_pay_city.view.*
import kotlinx.android.synthetic.main.pop_select_car_num.view.*
import kotlinx.android.synthetic.main.pop_select_number.view.*
import kotlinx.android.synthetic.main.pop_select_type_to.view.*
import org.jetbrains.anko.toast
import org.jetbrains.anko.startActivity
 
 
/**
 * @ClassName AddCityOrderActivity
 * @Description 添加订单 - 城际
 * @Author Administrator
 * @Date 2020/10/7 14:40
 * @Version 1.0
 */
class AddCityOrderActivity : BaseAlipayActivity() {
 
    val selectNumberAdapter: SelectNumberAdapter by lazy {
        SelectNumberAdapter()
    }
 
    var startCityName: String = "" //开始城市
    var startSiteName: String = "" //开始站点名称 ->选择起点
    var startCityId: String = "" //开始站点id ->选择起点
 
    var endCityName: String = "" // 结束城市
    var endSiteName: String = "" // 结束站点名称 ->选择终点
    var endCityId: String = "" //结束站点id ->选择终点
 
    var lineId = "" //线路id ->选择线路
    var lineName = "" //线路名字 ->选择线路
 
    var orderSource = 5 //固定数值 调度端下单
    var hasPeopleNum = -1 //最大可选择出行人数 -> 选择班次
    var classStartTime = ""  //开始时间 -> 选择班次
    var lineShiftDriverId = "" //排班id -> 选择班次
    var carId = ""//车辆id -> 选择班次
    var driverId = ""//司机id -> 选择班次
 
    /***
     * 起点与结束点选择 placement定位地址
     */
    var startAddress = "" //起点
    var startLat = ""//起点纬度
    var startLon = ""//起点经度
    var endAddress = ""//终点详细地址
    var endLat = ""//终点纬度
    var endLon = ""//终点经度
    var placementAddress = "" //下单位置 3个
    var placementLat = "" //下单经纬度
    var placementLon = "" //下单经纬度
 
 
    var peopleNumber = -1 //用户选择的出行人数
    var seatNumber = ""//用户选择的座位号
    var laveSeatNumber = "" //可用剩余座位编号
    var totalSeat = -1 //车辆总座位数
    var serverCarModelId = ""//服务车型id
    var distance = "5" //找后端要接口
    var travelMode = -1 // 不包车或包车
    var currentSiteType = 0 //1:上车点 2:下车点
    var selectCityLocation = 0 //1:起点 2:2终点
 
    var money = 0.0//订单金额
 
 
    override fun setContentView() {
        setContentView(R.layout.activity_add_city_order)
    }
 
    override fun initView() {
        setTitleText("添加订单")
        travelMode = 1
        tv_car_type.text = "不包车"
        var firstLocation = false
        AMapKit.initLocation(this, AMapLocationListener {
            if (it.errorCode == 0) {
                if (!it.address.isNullOrEmpty()) {
                    placementAddress = it.address
                }
                placementLat = it.latitude.toString()
                placementLon = it.longitude.toString()
            }
        })
    }
 
    override fun setOnclick() {
        //这儿添加一个接口 获取distance参数
        tv_sure_dan.clickDelay {
            if (carId.isEmpty() || driverId.isEmpty() || endAddress.isEmpty()
                    || endLat.isEmpty() || endLon.isEmpty() || lineId.isEmpty() || lineShiftDriverId.isEmpty() ||
                    carId.isEmpty() || et_phone_c.getContent().isEmpty() || peopleNumber == -1 ||
                    placementAddress.isEmpty() || placementLat.isEmpty() || placementLon.isEmpty() || serverCarModelId.isEmpty() ||
                    startAddress.isEmpty() || startLat.isEmpty() || startLon.isEmpty() || totalSeat == -1
            ) {
                toast("请填写完整信息")
                return@clickDelay
            }
            if (travelMode == 1 && seatNumber.isEmpty()) { //拼车 没选座位
                toast("请填写完整信息")
                return@clickDelay
            }
            if (!PhoneCheckUtil.phoneCheck(et_phone_c.getContent())) {
                toast("请输入正确的乘车人电话")
                return@clickDelay
            }
            callMoney() {
                var map = getMapByAny()
                map["carId"] = carId
                map["distance"] = it.distance
                map["driverId"] = driverId
                map["endAddress"] = endAddress
                map["endLat"] = endLat
                map["endLon"] = endLon
                map["lineId"] = lineId
                map["lineShiftDriverId"] = lineShiftDriverId
                map["orderSource"] = orderSource
                if (!et_name_c.getContent().isEmpty()) {
                    map["passengers"] = et_name_c.getContent()
                }
                map["passengersPhone"] = et_phone_c.getContent()
                map["peopleNumber"] = peopleNumber
                map["placementAddress"] = placementAddress
                map["placementLat"] = placementLat
                map["placementLon"] = placementLon
                map["seatNumber"] = seatNumber
                map["serverCarModelId"] = serverCarModelId
                map["startAddress"] = startAddress
                map["startLat"] = startLat
                map["startLon"] = startLon
                map["totalSeat"] = totalSeat
                map["travelMode"] = travelMode
                map["travelTime"] = tv_select_class.text.toString().substring(0,16)+":00"
                callNet(Api.orderCrossCity, map) {
                    var bean = gson.fromJson<AddOrderBean>(it, AddOrderBean::class.java)
                    money = bean.data.amount
                    showPatTypeDialog(bean.data.id.toString())
                }
            }
        }
 
        ll_select_type.clickDelay {
            var pop = DialogUtil.getPopupwindow(this, R.layout.pop_select_type_to)
            pop.contentView.view_top_zc.clickDelay {
                pop.dismiss()
            }
            pop.contentView.tv_pc.clickDelay {
                travelMode = 1
                tv_car_type.text = "不包车"
                ll_select_number.visible()
                pop.dismiss()
            }
            pop.contentView.tv_zc.clickDelay {
                travelMode = 2
                tv_car_type.text = "包车"
                pop.dismiss()
                ll_select_number.gone()
            }
            pop.showDown(window.decorView)
        }
 
 
        ll_select_city_end.clickDelay {
            selectCityLocation = 2
            if (startSiteName.isEmpty()) {
                toast("请先选择起点")
                return@clickDelay
            }
            startActivity<SelectCityStartActivity>("startCityId" to startCityId)
        }
 
        ll_select_city_start.clickDelay {
            selectCityLocation = 1
            startActivity<SelectCityStartActivity>()
        }
 
        ll_select_car_num.clickDelay {
            if (lineId.isEmpty()) {
                toast("请先选择线路")
                return@clickDelay
            }
            startActivity<SelectClassActivity>("lineId" to lineId, "startCityName" to startSiteName, "endCityName" to endSiteName)
        }
 
        ll_select_car_line.clickDelay {
            if (startCityId.isEmpty() || endCityId.isEmpty()) {
                toast("请先选择起点和终点")
                return@clickDelay
            }
            startActivity<SelectLineActivity>("endId" to endCityId, "startId" to startCityId)
        }
 
        ll_start_point.clickDelay {
            if (startCityId.isEmpty()) {
                toast("请先选择起点城市")
                return@clickDelay
            }
            currentSiteType = 1
            startActivity<SelectStartPointActivity>(
                    "startCityId" to startCityId, "name" to startCityName
            )
        }
 
        ll_end_point.clickDelay {
            if (endCityId.isEmpty()) {
                toast("请先选择终点城市")
                return@clickDelay
            }
            currentSiteType = 2
            startActivity<SelectStartPointActivity>("endCityId" to endCityId, "name" to endCityName)
        }
 
        ll_select_car_people_num.clickDelay {
            if (hasPeopleNum == -1) {
                toast("请先选择班次")
                return@clickDelay
            }
            var pop = DialogUtil.getPopupwindow(this, R.layout.pop_select_car_num)
            pop.contentView.recycler_view_people_num.layoutManager = LinearLayoutManager(this)
            var popPeopleNumAdapter = PopPeopleNUmAdapter(hasPeopleNum)
            pop.contentView.recycler_view_people_num.adapter = popPeopleNumAdapter
            popPeopleNumAdapter.selectPosition = 0
            pop.contentView.view_top.clickDelay {
                pop.dismiss()
            }
            popPeopleNumAdapter.setOnItemClickListener { view, position ->
                popPeopleNumAdapter.selectPosition = position
                popPeopleNumAdapter.notifyDataSetChanged()
            }
            pop.contentView.tv_pop_sure_people_num.clickDelay {
                tv_select_people_num.text =
                        (popPeopleNumAdapter.selectPosition + 1).toString() + "人"
                peopleNumber = popPeopleNumAdapter.selectPosition + 1
                pop.dismiss()
            }
            pop.showDown(window.decorView)
        }
 
        ll_select_number.clickDelay {
            if (peopleNumber == -1) {
                toast("请先选择乘车人数")
                return@clickDelay
            }
            if (laveSeatNumber.isEmpty()) {
                toast("无可用座位")
                return@clickDelay
            }
            callSeat(lineShiftDriverId) {
                var list = mutableListOf<String>()
                var listHave = it.content.split(",")
                var pop = DialogUtil.getPopupwindow(this, R.layout.pop_select_number)
                if (totalSeat < 6) {
                    addSeat(4, list)
                    pop.contentView.iv_leat_num.setImageResource(R.mipmap.seat_five)
                } else {
                    addSeat(6, list)
                    pop.contentView.iv_leat_num.setImageResource(R.mipmap.seat_seven)
                }
                pop.contentView.recycler_view_people_number.layoutManager = GridLayoutManager(this, 3)
                pop.contentView.recycler_view_people_number.adapter = selectNumberAdapter
                selectNumberAdapter.haveContent.clear()
                selectNumberAdapter.selectPosition.clear()
                selectNumberAdapter.haveContent.addAll(listHave)
                selectNumberAdapter.data.clear()
                selectNumberAdapter.data.addAll(list)
                selectNumberAdapter.notifyDataSetChanged()
                pop.contentView.tv_pop_sure_people_number.clickDelay {
                    if (peopleNumber != selectNumberAdapter.selectPosition.size) {
                        toast("请选择" + peopleNumber + "个座位")
                        return@clickDelay
                    }
                    if (selectNumberAdapter.selectPosition.size == 0) {
                        toast("请选择位置")
                        return@clickDelay
                    }
                    seatNumber = selectNumberAdapter.getPeopleStr()
                    rv_select_zw.text = selectNumberAdapter.getPeopleStrAll()
                    pop.dismiss()
                }
                pop.contentView.view_top_number.clickDelay {
                    pop.dismiss()
                }
                pop.showDown(window.decorView)
            }
        }
 
 
    }
 
    private fun addSeat(i: Int, list: MutableList<String>) {
        var c = 0
        while (c < i) {
            c++
            list.add(c.toString())
        }
    }
 
    private fun callSeat(lineShiftDriverId: String, function: (SeatBean.DataBeanX) -> Unit) {
        var map = getMapByAny()
        map["id"] = lineShiftDriverId
        callNet(Api.querySeat, map) {
            var bean = gson.fromJson<SeatBean>(it, SeatBean::class.java)
            function(bean!!.data)
        }
    }
 
    override fun aliPaySuccess() {
        super.aliPaySuccess()
        onBackPressed()
    }
 
 
    private fun showPatTypeDialog(orderId: String) {
        var pop = DialogUtil.getPopupwindow(this, R.layout.pop_pay_city)
        pop.showDown(window.decorView)
        pop.contentView.btn_money.clickDelay {
            //二维码
            downOrder("3", orderId)
            pop.dismiss()
        }
        pop.contentView.button_cancel.clickDelay {
            pop.dismiss()
        }
 
        pop.contentView.btn_album.clickDelay {
//            showPat("1")
//            val content = ReassignActivity.RemarkData("改派原因啊", "这个是备注", CacheKey.getUserId())
//            val path =
//                "pages/appPay/appPay?orderId=$orderId&orderType=3&type=1" + "&uid=" + CacheKey.getUserId() + "&userType=2"
//            WXPayEntryActivity.toWx(this, intent, path)
 
            pop.dismiss()
        }
 
        pop.contentView.btn_alipay.clickDelay {
            downOrder("2", orderId)
            pop.dismiss()
        }
    }
 
    private fun downOrder(paytype: String, orderId: String) {
        var map = getMapByAny()
        map["orderId"] = orderId
        map["orderType"] = "3"
        map["payType"] = paytype
        map["type"] = "2"
        callNet(Api.payTaxiOrder, map) {
            if (paytype == "2") {
                var data = gson.fromJson<AlipayBean2>(it, AlipayBean2::class.java)
                payV2(data.data.orderString)
            }
            if (paytype == "3" || paytype.isEmpty()) {
                var data = gson.fromJson<AlipayBean2>(it, AlipayBean2::class.java)
                startActivity<PayQrCodeActivity>("url" to data.data.code_url,"money" to money)
                finish()
            }
        }
    }
 
 
    private fun callMoney(function: (QueryOrderMoneyBean.DataBean) -> Unit) {
        var map = getMapByAny()
        map["endLonLat"] = "$endLon,$endLat"
        map["lineId"] = lineId
        map["peopleNumber"] = peopleNumber
        map["seatNumber"] = seatNumber
        map["serverCarModelId"] = serverCarModelId
        map["startLonLat"] = "$startLon,$startLat"
        map["totalSeat"] = totalSeat
        map["travelMode"] = travelMode
        callNet(Api.queryOrderMoney, map) {
            var bean = gson.fromJson<QueryOrderMoneyBean>(it, QueryOrderMoneyBean::class.java)
            function(bean.data)
        }
 
    }
 
//    /***
//     * 根据排班id获取最大出行人数
//     */
//    private fun callPeopleNum() {
//        var map = getMapByAny()
//        map["id"] = lineShiftDriverId
//        callNet(Api.querySeat,map){
//            var bean = gson.fromJson<PeopleNumBean>(it,PeopleNumBean::class.java)
//        }
//
//    }
 
 
    override fun onEventMainThread(event: BaseEvent?) {
        super.onEventMainThread(event)
        when (event!!.code) {
            BaseEvent.SELECT_POINT_SITE -> {
                if (selectCityLocation == 1) {
                    startSiteName = event.msg
                    startCityId = event.msgTwo
                    startCityName = event.msgthree
                    tv_start_point.text = startSiteName
                    clearByType(1)
                }
                if (selectCityLocation == 2) {
                    endSiteName = event.msg
                    endCityId = event.msgTwo
                    endCityName = event.msgthree
                    tv_end_point.text = endSiteName
                    clearByType(2)
                    callLine()
                }
            }
            BaseEvent.SELECT_LINE_SITE -> {
                lineId = event.msg
                lineName = event.msgTwo
                tv_line.text = lineName
                clearByType(3)
            }
            BaseEvent.SELECT_CLASS_SITE -> {
                var data = gson.fromJson<SelectClassBean.DataBean>(
                        event.msg,
                        SelectClassBean.DataBean::class.java
                )
                lineShiftDriverId = data.lineShiftDriverId.toString()
                classStartTime = data.startTime
                carId = data.carId.toString()
                driverId = data.driverId.toString()
                tv_select_class.text = data.allTime
                laveSeatNumber = data.laveSeatNumber
                totalSeat = data.totalSeat
                hasPeopleNum = data.laveSeat
                serverCarModelId = data.serverCarModelId.toString()
                tv_driver.text = data.name
                tv_car_num.text = data.carLicensePlate
                clearByType(4)
            }
 
            BaseEvent.SELECT_POINT_SITE_DETAIL -> {
                if (currentSiteType == 1) {
                    startAddress = event.msg
                    startLat = event.msgTwo
                    startLon = event.msgthree
                    tv_up_point.text = startAddress
                    if (startAddress.length > 15) {
                        tv_up_point.text = startAddress.substring(0, 15) + "..."
                    }
                }
                if (currentSiteType == 2) {
                    endAddress = event.msg
                    endLat = event.msgTwo
                    endLon = event.msgthree
                    tv_down_point.text = endAddress
                    if (endAddress.length > 15) {
                        tv_down_point.text = endAddress.substring(0, 15) + "..."
                    }
                }
            }
        }
    }
 
    private fun callLine() {
        var map = getMapByAny()
        map["driverId"] = getUserId()
        map["endId"] = endCityId
        map["startId"] = startCityId
        callNet(Api.queryLines_by_line, map) {
            var bean = gson.fromJson<LineBean>(it, LineBean::class.java)
            if (bean.data.isEmpty() || bean.data.size > 1) {
 
            } else {
                lineId = bean.data[0].id.toString()
                lineName = bean.data[0].name
                tv_line.text = lineName
                clearByType(3)
            }
        }
    }
 
    /***
     * 根据选项 删除以后的数据
     */
    private fun clearByType(i: Int) {
        if (i < 5) {
            tv_select_people_num.text = ""
            peopleNumber = -1
            seatNumber = ""
            rv_select_zw.text = ""
        }
        if (i < 4) {
            lineShiftDriverId = ""
            classStartTime = ""
            carId = ""
            driverId = ""
            tv_select_class.text = ""
            laveSeatNumber = ""
            totalSeat = -1
            hasPeopleNum = -1
            serverCarModelId = ""
            tv_driver.text = ""
            tv_car_num.text = ""
        }
        if (i < 3) {
            lineId = ""
            lineName = ""
            tv_line.text = ""
            endAddress = ""
            endLat = ""
            endLon = ""
            tv_down_point.text = ""
        }
        if (i < 2) {
            endSiteName = ""
            endCityId = ""
            tv_end_point.text = ""
            endAddress = ""
            endLat = ""
            endLon = ""
            tv_down_point.text = ""
            startAddress = ""
            startLat = ""
            startLon = ""
            tv_up_point.text = ""
        }
 
    }
 
 
}