package com.fuban.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.fuban.driver.R
|
import com.fuban.driver.base.BaseAlipayActivity
|
import com.fuban.driver.base.BaseEvent
|
import com.fuban.driver.base.gaode.AMapKit
|
import com.fuban.driver.bean.*
|
import com.fuban.driver.netUtls.Api
|
import com.fuban.driver.netUtls.callNet
|
import com.fuban.driver.netUtls.getMapByAny
|
import com.fuban.driver.netUtls.getUserId
|
import com.fuban.driver.ui.DialogUtil
|
import com.fuban.driver.ui.adapter.PopPeopleNUmAdapter
|
import com.fuban.driver.ui.adapter.SelectNumberAdapter
|
import com.fuban.driver.utils.Cache.CacheKey
|
import com.fuban.driver.utils.DateUtil
|
import com.fuban.driver.utils.PhoneCheckUtil
|
import com.fuban.driver.wxapi.WXPayEntryActivity
|
|
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 startCityId: String = "" //开始站点id ->选择起点
|
|
var endCityName: 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终点
|
|
|
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"] = DateUtil.getTime(DateUtil.TYPE0, System.currentTimeMillis())
|
callNet(Api.orderCrossCity, map) {
|
var bean = gson.fromJson<AddOrderBean>(it, AddOrderBean::class.java)
|
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 (startCityName.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 startCityName, "endCityName" to endCityName)
|
}
|
|
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, 4)
|
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)
|
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) {
|
startCityName = event.msg
|
startCityId = event.msgTwo
|
tv_start_point.text = startCityName
|
clearByType(1)
|
}
|
if (selectCityLocation == 2) {
|
endCityName = event.msg
|
endCityId = event.msgTwo
|
tv_end_point.text = endCityName
|
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) {
|
endCityName = ""
|
endCityId = ""
|
tv_end_point.text = ""
|
endAddress = ""
|
endLat = ""
|
endLon = ""
|
tv_down_point.text = ""
|
startAddress = ""
|
startLat = ""
|
startLon = ""
|
tv_up_point.text = ""
|
}
|
|
}
|
|
|
}
|