//
|
// WorldCupRankVC.swift
|
// WanPai
|
//
|
// Created by 无故事王国 on 2024/2/27.
|
//
|
|
import UIKit
|
import JQTools
|
import QMUIKit
|
import RxSwift
|
import RxRelay
|
|
class WorldCupRankViewModel:RefreshModel<WorldCupMatchRankModel>{
|
|
var id = BehaviorRelay<Int>(value: 0)
|
var isStudent = BehaviorRelay<Int>(value: 0)
|
var radius = BehaviorRelay<Int>(value: 2)
|
var sort = BehaviorRelay<Int>(value: 2)
|
var year = BehaviorRelay<Int?>(value: nil)
|
|
override func api() -> (Observable<BaseResponse<[WorldCupMatchRankModel]>>)? {
|
return Services.getWorldCupRank(id: id.value, isStudent: isStudent.value, radius: radius.value, sort: sort.value,year: year.value)
|
}
|
}
|
|
class WorldCupRankVC: BaseVC {
|
|
private(set) var viewModel = WorldCupRankViewModel()
|
var partModel:BehaviorRelay<ActivityDetailPartModel?>?
|
var currentRankModel:BehaviorRelay<WorldCupMatchRankModel?>?
|
// private var worldCupRankModel:WorldCupRankModel?
|
// private let cityBtn = UIButton(type: .custom)
|
private let yearBtn = QMUIButton(type: .custom)
|
private let ratioRankBtn = QMUIButton(type: .custom)
|
// private let provinceBtn = UIButton(type: .custom)
|
private var tableView:BaseScrollInnerTableView!
|
var superScrollView:UIScrollView?
|
|
var flowCell:WorldCupRankTCell?
|
override func viewDidLoad() {
|
super.viewDidLoad()
|
view.backgroundColor = .clear
|
}
|
|
override func setUI() {
|
superScrollView?.delegate = self
|
tableView = BaseScrollInnerTableView(frame: .zero, style: .plain)
|
tableView.delegate = self
|
tableView.dataSource = self
|
tableView.showsVerticalScrollIndicator = false
|
tableView.showsHorizontalScrollIndicator = false
|
tableView.backgroundColor = .clear
|
tableView.separatorStyle = .none
|
tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 100 - UIDevice.jq_safeEdges.bottom, right: 0)
|
if #available(iOS 15.0, *) {
|
tableView.sectionHeaderTopPadding = 0
|
}
|
tableView.register(WorldCupRankTCell.self, forCellReuseIdentifier: "rankTCell")
|
|
view.addSubview(tableView)
|
tableView.snp.makeConstraints { make in
|
make.top.left.right.equalToSuperview().inset(UIEdgeInsets(top: 0, left: 14, bottom: 0, right: 14))
|
make.bottom.equalToSuperview().offset(-69)
|
}
|
|
viewModel.id.subscribe(onNext: {[weak self] _ in
|
guard let weakSelf = self else { return }
|
self?.viewModel.configure(weakSelf.tableView,needMore: false)
|
self?.viewModel.beginRefresh()
|
}).disposed(by: disposeBag)
|
}
|
|
override func setRx() {
|
partModel?.subscribe(onNext: {[weak self] model in
|
guard let weakSelf = self else { return }
|
if let m = model{
|
self?.viewModel.id.accept(m.id)
|
self?.viewModel.isStudent.accept(m.isStudent)
|
self?.viewModel.beginRefresh()
|
|
// Services.getEntrantRank(id: m.id, isStudent: m.isStudent).subscribe(onNext: {[weak self] data in
|
// if let model = data.data{
|
// self?.worldCupRankModel = model
|
// self?.cityBtn.setTitle(model.cityName, for: .normal)
|
// self?.cityBtn.layoutIfNeeded()
|
// self?.cityBtn.layoutSubviews()
|
// }
|
// }).disposed(by: weakSelf.disposeBag)
|
}
|
|
}).disposed(by: disposeBag)
|
|
viewModel.dataSource.subscribe(onNext: {[weak self] data in
|
guard let weakSelf = self else { return }
|
data.forEach { model in
|
if model.oneself == 1{
|
weakSelf.currentRankModel?.accept(model)
|
}
|
}
|
}).disposed(by: disposeBag)
|
|
// Observable.combineLatest(superScrollView!.rx.contentOffset, tableView.rx.contentOffset).subscribe { v1,v2 in
|
// //获取rankTCell是否出现在屏幕内
|
// if let cell = self.flowCell{
|
// let rect = cell.convert(cell.bounds, to: app.window)
|
// if rect.origin.y < 0 || rect.origin.y > self.view.height{
|
// NotificationCenter.default.post(name: ShowOrHiddenFlowImage_Noti, object: false)
|
// }else{
|
// NotificationCenter.default.post(name: ShowOrHiddenFlowImage_Noti, object: true)
|
// }
|
// }
|
// }.disposed(by: disposeBag)
|
}
|
|
// @objc func radiusAction(btn:UIButton){
|
// if btn.tag == 10{
|
// provinceBtn.jq_borderWidth = 0
|
// provinceBtn.setTitleColor(.white, for: .normal)
|
// provinceBtn.backgroundColor = UIColor(hexString: "#FE7E03")
|
//
|
// cityBtn.setTitleColor(UIColor(hexString: "#FE7E03"), for: .normal)
|
// cityBtn.backgroundColor = .white
|
// cityBtn.jq_borderWidth = 1
|
// cityBtn.jq_borderColor = UIColor(hexString: "#FE7E03")
|
// viewModel.radius.accept(1)
|
// }else{
|
// cityBtn.jq_borderWidth = 0
|
// cityBtn.setTitleColor(.white, for: .normal)
|
// cityBtn.backgroundColor = UIColor(hexString: "#FE7E03")
|
//
|
// provinceBtn.setTitleColor(UIColor(hexString: "#FE7E03"), for: .normal)
|
// provinceBtn.backgroundColor = .white
|
// provinceBtn.jq_borderWidth = 1
|
// viewModel.radius.accept(2)
|
// }
|
// viewModel.beginRefresh()
|
//
|
// }
|
|
@objc func filterAction(){
|
CommonYearsPickerView.show {[weak self] index in
|
if index == 0{
|
self?.viewModel.year.accept(nil)
|
self?.yearBtn.setTitle(" 全部", for: .normal)
|
}else{
|
self?.viewModel.year.accept(index)
|
self?.yearBtn.setTitle(" \(index)年", for: .normal)
|
}
|
self?.viewModel.beginRefresh()
|
}
|
}
|
|
@objc func rateAction(sender:UIButton){
|
sender.isSelected = !sender.isSelected
|
viewModel.sort.accept(sender.isSelected ? 2 : 1)
|
ratioRankBtn.setTitle(viewModel.sort.value == 1 ? "按场次排名":"按胜率排名", for: .normal)
|
viewModel.beginRefresh()
|
}
|
}
|
|
extension WorldCupRankVC: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 WorldCupRankVC:UITableViewDelegate,UITableViewDataSource{
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
if section == 0{
|
return 1
|
}
|
return viewModel.dataSource.value.count
|
}
|
|
func numberOfSections(in tableView: UITableView) -> Int {
|
return 2
|
}
|
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
if indexPath.section == 0{
|
var cell = tableView.dequeueReusableCell(withIdentifier: "topHanderView")
|
if cell == nil{
|
cell = UITableViewCell(style: .default, reuseIdentifier: "topHanderView")
|
let label = UILabel()
|
label.text = "排名"
|
label.textAlignment = .center
|
label.font = UIFont.systemFont(ofSize: 12, weight: .medium)
|
label.textColor = .black.withAlphaComponent(0.8)
|
cell?.contentView.addSubview(label)
|
label.snp.makeConstraints { make in
|
make.top.bottom.equalToSuperview()
|
make.left.equalToSuperview()
|
make.width.equalTo((JQ_ScreenW - 28) * 0.138)
|
make.height.equalTo(32)
|
}
|
|
label.addLine(UIColor(hexStr: "#E1E1E1"), true, true, true, false, 0.4)
|
|
let label1 = UILabel()
|
label1.text = "用户"
|
label1.textAlignment = .center
|
label1.font = UIFont.systemFont(ofSize: 12, weight: .medium)
|
label1.textColor = .black.withAlphaComponent(0.8)
|
cell?.contentView.addSubview(label1)
|
label1.snp.makeConstraints { make in
|
make.top.bottom.equalToSuperview()
|
make.width.equalTo((JQ_ScreenW - 28) * 0.337)
|
make.height.equalTo(32)
|
make.left.equalTo(label.snp.right)
|
}
|
label1.addLine(UIColor(hexStr: "#E1E1E1"), true, true, true, false, 0.4)
|
|
let label2 = UILabel()
|
label2.text = "总场次"
|
label2.textAlignment = .center
|
label2.font = UIFont.systemFont(ofSize: 12, weight: .medium)
|
label2.textColor = .black.withAlphaComponent(0.8)
|
cell?.contentView.addSubview(label2)
|
label2.snp.makeConstraints { make in
|
make.top.bottom.equalToSuperview()
|
make.width.equalTo((JQ_ScreenW - 28) * 0.3314)
|
make.height.equalTo(32)
|
make.left.equalTo(label1.snp.right)
|
}
|
label2.addLine(UIColor(hexStr: "#E1E1E1"), true, true, true, false, 0.4)
|
|
let label3 = UILabel()
|
label3.text = "胜率"
|
label3.textAlignment = .center
|
label3.font = UIFont.systemFont(ofSize: 12, weight: .medium)
|
label3.textColor = .black.withAlphaComponent(0.8)
|
cell?.contentView.addSubview(label3)
|
label3.snp.makeConstraints { make in
|
make.top.bottom.equalToSuperview()
|
make.width.equalTo((JQ_ScreenW - 28) * 0.2016)
|
make.height.equalTo(32)
|
make.left.equalTo(label2.snp.right)
|
}
|
label3.addLine(UIColor(hexStr: "#E1E1E1"), true, true, true, true, 0.4)
|
}
|
return cell!
|
}
|
let cell = tableView.dequeueReusableCell(withIdentifier: "rankTCell") as! WorldCupRankTCell
|
cell.indexPath = indexPath
|
cell.model = viewModel.dataSource.value[indexPath.row]
|
|
cell.addLine(UIColor(hexStr: "#E1E1E1"), false, true, false, true, 0.4)
|
return cell
|
}
|
|
// func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
|
// if let rankTCell = cell as? WorldCupRankTCell{
|
// if viewModel.dataSource.value[indexPath.row].oneself == 1{
|
// flowCell = rankTCell
|
// NotificationCenter.default.post(name: FlowImage_Noti, object: rankTCell.jq_captureToImage())
|
// }
|
// }
|
// }
|
|
|
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
if indexPath.section == 0{
|
return 32
|
}
|
return 45
|
}
|
|
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
|
|
if section != 0{return nil}
|
|
var headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "header")
|
if headerView == nil{
|
headerView = UITableViewHeaderFooterView(reuseIdentifier: "header")
|
headerView?.backgroundColor = .clear
|
headerView?.contentView.backgroundColor = .clear
|
|
let label = UILabel(text: "参与年份: ")
|
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.centerY.equalToSuperview()
|
}
|
|
if viewModel.year.value == nil{
|
yearBtn.setTitle(" 全部", for: .normal)
|
}else{
|
yearBtn.setTitle(" \(viewModel.year.value!)年", for: .normal)
|
}
|
|
yearBtn.setTitleColor(.black.withAlphaComponent(0.74), for: .normal)
|
yearBtn.titleLabel?.font = UIFont.systemFont(ofSize: 16)
|
yearBtn.borderColor = UIColor(hexString: "#D9D9D9")
|
yearBtn.borderWidth = 1
|
yearBtn.setImage(UIImage(named: "icon_down_arrow"), for: .normal)
|
yearBtn.addTarget(self, action: #selector(filterAction), for: .touchUpInside)
|
yearBtn.spacingBetweenImageAndTitle = 5
|
yearBtn.imagePosition = .right
|
yearBtn.jq_cornerRadius = 5
|
headerView?.contentView.addSubview(yearBtn)
|
yearBtn.snp.makeConstraints { make in
|
make.left.equalTo(label.snp.right).offset(2)
|
make.centerY.equalToSuperview()
|
make.width.greaterThanOrEqualTo(68)
|
make.height.equalTo(35)
|
}
|
|
ratioRankBtn.setTitle("按胜率排名", for: .normal)
|
ratioRankBtn.setTitle(viewModel.sort.value == 1 ? "按场次排名":"按胜率排名", for: .normal)
|
ratioRankBtn.setTitleColor(UIColor(hexString: "#3876F2"), for: .normal)
|
ratioRankBtn.titleLabel?.font = UIFont.systemFont(ofSize: 16,weight: .medium)
|
ratioRankBtn.setImage(UIImage(named: "icon_reset"), for: .normal)
|
ratioRankBtn.addTarget(self, action: #selector(rateAction), for: .touchUpInside)
|
ratioRankBtn.spacingBetweenImageAndTitle = 5
|
ratioRankBtn.isSelected = true
|
ratioRankBtn.imagePosition = .right
|
headerView?.contentView.addSubview(ratioRankBtn)
|
ratioRankBtn.snp.makeConstraints { make in
|
make.right.equalToSuperview().offset(-14)
|
make.centerY.equalToSuperview()
|
make.height.equalTo(22)
|
}
|
}
|
return headerView
|
}
|
|
// func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
|
//
|
// if section == 0{return nil}
|
// var footView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "footer")
|
// if footView == nil{
|
// footView = UITableViewHeaderFooterView(reuseIdentifier: "footer")
|
// let stackView = UIStackView()
|
// stackView.axis = .horizontal
|
// stackView.distribution = .fillEqually
|
// stackView.spacing = 10
|
//
|
// provinceBtn.setTitle("全国", for: .normal)
|
// provinceBtn.tag = 10
|
// provinceBtn.titleLabel?.font = UIFont.systemFont(ofSize: 15, weight: .medium)
|
// provinceBtn.setTitleColor(UIColor(hexString: "#FE7E03"), for: .normal)
|
// provinceBtn.borderColor = UIColor(hexString: "#FE7E03")
|
// provinceBtn.borderWidth = 1
|
// provinceBtn.cornerRadius = 20
|
// provinceBtn.addTarget(self, action: #selector(radiusAction), for: .touchUpInside)
|
//
|
// cityBtn.titleLabel?.font = UIFont.systemFont(ofSize: 15, weight: .medium)
|
// cityBtn.tag = 11
|
// cityBtn.setTitleColor(.white, for: .normal)
|
// cityBtn.backgroundColor = UIColor(hexString: "#FE7E03")
|
// cityBtn.cornerRadius = 20
|
// cityBtn.addTarget(self, action: #selector(radiusAction), for: .touchUpInside)
|
//
|
// stackView.addArrangedSubview(provinceBtn)
|
// stackView.addArrangedSubview(cityBtn)
|
//
|
// footView?.contentView.addSubview(stackView)
|
// footView?.contentView.backgroundColor = .white
|
// stackView.snp.makeConstraints { make in
|
// make.left.right.equalToSuperview().inset(UIEdgeInsets(top: 0, left: 27, bottom: 0, right: 27))
|
// make.bottom.equalToSuperview()
|
// make.height.equalTo(40)
|
// }
|
//
|
// let cell = WorldCupRankTCell(style: .default, reuseIdentifier: nil)
|
// cell.tag = 1100
|
// cell.borderColor = UIColor(hexString: "#FC743A")
|
// cell.jq_borderWidth = 1
|
// footView?.addSubview(cell)
|
// cell.snp.makeConstraints { make in
|
// make.left.top.right.equalToSuperview()
|
// make.height.equalTo(45)
|
// }
|
// }
|
// if let cell = footView?.viewWithTag(1100) as? WorldCupRankTCell{
|
// if let model = viewModel.dataSource.value.filter({$0.oneself == 1}).first{
|
// cell.model = model
|
// }
|
// }
|
// return footView
|
// }
|
|
// func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
|
// if section == 0{
|
// return 0.001
|
// }
|
// return 100
|
// }
|
|
|
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
|
if section != 0{
|
return 0.0001
|
}
|
return 85
|
}
|
}
|
|
extension UIView{
|
//给当前的view边界换上线,可以任意设置4个边
|
func addLine(_ color:UIColor = UIColor.lightGray.withAlphaComponent(0.3),_ top:Bool = false,_ left:Bool = false,_ bottom:Bool = false,_ right:Bool = false,_ width:CGFloat = 0.5){
|
if top{
|
let line = UIView()
|
line.backgroundColor = color
|
addSubview(line)
|
line.snp.makeConstraints { make in
|
make.top.left.right.equalToSuperview()
|
make.height.equalTo(width)
|
}
|
}
|
|
if left{
|
let line = UIView()
|
line.backgroundColor = color
|
addSubview(line)
|
line.snp.makeConstraints { make in
|
make.top.left.bottom.equalToSuperview()
|
make.width.equalTo(width)
|
}
|
}
|
|
if bottom{
|
let line = UIView()
|
line.backgroundColor = color
|
addSubview(line)
|
line.snp.makeConstraints { make in
|
make.bottom.left.right.equalToSuperview()
|
make.height.equalTo(width)
|
}
|
}
|
|
if right{
|
let line = UIView()
|
line.backgroundColor = color
|
addSubview(line)
|
line.snp.makeConstraints { make in
|
make.top.bottom.equalToSuperview()
|
make.right.equalToSuperview().offset(-0.4)
|
make.width.equalTo(width)
|
}
|
}
|
}
|
}
|