无故事王国
2024-07-04 a4a30347df295a77657a4b87ee3293ef38ece503
DolphinEnglishLearnStudent/Moudle/Home/Listen/VC/HomeListenFightVC.swift
@@ -72,6 +72,7 @@
                        }
            }
            /// 回答错误数量
            var errorNum:Int = 0{
                        didSet{
                                    print("回答错误:\(correctNum)")
@@ -165,7 +166,7 @@
                                    self.viewModel.maxPage.accept(1)
                        }
            }
            required init?(coder: NSCoder) {
                        fatalError("init(coder:) has not been implemented")
            }
@@ -175,8 +176,8 @@
                        sceneDelegate?.suspendTimer()
            }
    override func viewDidLoad() {
        super.viewDidLoad()
            override func viewDidLoad() {
                        super.viewDidLoad()
                        yy_popBlock = {[weak self] in
                                    self?.quitAction(isPop: true)
@@ -195,7 +196,38 @@
                        timer.fire()
                        RunLoop.current.add(timer, forMode: .common)
    }
                        Services.teamSchedule(type: viewModel.listenType.value, week: viewModel.week.value!, day: viewModel.day.value!).subscribe(onNext: {[weak self] data in
                                    guard let weakSelf = self else { return }
                                    if let model = data.data{
                                                weakSelf.viewModel.correctNum = weakSelf.viewModel.correctNum + model.correctNumber
                                                weakSelf.viewModel.errorNum = model.answerNumber - model.correctNumber
                                                //跳转至指定页面
                                                let page = max(0,model.topicIds.count - 1)
                                                if weakSelf.pageVC.currentPage != page{
                                                            weakSelf.pageVC.scroll(toPage: page, animation: false)
                                                }
                                                DispatchQueue.main.asyncAfter(wallDeadline: .now()+0.5){
                                                            switch weakSelf.viewModel.listenType.value {
                                                                        case .lesson1:
                                                                                    let vc = weakSelf.pageVC.currentController as! HomeListenFight_lesson_1_VC
                                                                        case .lesson2:
                                                                                    let vc = weakSelf.pageVC.currentController as! HomeListenFight_lesson_2_VC
                                                                        case .lesson3:
                                                                                    let vc = weakSelf.pageVC.currentController as! HomeListenFight_lesson_3_VC
                                                                        case .lesson4:
                                                                                    let vc = weakSelf.pageVC.currentController as! HomeListenFight_lesson_4_VC
                                                                        case .lesson5:
                                                                                    let vc = weakSelf.pageVC.currentController as! HomeListenFight_lesson_5_VC
                                                                        default:
                                                                                    break
                                                            }
                                                }
                                    }
                        }).disposed(by: disposeBag)
            }
            override func setUI() {
                        super.setUI()
@@ -298,7 +330,7 @@
                                                            case .story1,.story2:
                                                                        if let dict = noti.object as? Dictionary<String,Any>{
                                                                                    let type = weakSelf.viewModel.listenType.value == .story1 ? 1:2
                                                                                    let accracy = Int(Double(weakSelf.viewModel.correctNum) / Double(weakSelf.viewModel.correctNum + weakSelf.viewModel.errorNum) * 100)
                                                                                    let accracy = String(format: "%.0lf", Double(weakSelf.viewModel.correctNum) / Double(weakSelf.viewModel.correctNum + weakSelf.viewModel.errorNum) * 100).int ?? 0
                                                                                    weakSelf.storyComplete(storyId: dict["storyId"] as! Int, accuracy: accracy, studyTime: weakSelf.viewModel.times, type: type, integral: dict["storyIntegral"] as! Int)
                                                                        }
                                                }
@@ -362,17 +394,17 @@
            /// 学习类完成
            /// - Parameter ignorePush: 是否忽略跳转(未完成答题 :true)
            private func studyComplete(){
                        var toalIntegral:Int = 0
                        //                        var toalIntegral:Int = 0
                        let ids:String = viewModel.answerItems_1.keys.sorted().joined(separator: ",")
                        switch viewModel.listenType.value {
                                    case .lesson1,.lesson2,.lesson3,.lesson4,.lesson5:
                                                let data = (data as! ListenNewModel).data
                                                toalIntegral = data?.integral ?? 0
                                                //                                                toalIntegral = data?.integral ?? 0
                                    default:break
                        }
                        //正确率
                        let accracy = Int(Double(viewModel.correctNum) / Double(viewModel.correctNum + viewModel.errorNum) * 100)
                        let accracy = String(format: "%.0lf", Double(viewModel.correctNum) / Double(viewModel.correctNum + viewModel.errorNum) * 100).int ?? 0
                        Services.completeLearing(type: viewModel.listenType.value.rawValue, studyTime: viewModel.times, studyIds: ids, quarter: viewModel.quarter.value!, week: viewModel.week.value!, day: viewModel.day.value!, accracy: accracy).subscribe(onNext: {data in
                                    NotificationCenter.default.post(name: Refresh_ListenSchedule_Noti, object: nil)
@@ -381,9 +413,9 @@
                        timer.invalidate()
                        toalIntegral = floor(Double(toalIntegral) * (Double(accracy) / 100.0)).int
                        //                        toalIntegral = floor(Double(toalIntegral) * (Double(accracy) / 100.0)).int
                        let vc = HomeStudyCompleteVC(totalCoin: toalIntegral,viewModel: viewModel,studyScheduleModel: studyScheduleModel!)
                        let vc = HomeStudyCompleteVC(viewModel: viewModel,studyScheduleModel: studyScheduleModel!)
                        vc.title = viewModel.listenType.value.rawTitle
                        vc.viewModel = viewModel
                        push(vc: vc)
@@ -395,27 +427,27 @@
                        var name = ""
                        var accuracy:Int = 0
                        var totalNum:Double = 0
                        var toalIntegral:Int = 0
                        //                        var toalIntegral:Int = 0
                        if viewModel.listenType.value == .game1{
                                    name = "超级听力"
                                    totalNum =  Double(viewModel.correctNum + viewModel.errorNum)
                                    if totalNum > 0{
                                                accuracy = Int(Double(viewModel.correctNum) / totalNum * 100)
                                                accuracy = String(format: "%.0lf", Double(viewModel.correctNum) / totalNum * 100).int ?? 0
                                    }
                                    toalIntegral = floor(Double(integral) * (Double(accuracy) / 100.0)).int
                                    //                                    toalIntegral = floor(Double(integral) * (Double(accuracy) / 100.0)).int
                        }else{
                                    name = "超级记忆"
                                    let v = viewModel.answerItems.first?.value as! Listen1Model
                                    //11887:完成答题页,总题目、错误题目 数量计算逻辑错误(只要是没有答对的题目就算错误题目,不管是否答,相当于错误题目就是总题目减去正确题目)
                                    totalNum = Double(v.photoList.count)
                                    if totalNum > 0 && viewModel.correctNum > 0 && viewModel.errorNum > 0{
                                                accuracy = Int(Double(viewModel.correctNum) / Double(totalNum) * 100)
                                                accuracy = String(format: "%.0lf", Double(viewModel.correctNum) / Double(totalNum) * 100).int ?? 0
                                    }
                                    viewModel.errorNum = Int(totalNum) - viewModel.correctNum
                                    toalIntegral = floor(Double(integral) * (Double(accuracy) / 100.0)).int
                                    //                                    toalIntegral = floor(Double(integral) * (Double(accuracy) / 100.0)).int
                        }
                        Services.completeGames(gameId: gameId, gameName: name, difficulty: viewModel.gameLevel.value, accuracy: accuracy, useTime: viewModel.times).subscribe(onNext: {data in
@@ -425,7 +457,7 @@
                        timer.invalidate()
                        let vc = HomeStudyCompleteVC(totalCoin: toalIntegral,totalNum:totalNum.int,viewModel: viewModel,studyScheduleModel: studyScheduleModel!)
                        let vc = HomeStudyCompleteVC(totalNum:totalNum.int,viewModel: viewModel,studyScheduleModel: studyScheduleModel!)
                        vc.title = viewModel.listenType.value.rawTitle
                        vc.viewModel = viewModel
                        push(vc: vc)
@@ -438,7 +470,7 @@
                                    NotificationCenter.default.post(name: StudyCompleteCoinUpdate_Noti, object: data.data ?? 0)
                        }).disposed(by: disposeBag)
                        let vc = HomeStudyCompleteVC(totalCoin: integral,viewModel: viewModel,studyScheduleModel: studyScheduleModel!)
                        let vc = HomeStudyCompleteVC(viewModel: viewModel,studyScheduleModel: studyScheduleModel!)
                        vc.title = viewModel.listenType.value.rawTitle
                        vc.viewModel = viewModel
                        push(vc: vc)
@@ -456,13 +488,13 @@
                                                            CommonAlertView.show(content: "未完成全部答题,确认退出吗?") {[weak self] () in
                                                                        guard let weakSelf = self else { return }
                                                                        for vc in weakSelf.navigationController?.viewControllers ?? []{
                                                                                    if vc.isKind(of: HomeListenMenuVC.self){
                                                                                                weakSelf.navigationController?.popToViewController(vc, animated: true);break
                                                                                    }
                                                                                    if vc.isKind(of: HomeListenVC.self){
                                                                                                weakSelf.navigationController?.popToViewController(vc, animated: true);break
                                                                                    }
//                                                                                    if vc.isKind(of: HomeListenMenuVC.self){
//                                                                                                weakSelf.navigationController?.popToViewController(vc, animated: true);break
//                                                                                    }
                                                                        }
                                                            }
                                                            return
@@ -477,6 +509,23 @@
                                                storyComplete(storyId: v.data!.id, accuracy: accuracy, studyTime: viewModel.times, type: viewModel.listenType.value == .story1 ? 1:2, integral: v.data!.integral)
                                    }
                        }else if btn_exit.titleLabel?.text == "提交"{
                                    if isPop{
                                                CommonAlertView.show(content: "未完成全部答题,确认退出吗?") {[weak self] () in
                                                            guard let weakSelf = self else { return }
                                                            for vc in weakSelf.navigationController?.viewControllers ?? []{
                                                                        if vc.isKind(of: HomeListenVC.self){
                                                                                    weakSelf.navigationController?.popToViewController(vc, animated: true);break
                                                                        }
//                                                                        if vc.isKind(of: HomeListenMenuVC.self){
//                                                                                    weakSelf.navigationController?.popToViewController(vc, animated: true);break
//                                                                        }
                                                            }
                                                }
                                                return
                                    }
                                    if viewModel.listenType.value == .game1 || viewModel.listenType.value == .game2{
                                                if let dict = notiObject{
                                                            gamesComplete(gameId: dict["gameId"] as! Int,integral: dict["gameIntegral"] as! Int)
@@ -513,13 +562,13 @@
                                                                        }).disposed(by: weakSelf.disposeBag)
                                                }
                                                for vc in weakSelf.navigationController?.viewControllers ?? []{
                                                            if vc.isKind(of: HomeListenMenuVC.self){
                                                                        weakSelf.navigationController?.popToViewController(vc, animated: true);break
                                                            }
                                                            if vc.isKind(of: HomeListenVC.self){
                                                                        weakSelf.navigationController?.popToViewController(vc, animated: true);break
                                                            }
//
//                                                            if vc.isKind(of: HomeListenMenuVC.self){
//                                                                        weakSelf.navigationController?.popToViewController(vc, animated: true);break
//                                                            }
                                                }
                                    }
                        }
@@ -543,8 +592,10 @@
            @objc func beforeAction(){
                        guard (pageVC.currentController as! HomeListenStory_2_VC).isPlayEnd else {
                                    alert(msg: "请听完");return
                        if viewModel.listenType.value == .story2{
                                    guard (pageVC.currentController as! HomeListenStory_2_VC).isPlayEnd else {
                                                alert(msg: "请听完");return
                                    }
                        }
                        listenFightLine = .before