lmw
2023-06-13 4b7d8d9a038f6522df46d0f14fa07eb940a1b34d
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
139
140
141
142
143
144
145
146
147
package com.kuanzhai.driver.ui.merchant
 
import android.content.Intent
import android.view.View
import cn.sinata.xldutils.utils.clickDelay
import cn.sinata.xldutils.utils.textColor
import com.kuanzhai.driver.R
import com.kuanzhai.driver.base.BaseEvent
import com.kuanzhai.driver.base.MyBaseActivity
import com.kuanzhai.driver.bean.AllPhoneBean
import com.kuanzhai.driver.bean.CouponDetailBean
import com.kuanzhai.driver.bean.CouponDetailData
import com.kuanzhai.driver.bean.MerchantInfo
import com.kuanzhai.driver.netUtls.Api
import com.kuanzhai.driver.netUtls.callNet
import com.kuanzhai.driver.netUtls.getMapByAny
import com.kuanzhai.driver.utils.glide.GlideUtil
import com.google.zxing.integration.android.IntentIntegrator
import com.tbruyelle.rxpermissions2.RxPermissions
import kotlinx.android.synthetic.main.activity_main_merchant.*
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.toast
 
 
/**
 * @ClassName MerchantMainActivity
 * @Description TODO
 * @Author Administrator
 * @Date 2022/2/9 15:28
 * @Version 1.0
 */
class MerchantMainActivity: MyBaseActivity() {
 
    val merchantId by lazy {
        intent.getStringExtra("merchantId")
    }
 
    val conponMerchantListFragment by lazy {
        ConponMerchantListFragment()
    }
 
    override fun setContentView() {
        setContentView(R.layout.activity_main_merchant)
    }
 
    override fun initView() {
        showTitle(false)
        addFragment(conponMerchantListFragment, R.id.container)
        callMerchant{
            tv_name_title.text = it.data.name
            GlideUtil.loady(this, it.data.headImg, iv_img)
        }
 
        callNet(Api.queryPhoneAll, getMapByAny()){
            var bean = gson.fromJson<AllPhoneBean>(it, AllPhoneBean::class.java)
//            tv_phone_three.text = bean.data.platform
//            tv_phone_two.text = bean.data.branch
//            tv_phone_one.text = bean.data.franchisee
            tv_phone_store.text = "平台电话:"+bean.data.platform
 
        }
    }
 
    private fun callMerchant(function: (MerchantInfo) -> Unit) {
        var map = getMapByAny()
        callNet(Api.getMerchant, map) {
            var merchatInfo = gson.fromJson<MerchantInfo>(it, MerchantInfo::class.java)
            function(merchatInfo)
        }
    }
 
    override fun setOnclick() {
        tv_server_ing.clickDelay {
            tv_server_ing.textColor(this, R.color.main_yellow)
            tv_wait_server.textColor(this, R.color.main_gray)
            conponMerchantListFragment.type = 1
            conponMerchantListFragment.refresh()
        }
 
        tv_wait_server.clickDelay {
            tv_wait_server.textColor(this, R.color.main_yellow)
            tv_server_ing.textColor(this, R.color.main_gray)
            conponMerchantListFragment.type = 2
            conponMerchantListFragment.refresh()
        }
 
        iv_mer_back.clickDelay {
            onBackPressed()
        }
 
        iv_scan.clickDelay {
            RxPermissions(this).request(
                "android.permission.READ_EXTERNAL_STORAGE",
                "android.permission.CAMERA"
            ).subscribe {
                if (it){
                    val intentIntegrator = IntentIntegrator(this)
                    intentIntegrator.captureActivity = MerQrCodeActivity::class.java
                    intentIntegrator.initiateScan()
                }else{
                    toast("扫描二维码需要打开相机和散光灯的权限")
                }
            }
        }
    }
 
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == IntentIntegrator.REQUEST_CODE){
            val intentResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data)
            intentResult?.contents?.let {
                if (it.startsWith("merchantCoupon:")){
                    var id = it.replace("merchantCoupon:","")
                    callDetail(id){
                        startActivity<MerchantDetailActivity>("code" to id)
                    }
                }else{
                    toast("无效二维码")
                }
            }
        }
    }
 
 
    private fun callDetail(code:String,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 onRestart() {
        super.onRestart()
        conponMerchantListFragment.refresh()
    }
 
    override fun onEventMainThread(event: BaseEvent?) {
        super.onEventMainThread(event)
        when(event!!.code){
            BaseEvent.MER_SHOW_BACK -> {
                container.visibility = if (event.b) View.GONE else View.VISIBLE
            }
        }
    }
}