CNLiveAuthViewController.swift 29.5 KB
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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621
//
//  CNLiveAuthViewController.swift
//  metaCode
//
//  Created by zx on 2023/12/28.
//  首页-根控制器

import Foundation
import MJRefresh
class CNLiveAuthViewController:CNLiveBaseViewController,UITableViewDelegate,UITableViewDataSource{
                        
    let kCNLiveDownSlideAllCourseCellIdentifier = "kCNLiveDownSlideAllCourseCellIdentifier"
    let kCNLiveDownSlideRecommendCellIdentifier = "kCNLiveDownSlideRecommendCellIdentifier"
    let kCNLiveDownSlideTodayRecommendCellIdentifier = "kCNLiveDownSlideTodayRecommendCellIdentifier"
    let kCNLiveDownSlideSingleCourseCellIdentifier = "kCNLiveDownSlideSingleCourseCellIdentifier"
    let kCNLiveDownSlideBannerCellIdentifier = "kCNLiveDownSlideBannerCellIdentifier"
    let kCNLiveHomePageDuanJuCellIdentifier = "kCNLiveHomePageDuanJuCellIdentifier"
    let kCNLiveDownSlideTwoDuanJuCellIdentifier = "kCNLiveDownSlideTwoDuanJuCellIdentifier"
    let kCNLiveDownSlideRealHotListCellIdentifier = "kCNLiveDownSlideRealHotListCellIdentifier"
    
    let group = DispatchGroup()
    let queue = DispatchQueue.global(qos: .default)
    
    var isHaveDuanJU = false//是否有在追短剧
    var isHaveReBang = false//是否有实时热榜
    var totolNum = 0//一共显示多少行cell
    
    var selectedCell: CNDownSlideSingleCourseCell?
    var selectedDuanjuCell: CNLiveHomePageDuanJuCell?

    var statusBarShouldBeHidden = false
    //we need to set `View controller-based status bar appearance = YES` in info.plist.
    //so we can be able to hide statusBar.
    override var prefersStatusBarHidden: Bool {
        return statusBarShouldBeHidden
    }
    
    override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation {
        return .slide
    }
    
    // MARK: - 懒加载
    ///数据源
    lazy var dataArray: NSMutableArray = {
        var dataArray = NSMutableArray()
        return dataArray
    }()
    
