Pu Zhibing
2025-12-11 ab0c19e49fabdb8cc6eea454ea455bce2efbb718
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
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"))
            }
        }
    }
}