18034727885
2026-09-18 1328a7b0b90825b1fd63bca8f7675e52df8b151d
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
package com.igo.user.dialog
 
import android.os.Bundle
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.CheckBox
import android.widget.ImageView
import androidx.fragment.app.DialogFragment
import cn.sinata.xldutils.utils.myToast
import cn.sinata.xldutils.visible
import com.igo.user.R
import com.igo.user.interfaces.StringCallback
import org.jetbrains.anko.imageResource
import org.jetbrains.anko.matchParent
import org.jetbrains.anko.support.v4.find
import org.jetbrains.anko.wrapContent
 
class SeatDialog : DialogFragment() {
    private val max by lazy { //最大座位数 6:七座 4:五座
        arguments?.getInt("max",6)?:6
    }
    private val count by lazy { //乘客数
        arguments?.getInt("count",1)?:1
    }
    private val seat by lazy { //可选座位编号
        arguments?.getString("seat")?:"1,2,3,4"
    }
    private val selected by lazy { //已选座位编号
        arguments?.getString("selected")?:""
    }
 
    private val remark_1 by lazy { find<CheckBox>(R.id.remark_1) }
    private val remark_2 by lazy { find<CheckBox>(R.id.remark_2) }
    private val remark_3 by lazy { find<CheckBox>(R.id.remark_3) }
    private val remark_4 by lazy { find<CheckBox>(R.id.remark_4) }
    private val remark_5 by lazy { find<CheckBox>(R.id.remark_5) }
    private val remark_6 by lazy { find<CheckBox>(R.id.remark_6) }
    private val iv_seat by lazy { find<ImageView>(R.id.iv_seat) }
    private val tv_action by lazy { find<View>(R.id.tv_action) }
 
    private val seats by lazy {
        arrayListOf(remark_1,remark_2,remark_3,remark_4,remark_5,remark_6)
    }
 
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(R.layout.dialog_seat, container, false)
    }
 
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setStyle(STYLE_NO_FRAME, cn.sinata.xldutils.R.style.Dialog)
    }
 
    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        dialog?.window?.setLayout(matchParent, wrapContent)
        dialog?.window?.setGravity(Gravity.BOTTOM)
        dialog?.setCanceledOnTouchOutside(true)
    }
 
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
 
        iv_seat.imageResource = if (max == 6){
            remark_5.visible()
            remark_6.visible()
            R.mipmap.seat_7
        } else R.mipmap.seat_5
 
//        if (seat.isEmpty())
//            tv_empty.visible()
//        else
            seat.split(",").filter { it.isNotEmpty() }
                .forEach {
                    seats[it.toInt()-1].isEnabled = true
                    seats[it.toInt()-1].alpha = 1f
                    seats[it.toInt()-1].isChecked = it in selected.split(",")
            }
 
        tv_action.setOnClickListener {
            if (seat.isEmpty())
                return@setOnClickListener
            val checked = seats.filter {
                it.isChecked
            }
            if (checked.size!=count){
                myToast("请选择${count}个座位")
                return@setOnClickListener
            }
            val s = checked.joinToString(",") {
                it.text.substring(0,1)
            }
            callback?.onRlt(s)
            dismiss()
        }
    }
 
    private var callback: StringCallback? = null
 
    fun setCallback(callback: StringCallback) {
        this.callback = callback
    }
}