    //短剧的数据源
    lazy var duanjuDataArray: NSMutableArray = {
        var dataArray = NSMutableArray()
        return dataArray
    }()
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.tabBarController?.tabBar.isHidden = false
        self.updateStatusBarAndTabbarFrame(visible: true)
//        self.getMyAlbumCollection(page: 1)
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = HexColor(kCNDownSlideBackgroundColorHex)
        view.addSubview(tableView)
        tableView.frame = CGRect(x: 0, y: KStatusBarHeight, width: KSreenWidth, height: KSreenHeight-DownSlideBottomViewHeight-KStatusBarHeight)
        self.addRefreshView()
        self.getHomePageConfigListApi()
    }
    
    lazy var tableView : UITableView = {
        let tableView = UITableView(frame: .zero, style: .plain)
        tableView.dataSource = self
        tableView.delegate = self
        tableView.separatorStyle = .none
        tableView.register(CNLiveHomePageDuanJuCell.self, forCellReuseIdentifier: kCNLiveHomePageDuanJuCellIdentifier)
        tableView.register(CNLiveDownSlideBannerCell.self, forCellReuseIdentifier: kCNLiveDownSlideBannerCellIdentifier)
        tableView.register(CNLiveDownSlideRecommendCell.self, forCellReuseIdentifier: kCNLiveDownSlideRecommendCellIdentifier)
        tableView.register(CNLiveDownSlideTodayRecommendCell.self, forCellReuseIdentifier: kCNLiveDownSlideTodayRecommendCellIdentifier)
        tableView.register(CNDownSlideSingleCourseCell.self, forCellReuseIdentifier: kCNLiveDownSlideAllCourseCellIdentifier)
        tableView.register(CNDownSlideSingleCourseCell.self, forCellReuseIdentifier:kCNLiveDownSlideSingleCourseCellIdentifier)
        
        tableView.register(CNDownSlideSingleCourseCell.self, forCellReuseIdentifier:kCNLiveDownSlideTwoDuanJuCellIdentifier)
        tableView.register(CNDownSlideSingleCourseCell.self, forCellReuseIdentifier:kCNLiveDownSlideRealHotListCellIdentifier)
        
        tableView.backgroundColor = HexColor(kCNDownSlideBackgroundColorHex)
        return tableView
    }()
    
    private func updateStatusBarAndTabbarFrame(visible: Bool) {
        statusBarShouldBeHidden = !visible
        UIView.animate(withDuration: 0.25) {
            self.setNeedsStatusBarAppearanceUpdate()
        }
    }
    
    // MARK: - UITableViewDelegate
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
//        if self.isHaveDuanJU{
//            return 2
//        }else{
//            return 1
//        }
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.dataArray.count
//        if self.isHaveDuanJU && section == 0{
//            return 1
//        }else{
//            return self.dataArray.count
//        }
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        if let slideModel = self.dataArray[indexPath.row] as? CNLiveDownSlideModel{
            //除了短剧的model
            let slideModel = self.dataArray[indexPath.row] as! CNLiveDownSlideModel
            
            //type=4一排两个 推荐课程&推荐活动; 74今日推荐; 12列表全部课程; 75单课程大图 1大图banner
            if slideModel.type == SlideModelTypeRecommend4{
                guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveDownSlideRecommendCellIdentifier) as? CNLiveDownSlideRecommendCell
                else {
                    return CNLiveDownSlideRecommendCell()
                }
                cell.slideModel = slideModel
                return cell
            }else if slideModel.type == SlideModelTypeTodayRecommend74{
                guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveDownSlideTodayRecommendCellIdentifier) as? CNLiveDownSlideTodayRecommendCell
                else {
                    let cell = CNLiveDownSlideTodayRecommendCell()
                    return cell
                }
                cell.slideModel = slideModel
                return cell
            }else if slideModel.type == SlideModelTypeAllCourse12{
                guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveDownSlideAllCourseCellIdentifier) as? CNDownSlideSingleCourseCell
                else {
                    let cell = CNDownSlideSingleCourseCell()
                    return cell
                }
                cell.slideModel = slideModel
                return cell
            }else if slideModel.type == SlideModelTypeOneCourse75{
                guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveDownSlideSingleCourseCellIdentifier) as? CNDownSlideSingleCourseCell
                else {
                    let cell = CNDownSlideSingleCourseCell()
                    return cell
                }
                cell.slideModel = slideModel
                return cell
            }else if slideModel.type == SlideModelTypeTwoDuanJu5{
                guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveDownSlideTwoDuanJuCellIdentifier) as? CNDownSlideSingleCourseCell
                else {
                    let cell = CNDownSlideSingleCourseCell()
                    return cell
                }
                cell.slideModel = slideModel
                return cell
            }else if slideModel.type == SlideModelTypeRealHotList7{
                guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveDownSlideRealHotListCellIdentifier) as? CNDownSlideSingleCourseCell
                else {
                    let cell = CNDownSlideSingleCourseCell()
                    return cell
                }
                cell.slideModel = slideModel
                return cell
            }else if slideModel.type == SlideModelTypeRecommend1{
                guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveDownSlideBannerCellIdentifier) as? CNLiveDownSlideBannerCell
                else {
                    let cell = CNLiveDownSlideBannerCell()
                    return cell
                }
                cell.slideModel = slideModel
                return cell
            }else{
                return UITableViewCell()
            }
        }else{
            //短剧model
            guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveHomePageDuanJuCellIdentifier) as? CNLiveHomePageDuanJuCell
            else {
                return CNLiveHomePageDuanJuCell()
            }
            
            cell.setModelArr(modelArr: self.duanjuDataArray)
            cell.DuanJUCellSelectedCallBack = {
                duanJuCell in
                self.selectedDuanjuCell = duanJuCell

                let detailVC = CNHomePageBaseNavigationController(rootViewController:CNHomepageDuanJuDetailViewController(cell: duanJuCell))
                
                detailVC.dismissClosure = { [weak self] in
                    guard let StrongSelf = self else { return }
                    StrongSelf.updateStatusBarAndTabbarFrame(visible: true)
                }
                self.updateStatusBarAndTabbarFrame(visible: false)
                self.present(detailVC, animated: true, completion: nil)
            }
            return cell
        }

        
