fix
无故事王国
2024-02-28 4468d9f9b3b8c70597f04e5f1ecb61118c404d2c
WanPai/Root/Games/VC/GamesDataSourceSubListVC.swift
@@ -10,70 +10,70 @@
import RxSwift
class GamesDataSourceViewModel:RefreshModel<GamesRecordModel>{
   private var type:GamesSubType!
            private var type:GamesSubType!
   init(type:GamesSubType) {
      super.init()
      self.type = type
   }
            init(type:GamesSubType) {
                        super.init()
                        self.type = type
            }
   let userId = BehaviorRelay<Int>(value:0)
            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)
      }
   }
            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!
            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)
   }
            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")
   }
            required init?(coder: NSCoder) {
                        fatalError("init(coder:) has not been implemented")
            }
   override func viewDidLoad() {
      super.viewDidLoad()
            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
                        //      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)
   }
                        }.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))
      }
   }
            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{
@@ -81,21 +81,21 @@
}
extension GamesDataSourceSubListVC:UITableViewDataSource{
   func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
      let cell = tableView.dequeueReusableCell(withIdentifier: "_GamesDataSourceTCell") as! GamesDataSourceTCell
            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
   }
                        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
   }
            func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
                        if type == .offline{
                                    return viewModel.dataSource.value.count
                        }
                        return 0
            }
}