杨锴
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
102
//
//  GamesSubListVC.swift
//  WanPai
//
//  Created by 无故事王国 on 2023/9/15.
//
 
import UIKit
import RxRelay
import RxSwift
 
enum GamesSubType:Int{
                case offline = 0
                case crossMatch = 1
                case accuracyMatch = 2
}
 
class GamesOffLineViewModel:RefreshModel<GameListModel>{
                let spaceId = BehaviorRelay<Int>(value: 0)
                let sutuId = BehaviorRelay<Int>(value: 0)
                let storeId = BehaviorRelay<Int>(value: 0)
 
                override func api() -> (Observable<BaseResponse<[GameListModel]>>)? {
                                return Services.game_gameList(spaceId: spaceId.value, storeId: storeId.value)
                }
}
 
class GamesSubListVC: BaseVC {
                private var type:GamesSubType!
                private var model:QRCodeModel!
 
                private let offLineViewModel = GamesOffLineViewModel()
                private var homeStoreModel:HomeStoreModel!
                private var tableView:BaseTableView!
 
                init(type:GamesSubType,model:QRCodeModel) {
                                super.init(nibName: nil, bundle: nil)
                                self.type = type
                                self.model = model
                }
 
                required init?(coder: NSCoder) {
                                fatalError("init(coder:) has not been implemented")
                }
 
                override func viewDidLoad() {
                                super.viewDidLoad()
 
                                if let storeStr = UserDefaults.standard.object(forKey: "CurrentStore") as? String{
                                                if let deserModel = HomeStoreModel.deserialize(from: storeStr){
                                                                offLineViewModel.storeId.accept(deserModel.storeId)
 
                                                                if type == .offline{
                                                                                offLineViewModel.spaceId.accept(model.space_id!)
                                                                                offLineViewModel.sutuId.accept(model.sutu_id!)
                                                                                offLineViewModel.configure(tableView, needMore: false)
                                                                                offLineViewModel.beginRefresh()
                                                                }
                                                }
                                }
                }
 
                override func setUI() {
                                tableView = BaseTableView(frame: .zero, style: .plain)
                                tableView.delegate = self
                                tableView.dataSource = self
                                tableView.register(UINib(nibName: "GamesTCell", bundle: nil), forCellReuseIdentifier: "_GamesTCell")
                                view.addSubview(tableView)
                                tableView.snp.makeConstraints { make in
                                                make.edges.equalToSuperview()
                                }
 
                                //        tableView.jq_setEmptyView()
                }
}
 
extension GamesSubListVC:UITableViewDelegate{
                
}
 
extension GamesSubListVC:UITableViewDataSource{
                func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
 
                                let cell = tableView.dequeueReusableCell(withIdentifier: "_GamesTCell") as! GamesTCell
                                if type == .offline{
                                                cell.gameListModel = offLineViewModel.dataSource.value[indexPath.row]
                                                cell.QRCodeModel = model
                                                cell.spaceId = offLineViewModel.spaceId.value
                                                cell.storeId = offLineViewModel.storeId.value
                                                cell.sutuId = offLineViewModel.sutuId.value
                                }
                                return cell
                }
 
                func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
                                return 212
                }
 
                func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
                                return offLineViewModel.dataSource.value.count
                }
}