杨锴
2024-09-12 e15c976316feef72ff9bcabce38e0a078f9505db
XQMuse/Root/Course/VC/CourseDetialVC.swift
@@ -24,6 +24,13 @@
            private var currentShowIndex:IndexPath = IndexPath(row: 0, section: 0)
            var isAnimationing = false
            private var style:CourseDetialStyle = .style1
            private var courseId:Int!
            private var courseDetailModel:CourseModel?
            private var section0TCell:CourseDetail_1_TCell!
            private var section1TCell:CourseDetail_2_TCell!
            private var section2TCell:CourseDetail_3_TCell!
            private var section0Height:Double = 0
            private(set) var pageMenu:SPPageMenu = {
                        let pageMenu = SPPageMenu(frame: .zero, trackerStyle: .line)
@@ -61,9 +68,9 @@
                        navigationController?.navigationBar.standardAppearance.backgroundColor = .clear
            }
            init(courseSytle:CourseDetialStyle) {
            init(courseId:Int) {
                        super.init(nibName: nil, bundle: nil)
                        self.style = courseSytle
                        self.courseId = courseId
            }
            
            required init?(coder: NSCoder) {
@@ -74,11 +81,23 @@
        super.viewDidLoad()
                        title = "课程详情"
                        if style == .style1{
                                    pageMenu.setItems(["简介","章节","相关推荐"], selectedItemIndex: 0)
                        }else{
                                    pageMenu.setItems(["简介"], selectedItemIndex: 0)
                        }
                        Services.getCourseDetail(courseId: courseId).subscribe(onNext: {data in
                                    if let m = data.data{
                                                self.courseDetailModel = m
                                                self.headerView.setCourseModel(m)
                                                self.section1TCell.setItems(m.list)
                                                self.section2TCell.setItems(m.list2)
                                                if m.detailUrl.jq_isVideo{
                                                            self.style = .style1
                                                            self.pageMenu.setItems(["简介","章节","相关推荐"], selectedItemIndex: 0)
                                                }else{
                                                            self.style = .style2
                                                            self.pageMenu.setItems(["简介"], selectedItemIndex: 0)
                                                }
                                                self.tableView?.reloadData()
                                    }
                        }).disposed(by: disposeBag)
    }
            override func setUI() {
@@ -98,6 +117,10 @@
                        tableView!.register(UINib(nibName: "CourseDetail_1_TCell", bundle: nil), forCellReuseIdentifier: "_CourseDetail_1_TCell")
                        tableView!.register(UINib(nibName: "CourseDetail_2_TCell", bundle: nil), forCellReuseIdentifier: "_CourseDetail_2_TCell")
                        tableView!.register(UINib(nibName: "CourseDetail_3_TCell", bundle: nil), forCellReuseIdentifier: "_CourseDetail_3_TCell")
                        section0TCell = (tableView!.dequeueReusableCell(withIdentifier: "_CourseDetail_1_TCell") as! CourseDetail_1_TCell)
                        section1TCell = (tableView!.dequeueReusableCell(withIdentifier: "_CourseDetail_2_TCell") as! CourseDetail_2_TCell)
                        section2TCell = (tableView!.dequeueReusableCell(withIdentifier: "_CourseDetail_3_TCell") as! CourseDetail_3_TCell)
                        view.addSubview(tableView!)
                        tableView!.snp.makeConstraints { make in
@@ -150,14 +173,35 @@
                        }
            }
            @objc func handleAction(_ btn:QMUIButton){
            override func setRx() {
                        section0TCell.webView.scrollView.rx.observe(CGSize.self, "contentSize").map { (size) -> CGFloat? in
                                    if let size = size{
                                                return size.height
                                    }
                                    return nil
                        }.subscribe(onNext: { [unowned self](height) in
                                    if let height = height{
                                                if height > section0Height{
                                                            self.section0Height = height
                                                            self.tableView?.reloadData()
                                                }
                                    }
                        }).disposed(by: disposeBag)
            }
            @objc func handleAction(_ btn:QMUIButton){
                        if let items = courseDetailModel?.list{
                                    let vc = CourseDetialVideoVC(items: items, selectIndex: IndexPath(row: 0, section: 0))
                                    push(vc: vc)
                        }
            }
            @objc func sendGift(_ btn:QMUIButton){
                        CourseSendGiftView.show {
                                    let vc = PaymentOrderVC()
                                    self.push(vc: vc)
                        if let price = courseDetailModel?.generalPrice{
                                    CourseSendGiftView.show(price:price) {
                                                let vc = PaymentOrderVC()
                                                self.push(vc: vc)
                                    }
                        }
            }
@@ -182,30 +226,25 @@
            }
            func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
                        if indexPath.row == 0 || indexPath.row == 1{
                                    return UITableView.automaticDimension
                        }
                        return 770.736
                        return UITableView.automaticDimension
            }
            func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
                        if indexPath.row == 0{
                                    let cell = tableView.dequeueReusableCell(withIdentifier: "_CourseDetail_1_TCell") as! CourseDetail_1_TCell
                                    cell.backgroundColor = UIColor(hexString: "#f6f6f6")
                                    return cell
                                    section0TCell.webView.loadHTMLString(courseDetailModel?.briefIntroduction.jq_wrapHtml() ?? "", baseURL: nil)
                                    section0TCell.backgroundColor = UIColor(hexString: "#f6f6f6")
                                    return section0TCell
                        }
                        if indexPath.row == 1{
                                    let cell = tableView.dequeueReusableCell(withIdentifier: "_CourseDetail_2_TCell") as! CourseDetail_2_TCell
                                    cell.backgroundColor = UIColor(hexString: "#f6f6f6")
                                    return cell
                                    section1TCell.backgroundColor = UIColor(hexString: "#f6f6f6")
                                    return section1TCell
                        }
                        if indexPath.row == 2{
                                    let cell = tableView.dequeueReusableCell(withIdentifier: "_CourseDetail_3_TCell") as! CourseDetail_3_TCell
                                    cell.backgroundColor = UIColor(hexString: "#f6f6f6")
                                    return cell
                                    section2TCell.backgroundColor = UIColor(hexString: "#f6f6f6")
                                    return section2TCell
                        }
                        var cell = tableView.dequeueReusableCell(withIdentifier: "cell")