无故事王国
2024-03-08 4966eb10cbf5ce9c6ee37a13d393fb0ae2d85b60
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
//
//  StudentChoose2View.swift
//  WanPai
//
//  Created by 无故事王国 on 2024/3/4.
//
 
import UIKit
import JQTools
import QMUIKit
import RxSwift
import RxCocoa
import HandyJSON
 
class StudentWorldCupViewModel:RefreshModel<ActivityDetailPartModel>{
                override func api() -> (Observable<BaseResponse<[ActivityDetailPartModel]>>)? {
                                return     Services.getParticipant()
                }
}
 
 
class StudentChoose2View: UIView,JQNibView {
 
                @IBOutlet weak var tableView: UITableView!
                @IBOutlet weak var view_container: UIView!
                @IBOutlet weak var cons_bottom: NSLayoutConstraint!
                @IBOutlet weak var cons_tableHei: NSLayoutConstraint!
                @IBOutlet weak var cons_tableLeading: NSLayoutConstraint!
                @IBOutlet weak var cons_tableTrailing: NSLayoutConstraint!
 
                private var clickClouse:((ActivityDetailPartModel)->Void)!
                private var needAddClouse:(()->Void)!
                private var selectStudents:ActivityDetailPartModel?
                private var disposeBag = DisposeBag()
                private var viewModel = StudentWorldCupViewModel()
 
                override func awakeFromNib() {
                                super.awakeFromNib()
                                cons_bottom.constant = -(JQ_ScreenW * 1.1)
                                tableView.delegate = self
                                tableView.dataSource = self
                                tableView.separatorStyle = .none
                                alpha = 0
                                layoutIfNeeded()
                                setRx()
                }
 
                static func show(defaultStu:ActivityDetailPartModel? = nil,clickClouse:@escaping (ActivityDetailPartModel)->Void){
                                let studentChooseView = StudentChoose2View.jq_loadNibView()
                                if defaultStu != nil{
                                                studentChooseView.selectStudents = defaultStu!
                                }
                                studentChooseView.tableView.register(UINib(nibName: "StudentInfo_2_TCell", bundle: nil), forCellReuseIdentifier: "_StudentInfo_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()
                                }
                }
 
                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)
 
                }
 
                @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)
                                UIView.animate(withDuration: 0.4) {
                                                self.alpha = 0
                                                self.layoutIfNeeded()
                                } completion: { _ in
                                                self.removeFromSuperview()
                                }
                }
 
                @IBAction func completeAction(_ sender: UIButton) {
                                guard selectStudents != nil else {
                                                alert(msg: "请选择"    );return
                                }
                                clickClouse!(selectStudents!)
                                closeAction()
                }
}
 
extension StudentChoose2View:UITableViewDelegate{
                func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
                                let item = viewModel.dataSource.value[indexPath.row]
                                self.selectStudents = item
                                tableView.reloadData()
                }
}
 
extension StudentChoose2View: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_TCell") as! StudentInfo_2_TCell
                                cell.indexPath = indexPath
                                cell.activityDetailPartModel = viewModel.dataSource.value[indexPath.row]
                                cell.img_radio.isHidden = false
                                cell.btn_delete.isHidden = true
                                cell.btn_edit.isHidden = true
 
                                cell.img_radio.image = UIImage(named: selectStudents?.id == viewModel.dataSource.value[indexPath.row].id ? "btn_select" : "btn_select_u")
                                return cell
                }
}