fix
无故事王国
2 天以前 2aac1ba6449741aedbf97d75c340719a7b67d7db
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
//
//  StudentChoose3View.swift
//  WanPai
//
//  Created by 无故事王国 on 2025/3/27.
//
 
import UIKit
import JQTools
import QMUIKit
import RxSwift
import RxCocoa
import HandyJSON
 
class StudentChoose3View: UIView,JQNibView{
 
    @IBOutlet weak var tableView: UITableView!
    @IBOutlet weak var btn_add: QMUIButton!
    @IBOutlet weak var view_container: UIView!
    @IBOutlet weak var cons_bottom: NSLayoutConstraint!
    @IBOutlet weak var cons_tableHei: NSLayoutConstraint!
 
    private var clickClouse:((Set<StudentProfile1Model>)->Void)!
    private var closeClouse:(()->Void)!
    private var needAddClouse:(()->Void)!
    private var disposeBag = DisposeBag()
    private var selectStudents = Set<StudentProfile1Model>()
    private var viewModel = StudentExchangeViewModel()
 
    override func awakeFromNib() {
        super.awakeFromNib()
        cons_bottom.constant = -(JQ_ScreenW * 1.1)
        tableView.delegate = self
        tableView.dataSource = self
        tableView.separatorStyle = .none
        tableView.showsVerticalScrollIndicator = false
        tableView.showsHorizontalScrollIndicator = false
        btn_add.spacingBetweenImageAndTitle = 4
        btn_add.imagePosition = .right
        alpha = 0
        layoutIfNeeded()
        setRx()
 
        NotificationCenter.default.rx.notification(Noti_hiddenCardCenter_Add).take(until: self.rx.deallocated).subscribe(onNext: {[unowned self] noti in
            guard let state = noti.object as? Bool else { return }
            self.alpha = state ? 0:1
            self.viewModel.beginRefresh()
        }).disposed(by: disposeBag)
    }
 
    @discardableResult
    static func show(defaultStu:Set<StudentProfile1Model>? = nil,clickClouse:@escaping (Set<StudentProfile1Model>)->Void,closeClouse:@escaping()->Void)->StudentChoose3View{
        let studentChooseView = StudentChoose3View.jq_loadNibView()
        if defaultStu != nil{
            studentChooseView.selectStudents = defaultStu!
        }
        studentChooseView.closeClouse = closeClouse
        studentChooseView.tag = 1293
        studentChooseView.tableView.register(UINib(nibName: "StudentInfo_2_2_TCell", bundle: nil), forCellReuseIdentifier: "_StudentInfo_2_2_TCell")
        studentChooseView.frame = sceneDelegate?.window?.frame ?? .zero
        studentChooseView.clickClouse = clickClouse
        sceneDelegate?.window?.addSubview(studentChooseView)
        studentChooseView.cons_bottom.constant = 0
        studentChooseView.viewModel.configure(studentChooseView.tableView,needMore: false)
        studentChooseView.viewModel.beginRefresh()
 
        UIView.animate(withDuration: 0.4) {
            studentChooseView.alpha = 1
            studentChooseView.layoutIfNeeded()
            studentChooseView.tableView.reloadData()
        }
        return studentChooseView
    }
 
    private func setRx(){
        viewModel.dataSource.subscribe(onNext: {[weak self] data in
            let hei = min(360,Double(data.count) * 90.0)
            self?.cons_tableHei.constant = hei
            UIView.animate(withDuration: 0.4) {
                self?.layoutIfNeeded()
            }
        }).disposed(by: disposeBag)
 
        NotificationCenter.default.rx.notification(StudentUpdate_Nofi, object: nil).subscribe(onNext: {_ in
            self.viewModel.beginRefresh()
        }).disposed(by: disposeBag)
    }
 
    @IBAction func closeAction(_ sender: UIButton) {
        closeAction()
    }
 
    override func layoutSubviews() {
        super.layoutSubviews()
        DispatchQueue.main.asyncAfter(wallDeadline: .now()+0.1) {
            self.view_container.jq_addCorners(corner: [.topLeft,.topRight], radius: 20)
        }
    }
 
    private func closeAction(){
        self.cons_bottom.constant = -(JQ_ScreenW * 1.1)
        self.closeClouse?()
        UIView.animate(withDuration: 0.4) {
            self.alpha = 0
            self.layoutIfNeeded()
        } completion: { _ in
            self.removeFromSuperview()
        }
    }
    @IBAction func addPersionAction(_ sender: Any) {
        NotificationCenter.default.post(name: Noti_hiddenCardCenter_Add, object: true)
        let vc = CardCenterAddUserVC()
        JQ_currentNavigationController().pushViewController(vc)
    }
    
    @IBAction func completeAction(_ sender: UIButton) {
        guard !selectStudents.isEmpty else {
            alert(msg: "请选择");return
        }
        clickClouse!(selectStudents)
        closeAction()
    }
}
 
extension StudentChoose3View:UITableViewDelegate{
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let item = viewModel.dataSource.value[indexPath.row]
 
        if selectStudents.contains(item){
            selectStudents.remove(item)
        }else{
            selectStudents.insert(item)
        }
        tableView.reloadData()
    }
}
 
extension StudentChoose3View:UITableViewDataSource{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return viewModel.dataSource.value.count
    }
 
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "_StudentInfo_2_2_TCell") as! StudentInfo_2_2_TCell
        cell.indexPath = indexPath
        cell.studentProfile1Model = viewModel.dataSource.value[indexPath.row]
        cell.img_radio.isHidden = false
 
        let isSelect = selectStudents.contains(viewModel.dataSource.value[indexPath.row])
 
        cell.img_radio.image = UIImage(named: isSelect ? "btn_select" : "btn_select_u")
        if isSelect{
            cell.view_container.jq_borderColor = UIColor(hexString: "#FD7902")?.withAlphaComponent(0.28)
            cell.img_radio.isHidden = false
        }else{
            cell.view_container.jq_borderColor = UIColor(hexString: "#ADADAD")?.withAlphaComponent(0.28)
            cell.img_radio.isHidden = true
        }
 
        return cell
    }
 
}