//
|
// 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
|
}
|
}
|