Commit fd27edb4 ilCode

完成比赛筛选

1 个父辈 57fa5f79
......@@ -32,6 +32,7 @@
5E720D062C2B9D7500D30A16 /* HadoopProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E720D052C2B9D7500D30A16 /* HadoopProvider.swift */; };
5E720D082C2B9FBE00D30A16 /* HadoopRequestModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E720D072C2B9FBE00D30A16 /* HadoopRequestModel.swift */; };
5E720D0A2C2BB24200D30A16 /* ScoreTools.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E720D092C2BB24200D30A16 /* ScoreTools.swift */; };
5E720D0C2C2C200700D30A16 /* HadoopMatchFilterGroupModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E720D0B2C2C200700D30A16 /* HadoopMatchFilterGroupModel.swift */; };
5E9165D82C1D3F45004A3C5E /* UserProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E9165D72C1D3F45004A3C5E /* UserProvider.swift */; };
5E9165DA2C1D9A09004A3C5E /* ServerApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E9165D92C1D9A09004A3C5E /* ServerApi.swift */; };
5E93B4882C1A7DA200CD6536 /* BaseTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E93B4872C1A7DA200CD6536 /* BaseTableViewCell.swift */; };
......@@ -90,6 +91,7 @@
5EC03E4E2C1155720068A5CB /* CacheTools.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EC03E4D2C1155720068A5CB /* CacheTools.swift */; };
5EC03E502C118A420068A5CB /* AppInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EC03E4F2C118A420068A5CB /* AppInfo.swift */; };
5EC03E532C118FA00068A5CB /* ScoreProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EC03E522C118FA00068A5CB /* ScoreProvider.swift */; };
5EC3AD932C2CEB7200DCFB26 /* RaceTypeModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EC3AD922C2CEB7200DCFB26 /* RaceTypeModel.swift */; };
5EC6E64A2C211735006F778C /* RefreshHeaderAnimator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EC6E6482C211735006F778C /* RefreshHeaderAnimator.swift */; };
5EC6E64E2C2192C9006F778C /* MatchInfoCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EC6E64D2C2192C9006F778C /* MatchInfoCell.swift */; };
/* End PBXBuildFile section */
......@@ -122,6 +124,7 @@
5E720D052C2B9D7500D30A16 /* HadoopProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HadoopProvider.swift; sourceTree = "<group>"; };
5E720D072C2B9FBE00D30A16 /* HadoopRequestModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HadoopRequestModel.swift; sourceTree = "<group>"; };
5E720D092C2BB24200D30A16 /* ScoreTools.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScoreTools.swift; sourceTree = "<group>"; };
5E720D0B2C2C200700D30A16 /* HadoopMatchFilterGroupModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HadoopMatchFilterGroupModel.swift; sourceTree = "<group>"; };
5E9165D72C1D3F45004A3C5E /* UserProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserProvider.swift; sourceTree = "<group>"; };
5E9165D92C1D9A09004A3C5E /* ServerApi.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerApi.swift; sourceTree = "<group>"; };
5E93B4872C1A7DA200CD6536 /* BaseTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseTableViewCell.swift; sourceTree = "<group>"; };
......@@ -184,6 +187,7 @@
5EC03E4D2C1155720068A5CB /* CacheTools.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CacheTools.swift; sourceTree = "<group>"; };
5EC03E4F2C118A420068A5CB /* AppInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppInfo.swift; sourceTree = "<group>"; };
5EC03E522C118FA00068A5CB /* ScoreProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScoreProvider.swift; sourceTree = "<group>"; };
5EC3AD922C2CEB7200DCFB26 /* RaceTypeModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RaceTypeModel.swift; sourceTree = "<group>"; };
5EC6E6482C211735006F778C /* RefreshHeaderAnimator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RefreshHeaderAnimator.swift; sourceTree = "<group>"; };
5EC6E64D2C2192C9006F778C /* MatchInfoCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MatchInfoCell.swift; sourceTree = "<group>"; };
EA8E48B8C50E8D94161797C6 /* Pods-AoleiSports.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AoleiSports.release.xcconfig"; path = "Target Support Files/Pods-AoleiSports/Pods-AoleiSports.release.xcconfig"; sourceTree = "<group>"; };
......@@ -421,6 +425,8 @@
5E5A69D82C2ACA9B0063B726 /* HadoopMatchFilterView.swift */,
5E720D052C2B9D7500D30A16 /* HadoopProvider.swift */,
5E720D072C2B9FBE00D30A16 /* HadoopRequestModel.swift */,
5E720D0B2C2C200700D30A16 /* HadoopMatchFilterGroupModel.swift */,
5EC3AD922C2CEB7200DCFB26 /* RaceTypeModel.swift */,
);
path = Discover;
sourceTree = "<group>";
......@@ -628,6 +634,7 @@
5E9A1A312C0EF51600321AC5 /* UINavigationController+GKExtension.swift in Sources */,
5E47C9772C1FD7F6002EA39E /* InfoModel.swift in Sources */,
5E93B48E2C1A98BE00CD6536 /* RegisterController.swift in Sources */,
5E720D0C2C2C200700D30A16 /* HadoopMatchFilterGroupModel.swift in Sources */,
5E6CF0222C1305DD00BF3CF5 /* AoleiSports.xcdatamodeld in Sources */,
5E1E66B02C194337009339F0 /* LayoutTools.swift in Sources */,
5E93B4922C1AA0D200CD6536 /* UIViewController+Ext.swift in Sources */,
......@@ -656,6 +663,7 @@
5E9A1A262C0EF51600321AC5 /* Bundle+GKExtension.swift in Sources */,
5EB4F8B22C23D1B300A3667D /* DateTools.swift in Sources */,
5E9A1A2E2C0EF51600321AC5 /* GKPushAnimatedTransition.swift in Sources */,
5EC3AD932C2CEB7200DCFB26 /* RaceTypeModel.swift in Sources */,
5E66B2D72C1BE2ED00590452 /* UIImage+Ext.swift in Sources */,
5E9A1A302C0EF51600321AC5 /* UIImage+GKExtension.swift in Sources */,
5E65F8972C22CAF40082D374 /* UserDefaultTools.swift in Sources */,
......
......@@ -10,7 +10,6 @@ import UIKit
/// 大数据研究页面
class HadoopController: BaseController {
var provider: HadoopProvider<HadoopTarget>?
var matchCount = 0
private lazy var leftBtn: UIButton = {
let btn = UIButton()
......@@ -63,11 +62,7 @@ class HadoopController: BaseController {
}()
private lazy var filterView: HadoopMatchFilterView = {
let view = HadoopMatchFilterView()
view.dataSource = [
["赛事类型选择:": ["全部", "竞足", "北单", "欧洲杯"]],
["联赛选择:": ["全部", "欧洲杯", "日佳"]]
]
let view = HadoopMatchFilterView(provider: provider)
return view
}()
......@@ -84,10 +79,31 @@ class HadoopController: BaseController {
handleRefresh()
}
override func handleRefresh() {
super.handleRefresh()
provider?.bigDataListRequest(completion: { logicResult in
if case .failure(let err) = logicResult {
if case AsError.netErr(let message) = err {
self.showEmpty(type: .netErr, message: message)
} else {
self.showEmpty(type: .other, message: err.localizedDescription)
}
self.emptyStateDeal()
}
})
}
override var preferredStatusBarStyle: UIStatusBarStyle {
return gk_statusBarStyle
}
}
extension HadoopController {
private func initProvider() {
provider = HadoopProvider(vc: self, showErr: false)
provider?.bigDataList
provider?.matchList
.asObservable()
.subscribe(onNext: { tmpModels in
self.matchListView.reloadData()
......@@ -108,49 +124,11 @@ class HadoopController: BaseController {
self.header.update(predictData: tmpPredictData)
})
.disposed(by: disposeBag)
provider?.matchTotalCount
.asObservable()
.subscribe(onNext: { tmpCount in
self.matchCount = tmpCount
// 确保tableView已经被添加到视图层次结构中并且可见
if self.matchListView.window != nil {
self.matchListView.reloadSections(IndexSet(integer: 0), with: .none)
} else {
DispatchQueue.main.async {
self.matchListView.reloadSections(IndexSet(integer: 0), with: .none)
}
}
})
.disposed(by: disposeBag)
provider?.comList
.asObservable()
.subscribe(onNext: { tmpComList in
self.filterView.update(comList: tmpComList)
})
.disposed(by: disposeBag)
}
override func handleRefresh() {
super.handleRefresh()
provider?.bigDataListRequest(completion: { logicResult in
if case .failure(let err) = logicResult {
if case AsError.netErr(let message) = err {
self.showEmpty(type: .netErr, message: message)
} else {
self.showEmpty(type: .other, message: err.localizedDescription)
}
self.emptyStateDeal()
}
})
}
private func emptyStateDeal(isShow: Bool = true) {
leftBtn.isSelected = isShow
rightLab.isHidden = (provider?.bigDataList.value.isEmpty ?? true)
rightLab.isHidden = (provider?.matchList.value.isEmpty ?? true)
gk_statusBarStyle = leftBtn.isSelected ? .darkContent : .lightContent
gk_navBarAlpha = leftBtn.isSelected ? 1 : 0
}
......@@ -159,11 +137,11 @@ class HadoopController: BaseController {
//MARK: - UITableViewDataSource && UITableViewDelegate
extension HadoopController: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return provider?.bigDataList.value.count ?? 0
return provider?.matchList.value.count ?? 0
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let model = provider?.bigDataList.value[indexPath.row]
let model = provider?.matchList.value[indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier: HustleScoreCell.reuseIdentifier, for: indexPath) as! HustleScoreCell
cell.model = model
return cell
......@@ -171,10 +149,10 @@ extension HadoopController: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let header = tableView.dequeueReusableHeaderFooterView(withIdentifier: MatchFilterHeaderView.reuseIdentifier) as? MatchFilterHeaderView
header?.setProvider(provider)
header?.rightBtn.rx.tap.subscribe(onNext: {
self.filterView.showInView(self.view)
}).disposed(by: disposeBag)
header?.update(matchCount: matchCount)
return header
}
......@@ -197,7 +175,7 @@ extension HadoopController: UITableViewDataSource, UITableViewDelegate {
extension HadoopController: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if provider?.bigDataList.value.isEmpty ?? true {
if provider?.matchList.value.isEmpty ?? true {
emptyStateDeal()
} else {
var isShow = true
......@@ -210,8 +188,4 @@ extension HadoopController: UIScrollViewDelegate {
emptyStateDeal(isShow: isShow)
}
}
override var preferredStatusBarStyle: UIStatusBarStyle {
return gk_statusBarStyle
}
}
//
// HadoopMatchFilterGroupModel.swift
// AoleiSports
//
// Created by ilCode on 2024/6/26.
//
import Foundation
// 大数据赛事筛选分组模型
struct HadoopMatchFilterGroupModel {
enum GroupType {
// 赛事类型选择
case raceType
// 联赛类型选择
case comType
}
let type: GroupType
let title: String?
var raceItems: [RaceTypeModel]?
var comItems: [HadoopComModel]?
static func assembleNewGroupModels(oriGroupModels: [HadoopMatchFilterGroupModel], newComModels: [HadoopComModel]) -> [HadoopMatchFilterGroupModel] {
if newComModels.isEmpty { return [] }
var tmpNewComList: [HadoopComModel] = []
let allComModel = Mapper<HadoopComModel>().map(JSON: ["competition_id": HadoopComModel.allId, "competition_name": "全部", "isSelected": true])
tmpNewComList.append(allComModel!)
tmpNewComList.append(contentsOf: newComModels)
var tmpTypeGroupModel: HadoopMatchFilterGroupModel
var tmpComGroupModel: HadoopMatchFilterGroupModel
if oriGroupModels.isEmpty {
let typeNames = ["全部", "竞足", "单场", "欧洲杯"]
let types = [RaceTypeModel.RaceType.all, .jz, .dc, .euroCup]
var tmpRaceModels: [RaceTypeModel] = []
typeNames.enumerated().forEach { (index, value) in
let raceType = types[index]
let model = RaceTypeModel(raceType: raceType, itemName: value, isSelected: raceType == .all)
tmpRaceModels.append(model)
}
tmpTypeGroupModel = HadoopMatchFilterGroupModel(type: .raceType, title: "赛事类型选择:", raceItems: tmpRaceModels, comItems: nil)
tmpComGroupModel = HadoopMatchFilterGroupModel(type: .comType, title: "联赛选择:", raceItems: nil, comItems: tmpNewComList)
} else {
tmpTypeGroupModel = oriGroupModels.first!
tmpComGroupModel = oriGroupModels.last!
}
return [tmpTypeGroupModel, tmpComGroupModel]
}
}
......@@ -9,6 +9,11 @@ import UIKit
// 大数据赛事筛选view
class HadoopMatchFilterView: UIView {
let disposeBag = DisposeBag()
var provider: HadoopProvider<HadoopTarget>?
var selectedRaceType = RaceTypeModel.RaceType.all
var selectedComId = HadoopComModel.allId
private var overlayView: UIView!
private var contentView: UIView!
private var titleLabel: UILabel!
......@@ -16,23 +21,45 @@ class HadoopMatchFilterView: UIView {
private var collectionView: UICollectionView!
private var confirmButton: UIButton!
var dataSource: [[String: [String]]] = []
var selectedItems: [IndexPath: String] = [:]
var oriMatchList: [HadoopMatchModel] = []
var oriGroupModels: [HadoopMatchFilterGroupModel] = []
var groupModels: [HadoopMatchFilterGroupModel] = []
override init(frame: CGRect) {
init(provider: HadoopProvider<HadoopTarget>?) {
super.init(frame: CGRect(x: 0, y: 0, width: kScreenW, height: kScreenH))
self.provider = provider
setupOverlayView()
setupContentView()
setupTitleLabel()
setupCollectionView()
setupConfirmButton()
provider?.oriMatchList
.asObservable()
.subscribe(onNext: { tmpMatchList in
self.oriMatchList = tmpMatchList
})
.disposed(by: disposeBag)
provider?.comList
.asObservable()
.subscribe(onNext: { tmpComList in
self.oriGroupModels = HadoopMatchFilterGroupModel.assembleNewGroupModels(oriGroupModels: self.groupModels, newComModels: tmpComList)
self.groupModels = self.oriGroupModels
self.collectionView.reloadData()
})
.disposed(by: disposeBag)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
//MARK: - HadoopMatchFilterView初始化
extension HadoopMatchFilterView {
private func setupOverlayView() {
overlayView = UIView(frame: self.bounds)
overlayView.backgroundColor = UIColor.black.withAlphaComponent(0.3)
......@@ -90,15 +117,16 @@ class HadoopMatchFilterView: UIView {
collectionView.backgroundColor = .white
collectionView.dataSource = self
collectionView.delegate = self
collectionView.showsVerticalScrollIndicator = false
collectionView.showsHorizontalScrollIndicator = false
collectionView.register(HadoopFilterCell.self, forCellWithReuseIdentifier: HadoopFilterCell.reuseIdentifier)
collectionView.register(HadoopFilterHeaderView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: HadoopFilterHeaderView.reuseIdentifier)
contentView.addSubview(collectionView)
collectionView.border()
collectionView.snp.makeConstraints { make in
make.left.equalToSuperview().offset(10)
make.right.equalToSuperview().offset(-10)
make.top.equalTo(titleLabel.snp.bottom)
make.top.equalTo(titleLabel.snp.bottom).offset(1)
}
}
......@@ -120,27 +148,87 @@ class HadoopMatchFilterView: UIView {
make.bottom.equalToSuperview().offset(-10)
}
}
func update(comList: [HadoopComModel]) {
}
//MARK: - 事件处理
extension HadoopMatchFilterView {
// 更新联赛列表
private func updateComList(raceType: RaceTypeModel.RaceType) {
if oriMatchList.isEmpty { return }
}
// MARK: - Actions
@objc private func dismiss() {
UIView.animate(withDuration: 0.3, animations: {
self.alpha = 0
}) { _ in
self.removeFromSuperview()
var tmpMatchList = [HadoopMatchModel]()
switch raceType {
case .all:
tmpMatchList.append(contentsOf: oriMatchList)
case .jz:
tmpMatchList = oriMatchList.filter { tmpMatch in
return tmpMatch.issueNameJc != nil
}
case .dc:
tmpMatchList = oriMatchList.filter { tmpMatch in
return tmpMatch.issueNameBd != nil
}
case .euroCup:
tmpMatchList = oriMatchList.filter { tmpMatch in
return tmpMatch.comName == "欧洲杯"
}
}
if let index = oriGroupModels.firstIndex(where: { $0.type == .comType }) {
let oriComGroupModel = oriGroupModels[index]
var comGroupModel = groupModels[index]
let newComItems = oriComGroupModel.comItems?.filter({ tmpComModel in
var isExist = false
for tmpMatch in tmpMatchList {
if tmpMatch.comName == tmpComModel.comName || tmpComModel.comId == HadoopComModel.allId {
isExist = true
break
}
}
return isExist
})
comGroupModel.comItems = newComItems
groupModels[index] = comGroupModel
collectionView.reloadSections(IndexSet(integer: index))
}
}
@objc private func confirmButtonTapped() {
dismiss()
// 刷新选中的数据
// 可以在此处添加回调或通知外部调用者刷新数据
// 根据选中赛事类型和的联赛筛选比赛列表
var tmpMatchList = [HadoopMatchModel]()
// 先筛选类型
switch selectedRaceType {
case .all:
tmpMatchList.append(contentsOf: oriMatchList)
case .jz:
tmpMatchList = oriMatchList.filter { tmpMatch in
return tmpMatch.issueNameJc != nil
}
case .dc:
tmpMatchList = oriMatchList.filter { tmpMatch in
return tmpMatch.issueNameBd != nil
}
case .euroCup:
tmpMatchList = oriMatchList.filter { tmpMatch in
return tmpMatch.comName == "欧洲杯"
}
}
// 再筛选联赛
if selectedComId != HadoopComModel.allId {
tmpMatchList = tmpMatchList.filter({ tmpMatch in
return (tmpMatch.comId ?? 0) == selectedComId
})
}
provider?.matchList.accept(tmpMatchList)
}
// MARK: - 显示弹框
func showInView(_ view: UIView) {
self.frame = view.bounds
view.addSubview(self)
......@@ -149,29 +237,38 @@ class HadoopMatchFilterView: UIView {
self.alpha = 1
}
}
@objc private func dismiss() {
UIView.animate(withDuration: 0.3, animations: {
self.alpha = 0
}) { _ in
self.removeFromSuperview()
}
}
}
//MARK: - UICollectionViewDataSource && UICollectionViewDelegate
extension HadoopMatchFilterView: UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
func numberOfSections(in collectionView: UICollectionView) -> Int {
return dataSource.count
return groupModels.count
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
let sectionData = dataSource[section]
let values = sectionData.values.first
return values?.count ?? 0
let groupModel = groupModels[section]
return groupModel.type == .raceType ? (groupModel.raceItems?.count ?? 0) : (groupModel.comItems?.count ?? 0)
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: HadoopFilterCell.reuseIdentifier, for: indexPath) as? HadoopFilterCell else {
return UICollectionViewCell()
return HadoopFilterCell()
}
let sectionData = dataSource[indexPath.section]
let values = sectionData.values.first
let title = values?[indexPath.item] ?? ""
cell.configure(with: title, isSelected: selectedItems[indexPath] == title)
let groupModel = groupModels[indexPath.section]
if groupModel.type == .raceType {
cell.raceModel = groupModel.raceItems?[indexPath.row]
} else {
cell.comModel = groupModel.comItems?[indexPath.row]
}
return cell
}
......@@ -181,18 +278,49 @@ extension HadoopMatchFilterView: UICollectionViewDataSource, UICollectionViewDel
return UICollectionReusableView()
}
let sectionData = dataSource[indexPath.section]
let title = sectionData.keys.first ?? ""
header.configure(with: title)
let groupModel = groupModels[indexPath.section]
header.configure(with: groupModel.title ?? "")
return header
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let sectionData = dataSource[indexPath.section]
let values = sectionData.values.first
let selectedValue = values?[indexPath.item]
selectedItems[indexPath] = selectedValue
var groupModel = groupModels[indexPath.section]
if groupModel.type == .raceType {
if var raceItems = groupModel.raceItems {
let curRaceModel = raceItems[indexPath.row]
if curRaceModel.isSelected ?? false { return }
for index in raceItems.indices {
raceItems[index].isSelected = index == indexPath.row
}
groupModel.raceItems = raceItems
// 通过赛事中的相关字段去筛选联赛列表
selectedRaceType = curRaceModel.raceType
selectedComId = HadoopComModel.allId
updateComList(raceType: selectedRaceType)
}
} else {
if var comItems = groupModel.comItems {
let curComModel = comItems[indexPath.row]
if curComModel.isSelected ?? false { return }
for index in comItems.indices {
comItems[index].isSelected = index == indexPath.row
}
groupModel.comItems = comItems
selectedComId = curComModel.comId ?? 0
}
}
if let index = groupModels.firstIndex(where: { $0.type == groupModel.type }) {
groupModels[index] = groupModel
}
collectionView.reloadSections(IndexSet(integer: indexPath.section))
}
}
......@@ -264,10 +392,20 @@ class HadoopFilterCell: UICollectionViewCell {
}
}
func configure(with title: String, isSelected: Bool) {
itemBtn.setTitle(title, for: .normal)
itemBtn.backgroundColor = UIColor.colorWith(hexString: isSelected ? "C49225" : "F0F0F0")
itemBtn.isSelected = isSelected
var raceModel: RaceTypeModel? {
didSet {
itemBtn.setTitle(raceModel?.itemName, for: .normal)
itemBtn.isSelected = raceModel?.isSelected ?? false
itemBtn.backgroundColor = UIColor.colorWith(hexString: itemBtn.isSelected ? "C49225" : "F0F0F0")
}
}
var comModel: HadoopComModel? {
didSet {
itemBtn.setTitle(comModel?.comName, for: .normal)
itemBtn.isSelected = comModel?.isSelected ?? false
itemBtn.backgroundColor = UIColor.colorWith(hexString: itemBtn.isSelected ? "C49225" : "F0F0F0")
}
}
}
......
......@@ -21,10 +21,11 @@ enum HadoopTarget: TargetType {
}
class HadoopProvider<Target: TargetType>: BaseMoyaProvider<Target> {
var bigDataList = BehaviorRelay<[HadoopMatchModel]>(value: [])
var oriMatchList = BehaviorRelay<[HadoopMatchModel]>(value: [])
var predictData = BehaviorRelay<(Int, String)>(value: (0, "0"))
var matchTotalCount = BehaviorRelay<Int>(value: 0)
var comList = BehaviorRelay<[HadoopComModel]>(value: [])
var matchList = BehaviorRelay<[HadoopMatchModel]>(value: [])
func bigDataListRequest(completion: @escaping (Result<Bool, AsError>) -> Void) {
moyaPost(api: APIs.kBigDataList, target: HadoopTarget.bigDataList) { midResult in
......@@ -35,11 +36,12 @@ class HadoopProvider<Target: TargetType>: BaseMoyaProvider<Target> {
let requestModel = HadoopRequestModel(JSON: midSuccessResult)
if let tmpReult = requestModel?.result, !tmpReult.isEmpty {
self.bigDataList.accept(tmpReult)
self.oriMatchList.accept(tmpReult)
self.matchList.accept(tmpReult)
}
if let predictData = requestModel?.predictData,
let predictResult = predictData.predictResult,
let predictResult = predictData.predictResult,
let totalCount = predictResult["total_count"] as? Int,
let predict = predictResult["predict"] as? [String : Any],
let rate = predict["rate"] as? String {
......
......@@ -56,14 +56,19 @@ struct PredictTopModel: Mappable {
}
struct HadoopComModel: Mappable {
// 全部特殊id
static let allId = -999
var comId: Int?
var comName: String?
var isSelected: Bool?
init?(map: ObjectMapper.Map) { }
mutating func mapping(map: ObjectMapper.Map) {
comId <- map["competition_id"]
comName <- map["competition_name"]
isSelected <- map["isSelected"]
}
}
......
......@@ -7,17 +7,26 @@
import UIKit
// 筛选分组悬浮头
class MatchFilterHeaderView: UITableViewHeaderFooterView {
static let reuseIdentifier = "MatchFilterHeaderView"
let disposeBag = DisposeBag()
private lazy var leftLabel: UILabel = {
var provider: HadoopProvider<HadoopTarget>?
private lazy var totalLabel: UILabel = {
let label = UILabel()
label.textColor = kMainTitleColor
label.font = kFontSize(14)
return label
}()
private lazy var filterLabel: UILabel = {
let label = UILabel()
label.textColor = UIColor.colorWith(hexString: "AA947A")
label.font = kBoldFontSize(12)
return label
}()
lazy var rightBtn: UIButton = {
let btn = UIButton()
btn.setTitle("筛选比赛", for: .normal)
......@@ -26,7 +35,7 @@ class MatchFilterHeaderView: UITableViewHeaderFooterView {
btn.setImage(R.image.hadoop_match_filter(), for: .normal)
btn.adjustImage(position: .left, spacing: 5)
btn.contentHorizontalAlignment = .right
return btn
return btn
}()
override init(reuseIdentifier: String?) {
......@@ -35,14 +44,19 @@ class MatchFilterHeaderView: UITableViewHeaderFooterView {
let bgView = UIView()
bgView.backgroundColor = kMainBgColor
backgroundView = bgView
contentView.addSubview(leftLabel)
contentView.addSubview(totalLabel)
contentView.addSubview(filterLabel)
contentView.addSubview(rightBtn)
leftLabel.snp.makeConstraints { make in
totalLabel.snp.makeConstraints { make in
make.centerY.equalToSuperview()
make.left.equalToSuperview().offset(10)
}
filterLabel.snp.makeConstraints { make in
make.centerY.equalToSuperview()
make.left.equalTo(totalLabel.snp.right).offset(10)
}
rightBtn.snp.makeConstraints { make in
make.centerY.equalToSuperview()
make.right.equalToSuperview().offset(-10)
......@@ -53,7 +67,21 @@ class MatchFilterHeaderView: UITableViewHeaderFooterView {
fatalError("init(coder:) has not been implemented")
}
func update(matchCount: Int) {
leftLabel.text = "共\(matchCount)场比赛"
func setProvider(_ provider: HadoopProvider<HadoopTarget>?) {
self.provider = provider
self.provider?.matchTotalCount
.asObservable()
.subscribe(onNext: { tmpCount in
self.totalLabel.text = "共\(tmpCount)场比赛"
})
.disposed(by: disposeBag)
self.provider?.matchList
.asObservable()
.subscribe(onNext: { tmpModels in
self.filterLabel.text = self.provider?.matchTotalCount.value == tmpModels.count ? "" : "(已筛选\(tmpModels.count)场)"
})
.disposed(by: disposeBag)
}
}
//
// RaceTypeModel.swift
// AoleiSports
//
// Created by ilCode on 2024/6/27.
//
import Foundation
// 赛事类型模型
struct RaceTypeModel {
enum RaceType {
case all // 全部
case jz // 竞足
case dc // 单场
case euroCup // 欧洲杯
}
let raceType: RaceType
let itemName: String?
var isSelected: Bool?
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!