lmw
2024-06-16 03172fc2d9a7717f4a9d8de1c5eca3158a550b30
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
package com.dollearn.student.dialog
 
import android.view.Gravity
import androidx.core.os.bundleOf
import androidx.fragment.app.FragmentManager
import cn.sinata.xldutils.gone
import cn.sinata.xldutils.utils.SpanBuilder
import cn.sinata.xldutils.utils.showAllowingStateLoss
import com.dollearn.student.R
import com.dollearn.student.utils.extention.clickDelay
import com.dollearn.student.utils.interfaces.StringCallback
import kotlinx.android.synthetic.main.dialog_pay.*
import org.jetbrains.anko.support.v4.toast
 
class PayDialog: BaseDialogFragment() {
    override fun setContentView() = R.layout.dialog_pay
 
    private val isVip by lazy {
        arguments?.getBoolean("isVip",false)?:false
    }
    private val coin by lazy {//玩湃币
        arguments?.getInt("coin",0)?:0
    }
    private val course by lazy {//课时
        arguments?.getInt("course",0)?:0
    }
    private val integral by lazy { //积分
        arguments?.getInt("integral",0)?:0
    }
    private val price by lazy {//钱
        arguments?.getDouble("price",0.0)?:0.0
    }
    private val courseEnable by lazy { //课时支付是否可用,不可用需将按钮置灰
        arguments?.getBoolean("courseEnable",true)?:true
    }
    var callback:StringCallback? = null
 
    override fun setGravity() = Gravity.BOTTOM
 
    override fun initView() {
        if (isVip){
            tv_coin.gone()
            line.gone()
            tv_course.gone()
            line3.gone()
            tv_integral.gone()
            line4.gone()
            tv_wx.text = SpanBuilder("微信支付 ¥199").color(requireContext(),0,4,R.color.textColor66).build()
            tv_ali.text = SpanBuilder("支付宝支付 ¥199").color(requireContext(),0,5,R.color.textColor66).build()
        }else{
            if (price == 0.0){
                line1.gone()
                line2.gone()
                tv_wx.gone()
                tv_ali.gone()
                tv_coin.isChecked = true
            }else{
                tv_wx.text = SpanBuilder("微信支付 ¥%.2f".format(price)).color(requireContext(),0,4,R.color.textColor66).build()
                tv_ali.text = SpanBuilder("支付宝支付 ¥%.2f".format(price)).color(requireContext(),0,5,R.color.textColor66).build()
            }
            if (coin == 0){
                tv_coin.gone()
                line.gone()
            }else
                tv_coin.text = SpanBuilder("玩湃币支付 ${coin}币").color(requireContext(),0,5,R.color.textColor66).build()
            if (course == 0){
                tv_course.gone()
                line3.gone()
            }else{
                tv_course.text = SpanBuilder("课时支付 ${course}课时").color(requireContext(),0,4,R.color.textColor66).build()
                if (!courseEnable){
                    tv_course.isEnabled = false
                    tv_course.alpha = 0.5f
                }
            }
 
            if (integral == 0){
                tv_integral.gone()
                line4.gone()
            }else
                tv_integral.text = SpanBuilder("积分支付 ${integral}积分").color(requireContext(),0,4,R.color.textColor66).build()
        }
        tv_cancel.setOnClickListener {
            dismissAllowingStateLoss()
        }
        tv_pay.clickDelay {
//            val type = if (tv_ali.isChecked) 2 else if (tv_wx.isChecked) 1 else 3
            val type = when(rg_pay.checkedRadioButtonId){
                R.id.tv_ali->2
                R.id.tv_wx->1
                R.id.tv_integral->5
                R.id.tv_coin->3
                else->4
            }
            callback?.onResult(type.toString())
            dismissAllowingStateLoss()
        }
    }
 
    companion object{
        /**
         * @param courseEnable 赛事可以用课时支付,但当参赛学员有非学员身份时,课时支付需要置灰
         */
        fun show(fm:FragmentManager,isVip:Boolean,callback:StringCallback,price:Double? = null,coin:Int? = null,course:Int? = null,integral:Int? = null,courseEnable:Boolean? = null){
            val payDialog = PayDialog()
            payDialog.arguments = bundleOf("isVip" to isVip,"price" to price,"coin" to coin,"course" to course,"integral" to integral,"courseEnable" to courseEnable)
            payDialog.callback = callback
            payDialog.showAllowingStateLoss(fm,"pay")
        }
    }
 
}