lmw
2023-05-27 ff365ff4346d220edf2ec1d0041f2284befe3870
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
package com.fanghua.driver.ui.pub
 
import android.text.Editable
import android.text.TextWatcher
import android.widget.TextView
import cn.sinata.xldutils.utils.clickDelay
import cn.sinata.xldutils.utils.getString
import com.fanghua.driver.R
import com.fanghua.driver.base.MyApplication
import com.fanghua.driver.base.local.BaseLoginActivity
import com.fanghua.driver.bean.LoginBean
import com.fanghua.driver.netUtls.Api
import com.fanghua.driver.netUtls.callNet
import com.fanghua.driver.netUtls.getMapByAny
import com.fanghua.driver.ui.main.MainActivity
import com.fanghua.driver.utils.Cache.CacheKey
import kotlinx.android.synthetic.main.activity_input_code.*
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.toast
 
class InputCodeActivity:BaseLoginActivity() {
    private val phone by lazy { intent.getStringExtra("phone") }
 
    override fun tvInit(tv_code: TextView) {
        tv_code.text = "重新获取"
    }
 
    override fun tvIniting(tv_code: TextView, time: String) {
        tv_code.text = "重新获取($time)"
    }
 
    override fun setContentView() {
        setContentView(R.layout.activity_input_code)
    }
 
    override fun initView() {
        setTitleText("芳华代驾")
        tv_phone.text = phone
        et_code.addTextChangedListener(object :TextWatcher{
            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
                et_code.setSelection(et_code.text.length)
            }
 
            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
 
            }
 
            override fun afterTextChanged(s1: Editable?) {
                val s = s1.toString()
                when(s.length){
                    0->{
                        tv_code_1.text = ""
                        tv_code_2.text = ""
                        tv_code_3.text = ""
                        tv_code_4.text = ""
                        tv_code_5.text = ""
                    }
                    1->{
                        tv_code_1.text = s[0].toString()
                        tv_code_2.text = ""
                        tv_code_3.text = ""
                        tv_code_4.text = ""
                        tv_code_5.text = ""
                    }
                    2->{
                        tv_code_1.text = s[0].toString()
                        tv_code_2.text = s[1].toString()
                        tv_code_3.text = ""
                        tv_code_4.text = ""
                        tv_code_5.text = ""
                    }
                    3->{
                        tv_code_1.text = s[0].toString()
                        tv_code_2.text = s[1].toString()
                        tv_code_3.text = s[2].toString()
                        tv_code_4.text = ""
                        tv_code_5.text = ""
                    }
                    4->{
                        tv_code_1.text = s[0].toString()
                        tv_code_2.text = s[1].toString()
                        tv_code_3.text = s[2].toString()
                        tv_code_4.text = s[3].toString()
                        tv_code_5.text = ""
                    }
                    5->{
                        tv_code_1.text = s[0].toString()
                        tv_code_2.text = s[1].toString()
                        tv_code_3.text = s[2].toString()
                        tv_code_4.text = s[3].toString()
                        tv_code_5.text = s[4].toString()
                    }
                }
            }
        })
        refreshTime(tv_get_code)
    }
    override fun setOnclick() {
        tv_get_code.clickDelay {
            var map = getMapByAny()
            map["phone"] = phone
            map["receiver"] = "86"
            map["type"] = 1
            callNet(Api.queryCaptcha,map){
                toast("发送成功")
                refreshTime(tv_get_code)
            }
        }
 
        tv_login.clickDelay {
            val code = et_code.getString()
            if (code.length!=5)
                toast("请输入5位验证码")
            else{
                var map = getMapByAny()
                map["phone"] = phone
                map["code"] = code
                map["receiver"] = "86"
                callNet(Api.driverCodeLogin,map){
                    var bean = gson.fromJson<LoginBean>(it, LoginBean::class.java)
                    if (bean.resultUtil.code == 10000){
                        CacheKey.putKeyStr("phone",phone)
                        CacheKey.putKeyStr("token",bean.resultUtil.data.token)
                        CacheKey.putKeyStr("hasPwd",bean.resultUtil.data.isSetPassword.toString())
                        MyApplication.getInstance()!!.setAlisa()
                        toast("登录成功")
                        setResult(RESULT_OK)
                        finish()
                    }else{
                        toast(bean.resultUtil.msg)
                    }
                }
            }
        }
 
    }
 
}