From 7b57c2ab04da74514d75ab722088a039e257fef5 Mon Sep 17 00:00:00 2001
From: 无故事王国 <841720330@qq.com>
Date: 星期五, 07 六月 2024 18:57:27 +0800
Subject: [PATCH] 提交fix

---
 DolphinEnglishLearnStudent/Moudle/Home/Listen/VC/HomeListenFightVC.swift |  118 ++++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 97 insertions(+), 21 deletions(-)

diff --git a/DolphinEnglishLearnStudent/Moudle/Home/Listen/VC/HomeListenFightVC.swift b/DolphinEnglishLearnStudent/Moudle/Home/Listen/VC/HomeListenFightVC.swift
index f18f61c..9aacf3b 100644
--- a/DolphinEnglishLearnStudent/Moudle/Home/Listen/VC/HomeListenFightVC.swift
+++ b/DolphinEnglishLearnStudent/Moudle/Home/Listen/VC/HomeListenFightVC.swift
@@ -44,6 +44,11 @@
 				var maxPage = BehaviorRelay<Int>(value: 5)
 				var listenType = BehaviorRelay<ListenType>(value:.lesson1)
 				var times:Int = 0
+				var quarter = BehaviorRelay<Int?>(value: 0)
+				var week = BehaviorRelay<Int?>(value: 0)
+
+				//游戏专属,游戏等级
+				var gameLevel = BehaviorRelay<Int>(value:0)
 
 				//回答错误数量
 				var correctNum:Int = 0{
@@ -120,9 +125,15 @@
 				private var timer:Timer!
 
 
-				init(listenType:ListenType) {
+				init(listenType:ListenType,quarter:Int? = nil,week:Int? = nil) {
 								super.init(nibName: nil, bundle: nil)
 								self.viewModel.listenType.accept(listenType)
+								self.viewModel.week.accept(week)
+								self.viewModel.quarter.accept(quarter)
+
+								if listenType == .game1 || listenType == .game2{
+												self.viewModel.maxPage.accept(1)
+								}
 				}
 				
 				required init?(coder: NSCoder) {
@@ -136,8 +147,6 @@
 												self?.quitAction()
 								}
 
-								pageVC.reloadData()
-
 								btn_exit.addTarget(self, action: #selector(quitAction), for: .touchUpInside)
 								btn_forward.addTarget(self, action: #selector(beforeAction), for: .touchUpInside)
 
@@ -145,6 +154,12 @@
 								if viewModel.listenType.value == .game1 || viewModel.listenType.value == .game2{
 												btn_forward.isHidden = true
 												label_pageNum.isHidden = true
+
+												if viewModel.listenType.value == .game1{
+																showGameLevel()
+												}
+								}else{
+												pageVC.reloadData()
 								}
 
 								timer = Timer(fire: .distantPast, interval: 1.0, repeats: true, block: {[weak self] _ in
@@ -169,6 +184,23 @@
 												}else{
 																make.bottom.equalTo(self.label_pageNum.snp.top).offset(-32)
 												}
+								}
+				}
+
+				private func showGameLevel(){
+								ChooseLevelView.show {[weak self] level in
+												guard let weakSelf = self else { return }
+												weakSelf.viewModel.gameLevel.accept(level)
+												Services.gameHearing(difficulty: level, quarter: weakSelf.viewModel.quarter.value!, week: weakSelf.viewModel.week.value!).subscribe(onNext: {result in
+																GameBeginTipView.show {
+																				if let data = result.data{
+																								weakSelf.data = data
+																								weakSelf.pageVC.reloadData()
+																				}
+																}
+												},onError: { _ in
+																weakSelf.showGameLevel()
+												}).disposed(by: weakSelf.disposeBag)
 								}
 				}
 
@@ -213,24 +245,16 @@
 
 												//完成
 												if nextPage >= weakSelf.viewModel.maxPage.value{
-
-																var toalIntegral:Int = 0
-																var ids = [Int]()
-																for v in weakSelf.viewModel.answerItems.values{
-																				if let v =  v as? Listen1Model{
-																								toalIntegral += v.data?.integral ?? 0
-																								ids.append(v.data?.studyId ?? 0)
-																				}
+																switch weakSelf.viewModel.listenType.value {
+																				case .game1,.game2:
+																								if let dict = noti.object as? Dictionary<String,Any>{
+																												weakSelf.gamesComplete(gameId: dict["gameId"] as! Int,integral: dict["gameIntegral"] as! Int)
+																								}
+																				case .lesson1,.lesson2,.lesson3,.lesson4,.lesson5:
+																								weakSelf.studyComplete()
+																				case .story1,.story2:break
 																}
 
-																Services.completeLearing(type: weakSelf.viewModel.listenType.value.rawValue, studyTime: weakSelf.viewModel.times, studyIds: ids, isComplete: false).subscribe(onNext: {data in
-
-																}).disposed(by: weakSelf.disposeBag)
-
-																weakSelf.timer.invalidate()
-																let vc = HomeStudyCompleteVC(correctNum: weakSelf.viewModel.correctNum, errorNum: weakSelf.viewModel.errorNum, totalCoin: toalIntegral)
-																vc.title = weakSelf.viewModel.listenType.value.rawTitle
-																				weakSelf.push(vc: vc)
 																return
 												}
 
@@ -243,6 +267,50 @@
 												self?.btn_forward.isHidden = currentPage <= 0
 												self?.label_pageNum.text = "已完成:\(weakSelf.viewModel.currentPage.value + 1)/\(weakSelf.viewModel.maxPage.value)"
 								}).disposed(by: disposeBag)
+				}
+
+				//学习类完成
+				private func studyComplete(){
+								var toalIntegral:Int = 0
+								var ids = [Int]()
+								for v in viewModel.answerItems.values{
+												if let v =  v as? Listen1Model{
+																toalIntegral += v.data?.integral ?? 0
+																ids.append(v.data?.studyId ?? 0)
+												}
+								}
+
+								Services.completeLearing(type: viewModel.listenType.value.rawValue, studyTime: viewModel.times, studyIds: ids, isComplete: false).subscribe(onNext: {data in
+
+								}).disposed(by: disposeBag)
+
+								timer.invalidate()
+
+								let vc = HomeStudyCompleteVC(correctNum: viewModel.correctNum, errorNum: viewModel.errorNum, totalCoin: toalIntegral)
+								vc.title = viewModel.listenType.value.rawTitle
+								push(vc: vc)
+				}
+
+				private func gamesComplete(gameId:Int,integral:Int){
+
+								var name = ""
+								if viewModel.listenType.value == .game1{
+												name = "超级听力"
+								}else{
+												name = "超级记忆"
+								}
+
+								let accuracy = Int(Double(viewModel.correctNum) / Double(viewModel.correctNum + viewModel.errorNum) * 100)
+
+								Services.completeGames(gameId: gameId, gameName: name, difficulty: viewModel.gameLevel.value, accuracy: accuracy, useTime: viewModel.times).subscribe(onNext: {data in
+
+								}).disposed(by: disposeBag)
+
+								timer.invalidate()
+
+								let vc = HomeStudyCompleteVC(correctNum: viewModel.correctNum, errorNum: viewModel.errorNum, totalCoin: integral)
+								vc.title = viewModel.listenType.value.rawTitle
+								push(vc: vc)
 				}
 
 				deinit{
@@ -264,6 +332,11 @@
 
 extension HomeListenFightVC:FFPageViewControllerDelegate{
 				func totalPagesOfpageViewController(_ pageViewConteoller: FFPageViewController) -> UInt {
+
+								//超级听力,只有一页
+								if viewModel.listenType.value == .game1 || viewModel.listenType.value == .game2{
+												return 1
+								}
 								return UInt(viewModel.maxPage.value)
 				}
 
@@ -304,12 +377,15 @@
 								}
 
 								if viewModel.listenType.value == .game1{
-												let vc = HomeListenGame_1_VC()
+												if data == nil{return UIViewController()}
+												let vc = HomeListenGame_1_VC(listen1Model: data as! Listen1Model)
+												vc.rootViewModel = viewModel
 												return vc
 								}
 
 								if viewModel.listenType.value == .game2{
-												let vc = HomeListenGame_2_VC()
+												let vc = HomeListenGame_2_VC(listen1Model: data as! Listen1Model)
+												vc.rootViewModel = viewModel
 												return vc
 								}
 

--
Gitblit v1.7.1