杨锴
2025-06-04 ac84f81ca2311300b431c1bfb9f71253b59073f2
DolphinEnglishLearnStudent/Moudle/Home/Listen/VC/HomeListenFight_lesson_3_VC.swift
@@ -10,482 +10,530 @@
class HomeListenFight_lesson_3_VC: BaseVC {
            private var viewModel = FightAnswerViewModel()
    private var viewModel = FightAnswerViewModel()
            private lazy var collectionView:UICollectionView = {
                        let flowLayout = UICollectionViewFlowLayout()
                        let w = (JQ_ScreenW - 97 - 54 - 36) / 3.0
                        flowLayout.itemSize = CGSize(width: w, height: w * 0.947)
                        flowLayout.minimumInteritemSpacing = 18
                        flowLayout.scrollDirection = .vertical
                        let collection = UICollectionView(frame: .zero, collectionViewLayout: flowLayout)
                        collection.register(UINib(nibName: "ListenFight_lesson_3_CCell", bundle: nil), forCellWithReuseIdentifier: "_ListenFight_lesson_3_CCell")
                        collection.register(UICollectionReusableView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "header")
                        collection.isScrollEnabled = false
                        return collection
            }()
    private lazy var collectionView:UICollectionView = {
        let flowLayout = UICollectionViewFlowLayout()
        let w = (JQ_ScreenW - 97 - 54 - 36) / 3.0
        flowLayout.itemSize = CGSize(width: w, height: w * 0.947)
        flowLayout.minimumInteritemSpacing = 18
        flowLayout.scrollDirection = .vertical
        let collection = UICollectionView(frame: .zero, collectionViewLayout: flowLayout)
        collection.register(UINib(nibName: "ListenFight_lesson_3_CCell", bundle: nil), forCellWithReuseIdentifier: "_ListenFight_lesson_3_CCell")
        collection.register(UICollectionReusableView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "header")
        collection.isScrollEnabled = false
        return collection
    }()
            private lazy var stackView:UIStackView = {
                        let sta = UIStackView()
                        sta.spacing = 5
                        sta.distribution = .equalSpacing
                        sta.axis = .horizontal
                        return sta
            }()
    private lazy var stackView:UIStackView = {
        let sta = UIStackView()
        sta.spacing = 5
        sta.distribution = .equalSpacing
        sta.axis = .horizontal
        return sta
    }()
            private var listenNewModel:ListenNewModel!
            private var page:Int!
            private var answterCount:Int = 0 //回答计数,用于确定角标
            var rootViewModel:HomeListenFightViewModel!
            var teamScheduleModel:TeamScheduleModel?
            private var voicePlayer = VoicePlayer.share()
            private var playIndex = Set<IndexPath>() //顺序播放
            private var isPlayingIndex:IndexPath? //正在播放中
            private var islisten:Bool = false
    private var listenNewModel:ListenNewModel!
    private var page:Int!
    private var answterCount:Int = 0 //回答计数,用于确定角标
    var rootViewModel:HomeListenFightViewModel!
    var teamScheduleModel:TeamScheduleModel?
    private var voicePlayer = VoicePlayer.share()
    private var playIndex = Set<IndexPath>() //顺序播放
    private var currentPlayIndex = IndexPath(row: 0, section: 0)
    private var isPlayingIndex:IndexPath? //正在播放中
    private var islisten:Bool = false
    private var handleClouse:(()->Void)?
            required init(page:Int,listenNewModel:ListenNewModel){
                        super.init(nibName: nil, bundle: nil)
                        self.page = page
                        self.listenNewModel = listenNewModel
            }
    required init(page:Int,listenNewModel:ListenNewModel){
        super.init(nibName: nil, bundle: nil)
        self.page = page
        self.listenNewModel = listenNewModel
    }
            required init?(coder: NSCoder) {
                        fatalError("init(coder:) has not been implemented")
            }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
            override func viewDidAppear(_ animated: Bool) {
                        super.viewDidAppear(animated)
                        voicePlayer.delegate = self
            }
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        voicePlayer.delegate = self
    }
            override func viewDidDisappear(_ animated: Bool) {
                        super.viewDidDisappear(animated)
                        voicePlayer.delegate = nil
                        VoicePlayer.share().playerInterrupt()
            }
    override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
        voicePlayer.delegate = nil
        VoicePlayer.share().playerInterrupt()
    }
            override func viewDidLoad() {
                        super.viewDidLoad()
                        navigationItem.titleView = UIView()
                        playIndex.insert(IndexPath(row: 0, section: 0))
                        listenNewModel.subjectList[page][0].isQuestion = 1
                        listenNewModel.subjectList[page][1].isQuestion = 1
                        listenNewModel.subjectList[page][3].isQuestion = 1
    override func viewDidLoad() {
        super.viewDidLoad()
        navigationItem.titleView = UIView()
        playIndex.insert(IndexPath(row: 0, section: 0))
        listenNewModel.subjectList[page][0].isQuestion = 1
        listenNewModel.subjectList[page][1].isQuestion = 1
        listenNewModel.subjectList[page][3].isQuestion = 1
        DispatchQueue.main.asyncAfter(deadline: .now()+1) {
            self.isPlayingIndex = IndexPath(row: 0, section: 0)
            self.voicePlayer.playerAt(url: self.listenNewModel.subjectList[self.page][self.currentPlayIndex.row].correct)
            self.collectionView.reloadData()
        }
                        //回传记录,始终保持答题进度
                        if let team = teamScheduleModel{
                                    for teamId in team.teamIds{
                                                for v in listenNewModel.subjectList[page]{
                                                            if team.topicIds.contains(v.id){
                                                                        rootViewModel.insertCorrectAnswer(teamId: "\(teamId)", answerId: v.id)
                                                            }
                                                }
                                    }
                        }
            }
        //回传记录,始终保持答题进度
        if let team = teamScheduleModel{
            for teamId in team.teamIds{
                for v in listenNewModel.subjectList[page]{
                    if team.topicIds.contains(v.id){
                        rootViewModel.insertCorrectAnswer(teamId: "\(teamId)", answerId: v.id)
                    }
                }
            }
        }
    }
            func restore(){
                        playIndex.removeAll()
                        playIndex.insert(IndexPath(row: 0, section: 0))
                        answterCount = 0
                        for subView in view.subviews{
                                    if subView is Lesson_3_AnswerView{
                                                subView.removeFromSuperview()
                                    }
                        }
                        setUI()
                        collectionView.reloadData()
    func restore(){
        playIndex.removeAll()
        playIndex.insert(IndexPath(row: 0, section: 0))
        answterCount = 0
        for subView in view.subviews{
            if subView is Lesson_3_AnswerView{
                subView.removeFromSuperview()
            }
        }
        setUI()
        collectionView.reloadData()
            }
    }
            override func setUI() {
                        super.setUI()
                        if !view.subviews.contains(collectionView){
                                    collectionView.delegate = self
                                    collectionView.dataSource = self
                                    collectionView.showsVerticalScrollIndicator = false
                                    collectionView.contentInset = UIEdgeInsets(top: 33, left: 0, bottom: 0, right: 0)
                                    collectionView.backgroundColor = .clear
                                    view.addSubview(collectionView)
                        }
    override func setUI() {
        super.setUI()
        if !view.subviews.contains(collectionView){
            collectionView.delegate = self
            collectionView.dataSource = self
            collectionView.showsVerticalScrollIndicator = false
            collectionView.contentInset = UIEdgeInsets(top: 33, left: 0, bottom: 0, right: 0)
            collectionView.backgroundColor = .clear
            view.addSubview(collectionView)
        }
                        collectionView.snp.makeConstraints { make in
                                    make.top.equalTo(self.view.safeAreaLayoutGuide.snp.top).offset(0)
                                    make.left.equalTo(97)
                                    make.right.equalTo(-54)
                                    make.bottom.equalToSuperview()
                        }
            }
        collectionView.snp.makeConstraints { make in
            make.top.equalTo(self.view.safeAreaLayoutGuide.snp.top).offset(0)
            make.left.equalTo(97)
            make.right.equalTo(-54)
            make.bottom.equalToSuperview()
        }
    }
            override func setRx() {
    override func setRx() {
        NotificationCenter.default.rx.notification(ResetLession_Noti).take(until: self.rx.deallocated).subscribe(onNext: {[weak self]_ in
            self?.restore()
            self?.viewDidLoad()
        }).disposed(by: disposeBag)
    }
            }
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        let flowLayout = collectionView.collectionViewLayout as! UICollectionViewFlowLayout
            override func viewDidLayoutSubviews() {
                        super.viewDidLayoutSubviews()
                        let flowLayout = collectionView.collectionViewLayout as! UICollectionViewFlowLayout
        let w = (collectionView.size.width - flowLayout.minimumLineSpacing) / 3.1
        let h = (collectionView.size.height - flowLayout.minimumInteritemSpacing) / 2 - 40
        if flowLayout.itemSize.width != w || flowLayout.itemSize.height != h{
            flowLayout.itemSize = CGSize(width: w, height: h)
            collectionView.reloadData()
        }
    }
                        let w = (collectionView.size.width - flowLayout.minimumLineSpacing) / 3.1
                        let h = (collectionView.size.height - flowLayout.minimumInteritemSpacing) / 2 - 40
                        if flowLayout.itemSize.width != w || flowLayout.itemSize.height != h{
                                    flowLayout.itemSize = CGSize(width: w, height: h)
                                    collectionView.reloadData()
                        }
            }
            private func setAnswerStackView(force:Bool = false){
    private func setAnswerStackView(force:Bool = false){
                        for v in stackView.arrangedSubviews{
                                    v.removeFromSuperview()
                        }
        for v in stackView.arrangedSubviews{
            v.removeFromSuperview()
        }
                                    var tempImageArray = [String]()
                                    tempImageArray.append(listenNewModel.subjectList[page][2].img)
                                    tempImageArray.append(listenNewModel.subjectList[page][4].img)
                                    tempImageArray.append(listenNewModel.subjectList[page][5].img)
        var tempImageArray = [String]()
        tempImageArray.append(listenNewModel.subjectList[page][2].img)
        tempImageArray.append(listenNewModel.subjectList[page][4].img)
        tempImageArray.append(listenNewModel.subjectList[page][5].img)
                                    view.addSubview(stackView)
                                    stackView.snp.makeConstraints { make in
                                                make.right.equalToSuperview().offset(-82)
                                                make.centerY.equalToSuperview().offset(10)
                                                make.height.equalTo(52)
                                    }
        view.addSubview(stackView)
        stackView.snp.makeConstraints { make in
            make.right.equalToSuperview().offset(-82)
            make.centerY.equalToSuperview().offset(10)
            make.height.equalTo(52)
        }
                                    var tempAnswerViews = [Lesson_3_AnswerView]()
                                    for i in 0...2{
                                                let answerView = Lesson_3_AnswerView.jq_loadNibView()
                                                answerView.alpha = 0
                                                answerView.btn_choose.addTarget(self, action: #selector(chooseAnswerAction), for: .touchUpInside)
                                                answerView.btn_fullscreen.addTarget(self, action: #selector(fullscreenAction), for: .touchUpInside)
                                                answerView.img_cover.contentMode = .scaleToFill
                                                answerView.btn_choose.tag = 10+i
                                                answerView.btn_fullscreen.tag = 20+i
                                                answerView.imageUrl = tempImageArray[i]
                                                answerView.img_cover.sd_setImage(with: URL(string: tempImageArray[i]))
                                                answerView.snp.makeConstraints { make in
                                                            make.width.equalTo(85)
                                                            make.height.equalTo(52)
                                                }
        var tempAnswerViews = [Lesson_3_AnswerView]()
        for i in 0...2{
            let answerView = Lesson_3_AnswerView.jq_loadNibView()
            answerView.alpha = 0
            answerView.btn_choose.addTarget(self, action: #selector(chooseAnswerAction), for: .touchUpInside)
            answerView.btn_fullscreen.addTarget(self, action: #selector(fullscreenAction), for: .touchUpInside)
            answerView.img_cover.contentMode = .scaleToFill
            answerView.btn_choose.tag = 10+i
            answerView.btn_fullscreen.tag = 20+i
            answerView.imageUrl = tempImageArray[i]
            answerView.img_cover.sd_setImage(with: URL(string: tempImageArray[i]))
            answerView.snp.makeConstraints { make in
                make.width.equalTo(85)
                make.height.equalTo(52)
            }
                                                UIView.animate(withDuration: 0.05 + Double(i)) {
                                                            answerView.alpha = 1
                                                }
                                                tempAnswerViews.append(answerView)
                                    }
                                    tempAnswerViews.shuffle()
                                    stackView.addArrangedSubviews(tempAnswerViews)
            }
            //            UIView.animate(withDuration: 0.05 + Double(i)) {
            answerView.alpha = 1
            //            }
            tempAnswerViews.append(answerView)
        }
        tempAnswerViews.shuffle()
        stackView.addArrangedSubviews(tempAnswerViews)
    }
            @objc private func chooseAnswerAction(btn:UIButton){
    func handleClouseAction(clouse:@escaping ()->Void){
        self.handleClouse = clouse
    }
                        guard viewModel.selectIndex.value != nil else {return}
    @objc private func chooseAnswerAction(btn:UIButton){
                        if !islisten{
                                    alertError(msg: "请先听题");return
                        }
        guard viewModel.selectIndex.value != nil else {return}
                        if answterCount == 0 && !playIndex.contains(IndexPath(row: 2, section: 0)){
                                    alertError(msg: "请先听题");return
                        }
        if !islisten{
            alertError(msg: "请先听题");return
        }
                        if answterCount == 1 && !playIndex.contains(IndexPath(row: 1, section: 1)){
                                    alertError(msg: "请先听题");return
                        }
        if answterCount == 0 && !playIndex.contains(IndexPath(row: 2, section: 0)){
            alertError(msg: "请先听题");return
        }
                        if answterCount == 2 && !playIndex.contains(IndexPath(row: 2, section: 1)){
                                    alertError(msg: "请先听题");return
                        }
        if answterCount == 1 && !playIndex.contains(IndexPath(row: 1, section: 1)){
            alertError(msg: "请先听题");return
        }
                        var subV:Lesson_3_AnswerView?
        if answterCount == 2 && !playIndex.contains(IndexPath(row: 2, section: 1)){
            alertError(msg: "请先听题");return
        }
                        for (_,v) in (stackView.arrangedSubviews as! [Lesson_3_AnswerView]).enumerated(){
                                    if v.btn_choose.tag == btn.tag{
                                                subV = v;break
                                    }
                        }
        var subV:Lesson_3_AnswerView?
                        var answerType:Fight_lessonType = .none
        for (_,v) in (stackView.arrangedSubviews as! [Lesson_3_AnswerView]).enumerated(){
            if v.btn_choose.tag == btn.tag{
                subV = v;break
            }
        }
                        var valueIndex:Int! //图片的角标
                        if viewModel.selectIndex.value?.section == 0{
                                    valueIndex = viewModel.selectIndex.value!.row
                        }
                        if viewModel.selectIndex.value?.section == 1{
                                    valueIndex = viewModel.selectIndex.value!.row + 3
                        }
        var answerType:Fight_lessonType = .none
                        if subV?.imageUrl == listenNewModel.subjectList[page][valueIndex].img{
                                    listenNewModel.subjectList[page][valueIndex].isAnster = true
                                    answerType = .success
                                    subV?.alpha = 0
                                    voicePlayer.playSuccessVoice()
                        }else{
                                    answerType = .fail
                                    voicePlayer.playFailVoice()
                        }
        var valueIndex:Int! //图片的角标
        if viewModel.selectIndex.value?.section == 0{
            valueIndex = viewModel.selectIndex.value!.row
        }
        if viewModel.selectIndex.value?.section == 1{
            valueIndex = viewModel.selectIndex.value!.row + 3
        }
                        switch answerType {
                                    case .success:
                                                rootViewModel.correctNum += 1
                                                viewModel.answerType.accept(.success)
                                                let copyViewFrame = subV?.convert(subV!.bounds, to: self.view)
                                                let copyView = subV?.copyView()
                                                copyView?.frame = copyViewFrame!
                                                copyView?.img_cover.contentMode = .scaleToFill
                                                copyView?.img_cover.image = subV?.img_cover.image
                                                self.view.addSubview(copyView!)
                                                copyView?.layoutIfNeeded()
        if subV?.imageUrl == listenNewModel.subjectList[page][valueIndex].img{
            listenNewModel.subjectList[page][valueIndex].isAnster = true
            answerType = .success
            subV?.alpha = 0
            voicePlayer.playSuccessVoice()
            currentPlayIndex = IndexPath(row: 0, section: 1)
            self.voicePlayer.playerAt(url: self.listenNewModel.subjectList[self.page][currentPlayIndex.row + 3].correct)
                                                var ansterIndePath:IndexPath?
                                                if viewModel.selectIndex.value?.section == 0{
                                                            ansterIndePath = IndexPath(row: 2, section: 0)
                                                            playIndex.insert(IndexPath(row: 0, section: 1)) //下一个准备播放
                                                }
            let model = listenNewModel.list[self.page]
            model.status = 2
            Services.answerQuestion(id: model.id, status: 2).subscribe(onNext: {_ in
                self.handleClouse?()
            }).disposed(by: self.disposeBag)
                                                if viewModel.selectIndex.value?.section == 1 && (viewModel.selectIndex.value?.row == 0 || viewModel.selectIndex.value?.row == 1){
                                                            ansterIndePath = IndexPath(row: 1, section: 1)
                                                            playIndex.insert(IndexPath(row: 2, section: 1)) //下一个准备播放
                                                }
        }else{
            answerType = .fail
            voicePlayer.playFailVoice()
                                                if viewModel.selectIndex.value?.section == 1 && viewModel.selectIndex.value?.row == 2{
                                                            ansterIndePath = IndexPath(row: 2, section: 1)
                                                }
            let model = listenNewModel.list[self.page]
            model.status = 3
            Services.answerQuestion(id: model.id, status: 3).subscribe(onNext: {_ in
                self.handleClouse?()
            }).disposed(by: self.disposeBag)
        }
                                                guard ansterIndePath != nil else {return}
        switch answerType {
        case .success:
            rootViewModel.correctNum += 1
            viewModel.answerType.accept(.success)
            let copyViewFrame = subV?.convert(subV!.bounds, to: self.view)
            let copyView = subV?.copyView()
            copyView?.frame = copyViewFrame!
            copyView?.img_cover.contentMode = .scaleToFill
            copyView?.img_cover.image = subV?.img_cover.image
            self.view.addSubview(copyView!)
            copyView?.layoutIfNeeded()
                                                if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_ListenFight_lesson_3_CCell", for: ansterIndePath!) as? ListenFight_lesson_3_CCell{
                                                            var newFrame = cell.img_cover.convert(cell.img_cover.bounds, to: self.view)
                                                            newFrame.origin.x += 0
                                                            newFrame.origin.y += 0
            var ansterIndePath:IndexPath?
            if viewModel.selectIndex.value?.section == 0{
                ansterIndePath = IndexPath(row: 2, section: 0)
                playIndex.insert(IndexPath(row: 0, section: 1)) //下一个准备播放
            }
                                                            let successImage = UIImageView(image: UIImage(named: "icon_success"))
                                                            successImage.bounds = CGRect(x: 0, y: 0, width: 75, height: 75)
                                                            successImage.center = newFrame.center
                                                            successImage.transform = .init(scaleX: 0.1, y: 0.1)
                                                            successImage.alpha = 0
                                                            successImage.layoutIfNeeded()
                                                            self.view.addSubview(successImage)
                                                            UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 0.4, initialSpringVelocity: 0.4) {
                                                                        successImage.transform = .init(scaleX: 1.0, y: 1.0)
                                                                        successImage.alpha = 1
                                                            }
            if viewModel.selectIndex.value?.section == 1 && (viewModel.selectIndex.value?.row == 0 || viewModel.selectIndex.value?.row == 1){
                ansterIndePath = IndexPath(row: 1, section: 1)
                playIndex.insert(IndexPath(row: 2, section: 1)) //下一个准备播放
            }
                                                            UIView.animate(withDuration: 0.5, delay: 3) {
                                                                        successImage.transform = .init(scaleX: 0.1, y: 0.1)
                                                                        successImage.alpha = 0
                                                            }completion: { _ in
                                                                        successImage.removeFromSuperview()
                                                            }
            if viewModel.selectIndex.value?.section == 1 && viewModel.selectIndex.value?.row == 2{
                ansterIndePath = IndexPath(row: 2, section: 1)
            }
                                                            UIView.animate(withDuration: 0.4) {
                                                                        copyView?.frame = newFrame
                                                            } completion: { _ in
                                                                        self.answterCount += 1
            guard ansterIndePath != nil else {return}
                                                                        let cell = self.collectionView.cellForItem(at: self.viewModel.selectIndex.value!) as! ListenFight_lesson_3_CCell
                                                                        self.isPlayingIndex = self.viewModel.selectIndex.value
                                                                        cell.isPlaying(isplaying: true)
            if let cell = collectionView.cellForItem(at: ansterIndePath!) as? ListenFight_lesson_3_CCell{
                var newFrame = cell.img_cover.convert(cell.img_cover.bounds, to: self.view)
                newFrame.origin.x += 0
                newFrame.origin.y += 0
                                                                        self.voicePlayer.playerAt(url: self.listenNewModel.subjectList[self.page][valueIndex].correct)
                let successImage = UIImageView(image: UIImage(named: "icon_success"))
                successImage.bounds = CGRect(x: 0, y: 0, width: 75, height: 75)
                successImage.center = newFrame.center
                successImage.transform = .init(scaleX: 0.1, y: 0.1)
                successImage.alpha = 0
                successImage.layoutIfNeeded()
                self.view.addSubview(successImage)
                UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 0.4, initialSpringVelocity: 0.4) {
                    successImage.transform = .init(scaleX: 1.0, y: 1.0)
                    successImage.alpha = 1
                }
                                                                        let teamId = self.listenNewModel.data?.id.components(separatedBy: ",")[self.page]
                                                                        let answerId = self.listenNewModel.subjectList[self.page][valueIndex].id
                                                                        self.rootViewModel.insertCorrectAnswer(teamId: teamId, answerId: answerId)
                UIView.animate(withDuration: 0.5, delay: 3) {
                    successImage.transform = .init(scaleX: 0.1, y: 0.1)
                    successImage.alpha = 0
                }completion: { _ in
                    successImage.removeFromSuperview()
                }
                                                                        for v in self.stackView.arrangedSubviews{
                                                                                    v.removeFromSuperview()
                                                                        }
                UIView.animate(withDuration: 0.4) {
                    copyView?.frame = newFrame
                } completion: { _ in
                    self.answterCount += 1
                                                                        DispatchQueue.main.asyncAfter(deadline: .now()+1.0) {
                                                                                    self.viewModel.selectIndex.accept(nil)
                                                                                    let v = self.rootViewModel.answerCount.value + 1
                                                                                    self.rootViewModel.answerCount.accept(v)
                                                                                    self.collectionView.reloadData()
                                                                        }
                                                            }
                                                }
                    let cell = self.collectionView.cellForItem(at: self.viewModel.selectIndex.value!) as! ListenFight_lesson_3_CCell
                    self.isPlayingIndex = self.viewModel.selectIndex.value
                    cell.isPlaying(isplaying: true)
                                    case .fail:
                                                rootViewModel.errorNum += 1
                                                viewModel.answerType.accept(.fail)
                                                UIView.animate(withDuration: 0.4) {
                                                            subV?.img_state.alpha = 1
                                                            subV?.btn_fullscreen.alpha = 0
                                                }completion: { _ in
                                                            DispatchQueue.main.asyncAfter(deadline: .now()+1.5) {
                                                                        self.islisten  = false
                                                                        for v in self.stackView.arrangedSubviews{
                                                                                    v.removeFromSuperview()
                                                                        }
                                                            }
                                                }
                                    default:break
                        }
            }
                    self.voicePlayer.playerAt(url: self.listenNewModel.subjectList[self.page][valueIndex].correct)
            @objc private func fullscreenAction(btn:UIButton){
                        var answerView:Lesson_3_AnswerView!
                        for (_,v) in (stackView.arrangedSubviews as! [Lesson_3_AnswerView]).enumerated(){
                                    if v.btn_fullscreen.tag == btn.tag{
                                                answerView = v;break
                                    }
                        }
                    let teamId = self.listenNewModel.data?.id.components(separatedBy: ",")[self.page]
                    let answerId = self.listenNewModel.subjectList[self.page][valueIndex].id
                    self.rootViewModel.insertCorrectAnswer(teamId: teamId, answerId: answerId)
                    for v in self.stackView.arrangedSubviews{
                        v.removeFromSuperview()
                    }
                    DispatchQueue.main.asyncAfter(deadline: .now()+1.0) {
                        //                                                                                    self.viewModel.selectIndex.accept(nil)
                        let v = self.rootViewModel.answerCount.value + 1
                        self.rootViewModel.answerCount.accept(v)
                        self.collectionView.reloadData()
                    }
                }
            }
        case .fail:
            rootViewModel.errorNum += 1
            viewModel.answerType.accept(.fail)
            UIView.animate(withDuration: 0.4) {
                subV?.img_state.alpha = 1
                subV?.btn_fullscreen.alpha = 0
            }completion: { _ in
                DispatchQueue.main.asyncAfter(deadline: .now()+1.5) {
                    self.islisten  = false
                    for v in self.stackView.arrangedSubviews{
                        v.removeFromSuperview()
                    }
                }
            }
        default:break
        }
    }
    @objc private func fullscreenAction(btn:UIButton){
        var answerView:Lesson_3_AnswerView!
        for (_,v) in (stackView.arrangedSubviews as! [Lesson_3_AnswerView]).enumerated(){
            if v.btn_fullscreen.tag == btn.tag{
                answerView = v;break
            }
        }
                        let lantern = Lantern()
                        lantern.numberOfItems = { () in
                                    return 1
                        }
        let lantern = Lantern()
        lantern.numberOfItems = { () in
            return 1
        }
                        lantern.cellClassAtIndex = { _ in
                                    LanternImageCell.self
                        }
        lantern.cellClassAtIndex = { _ in
            LanternImageCell.self
        }
                        lantern.transitionAnimator = LanternZoomAnimator(previousView: { index -> UIView? in
                                    return answerView.img_cover
                        })
        lantern.transitionAnimator = LanternZoomAnimator(previousView: { index -> UIView? in
            return answerView.img_cover
        })
                        // UIPageIndicator样式的页码指示器
                        lantern.pageIndicator = LanternDefaultPageIndicator()
        // UIPageIndicator样式的页码指示器
        lantern.pageIndicator = LanternDefaultPageIndicator()
                        lantern.pageIndex = 0
        lantern.pageIndex = 0
                        lantern.reloadCellAtIndex = { context in
                                    let lanternCell = context.cell as? LanternImageCell
                                    lanternCell?.imageView.image = answerView.img_cover.image
                        }
                        //不要使用push
                        lantern.show()
            }
        lantern.reloadCellAtIndex = { context in
            let lanternCell = context.cell as? LanternImageCell
            lanternCell?.imageView.image = answerView.img_cover.image
        }
        //不要使用push
        lantern.show()
    }
}
extension HomeListenFight_lesson_3_VC:UICollectionViewDelegate{
            func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
            }
    }
}
extension HomeListenFight_lesson_3_VC:UICollectionViewDelegateFlowLayout{
            func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
                        if section == 0{
                                    return CGSize.zero
                        }
                        return CGSizeMake(JQ_ScreenW, 65)
            }
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
        if section == 0{
            return CGSize.zero
        }
        return CGSizeMake(JQ_ScreenW, 65)
    }
}
extension HomeListenFight_lesson_3_VC:UICollectionViewDataSource{
            func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
                        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_ListenFight_lesson_3_CCell", for: indexPath) as! ListenFight_lesson_3_CCell
                        cell.backgroundColor = .clear
                        cell.indexPath = indexPath
                        cell.contentView.backgroundColor = .clear
                        cell.canClick(playIndex.contains(indexPath))
                        cell.palyVoiceAt {[weak self] index in
                                    guard let weakSelf = self else { return }
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_ListenFight_lesson_3_CCell", for: indexPath) as! ListenFight_lesson_3_CCell
        cell.indexPath = indexPath
        cell.canClick(playIndex.contains(indexPath))
        cell.palyVoiceAt {[weak self] index in
            guard let weakSelf = self else { return }
                                    weakSelf.isPlayingIndex = index
                                    weakSelf.viewModel.selectIndex.accept(index)
            weakSelf.isPlayingIndex = index
            weakSelf.viewModel.selectIndex.accept(index)
                                    weakSelf.voicePlayer.playerEnd()
            weakSelf.voicePlayer.playerEnd()
                                    if indexPath.section == 1{
                                                weakSelf.voicePlayer.playerAt(url:  weakSelf.listenNewModel.subjectList[weakSelf.page][indexPath.row + 3].correct)
                                    }else{
                                                weakSelf.voicePlayer.playerAt(url:  weakSelf.listenNewModel.subjectList[weakSelf.page][indexPath.row].correct)
                                    }
            if indexPath.section == 1{
                weakSelf.voicePlayer.playerAt(url:  weakSelf.listenNewModel.subjectList[weakSelf.page][indexPath.row + 3].correct)
            }else{
                weakSelf.voicePlayer.playerAt(url:  weakSelf.listenNewModel.subjectList[weakSelf.page][indexPath.row].correct)
            }
                                    if index == IndexPath(row: 2, section: 0) || index == IndexPath(row: 1, section: 1) || index == IndexPath(row: 2, section: 1){
            if index == IndexPath(row: 2, section: 0) || index == IndexPath(row: 1, section: 1) || index == IndexPath(row: 2, section: 1){
                                                var model:Listen1SubModel?
                                                if indexPath.section == 0{
                                                            model = weakSelf.listenNewModel.subjectList[weakSelf.page][indexPath.row]
                                                }
                var model:Listen1SubModel?
                if indexPath.section == 0{
                    model = weakSelf.listenNewModel.subjectList[weakSelf.page][indexPath.row]
                }
                                                if indexPath.section == 1{
                                                            model = weakSelf.listenNewModel.subjectList[weakSelf.page][indexPath.row + 3]
                                                }
                if indexPath.section == 1{
                    model = weakSelf.listenNewModel.subjectList[weakSelf.page][indexPath.row + 3]
                }
                                                if model?.isAnster == false{
                                                            //点击答案,就显示
                                                            weakSelf.setAnswerStackView()
                                                }
                                    }
                if model?.isAnster == false{
                    //点击答案,就显示
                    weakSelf.setAnswerStackView()
                }
            }
                                    collectionView.reloadItems(at: [index])
                        }
            collectionView.reloadItems(at: [index])
        }
                        if indexPath.section == 0{
                                    let model = listenNewModel.subjectList[page][indexPath.row]
                                    if indexPath.row != 2{
                                                cell.img_cover.sd_setImage(with: URL(string: model.img))
                                    }else{
                                                cell.img_cover.image = nil
                                    }
                                    cell.setModel(model,isplaying: isPlayingIndex == indexPath)
                        }
        if indexPath.section == 0{
            let model = listenNewModel.subjectList[page][indexPath.row]
            if indexPath.row != 2{
                cell.img_cover.sd_setImage(with: URL(string: model.img))
            }else{
                cell.img_cover.image = nil
            }
            cell.setModel(model,isplaying: isPlayingIndex == indexPath)
        }
                        if indexPath.section == 1{
                                    let model = listenNewModel.subjectList[page][indexPath.row + 3]
                                    if indexPath.row == 0{
                                                cell.img_cover.sd_setImage(with: URL(string: model.img))
                                    }else{
                                                cell.img_cover.image = nil
                                    }
                                    cell.setModel(model,isplaying: isPlayingIndex == indexPath)
                        }
                        return cell
            }
        if indexPath.section == 1{
            let model = listenNewModel.subjectList[page][indexPath.row + 3]
            if indexPath.row == 0{
                cell.img_cover.sd_setImage(with: URL(string: model.img))
            }else{
                cell.img_cover.image = nil
            }
            cell.setModel(model,isplaying: isPlayingIndex == indexPath)
        }
        return cell
    }
            func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
                        let reusableView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "header", for: indexPath)
                        return reusableView
    func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
        let reusableView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "header", for: indexPath)
        return reusableView
            }
    }
            func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
                        return 3
            }
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 3
    }
            func numberOfSections(in collectionView: UICollectionView) -> Int {
                        return 2
            }
    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 2
    }
}
extension HomeListenFight_lesson_3_VC:VoicePlayerDelegate{
            func playComplete() {
                        view.isUserInteractionEnabled = true
                        isPlayingIndex =  nil
                        islisten  = true
                        var nextRow = (viewModel.selectIndex.value?.row ?? 0) + 1
                        var section = (viewModel.selectIndex.value?.section ?? 0) + 0
    func playComplete() {
        view.isUserInteractionEnabled = true
        isPlayingIndex =  nil
        islisten  = true
        var nextRow = (viewModel.selectIndex.value?.row ?? 0) + 1
        var section = (viewModel.selectIndex.value?.section ?? 0) + 0
                        if nextRow >= 3{
                                    nextRow = 0;section = 1
                        }
        if nextRow >= 3{
            nextRow = 0;section = 1
        }
        currentPlayIndex.row+=1
        if currentPlayIndex.row < 3{
                        if self.answterCount == 3{
                                    NotificationCenter.default.post(name: NextLession_Noti, object: nil)
                                    return
                        }
            var row = currentPlayIndex.row
            if currentPlayIndex.section == 1{
                row += 3
            }
                        if (viewModel.selectIndex.value?.section == 0 && viewModel.selectIndex.value?.row == 2) || (viewModel.selectIndex.value?.section == 1 && viewModel.selectIndex.value?.row == 1){
                                    collectionView.reloadData()
                                    return
                        }
                        playIndex.insert(IndexPath(row: nextRow, section: section)) //下一个准备播放
                        collectionView.reloadData()
            }
            self.voicePlayer.playerAt(url: self.listenNewModel.subjectList[self.page][row].correct)
            self.isPlayingIndex = currentPlayIndex
            self.viewModel.selectIndex.accept(currentPlayIndex)
            self.playIndex.insert(currentPlayIndex)
        }
            func playing() {
                        islisten = false
                        view.isUserInteractionEnabled = false
            }
        if currentPlayIndex.row == 2{
            self.isPlayingIndex = currentPlayIndex
            self.viewModel.selectIndex.accept(currentPlayIndex)
            self.playIndex.insert(currentPlayIndex)
            self.setAnswerStackView()
        }
        if self.answterCount == 2{
            NotificationCenter.default.post(name: NextLession_Noti, object: nil)
            return
        }
        if (viewModel.selectIndex.value?.section == 0 && viewModel.selectIndex.value?.row == 2) || (viewModel.selectIndex.value?.section == 1 && viewModel.selectIndex.value?.row == 1){
            collectionView.reloadData()
            return
        }
        playIndex.insert(IndexPath(row: nextRow, section: section)) //下一个准备播放
        collectionView.reloadData()
    }
    func playing() {
        islisten = false
        view.isUserInteractionEnabled = false
    }
}