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