package com.future.dispatch.ui.order
|
|
import androidx.recyclerview.widget.GridLayoutManager
|
import com.example.oktrip.netUtls.callNet
|
import com.future.dispatch.R
|
import com.future.dispatch.base.BaseEvent
|
import com.future.dispatch.base.MyBaseActivity
|
import com.future.dispatch.bean.LineBean
|
import com.future.dispatch.netUtls.Api
|
import com.future.dispatch.ui.adapter.FilterStatueAdapter
|
import com.future.dispatch.ui.adapter.FilterStatueLineAdapter
|
import com.future.dispatch.utils.Cache.CacheKey
|
import com.future.dispatch.utils.clickDelay
|
import com.future.dispatch.utils.getMapByAny
|
import com.future.dispatch.utils.gone
|
import kotlinx.android.synthetic.main.activity_filter_statue.*
|
import org.greenrobot.eventbus.EventBus
|
|
/***
|
* 筛选页
|
*/
|
class FilterStatueActivity: MyBaseActivity() {
|
|
val type by lazy {
|
intent.getStringExtra("type") //1专车 2跨城
|
}
|
|
var typeString = arrayListOf("扫码下单","小程序下单","司机下单","调度下单")
|
var typeStringZc = arrayListOf("扫码下单","小程序下单")
|
|
var statueString = arrayListOf("待出发","待到达预约地点","待乘客上车","服务中","已完成","待支付","待评价","评价完成","已取消","改派中","取消待支付")
|
var statueInt = arrayListOf(2,3,4,5,6,7,8,9,10,11,12)
|
|
val typeAdapter by lazy {
|
FilterStatueAdapter()
|
}
|
|
val statueAdapter by lazy {
|
FilterStatueAdapter()
|
}
|
|
val lineAdapter by lazy {
|
FilterStatueLineAdapter()
|
}
|
|
var selectLineIdStr = CacheKey.getKeyStr("lineIds")
|
var selectTypeIdStr = CacheKey.getKeyStr("typeIds")
|
var selectStatueIdStr = CacheKey.getKeyStr("statueIds")
|
|
|
override fun setContentView() {
|
setContentView(R.layout.activity_filter_statue)
|
}
|
|
override fun initView() {
|
setTitleText("筛选")
|
if (type == "1"||type == "7"){
|
ll_city_to.gone()
|
}
|
typeAdapter.type = type
|
if (selectTypeIdStr.isNotEmpty()){
|
typeAdapter.selectPosition.addAll(selectTypeIdStr.split(",").toMutableList())
|
}
|
if(selectStatueIdStr.isNotEmpty()){
|
statueAdapter.selectPosition.addAll(selectStatueIdStr.split(",").toMutableList())
|
}
|
if(selectLineIdStr.isNotEmpty()){
|
lineAdapter.selectPosition.addAll(selectLineIdStr.split(",").toMutableList())
|
}
|
|
recycler_view_type.layoutManager = GridLayoutManager(this,4)
|
recycler_view_statue.layoutManager = GridLayoutManager(this,3)
|
recycler_view_line.layoutManager = GridLayoutManager(this,3)
|
typeAdapter.data.addAll(if (type == "1"||type == "7") typeStringZc else typeString)
|
statueAdapter.data.addAll(statueString)
|
recycler_view_type.adapter = typeAdapter
|
recycler_view_statue.adapter = statueAdapter
|
recycler_view_line.adapter = lineAdapter
|
if (type == "2"){
|
callLine()
|
}
|
|
}
|
|
private fun callLine() {
|
var map = getMapByAny()
|
callNet(Api.queryLine,map){
|
var bean = gson.fromJson<LineBean>(it, LineBean::class.java)
|
lineAdapter.data.addAll(bean.data)
|
lineAdapter.notifyDataSetChanged()
|
}
|
}
|
|
override fun setOnclick() {
|
tv_reset.clickDelay {
|
typeAdapter.selectPosition.clear()
|
statueAdapter.selectPosition.clear()
|
typeAdapter.notifyDataSetChanged()
|
statueAdapter.notifyDataSetChanged()
|
lineAdapter.selectPosition.clear()
|
lineAdapter.notifyDataSetChanged()
|
}
|
|
tv_sure.clickDelay {
|
EventBus.getDefault().post(BaseEvent(BaseEvent.FILTER_LIST_ORDER,getTypeOrder(),getStatueOrder(),getLineId()))
|
CacheKey.putKeyStr("lineIds",bySelectGetIds(lineAdapter.selectPosition))
|
CacheKey.putKeyStr("typeIds",bySelectGetIds(typeAdapter.selectPosition))
|
CacheKey.putKeyStr("statueIds",bySelectGetIds(statueAdapter.selectPosition))
|
onBackPressed()
|
}
|
}
|
|
private fun bySelectGetIds(selectPosition: MutableList<String>): String {
|
var ids = ""
|
for (item in selectPosition){
|
if(selectPosition.first() == item){
|
ids = item
|
}else{
|
ids = "$ids,$item"
|
}
|
}
|
return ids
|
}
|
|
|
private fun getLineId(): String {
|
if (lineAdapter.selectPosition.isNullOrEmpty()){
|
return ""
|
}
|
var lineIds = ""
|
for (item in lineAdapter.selectPosition){
|
var id = lineAdapter.data[item.toInt()].id.toString()
|
if (lineIds.isEmpty()){
|
lineIds = id;
|
}else{
|
lineIds = "$lineIds,$id"
|
}
|
}
|
return lineIds
|
}
|
|
private fun getTypeOrder(): String {
|
if (typeAdapter.selectPosition.isEmpty()){
|
return ""
|
}
|
var lineIds = ""
|
for (item in typeAdapter.selectPosition){
|
var id = (item.toInt()+2).toString()
|
if (lineIds.isEmpty()){
|
lineIds = id;
|
}else{
|
lineIds = "$lineIds,$id"
|
}
|
}
|
return lineIds
|
}
|
|
private fun getStatueOrder(): String {
|
if (statueAdapter.selectPosition.isEmpty()){
|
return ""
|
}
|
var lineIds = ""
|
for (item in statueAdapter.selectPosition){
|
var id = statueInt[item.toInt()].toString()
|
if (lineIds.isEmpty()){
|
lineIds = id;
|
}else{
|
lineIds = "$lineIds,$id"
|
}
|
}
|
return lineIds
|
}
|
}
|