lmw
2023-05-12 f67802a41f9e01444d1115f34ecc6e1beb05fc3b
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
package com.fuban.user.ui.logistics
 
import android.app.Activity
import androidx.core.os.bundleOf
import cn.sinata.xldutils.utils.isValidPhone
import cn.sinata.xldutils.utils.myToast
import com.fuban.user.BuildConfig
import com.fuban.user.R
import com.fuban.user.dialog.RegionDialog
import com.fuban.user.network.HttpManager
import com.fuban.user.network.entity.City
import com.fuban.user.network.request
import com.fuban.user.ui.TransparentStatusBarActivity
import kotlinx.android.synthetic.main.activity_receiver.*
import org.jetbrains.anko.sdk27.coroutines.onClick
 
class ReceiverActivity : TransparentStatusBarActivity() {
    override fun setContentView() = R.layout.activity_receiver
 
    private val province = arrayListOf<City>()
    private var provinceIndex = 0
    private var cityIndex = 0
    private var regionIndex = 0
 
    override fun initClick() {
        tv_region.onClick {
            if (province.isEmpty())
                getRegion()
            else{
                val regionDialog = RegionDialog()
                regionDialog.arguments = bundleOf("province" to province,"provinceIndex" to provinceIndex,
                    "cityIndex" to cityIndex,"regionIndex" to regionIndex)
                regionDialog.setCallback(object :RegionDialog.OnOkClick{
                    override fun onOk(region: String, provinceIndex: Int, cityIndex: Int, regionIndex: Int) {
                        tv_region.text = region
                        this@ReceiverActivity.provinceIndex = provinceIndex
                        this@ReceiverActivity.cityIndex = cityIndex
                        this@ReceiverActivity.regionIndex = regionIndex
                    }
                })
                regionDialog.show(supportFragmentManager,"region")
            }
        }
 
        tv_action.onClick {
            val name = et_name.text.toString()
            if (name.isEmpty()){
                myToast("请填写姓名")
                return@onClick
            }
            val phone = et_phone.text.toString()
            if (!phone.isValidPhone()){
                myToast("请填写正确的手机号")
                return@onClick
            }
            val region = tv_region.text.toString()
            if (region.isEmpty()){
                myToast("请选择地区")
                return@onClick
            }
            val address = et_address.text.toString()
            if (address.isEmpty()){
                myToast("请填写详细地址")
                return@onClick
            }
            setResult(Activity.RESULT_OK,intent.putExtra("name",name).putExtra("phone",phone)
                .putExtra("region",region).putExtra("address",address).putExtra("provinceIndex",provinceIndex)
                .putExtra("cityIndex",cityIndex).putExtra("regionIndex",regionIndex))
            finish()
        }
    }
 
    override fun initView() {
        et_name.setText(intent.getStringExtra("name"))
        et_phone.setText(intent.getStringExtra("phone"))
        tv_region.text = intent.getStringExtra("region")
        et_address.setText(intent.getStringExtra("address"))
        provinceIndex = intent.getIntExtra("provinceIndex",0)
        cityIndex = intent.getIntExtra("cityIndex",0)
        regionIndex = intent.getIntExtra("regionIndex",0)
 
        if (BuildConfig.DEBUG&&et_name.text.isEmpty()){
            et_name.setText("测试")
            et_phone.setText("18588888888")
            tv_region.text = "四川省成都市青羊区"
            et_address.setText("天府广场")
        }
    }
 
    private fun getRegion(){
        showDialog()
        HttpManager.queryRegions().request(this){_,data->
            province.clear()
            province.addAll(data?: arrayListOf())
            val dialog = RegionDialog()
            dialog.arguments = bundleOf("province" to province,"provinceIndex" to provinceIndex,
                "cityIndex" to cityIndex,"regionIndex" to regionIndex)
            dialog.setCallback(object :RegionDialog.OnOkClick{
                override fun onOk(region: String, provinceIndex: Int, cityIndex: Int, regionIndex: Int) {
                    tv_region.text = region
                    this@ReceiverActivity.provinceIndex = provinceIndex
                    this@ReceiverActivity.cityIndex = cityIndex
                    this@ReceiverActivity.regionIndex = regionIndex
                }
            })
            dialog.show(supportFragmentManager,"region")
        }
    }
}