//        if self.isHaveDuanJU && indexPath.section == 0{
//            guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveHomePageDuanJuCellIdentifier) as? CNLiveHomePageDuanJuCell
//            else {
//                return CNLiveHomePageDuanJuCell()
//            }
//            
//            cell.setModelArr(modelArr: self.duanjuDataArray)
//            cell.DuanJUCellSelectedCallBack = {
//                duanJuCell in
//                self.selectedDuanjuCell = duanJuCell
//
//                let detailVC = CNHomePageBaseNavigationController(rootViewController:CNHomepageDuanJuDetailViewController(cell: duanJuCell))
//                
//                detailVC.dismissClosure = { [weak self] in
//                    guard let StrongSelf = self else { return }
//                    StrongSelf.updateStatusBarAndTabbarFrame(visible: true)
//                }
//                self.updateStatusBarAndTabbarFrame(visible: false)
//                self.present(detailVC, animated: true, completion: nil)
//            }
//            return cell
//        }else{
//            let slideModel = self.dataArray[indexPath.row] as! CNLiveDownSlideModel
//            
//            //type=4一排两个 推荐课程&推荐活动; 74今日推荐; 12列表全部课程; 75单课程大图
//            if slideModel.type == SlideModelTypeRecommend4{
//                guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveDownSlideRecommendCellIdentifier) as? CNLiveDownSlideRecommendCell
//                else {
//                    return CNLiveDownSlideRecommendCell()
//                }
//                cell.slideModel = slideModel
//                return cell
//            }else if slideModel.type == SlideModelTypeTodayRecommend74{
//                guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveDownSlideTodayRecommendCellIdentifier) as? CNLiveDownSlideTodayRecommendCell
//                else {
//                    let cell = CNLiveDownSlideTodayRecommendCell()
//                    return cell
//                }
//                cell.slideModel = slideModel
//                return cell
//            }else if slideModel.type == SlideModelTypeAllCourse12{
//                guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveDownSlideAllCourseCellIdentifier) as? CNDownSlideSingleCourseCell
//                else {
//                    let cell = CNDownSlideSingleCourseCell()
//                    return cell
//                }
//                cell.slideModel = slideModel
//                return cell
//            }else if slideModel.type == SlideModelTypeOneCourse75{
//                guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveDownSlideSingleCourseCellIdentifier) as? CNDownSlideSingleCourseCell
//                else {
//                    let cell = CNDownSlideSingleCourseCell()
//                    return cell
//                }
//                cell.slideModel = slideModel
//                return cell
//            }else if slideModel.type == SlideModelTypeTwoDuanJu5{
//                guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveDownSlideTwoDuanJuCellIdentifier) as? CNDownSlideSingleCourseCell
//                else {
//                    let cell = CNDownSlideSingleCourseCell()
//                    return cell
//                }
//                cell.slideModel = slideModel
//                return cell
//            }else if slideModel.type == SlideModelTypeRealHotList7{
//                guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveDownSlideRealHotListCellIdentifier) as? CNDownSlideSingleCourseCell
//                else {
//                    let cell = CNDownSlideSingleCourseCell()
//                    return cell
//                }
//                cell.slideModel = slideModel
//                return cell
//            }else{
//                return UITableViewCell()
//            }
//        }
    }
    
    
    func tableView(_ tableView: UITableView, didHighlightRowAt indexPath: IndexPath) {
//        if self.isHaveDuanJU && indexPath.section == 0{
//
//        }else{
            
            guard let row = tableView.cellForRow(at: indexPath) as? CNDownSlideSingleCourseCell else { return }
            UIView.animate(withDuration: 0.1) {
                row.bgBackView.transform = CGAffineTransform(scaleX: 0.95, y: 0.95)
            }
//        }
    }
    
    func tableView(_ tableView: UITableView, didUnhighlightRowAt indexPath: IndexPath) {
//        if self.isHaveDuanJU && indexPath.section == 0{
//
//        }else{
            
            guard let row = tableView.cellForRow(at: indexPath) as? CNDownSlideSingleCourseCell else { return }
            UIView.animate(withDuration: 0.3) {
                row.bgBackView.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
            }
//        }
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
        if let slideModel = self.dataArray[indexPath.row] as? CNLiveDownSlideModel{
            //非短剧
            let slideModel = self.dataArray[indexPath.row] as! CNLiveDownSlideModel
            var cellType:CNLiveHomePageCellType = .course
            ///model
            ///(1) 1,2时跳转:sharelUrl后面拼接 ?contentId=contentId&videoId=pid
            ///(2) 3,4时跳转:thirdUrl
            ///(3)“album”,“album_video”,“album_ugc” -> http://wjjh5.cnlive.com/cnYmAlbumVideoList.html?aid=contentId&title=titlle
            if slideModel.contents.first?.model ?? "0" == "1" || slideModel.contents.first?.model ?? "0" == "2" || slideModel.contents.first?.model ?? "0" == "3" || slideModel.contents.first?.model ?? "0" == "4"{
                cellType = .playletToCourse
            }else if slideModel.contents.first?.model ?? "0" == kCNDownSlideContentsModelModelAlbum_ugc{
                cellType = .playlet
            }else{
                //新类型
            }

            //type=4一排两个 推荐课程&推荐活动; 74今日推荐; 12列表全部课程; 75单课程大图
            if slideModel.type == SlideModelTypeRecommend4{
                
            }else if slideModel.type == SlideModelTypeTodayRecommend74{
                
            }else if slideModel.type == SlideModelTypeAllCourse12 || slideModel.type == SlideModelTypeOneCourse75{
                guard let cell = tableView.cellForRow(at: indexPath) as? CNDownSlideSingleCourseCell else { return }
                selectedCell = cell
                let detailVC = CNSlideBaseNavigationController(rootViewController: CNUpSlideDetailViewController(cell: cell,slideModel: slideModel, albumModel: nil, cellType: cellType), cellType: cellType)
                detailVC.dismissClosure = { [weak self] in
                    guard let StrongSelf = self else { return }
                    StrongSelf.updateStatusBarAndTabbarFrame(visible: true)
                }
                updateStatusBarAndTabbarFrame(visible: false)
                present(detailVC, animated: true, completion: nil)
            }else if slideModel.type == SlideModelTypeTwoDuanJu5{
                //竖版短剧
                cellType = .playletList
                guard let cell = tableView.cellForRow(at: indexPath) as? CNDownSlideSingleCourseCell else { return }
                selectedCell = cell
                let detailVC = CNSlideBaseNavigationController(rootViewController: CNUpSlideDetailViewController(cell: cell,slideModel: slideModel, albumModel: nil, cellType: cellType), cellType: cellType)
                detailVC.dismissClosure = { [weak self] in
                    guard let StrongSelf = self else { return }
                    StrongSelf.updateStatusBarAndTabbarFrame(visible: true)
                }
                updateStatusBarAndTabbarFrame(visible: false)
                present(detailVC, animated: true, completion: nil)
            }else if slideModel.type == SlideModelTypeRealHotList7{
                //实时热榜
                //在当前堆栈里遍历删除 播放控制器CNLiveShortVideoViewController
                let tempArray = NSMutableArray.init()
                self.navigationController?.viewControllers.forEach({ item in
                    if (item.isKind(of: CNLiveTotalHotListController.self)) {
                        tempArray.remove(item)
                    }else{
                        tempArray.add(item)
                    }
                })
                self.navigationController?.viewControllers = tempArray as! [CNLiveBaseViewController]

                self.navigationController?.pushViewController(CNLiveTotalHotListController(slideModel: slideModel), animated: true)
            }
        }else{
            //短剧
            //点击在追短剧
            guard let cell = tableView.cellForRow(at: indexPath) as? CNLiveHomePageDuanJuCell else { return }
            selectedDuanjuCell = cell
            
            let detailVC = CNHomePageBaseNavigationController(rootViewController:CNHomepageDuanJuDetailViewController(cell: selectedDuanjuCell!))
            
            detailVC.dismissClosure = { [weak self] in
                guard let StrongSelf = self else { return }
                StrongSelf.updateStatusBarAndTabbarFrame(visible: true)
            }
            updateStatusBarAndTabbarFrame(visible: false)
            present(detailVC, animated: true, completion: nil)
        }

        
//        if self.isHaveDuanJU && indexPath.section == 0{
//            //点击在追短剧
//            guard let cell = tableView.cellForRow(at: indexPath) as? CNLiveHomePageDuanJuCell else { return }
//            selectedDuanjuCell = cell
//            
//            let detailVC = CNHomePageBaseNavigationController(rootViewController:CNHomepageDuanJuDetailViewController(cell: selectedDuanjuCell!))
//            
//            detailVC.dismissClosure = { [weak self] in
//                guard let StrongSelf = self else { return }
//                StrongSelf.updateStatusBarAndTabbarFrame(visible: true)
//            }
//            updateStatusBarAndTabbarFrame(visible: false)
//            present(detailVC, animated: true, completion: nil)
//
//        }else{
//            
//            let slideModel = self.dataArray[indexPath.row] as! CNLiveDownSlideModel
//            var cellType:CNLiveHomePageCellType = .course
//            ///model
//            ///(1) 1,2时跳转:sharelUrl后面拼接 ?contentId=contentId&videoId=pid
//            ///(2) 3,4时跳转:thirdUrl
//            ///(3)“album”,“album_video”,“album_ugc” -> http://wjjh5.cnlive.com/cnYmAlbumVideoList.html?aid=contentId&title=titlle
//            if slideModel.contents.first?.model ?? "0" == "1" || slideModel.contents.first?.model ?? "0" == "2" || slideModel.contents.first?.model ?? "0" == "3" || slideModel.contents.first?.model ?? "0" == "4"{
//                cellType = .playletToCourse
//            }else if slideModel.contents.first?.model ?? "0" == kCNDownSlideContentsModelModelAlbum_ugc{
//                cellType = .playlet
//            }else{
//                //新类型
//            }
//
//            //type=4一排两个 推荐课程&推荐活动; 74今日推荐; 12列表全部课程; 75单课程大图
//            if slideModel.type == SlideModelTypeRecommend4{
//                
//            }else if slideModel.type == SlideModelTypeTodayRecommend74{
//                
//            }else if slideModel.type == SlideModelTypeAllCourse12 || slideModel.type == SlideModelTypeOneCourse75{
//                guard let cell = tableView.cellForRow(at: indexPath) as? CNDownSlideSingleCourseCell else { return }
//                selectedCell = cell
//                let detailVC = CNSlideBaseNavigationController(rootViewController: CNUpSlideDetailViewController(cell: cell,slideModel: slideModel, albumModel: nil, cellType: cellType), cellType: cellType)
//                detailVC.dismissClosure = { [weak self] in
//                    guard let StrongSelf = self else { return }
//                    StrongSelf.updateStatusBarAndTabbarFrame(visible: true)
//                }
//                updateStatusBarAndTabbarFrame(visible: false)
//                present(detailVC, animated: true, completion: nil)
//            }else if slideModel.type == SlideModelTypeTwoDuanJu5{
//                //竖版短剧
//                cellType = .playletList
//                guard let cell = tableView.cellForRow(at: indexPath) as? CNDownSlideSingleCourseCell else { return }
//                selectedCell = cell
//                let detailVC = CNSlideBaseNavigationController(rootViewController: CNUpSlideDetailViewController(cell: cell,slideModel: slideModel, albumModel: nil, cellType: cellType), cellType: cellType)
//                detailVC.dismissClosure = { [weak self] in
//                    guard let StrongSelf = self else { return }
//                    StrongSelf.updateStatusBarAndTabbarFrame(visible: true)
//                }
//                updateStatusBarAndTabbarFrame(visible: false)
//                present(detailVC, animated: true, completion: nil)
//            }else if slideModel.type == SlideModelTypeRealHotList7{
//                //实时热榜
//                //在当前堆栈里遍历删除 播放控制器CNLiveShortVideoViewController
//                let tempArray = NSMutableArray.init()
//                self.navigationController?.viewControllers.forEach({ item in
//                    if (item.isKind(of: CNLiveTotalHotListController.self)) {
//                        tempArray.remove(item)
//                    }else{
//                        tempArray.add(item)
//                    }
//                })
//                self.navigationController?.viewControllers = tempArray as! [CNLiveBaseViewController]
//
//                self.navigationController?.pushViewController(CNLiveTotalHotListController(slideModel: slideModel), animated: true)
//            }
////                else if slideModel.type == SlideModelTypeOneCourse75{
////                guard let cell = tableView.cellForRow(at: indexPath) as? CNDownSlideSingleCourseCell else { return }
////                selectedCell = cell
////                let detailViewC = CNUpSlideDetailViewController(cell: cell,slideModel: slideModel, albumModel: nil, cellType: cellType) 
////                let detailVC = CNSlideBaseNavigationController(rootViewController: detailViewC, cellType: cellType)
////                
////                detailVC.dismissClosure = { [weak self] in
////                    guard let StrongSelf = self else { return }
////                    StrongSelf.updateStatusBarAndTabbarFrame(visible: true)
////                }
////                updateStatusBarAndTabbarFrame(visible: false)
////                present(detailVC, animated: true, completion: nil)
//        }
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        
        if let slideModel = self.dataArray[indexPath.row] as? CNLiveDownSlideModel{
            //非短剧
            let slideModel = self.dataArray[indexPath.row] as! CNLiveDownSlideModel
            return CGFloat(slideModel.cellH)
        }else{
            //短剧
            if self.duanjuDataArray.count > 4{
                //标题55+4个cell*(45+15*2)+首尾15+12圆角
                return CGFloat(4)*(45+15*2)+CGFloat(55)+15+15+12

            }else{
                //标题55+n个cell*(45+15*2)+首尾15+12圆角
                return CGFloat(self.duanjuDataArray.count)*(45+15*2)+CGFloat(55)+15+15+12

            }
        }
        
//        if self.isHaveDuanJU && indexPath.section == 0{
//            if self.duanjuDataArray.count > 4{
//                //标题55+4个cell*(45+15*2)+首尾15+12圆角
//                return CGFloat(4)*(45+15*2)+CGFloat(55)+15+15+12
//
//            }else{
//                //标题55+n个cell*(45+15*2)+首尾15+12圆角
//                return CGFloat(self.duanjuDataArray.count)*(45+15*2)+CGFloat(55)+15+15+12
//
//            }
//        }else{
//            let slideModel = self.dataArray[indexPath.row] as! CNLiveDownSlideModel
//            return CGFloat(slideModel.cellH)
//        }
    }
    
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0
    }
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 0
    }
    
    func addRefreshView() {
        tableView.mj_header = MJRefreshNormalHeader.init(refreshingBlock: {[weak self] in
            self!.getHomePageConfigListApi()
        })
    }
    //MARK: - 获取首页配置
    func getHomePageConfigListApi(){
        CNLiveHomePageViewModel.requestGetHomePageConfigList{ result, status in
            if status == .success{
                let dataModel = result as! CNLiveHomePageModel
                let homePageListMdls = dataModel.list
                for listModel in homePageListMdls {
                    if listModel.type == 3{
                        //在追短剧
                        self.group.enter()
                        self.getMyAlbumCollection(page: 1)
                    }else if listModel.type == 1{
                        //页面
                        self.group.enter()
                        self.getPageApi(pageID: listModel.content)
                    }
                }
                self.group.notify(queue: .main) {
                    // 所有网络请求都已完成,在这里执行你的任务
                    if self.duanjuDataArray.count > 0{
                        if self.isHaveReBang{
                            self.dataArray.insert(self.duanjuDataArray, at: 1)
                        }else{
                            self.dataArray.insert(self.duanjuDataArray, at: 0)
                        }
                    }
                    self.tableView.mj_header?.endRefreshing()
                    self.tableView.reloadData()
                }
            }else{
                self.getHomePageConfigListApi()
            }
        }
    }
    
    //MARK: - 我的专辑收藏--在追短剧
    //我的专辑收藏--在追短剧
    func getMyAlbumCollection(page:NSInteger){
        CNLiveHomePageViewModel.requestGetHomePageMyAlbum(page: page){ result, status in
            
            if status == .success{
                let arr = result as! Array<CNLiveAlbumMsgModel>
                if arr.count>0{
                    //显示在追短剧cell
                    self.isHaveDuanJU = true
                    
//                    if self.isHaveReBang{
//                        self.dataArray.insert(arr, at: 1)
//                    }else{
//                        self.dataArray.insert(arr, at: 0)
//                    }
                    
                    self.duanjuDataArray = NSMutableArray(array: arr)
                    
                }else{
                    //隐藏在追短剧cell
                    self.isHaveDuanJU = false
                }
                self.group.leave()

            }else{
                self.group.leave()
            }
        }
    }
    
    //MARK: - 网络请求获取区块详情页
    func getPageApi(pageID:String)
    {
        //        showLoading(message: "")
        CNLiveDownSlideViewModel.requestGetPage(pageId: pageID as NSString) { result, status in
            hiddenLoading()
            
            if status == .success{
                self.dataArray.removeAllObjects()
                let array = result as! [Any]
                let newDataArray = NSMutableArray()
                for slideModel in array {
                    if let model = slideModel as? CNLiveDownSlideModel{
                        
                        let layout = CNLiveDownSlideModelLayout.init(model: model)
                        let cellModel = layout.getCellHModel()
                        if cellModel.blockId == "11939"{//热播排行榜
                            newDataArray.insert(cellModel, at: 0)
                            self.isHaveReBang = true
                        }else{
                            newDataArray.addObjects(from: [cellModel])
                        }
                    }
                }
                self.dataArray.addObjects(from: newDataArray as! [Any])
                self.group.leave()
            }else if (status == .failed){
                self.group.leave()
                //                self.NetApiStatus = .apiError
            }else if (status == .noNetwork){
                self.group.leave()
                
                //                self.NetApiStatus = .notNetwork
            }
        }
        //
    }
}