lmw
2023-06-25 a988e7c15f5ce63785b77e01c89bec2565668982
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
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()
            }
        }
 
    }
}