18034727885
2026-09-18 1328a7b0b90825b1fd63bca8f7675e52df8b151d
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
package com.igo.user.ui.mine
 
import android.app.Activity
import android.content.Intent
import android.view.View
import android.widget.EditText
import android.widget.TextView
import androidx.core.os.bundleOf
import cn.sinata.xldutils.gone
import cn.sinata.xldutils.utils.myToast
import cn.sinata.xldutils.visible
import com.facebook.drawee.view.SimpleDraweeView
import com.igo.user.R
import com.igo.user.dialog.AlertDialog
import com.igo.user.dialog.TipDialog
import com.igo.user.network.HttpManager
import com.igo.user.network.request
import com.igo.user.ui.TransparentStatusBarActivity
import com.igo.user.ui.login.AreaCodeActivity
import org.jetbrains.anko.find
import org.jetbrains.anko.startActivityForResult
 
class GiveCouponActivity:TransparentStatusBarActivity() {
    override fun setContentView() = R.layout.activity_give_coupon
    private val id by lazy {
        intent.getIntExtra("id",0)
    }
    private var userId = 0
    private val areaCode by lazy { find<TextView>(R.id.areaCode) }
    private val et_phone by lazy { find<EditText>(R.id.et_phone) }
    private val tv_name by lazy { find<TextView>(R.id.tv_name) }
    private val tv_search by lazy { find<TextView>(R.id.tv_search) }
    private val fl_header by lazy { find<View>(R.id.fl_header) }
    private val tv_action by lazy { find<View>(R.id.tv_action) }
    private val iv_avatar by lazy { find<SimpleDraweeView>(R.id.iv_avatar) }
 
    override fun initClick() {
        areaCode.setOnClickListener {
            startActivityForResult<AreaCodeActivity>(10086)
        }
        tv_search.setOnClickListener {
            var phone = et_phone.text.toString()
            if (phone.isEmpty()){
                myToast(getString(R.string.请填写手机号))
                return@setOnClickListener
            }
            phone = areaCode.text.toString().replace("+","") + phone
 
            showDialog()
            HttpManager.queryUser(phone).request(this){_,data->
                data?.let {
                    userId = it.id
                    if (it.id!=0){
                        fl_header.visible()
                        tv_name.visible()
                        iv_avatar.setImageURI(it.avatar)
                        tv_name.text = it.nickName
                        tv_action.isEnabled = true
                    }else{
                        myToast(getString(R.string.未找到该用户))
                        fl_header.gone()
                        tv_name.gone()
                        tv_action.isEnabled = false
                    }
                }
            }
        }
 
        tv_action.setOnClickListener {
            val tipDialog = TipDialog()
            tipDialog.arguments = bundleOf("msg" to getString(R.string.是否确定赠送优惠券))
            tipDialog.setCallback(object :TipDialog.OnClickCallback{
                override fun onOk() {
                    showDialog()
                    tv_action.isEnabled = false
                    HttpManager.giveCoupon(id, userId).request(this@GiveCouponActivity,success = {_,_->
                        val successDialog = AlertDialog()
                        successDialog.arguments = bundleOf("msg" to getString(R.string.赠送成功),"isAlert" to true)
                        successDialog.setDismissCallback(object :AlertDialog.OnDismiss{
                            override fun onDismiss() {
                                setResult(Activity.RESULT_OK)
                                finish()
                            }
                        })
                        successDialog.show(supportFragmentManager,"success")
                    },error = {_,_->
                        tv_action.isEnabled = true
                    })
                }
 
                override fun onCancel() {
                }
            })
            tipDialog.show(supportFragmentManager,"tip")
        }
    }
 
    override fun initView() {
        title = getString(R.string.选择赠送人)
    }
 
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (resultCode == Activity.RESULT_OK && requestCode == 10086) {
            data?.getStringExtra("code")?.let {
                areaCode.text = it
            }
        }
    }
 
}