package com.kuanzhai.driver.ui.merchant
|
|
import cn.sinata.xldutils.utils.*
|
import com.kuanzhai.driver.R
|
import com.kuanzhai.driver.base.MyBaseActivity
|
import com.kuanzhai.driver.bean.CouponDetailBean
|
import com.kuanzhai.driver.bean.CouponDetailData
|
import com.kuanzhai.driver.netUtls.Api
|
import com.kuanzhai.driver.netUtls.callNet
|
import com.kuanzhai.driver.netUtls.getMapByAny
|
import com.kuanzhai.driver.ui.DialogUtil
|
import com.kuanzhai.driver.utils.DateUtil
|
import com.kuanzhai.driver.utils.HtmlUtils
|
import kotlinx.android.synthetic.main.activity_merchant_detail.*
|
import kotlinx.android.synthetic.main.dialog_use_mer.view.*
|
import kotlinx.android.synthetic.main.item_conpon_merchant_list.*
|
import org.jetbrains.anko.toast
|
|
/**
|
* @ClassName MerchantDetailActivity
|
* @Description TODO
|
* @Author Administrator
|
* @Date 2022/2/9 16:29
|
* @Version 1.0
|
*/
|
class MerchantDetailActivity : MyBaseActivity() {
|
|
val code by lazy {
|
intent.getStringExtra("code")
|
}
|
|
override fun setContentView() {
|
setContentView(R.layout.activity_merchant_detail)
|
}
|
|
override fun initView() {
|
tv_histoty.gone()
|
callDetail() {
|
tv_price.gone()
|
tv_name.gone()
|
tv_histoty.gone()
|
if (it!!.receive.isNullOrEmpty()){
|
it.receive = "0"
|
}
|
if (it!!.writeOff.isNullOrEmpty()){
|
it.writeOff = "0"
|
}
|
if (it.status == 1){
|
con_back.setBackgroundResource(R.mipmap.mer_item_back_orange)
|
}else{
|
con_back.setBackgroundResource(R.mipmap.mer_item_back_gray)
|
}
|
if (it!!.type == 1) { //券类型(1=优惠券,2=商品券)
|
tv_price.visible()
|
tv_price.text = "¥ "+ doubleTwo(it!!.discount)
|
} else {
|
tv_name.visible()
|
}
|
tv_name_main.text = it!!.name
|
var timestamp = DateUtil.dateToStamp(DateUtil.TYPE0, it!!.endTime)
|
var num = (timestamp - System.currentTimeMillis()) / (3600 * 1000 * 24)
|
tv_number.text = "距离到期仅剩" + (num.toInt() + 1).toString() + "天"
|
if (timestamp - System.currentTimeMillis() < 0){
|
tv_number.text = "已到期"
|
}
|
if (it.type == 1){
|
tv_hint.text = "店铺购买满"+it.fullAmount.toString()+"元使用"
|
}else{
|
tv_hint.text = HtmlUtils.getTextFromHtmlNum(it.content,1130)
|
}
|
tv_statue.text = if (it.status == 1) "有效" else "无效"
|
tv_name_m.text = it.userName
|
tv_user_phone.text = it.phone
|
setTitleText(it.merchantName)
|
tv_use.clickDelay {
|
callOffwer(code)
|
}
|
if (it.status != 1){
|
tv_use.setBackgroundResource(R.drawable.bg_login_false)
|
tv_use.isClickable = false
|
tv_use.isEnabled = false
|
}
|
}
|
}
|
|
private fun callOffwer(code: String?) {
|
DialogUtil.getDelAndSureDialog(this,"确定核销吗?",{}){
|
var map = getMapByAny()
|
map["code"] = code
|
callNet(Api.writeOffMerchantCoupon,map){
|
toast("核销成功")
|
onBackPressed()
|
}
|
}
|
}
|
|
private fun callDetail(function: (CouponDetailData) -> Unit) {
|
var map = getMapByAny()
|
map["code"] = code
|
callNet(Api.getUserMerchantCoupon, map) {
|
var bean = gson.fromJson<CouponDetailBean>(it, CouponDetailBean::class.java)
|
function(bean.data)
|
}
|
}
|
|
override fun setOnclick() {
|
tv_use.clickDelay {
|
var dialog = DialogUtil.getDialog(this, R.layout.dialog_use_mer)
|
var view = DialogUtil.getView(dialog)
|
view.tv_sure.clickDelay {
|
dialog.dismiss()
|
}
|
}
|
|
}
|
}
|