package com.kuanzhai.driver.ui.driver_server
|
|
import android.view.View
|
import androidx.core.content.ContextCompat
|
import androidx.recyclerview.widget.GridLayoutManager
|
import cn.sinata.xldutils.utils.*
|
import com.driver.emanagercar.ui.base.BaseWebActivity
|
import com.kuanzhai.driver.R
|
import com.kuanzhai.driver.base.BaseEvent
|
import com.kuanzhai.driver.base.local.BasePhotoActivity
|
import com.kuanzhai.driver.bean.*
|
import com.kuanzhai.driver.netUtls.Api
|
import com.kuanzhai.driver.netUtls.callNet
|
import com.kuanzhai.driver.netUtls.getMapByAny
|
import com.kuanzhai.driver.ui.DialogUtil
|
import com.kuanzhai.driver.ui.adapter.CarUpPhotoAdapter
|
import com.kuanzhai.driver.ui.adapter.UpPhotoAdapter
|
import com.kuanzhai.driver.ui.driver_server.adapter.CarAddAdapter
|
import com.kuanzhai.driver.ui.pub.ImageActivity
|
import com.kuanzhai.driver.utils.AndroidBug5497Workaround
|
import com.kuanzhai.driver.utils.Cache.CacheKey
|
import com.kuanzhai.driver.utils.DateUtil
|
import com.kuanzhai.driver.utils.citypickerview.picker.widget.builder.TimePickerBuilder
|
import com.kuanzhai.driver.utils.citypickerview.picker.widget.listener.OnOptionsSelectListener
|
import com.kuanzhai.driver.utils.glide.GlideUtil
|
import com.lljjcoder.Interface.OnCityItemClickListener
|
import com.lljjcoder.bean.CityBean
|
import com.lljjcoder.bean.DistrictBean
|
import com.lljjcoder.bean.ProvinceBean
|
import kotlinx.android.synthetic.main.activity_sell_car_send.*
|
import org.jetbrains.anko.startActivity
|
import org.jetbrains.anko.toast
|
import java.util.*
|
|
class SellCarSendActivity : BasePhotoActivity() {
|
val carId by lazy {
|
intent.getStringExtra("carId")
|
}
|
|
var category = true //是否营运车辆
|
var isPledge = false //是否有抵押
|
var containUserMoney = false //是否包含过户费用
|
var selectBook = false //是否勾选协议
|
var select_car_p_id = "" //品牌id
|
var img = "" //描述图片
|
var videoUrl = "" //视频图片
|
var contactsProvinceCode = "" //联系人省code
|
var contactscityCode = "" //联系人市code
|
|
val carAddAdapter by lazy {
|
CarAddAdapter()
|
}
|
|
val upPhotoAdapter by lazy {
|
CarUpPhotoAdapter()
|
}
|
|
|
val upPhotoAdapterOne by lazy {
|
CarUpPhotoAdapter()
|
}
|
|
override fun setContentView() {
|
setContentView(R.layout.activity_sell_car_send)
|
}
|
|
override fun onEventMainThread(event: BaseEvent?) {
|
super.onEventMainThread(event)
|
if (event!!.code == BaseEvent.UPDATE_CAE_NUM){
|
tv_car_phone_num.text = "*车辆图片"+ (upPhotoAdapter.data.size-1) +"/15"
|
}
|
}
|
|
|
override fun onBackPressed() {
|
DialogUtil.getDelAndSureDialog(this,"您的数据还未提交,确认返回?",{}){
|
super.onBackPressed()
|
}
|
}
|
|
|
override fun initView() {
|
AndroidBug5497Workaround.assistActivity(this)
|
setTitleText("卖车信息发布")
|
et_phone_num.setText(CacheKey.getUserInfo().phone)
|
et_phone_num.isEnabled = false
|
recycler_view_add.layoutManager = GridLayoutManager(this, 2)
|
recycler_view_add.adapter = carAddAdapter
|
carAddAdapter.setData()
|
|
recycler_view_img_all.layoutManager = GridLayoutManager(this, 3)
|
upPhotoAdapter.data.add("")
|
upPhotoAdapter.maxLength = 15
|
recycler_view_img_all.adapter = upPhotoAdapter
|
|
recycler_view_img_all_one.layoutManager = GridLayoutManager(this, 3)
|
upPhotoAdapterOne.data.add("")
|
upPhotoAdapterOne.maxLength = 8
|
recycler_view_img_all_one.adapter = upPhotoAdapterOne
|
|
showType(true)
|
if (!carId.isNullOrEmpty()){
|
callDetail()
|
}
|
}
|
|
fun showType(left: Boolean) {
|
category = left
|
ll_user_num.visibility = if (left) View.VISIBLE else View.GONE
|
ll_time_over.visibility = if (!left) View.VISIBLE else View.GONE
|
ll_time_change_car_company.visibility = if (!left) View.VISIBLE else View.GONE
|
if (left) {
|
tv_pub_car.setBackgroundResource(R.drawable.bg_main_back)
|
tv_pub_car.textColor(this, R.color.white)
|
tv_company_car.setBackgroundResource(R.color.white)
|
tv_company_car.textColor(this, R.color.color_989bb0)
|
} else {
|
tv_company_car.setBackgroundResource(R.drawable.bg_main_back)
|
tv_company_car.textColor(this, R.color.white)
|
tv_pub_car.setBackgroundResource(R.color.white)
|
tv_pub_car.textColor(this, R.color.color_989bb0)
|
}
|
}
|
|
|
|
override fun setOnclick() {
|
|
upPhotoAdapter.setOnItemClickListener { view, position ->
|
if (upPhotoAdapter.data[position].isEmpty()){
|
imgType = 2
|
showSelectPhone(16 - upPhotoAdapter.data.size,false)
|
}else{
|
startActivity<ImageActivity>("url" to upPhotoAdapter.data[position])
|
}
|
}
|
|
ll_photo_site.clickDelay {
|
hideKeyboard(this.window.decorView)
|
showCityPop() { province, city, area,provinceCode,cityCode, areaCode ->
|
tv_card_site.text = city
|
}
|
}
|
|
upPhotoAdapterOne.setOnItemClickListener { view, position ->
|
if (upPhotoAdapterOne.data[position].isEmpty()){
|
imgType = 1
|
showSelectPhone(9 - upPhotoAdapterOne.data.size,false)
|
}else{
|
startActivity<ImageActivity>("url" to upPhotoAdapterOne.data[position])
|
}
|
}
|
iv_select_video.clickDelay {
|
imgType = 3
|
openAlbumVideo(1)
|
}
|
|
|
ll_pai.clickDelay {
|
hideKeyboard(this.window.decorView)
|
callNet(Api.queryAllBrand, getMapByAny()) { carallStr ->
|
var carAll = gson.fromJson<AllCarBean>(carallStr, AllCarBean::class.java)
|
var position = getPositionCar(carAll,select_car_p_id)
|
DialogUtil.getNetOneDialog(position,carAll.data as ArrayList<AllCarBean.DataBean>, window.decorView, this) { selectCar ->
|
tv_select_car_p.text = selectCar.name
|
select_car_p_id = selectCar.id.toString()
|
}
|
}
|
}
|
|
ll_rank.clickDelay {
|
hideKeyboard(this.window.decorView)
|
var rankstr = "微型车、小型车、紧凑型车、中型车、中大型车、大型车、小型SUV、紧凑型SUV、中型SUV、中大型SUV、大型SUV、紧凑型MPV、中型MPV、中大型MPV、大型MPV、跑车、皮卡、微面、轻客、微卡";
|
var ranklist = rankstr.split("、").toMutableList()
|
DialogUtil.getOptionListDialog("选择级别",this,ranklist,object : OnOptionsSelectListener{
|
override fun onOptionsSelect(
|
view: View?,
|
options1: Int,
|
options2: Int,
|
options3: Int
|
): Boolean {
|
tv_rank.text = ranklist[options1]
|
return false
|
}
|
})
|
}
|
|
tv_pub_car.clickDelay {
|
hideKeyboard(this.window.decorView)
|
showType(true)
|
}
|
tv_company_car.clickDelay {
|
hideKeyboard(this.window.decorView)
|
showType(false)
|
}
|
|
tv_have.clickDelay {
|
hideKeyboard(this.window.decorView)
|
isPledge = true
|
setPledges(isPledge)
|
}
|
|
|
|
tv_none.clickDelay {
|
hideKeyboard(this.window.decorView)
|
isPledge = false
|
setPledges(isPledge)
|
}
|
|
ll_time_first_car.clickDelay {
|
hideKeyboard(this.window.decorView)
|
var startCalendar = Calendar.getInstance()
|
var endCalendar = Calendar.getInstance()
|
startCalendar.set(1950, 1, 1)
|
endCalendar.timeInMillis = (System.currentTimeMillis())
|
showTime(startCalendar,endCalendar,Calendar.getInstance()){
|
tv_first_time_str.text = DateUtil.getTime(DateUtil.TYPE1, it.time)
|
}
|
}
|
|
|
iv_select_add_user_money.clickDelay {
|
containUserMoney = !containUserMoney
|
iv_select_add_user_money.setImageResource(if (containUserMoney) R.mipmap.car_select_blue else R.mipmap.car_select_blue_false)
|
}
|
|
ll_time_change_car_company.clickDelay {
|
hideKeyboard(this.window.decorView)
|
var startCalendar = Calendar.getInstance()
|
var endCalendar = Calendar.getInstance()
|
startCalendar.timeInMillis = (System.currentTimeMillis() - (1000L * 3600L * 24L * 365L * 50L))
|
showTime(startCalendar,endCalendar,Calendar.getInstance()){
|
tv_time_change_car_company.text = DateUtil.getTime(DateUtil.TYPE1, it.time)
|
}
|
}
|
|
|
ll_insurance.clickDelay {
|
hideKeyboard(this.window.decorView)
|
var startCalendar = Calendar.getInstance()
|
var endCalendar = Calendar.getInstance()
|
endCalendar.timeInMillis = (System.currentTimeMillis() + (1000L * 3600L * 24L * 365L * 50L))
|
showTime(startCalendar,endCalendar,Calendar.getInstance()){
|
tv_insurance.text = DateUtil.getTime(DateUtil.TYPE1, it.time)
|
}
|
}
|
|
ll_year_time.clickDelay {
|
hideKeyboard(this.window.decorView)
|
var startCalendar = Calendar.getInstance()
|
var endCalendar = Calendar.getInstance()
|
endCalendar.timeInMillis = (System.currentTimeMillis() + (1000L * 3600L * 24L * 365L * 50L))
|
showTime(startCalendar,endCalendar,Calendar.getInstance()){
|
tv_year_time.text = DateUtil.getTime(DateUtil.TYPE1, it.time)
|
}
|
}
|
|
ll_business_time.clickDelay {
|
hideKeyboard(this.window.decorView)
|
var startCalendar = Calendar.getInstance()
|
var endCalendar = Calendar.getInstance()
|
endCalendar.timeInMillis = (System.currentTimeMillis() + (1000L * 3600L * 24L * 365L * 50L))
|
showTime(startCalendar,endCalendar,Calendar.getInstance()){
|
tv_business_time.text = DateUtil.getTime(DateUtil.TYPE1, it.time)
|
}
|
}
|
|
|
iv_select_book.clickDelay {
|
selectBook = !selectBook
|
iv_select_book.setImageResource(if (selectBook) R.mipmap.select_ture else R.mipmap.select_false)
|
}
|
|
tv_select_book.clickDelay {
|
hideKeyboard(this.window.decorView)
|
var map = getMapByAny()
|
map["type"] = 20
|
callNet(Api.queryByType, map) {
|
var data = gson.fromJson<AgreeBean>(it, AgreeBean::class.java)
|
BaseWebActivity.to(mContext, data.data.content, "宽窄优行汽车售卖协议", "1")
|
}
|
}
|
|
|
|
ll_contacts_site.clickDelay {
|
hideKeyboard(this.window.decorView)
|
showCityPop() { province, city, area,provinceCode,cityCode, areaCode ->
|
contactsProvinceCode = provinceCode
|
contactscityCode = cityCode
|
tv_province.text = province
|
tv_city_contacts.text = city
|
}
|
}
|
|
tv_add_commit.clickDelay {
|
hideKeyboard(this.window.decorView)
|
if (et_titie.getContent().isEmpty()
|
|| et_code.getContent().isEmpty()
|
|| et_plate.getContent().isEmpty()
|
|| tv_select_car_p.getContent().isEmpty()
|
|| et_color.getContent().isEmpty()
|
|| tv_first_time_str.getContent().isEmpty()
|
|| et_mileage.getContent().isEmpty()
|
|| tv_card_site.getContent().isEmpty()
|
|| (category && et_change_username_num.getContent().isEmpty())
|
|| tv_displacement.getContent().isEmpty()
|
|| et_transmission_case.getContent().isEmpty()
|
|| tv_rank.getContent().isEmpty()
|
|| (!category && et_time_over.getContent().isEmpty())
|
|| et_transfer_price.getContent().isEmpty()
|
|| et_remark.getContent().isEmpty()){
|
toast("请输入完整基本信息")
|
return@clickDelay
|
}
|
if (upPhotoAdapter.data.size < 2){
|
toast("上传完整车辆信息")
|
return@clickDelay
|
}
|
if (tv_insurance.getContent().isEmpty()
|
|| tv_year_time.getContent().isEmpty()
|
|| tv_business_time.getContent().isEmpty()){
|
toast("请填写完成更多信息模块")
|
return@clickDelay
|
}
|
if (et_phone_num.getContent().isEmpty()
|
|| et_phone_num.getContent().length < 11
|
|| tv_contacts_name.getContent().isEmpty()
|
|| tv_province.getContent().isEmpty()
|
|| tv_city_contacts.getContent().isEmpty()
|
|| tv_detail_site.getContent().isEmpty()){
|
toast("请填写完整联系人信息")
|
return@clickDelay
|
}
|
if (!selectBook){
|
toast("请勾选卖车协议")
|
return@clickDelay
|
}
|
var map = getMapByAny()
|
map["addres"] = tv_detail_site.getContent() //地址
|
// map["authRemark"] = ""//审核备注
|
map["brandId"] = select_car_p_id//品牌id
|
map["brandName"] = tv_select_car_p.getContent()//品牌名称
|
map["carColor"] = et_color.getContent()// 车辆颜色
|
map["carIdentificationCode"] = et_code.getContent()//车辆识别码
|
map["carLicensePlate"] = et_plate.getContent()//车牌号
|
map["category"] = if (category) 1 else 2 //类别 1 非运营 2营运
|
map["cityCode"] = contactscityCode//市Code
|
map["cityName"] = tv_city_contacts.getContent()//cityName
|
map["contactsName"] = tv_contacts_name.getContent()//联系人名称
|
map["contactsPhone"] = et_phone_num.getContent()
|
map["describe"] = et_remark.getContent()//描述
|
map["describeImgUrl"] = img//描述图片
|
map["displacement"] = tv_displacement.getContent()//排量
|
map["dueTimeOfCompulsoryInsurance"] = tv_insurance.getContent()//交强险到期时间
|
map["expirationTimeOfAnnualInspection"] = tv_year_time.getContent()//年检到期时间
|
if (!carId.isNullOrEmpty()){
|
map["id"] = carId//
|
}
|
map["imgUrl"] = upPhotoAdapter.getImg()//
|
map["includingTransferFee"] = if (containUserMoney) "1" else "2"//是否包含过户费(1=是,2=否)
|
map["installationConfiguration"] = carAddAdapter.getDataStr()//加装配置
|
map["level"] = tv_rank.getContent()//
|
map["licensingTime"] = tv_first_time_str.getContent()//上牌时间
|
map["locationOfLicensePlate"] = tv_card_site.getContent()//牌照所在地
|
map["maturityTimeOfCommercialInsurance"] = tv_business_time.getContent()//商业险到期时间
|
map["mileage"] = et_mileage.getContent()//行驶里程
|
map["mortgage"] = if (isPledge) "1" else "2"//是否有抵押(1=是,2=否)
|
map["newCarPrice"] = et_new_car_money.getContent()//新车价格
|
map["operationUpdateTime"] = tv_time_change_car_company.getContent()//营运更新时间
|
map["provinceCode"] = contactsProvinceCode //省Code
|
map["provinceName"] = tv_province.getContent()//
|
if (!et_time_over.getContent().isNullOrEmpty()){
|
map["remainingOperationTime"] = et_time_over.getContent()//剩余营运时间
|
}
|
// map["status"] = ""//状态(1=待审核,2=已上架,3=已下架,4=审核通过待上架,5=已拒绝,6=删除)
|
map["title"] = et_titie.getContent()//标题
|
map["transferPrice"] = et_transfer_price.getContent()//转让费
|
if (!et_change_username_num.getContent().isNullOrEmpty()){
|
map["transferTimes"] = et_change_username_num.getContent()//过户次数
|
}
|
map["transmissionCase"] = et_transmission_case.getContent()//变速箱
|
map["userId"] = CacheKey.getUserId()//
|
map["userType"] = "2"//
|
map["videoUrl"] = videoUrl//
|
callNet(Api.insertOrUpdateSellingCar,map){
|
startActivity<SendOverActivity>("title" to "卖车信息发布")
|
finish()
|
}
|
}
|
|
}
|
|
var imgType = -1 // 1 车况图片选择 2 车辆图片 3 车辆视频
|
|
fun showTime(startTime:Calendar,endTime:Calendar,currentTime:Calendar,function:(Date) -> Unit){
|
var timePic = TimePickerBuilder(
|
this
|
) { date, v ->
|
function(date)
|
}
|
.setTitleText("")
|
.setBgColor(ContextCompat.getColor(this, R.color.white))
|
.setCancelColor(ContextCompat.getColor(this, R.color.black_333333))
|
.setSubmitColor(ContextCompat.getColor(this, R.color.main_yellow))
|
.setRangDate(startTime, endTime)
|
.setDate(currentTime)
|
.setSubmitText("确认")
|
.setLineSpacingMultiplier(2f)
|
.build()
|
timePic.show()
|
}
|
|
|
override fun getPhoneUrl(url: String, type: Int, path: String) {
|
super.getPhoneUrl(url, type, path)
|
if (imgType == 1){
|
upPhotoAdapterOne.data.add(0,url)
|
upPhotoAdapterOne.notifyDataSetChanged()
|
img = upPhotoAdapterOne.getImg()
|
}
|
if (imgType == 2){
|
upPhotoAdapter.data.add(0,url)
|
upPhotoAdapter.notifyDataSetChanged()
|
tv_car_phone_num.text = "*车辆图片"+ (upPhotoAdapter.data.size-1) +"/15"
|
}
|
if (imgType == 3){
|
videoUrl = url
|
GlideUtil.load(this,url,iv_select_video,1)
|
tv_video_num.text = "车辆视频1/1"
|
}
|
}
|
|
|
/***
|
* type 1 2 3 省市县
|
*/
|
private fun showCityPop(onclick: (province: String, city: String, area: String, areaCode: String) -> Unit) {
|
DialogUtil.getCityDialog(this, object : OnCityItemClickListener() {
|
override fun onSelected(
|
province: ProvinceBean?,
|
city: CityBean?,
|
district: DistrictBean?
|
) {
|
super.onSelected(province, city, district)
|
onclick(
|
province!!.name,
|
city!!.name,
|
district!!.name,
|
district.id
|
)
|
}
|
})
|
}
|
|
/***
|
* type 1 2 3 省市县
|
*/
|
private fun showCityPop(onclick: (province: String, city: String, area: String,provinceCode:String,cityCode:String, areaCode: String) -> Unit) {
|
DialogUtil.getCityTwoDialog(this, object : OnCityItemClickListener() {
|
override fun onSelected(
|
province: ProvinceBean?,
|
city: CityBean?,
|
district: DistrictBean?
|
) {
|
super.onSelected(province, city, district)
|
onclick(
|
province!!.name,
|
city!!.name,
|
district!!.name,
|
province.id,
|
city.id,
|
district.id
|
)
|
}
|
})
|
}
|
|
private fun setPledges(b:Boolean){
|
if (b){
|
tv_have.setBackgroundResource(R.drawable.car_get_start_4)
|
tv_have.textColor(this, R.color.white)
|
tv_none.setBackgroundResource(R.drawable.city_color_btn)
|
tv_none.textColor(this, R.color.color_1d99ea)
|
}else{
|
tv_none.setBackgroundResource(R.drawable.car_get_start_4)
|
tv_none.textColor(this, R.color.white)
|
tv_have.setBackgroundResource(R.drawable.city_color_btn)
|
tv_have.textColor(this, R.color.color_1d99ea)
|
}
|
}
|
|
private fun callDetail() {
|
var map = getMapByAny()
|
map["id"] = carId
|
callNet(Api.getSellingCarDetail,map){
|
var bean = gson.fromJson<MyBuyCar>(it, MyBuyCar::class.java)
|
bean.data.apply {
|
et_titie.setText(title)
|
et_code.setText(carIdentificationCode)
|
et_plate.setText(carLicensePlate)
|
tv_select_car_p.setText(brandName)
|
et_color.setText(carColor)
|
tv_first_time_str.setText(licensingTime)
|
et_mileage.setText(mileage)
|
tv_card_site.setText(locationOfLicensePlate)
|
et_change_username_num.setText(transferTimes)
|
tv_displacement.setText(displacement)
|
et_transmission_case.setText(transmissionCase)
|
tv_rank.setText(level)
|
et_time_over.setText(remainingOperationTime)
|
tv_time_change_car_company.setText(operationUpdateTime)
|
et_transfer_price.setText(getTransferPriceStr().toString())
|
containUserMoney = includingTransferFee == 1
|
iv_select_add_user_money.setImageResource(if (containUserMoney) R.mipmap.car_select_blue else R.mipmap.car_select_blue_false)
|
et_new_car_money.setText(getNewCarPriceStr().toString())
|
et_remark.setText(describe)
|
img = this.describeImgUrl
|
upPhotoAdapterOne.data.addAll(this.describeImgUrl.split(","))
|
upPhotoAdapterOne.notifyDataSetChanged()
|
upPhotoAdapter.data.addAll(this.imgUrl.split(","))
|
upPhotoAdapter.notifyDataSetChanged()
|
this@SellCarSendActivity.videoUrl = this.videoUrl
|
tv_video_num.text = "车辆视频1/1"
|
GlideUtil.load(this@SellCarSendActivity,videoUrl,iv_select_video,1)
|
tv_insurance.setText(dueTimeOfCompulsoryInsurance)
|
tv_year_time.setText(expirationTimeOfAnnualInspection)
|
tv_business_time.setText(maturityTimeOfCommercialInsurance)
|
isPledge = mortgage == 1
|
setPledges(isPledge)
|
for (item in carAddAdapter.data){
|
if (installationConfiguration.contains(item.content)){
|
item.select = true
|
}
|
}
|
carAddAdapter.notifyDataSetChanged()
|
et_phone_num.setText(contactsPhone)
|
tv_contacts_name.setText(contactsName)
|
contactsProvinceCode = provinceCode
|
contactscityCode = cityCode
|
tv_province.text = provinceName
|
tv_city_contacts.text = cityName
|
tv_detail_site.setText(addres)
|
this@SellCarSendActivity.category = category == "1"
|
showType(this@SellCarSendActivity.category)
|
select_car_p_id = brandId.toString()
|
|
|
|
}
|
}
|
}
|
|
private fun getPositionCar(carAll: AllCarBean?, selectCarPId: String): Int {
|
if (selectCarPId.isEmpty()){
|
return 0
|
}else{
|
for (position in carAll?.data!!.indices){
|
if (carAll?.data!![position].id.toString() == selectCarPId){
|
return position
|
}
|
}
|
}
|
return 0
|
}
|
|
|
}
|