杨锴
2025-05-11 7453d2d0cef415b34323d1b91e6cfa4a6ba31178
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//
//  GamesDataSourceSubListVC.swift
//  WanPai
//
//  Created by 无故事王国 on 2023/9/15.
//
 
import UIKit
import RxRelay
import RxSwift
 
class GamesDataSourceViewModel:RefreshModel<GamesRecordModel>{
                private var type:GamesSubType!
 
                init(type:GamesSubType) {
                                super.init()
                                self.type = type
                }
 
                let userId = BehaviorRelay<Int>(value:0)
 
                override func api() -> (Observable<BaseResponse<[GamesRecordModel]>>)? {
                                if type == .offline{
                                                return Services.game_generalGameRecord(userId: userId.value, page: page)
                                }else if type == .crossMatch{
                                                return Services.game_generalGameCrossRecord(userId: userId.value, page: page)
                                }else{
                                                return Services.game_generalGameAccuracyRecord(userId: userId.value, page: page)
                                }
                }
}
 
class GamesDataSourceSubListVC: BaseVC {
 
                private var type:GamesSubType!
                private var tableView:BaseTableView!
                private var viewModel:GamesDataSourceViewModel!
 
                init(type:GamesSubType) {
                                super.init(nibName: nil, bundle: nil)
                                self.type = type
                                self.viewModel = GamesDataSourceViewModel(type: type)
                }
 
                required init?(coder: NSCoder) {
                                fatalError("init(coder:) has not been implemented")
                }
 
                override func viewDidLoad() {
                                super.viewDidLoad()
 
 
 
                                //        tableView.jq_setEmptyView()
                                viewModel.configure(tableView)
                                Services.userDetails().subscribe(onNext: {[weak self] data in
                                                if let userId = data.data?.userId{
                                                                self?.viewModel.userId.accept(userId)
                                                                self?.viewModel.beginRefresh()
                                                }
                                }) { error in
 
                                }.disposed(by: disposeBag)
                }
 
                override func setUI() {
                                tableView = BaseTableView(frame: .zero, style: .plain)
                                tableView.delegate = self
                                tableView.dataSource = self
                                tableView.separatorStyle = .none
                                tableView.register(UINib(nibName: "GamesDataSourceTCell", bundle: nil), forCellReuseIdentifier: "_GamesDataSourceTCell")
                                view.addSubview(tableView)
                                tableView.snp.makeConstraints { make in
                                                make.edges.equalToSuperview().inset(UIEdgeInsets(top: 7.5, left: 0, bottom: 0, right: 0))
                                }
                }
}
 
extension GamesDataSourceSubListVC:UITableViewDelegate{
 
}
 
extension GamesDataSourceSubListVC:UITableViewDataSource{
                func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
                                let cell = tableView.dequeueReusableCell(withIdentifier: "_GamesDataSourceTCell") as! GamesDataSourceTCell
 
                                if type == .offline{
                                                cell.label_gameName.text = viewModel.dataSource.value[indexPath.row].game_name
                                                cell.label_score.text = "\(viewModel.dataSource.value[indexPath.row].score)"
                                                cell.label_type.text = viewModel.dataSource.value[indexPath.row].time
                                }
                                return cell
                }
 
                func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
                                if type == .offline{
                                                return viewModel.dataSource.value.count
                                }
                                return 0
                }
}