package com.igo.user.ui.logistics
|
|
import android.app.Activity
|
import android.view.View
|
import android.widget.CheckedTextView
|
import android.widget.EditText
|
import android.widget.RadioButton
|
import android.widget.RadioGroup
|
import android.widget.TextView
|
import androidx.constraintlayout.widget.ConstraintLayout
|
import androidx.constraintlayout.widget.Group
|
import cn.sinata.xldutils.gone
|
import cn.sinata.xldutils.utils.myToast
|
import cn.sinata.xldutils.utils.optDouble
|
import cn.sinata.xldutils.utils.optInt
|
import cn.sinata.xldutils.visible
|
import com.igo.user.R
|
import com.igo.user.network.HttpManager
|
import com.igo.user.network.request
|
import com.igo.user.ui.TransparentStatusBarActivity
|
import org.jetbrains.anko.find
|
import org.jetbrains.anko.sdk27.coroutines.onClick
|
|
class GoodsTypeActivity:TransparentStatusBarActivity() {
|
override fun setContentView() = R.layout.activity_goods_type
|
|
private val address by lazy {
|
intent.getStringExtra("address")?:""
|
}
|
private val lat by lazy {
|
intent.getDoubleExtra("lat",0.0)
|
}
|
private val lon by lazy {
|
intent.getDoubleExtra("lon",0.0)
|
}
|
private val type by lazy {
|
intent.getIntExtra("type",0)
|
}
|
|
private val cl_normal by lazy { find<ConstraintLayout>(R.id.cl_normal) }
|
private val cl_expensive by lazy { find<ConstraintLayout>(R.id.cl_expensive) }
|
private val rb_normal by lazy { find<CheckedTextView>(R.id.rb_normal) }
|
private val rb_expensive by lazy { find<CheckedTextView>(R.id.rb_expensive) }
|
private val group_expensive by lazy { find<Group>(R.id.group_expensive) }
|
private val iv_plus by lazy { find<View>(R.id.iv_plus) }
|
private val iv_plus_expensive by lazy { find<View>(R.id.iv_plus_expensive) }
|
private val et_normal by lazy { find<EditText>(R.id.et_normal) }
|
private val et_expensive by lazy { find<EditText>(R.id.et_expensive) }
|
private val iv_minus by lazy { find<View>(R.id.iv_minus) }
|
private val iv_minus_expensive by lazy { find<View>(R.id.iv_minus_expensive) }
|
private val tv_action by lazy { find<View>(R.id.tv_action) }
|
private val et_remark by lazy { find<EditText>(R.id.et_remark) }
|
private val rg_expensive by lazy { find<RadioGroup>(R.id.rg_expensive) }
|
private val tv_price_normal by lazy { find<TextView>(R.id.tv_price_normal) }
|
private val tv_price_expensive by lazy { find<TextView>(R.id.tv_price_expensive) }
|
|
private var goodsType = 1 //货物类型(1=普通货物,2=贵重货物)
|
private var normal = 1
|
private var expensive = 1
|
private var expensiveName = "" //贵重物品名称
|
|
private var isFirstOrder = false //首次下单
|
|
override fun initClick() {
|
cl_normal.onClick {
|
rb_normal.isChecked = true
|
rb_expensive.isChecked = false
|
group_expensive.gone()
|
goodsType = 1
|
}
|
cl_expensive.onClick {
|
rb_expensive.isChecked = true
|
rb_normal.isChecked = false
|
group_expensive.visible()
|
goodsType = 2
|
}
|
iv_plus.onClick {
|
et_normal.setText((++normal).toString())
|
}
|
iv_plus_expensive.onClick {
|
et_expensive.setText((++expensive).toString())
|
}
|
iv_minus.onClick {
|
if (normal>1)
|
et_normal.setText((--normal).toString())
|
}
|
iv_minus_expensive.onClick {
|
if (expensive>1)
|
et_expensive.setText((--expensive).toString())
|
}
|
tv_action.onClick {
|
val remark = et_remark.text.toString()
|
if (goodsType == 2&&expensiveName.isEmpty()&&remark.isEmpty()) {
|
myToast("请选择或填写物品名称")
|
return@onClick
|
}
|
val remarks = arrayListOf(expensiveName, remark)
|
setResult(Activity.RESULT_OK,intent.putExtra("goodsType",goodsType).putExtra("goodsNum",if (goodsType==1) normal else expensive)
|
.putExtra("isFirstOrder",isFirstOrder).putExtra("remark", remarks.filter { it.isNotEmpty() }.joinToString(",") { it }))
|
finish()
|
}
|
}
|
|
override fun initView() {
|
rg_expensive.setOnCheckedChangeListener { group, checkedId ->
|
expensiveName = find<RadioButton>(checkedId).text.toString()
|
}
|
// et_normal.addTextChangedListener(object :TextWatcher{
|
// override fun afterTextChanged(s: Editable?) {
|
// normal = if (s.isNullOrEmpty()) 1 else s.toString().toInt()
|
// }
|
//
|
// override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
|
// }
|
//
|
// override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
|
// }
|
// })
|
// et_expensive.addTextChangedListener(object :TextWatcher{
|
// override fun afterTextChanged(s: Editable?) {
|
// expensive = if (s.isNullOrEmpty()) 1 else s.toString().toInt()
|
// }
|
//
|
// override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
|
// }
|
//
|
// override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
|
// }
|
// })
|
getData()
|
}
|
|
private fun getData(){
|
HttpManager.queryLogisticsUnitPrice(address,"$lon,$lat",type).request(this){_,data->
|
data?.apply {
|
isFirstOrder = optInt("first") == 0
|
tv_price_normal.text = "起步价 ¥%.2f".format(optDouble("ordinary"))
|
tv_price_expensive.text = "起步价 ¥%.2f".format(optDouble("precious"))
|
}
|
}
|
}
|
}
|