//
|
// WorldCupRecordVC.swift
|
// WanPai
|
//
|
// Created by 无故事王国 on 2024/2/27.
|
//
|
|
import UIKit
|
import RxSwift
|
import RxCocoa
|
import SnapKit
|
|
class WorldCupRecordViewModel:RefreshInnerModel<WorldCupMatchRecordDataModel>{
|
|
let studentId = BehaviorRelay<Int>(value:0)
|
let isStudent = BehaviorRelay<Int>(value:0)
|
|
override func api() -> (Observable<BaseResponse<BaseResponseList<WorldCupMatchRecordDataModel>>>)? {
|
return Services.getWorldCupMatchRecord(id: studentId.value, isStudent: isStudent.value, pageNo: page)
|
}
|
|
}
|
|
class WorldCupRecordVC: BaseVC {
|
|
private(set) var tableView:BaseScrollInnerTableView!
|
private var viewModel = WorldCupRecordViewModel()
|
var partModel:BehaviorRelay<ActivityDetailPartModel?>?
|
var superScrollView:UIScrollView?
|
override func viewDidLoad() {
|
super.viewDidLoad()
|
view.backgroundColor = .clear
|
}
|
|
override func setUI() {
|
superScrollView?.delegate = self
|
tableView = BaseScrollInnerTableView(frame: .zero, style: .grouped)
|
tableView.delegate = self
|
tableView.dataSource = self
|
tableView.separatorStyle = .none
|
tableView.backgroundColor = .clear
|
if #available(iOS 15.0, *) {
|
tableView.sectionHeaderTopPadding = 0
|
}
|
tableView.register(UINib(nibName: "WorldCupRecordTCell", bundle: nil), forCellReuseIdentifier: "_WorldCupRecordTCell")
|
|
view.addSubview(tableView)
|
tableView.snp.makeConstraints { make in
|
make.edges.equalToSuperview()
|
}
|
|
viewModel.configure(tableView)
|
viewModel.beginRefresh()
|
}
|
|
override func setRx() {
|
partModel?.subscribe(onNext: {[weak self]model in
|
if let m = model{
|
self?.viewModel.studentId.accept(m.id)
|
self?.viewModel.isStudent.accept(m.isStudent)
|
self?.viewModel.beginRefresh()
|
}
|
}).disposed(by: disposeBag)
|
}
|
}
|
extension WorldCupRecordVC:UIScrollViewDelegate{
|
|
func scrollViewDidScroll(_ scrollView: UIScrollView) {
|
var canScroll = true
|
if scrollView.tag == 2100{
|
|
if scrollView.contentOffset.y < 350 && scrollView.contentOffset.y != 0{
|
canScroll = false
|
}
|
print("\(scrollView.contentOffset.y)----\(canScroll)")
|
tableView.isScrollEnabled = canScroll
|
}
|
}
|
}
|
|
extension WorldCupRecordVC:UITableViewDelegate,UITableViewDataSource{
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
return viewModel.dataSource.value?.list.count ?? 0
|
}
|
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
let cell = tableView.dequeueReusableCell(withIdentifier: "_WorldCupRecordTCell") as! WorldCupRecordTCell
|
cell.backgroundColor = .clear
|
cell.model = viewModel.dataSource.value!.list[indexPath.row]
|
return cell
|
}
|
|
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
return 102
|
}
|
|
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
|
var headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "header")
|
if headerView == nil{
|
headerView = UITableViewHeaderFooterView(reuseIdentifier: "header")
|
headerView?.backgroundColor = .clear
|
headerView?.contentView.backgroundColor = .clear
|
let label = UILabel()
|
label.tag = 100
|
label.font = UIFont.systemFont(ofSize: 16, weight: .semibold)
|
label.textColor = .black.withAlphaComponent(0.8)
|
headerView?.contentView.addSubview(label)
|
label.snp.makeConstraints { make in
|
make.left.equalTo(14)
|
make.height.equalTo(22)
|
make.bottom.equalToSuperview().offset(-6.5)
|
}
|
}
|
|
if let label = headerView?.contentView.viewWithTag(100) as? UILabel{
|
label.text = "总场次:\(viewModel.dataSource.value?.totalSession ?? 0)场"
|
}
|
|
return headerView
|
}
|
|
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
|
return 54
|
}
|
|
}
|