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
|
}
|
}
|
}
|
|
}
|