无故事王国
2025-08-10 9d8138cb1690c4c1990535d0507eb17cdbe497f9
DolphinEnglishLearnStudent/Moudle/Home/Listen/VC/HomeListenMenuVC.swift
@@ -10,235 +10,235 @@
class HomeListenMenuVC: BaseVC {
            @IBOutlet weak var tableView: UITableView!
            @IBOutlet weak var collectionView: UICollectionView!
    @IBOutlet weak var tableView: UITableView!
    @IBOutlet weak var collectionView: UICollectionView!
            private var repeatColors = ["#F8A169","#92CADB","#9E8ADB","#6DD1BA","#37C06E","#DEB975","#C54A59","#5DA0D3","#F0C433","#DC4827"]
            private var titleItems = ["第一季","第二季","第三季","第四季"]
            private var selectIndexPath:IndexPath = IndexPath(row: 0, section: 0)
    private var repeatColors = ["#F8A169","#92CADB","#9E8ADB","#6DD1BA","#37C06E","#DEB975","#C54A59","#5DA0D3","#F0C433","#DC4827"]
    private var titleItems = ["第一季","第二季","第三季","第四季"]
    private var selectIndexPath:IndexPath = IndexPath(row: 0, section: 0)
            private var dataItems = Array<[ListenWeekModel]>(repeating: [], count: 4)
    private var dataItems = Array<[ListenWeekModel]>(repeating: [], count: 4)
            override func viewDidLoad() {
                        super.viewDidLoad()
                        getData()
    override func viewDidLoad() {
        super.viewDidLoad()
        getData()
            }
    }
            private func getData(){
                        Services.weekList(quarter: selectIndexPath.row + 1).subscribe(onNext: {result in
                                    self.dataItems[self.selectIndexPath.row] = result.data ?? []
                                    self.collectionView.reloadData()
                        }).disposed(by: disposeBag)
            }
    private func getData(){
        Services.weekList(quarter: selectIndexPath.row + 1).subscribe(onNext: {result in
            self.dataItems[self.selectIndexPath.row] = result.data ?? []
            self.collectionView.reloadData()
        }).disposed(by: disposeBag)
    }
            override func setUI() {
                        super.setUI()
                        tableView.delegate = self
                        tableView.dataSource = self
                        tableView.separatorStyle = .none
                        tableView.showsVerticalScrollIndicator = false
                        tableView.showsHorizontalScrollIndicator = false
                        tableView.register(HomeListenMenuTCell.self, forCellReuseIdentifier: "_HomeListenMenuTCell")
                        tableView.reloadData()
    override func setUI() {
        super.setUI()
        tableView.delegate = self
        tableView.dataSource = self
        tableView.separatorStyle = .none
        tableView.showsVerticalScrollIndicator = false
        tableView.showsHorizontalScrollIndicator = false
        tableView.register(HomeListenMenuTCell.self, forCellReuseIdentifier: "_HomeListenMenuTCell")
        tableView.reloadData()
                        collectionView.delegate = self
                        collectionView.dataSource = self
                        collectionView.showsVerticalScrollIndicator = false
                        collectionView.showsHorizontalScrollIndicator = false
                        collectionView.contentInset = .init(top: 20, left: 20, bottom: 20, right: 20)
                        collectionView.register(HomeListenMenuCCell.self, forCellWithReuseIdentifier: "_HomeListenMenuCCell")
            }
        collectionView.delegate = self
        collectionView.dataSource = self
        collectionView.showsVerticalScrollIndicator = false
        collectionView.showsHorizontalScrollIndicator = false
        collectionView.contentInset = .init(top: 20, left: 20, bottom: 20, right: 20)
        collectionView.register(HomeListenMenuCCell.self, forCellWithReuseIdentifier: "_HomeListenMenuCCell")
    }
}
extension HomeListenMenuVC:UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout{
            func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
                        var ind:Bool?
        var ind:Bool?
                        if selectIndexPath.row != 0{
                                    ind = dataItems[selectIndexPath.row - 1].filter({$0.canStudy == 0}).count > 0
                        }
        if selectIndexPath.row != 0{
            ind = dataItems[selectIndexPath.row - 1].filter({$0.canStudy == 0}).count > 0
        }
                        if ind == true{
                                    CommonAlertView.show(isSinple: true, content: "请先完成上一季度学习后再试")
                                    return
                        }
        if ind == true{
            CommonAlertView.show(isSinple: true, content: "请先完成上一季度学习后再试")
            return
        }
                        let model = dataItems[selectIndexPath.row][indexPath.row]
        let model = dataItems[selectIndexPath.row][indexPath.row]
                        guard model.canStudy == 1 else {
                                    CommonAlertView.show(isSinple: true, content: "请先完成上一周目学习后再试")
                                    return
                        }
        guard model.canStudy == 1 else {
            CommonAlertView.show(isSinple: true, content: "请先完成上一周目学习后再试")
            return
        }
                        Services.studySchedule(week: model.week).subscribe(onNext: {[weak self]data in
                                    guard let weakSelf = self else { return }
                                    var studyScheduleModel = StudyScheduleModel()
                                    if let m = data.data{
                                                studyScheduleModel = m
                                    }
                                    let quarter = weakSelf.selectIndexPath.row + 1 //季度
                                    let vc = HomeListenVC(quarter: quarter, week: model.week,studyScheduleModel: studyScheduleModel)
                                    weakSelf.push(vc: vc)
        Services.studySchedule(week: model.week).subscribe(onNext: {[weak self]data in
            guard let weakSelf = self else { return }
            var studyScheduleModel = StudyScheduleModel()
            if let m = data.data{
                studyScheduleModel = m
            }
            let quarter = weakSelf.selectIndexPath.row + 1 //季度
            let vc = HomeListenV2VC(quarter: quarter, week: model.week,studyScheduleModel: studyScheduleModel)
            weakSelf.push(vc: vc)
                        }).disposed(by: disposeBag)
            }
        }).disposed(by: disposeBag)
    }
            func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
                        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_HomeListenMenuCCell", for: indexPath) as! HomeListenMenuCCell
                        let seal = indexPath.row % 10
                        cell.contentView.backgroundColor = UIColor(hexString: repeatColors[seal])
                        let model = dataItems[selectIndexPath.row][indexPath.row]
                        cell.setTitle(week: "第\(model.week.jq_cn)周", title: model.title, coin: model.totalIntegral)
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_HomeListenMenuCCell", for: indexPath) as! HomeListenMenuCCell
        let seal = indexPath.row % 10
        cell.contentView.backgroundColor = UIColor(hexString: repeatColors[seal])
        let model = dataItems[selectIndexPath.row][indexPath.row]
        cell.setTitle(week: "第\(model.week.jq_cn)周", title: model.title, coin: model.totalIntegral)
                        return cell
            }
        return cell
    }
            func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
                        return dataItems[selectIndexPath.row].count
            }
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return dataItems[selectIndexPath.row].count
    }
            func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
                        let w = (collectionView.jq_width - 80) / 3
                        return CGSize(width: w, height:  w * 0.64)
            }
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        let w = (collectionView.jq_width - 80) / 3
        return CGSize(width: w, height:  w * 0.64)
    }
            func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
                        return 23
            }
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
        return 23
    }
            func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
                        return 19
            }
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
        return 19
    }
}
extension HomeListenMenuVC:UITableViewDataSource,UITableViewDelegate{
            func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
                        selectIndexPath = indexPath
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        selectIndexPath = indexPath
                        if dataItems[indexPath.row].count == 0{
                                    getData()
                        }
                        tableView.reloadData()
                        collectionView.reloadData()
            }
        if dataItems[indexPath.row].count == 0{
            getData()
        }
        tableView.reloadData()
        collectionView.reloadData()
    }
            func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
                        return 56
            }
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 56
    }
            func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
                        let cell = tableView.dequeueReusableCell(withIdentifier: "_HomeListenMenuTCell") as! HomeListenMenuTCell
                        cell.titleL.text = titleItems[indexPath.row]
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "_HomeListenMenuTCell") as! HomeListenMenuTCell
        cell.titleL.text = titleItems[indexPath.row]
                        if indexPath == selectIndexPath{
                                    cell.titleL.font = UIFont.systemFont(ofSize: 18, weight: .medium)
                                    cell.titleL.textColor = UIColor(hexStr: "#41A2EB")
                        }else{
                                    cell.titleL.font = UIFont.systemFont(ofSize: 18)
                                    cell.titleL.textColor = .black.withAlphaComponent(0.4)
                        }
        if indexPath == selectIndexPath{
            cell.titleL.font = UIFont.systemFont(ofSize: 18, weight: .medium)
            cell.titleL.textColor = UIColor(hexStr: "#41A2EB")
        }else{
            cell.titleL.font = UIFont.systemFont(ofSize: 18)
            cell.titleL.textColor = .black.withAlphaComponent(0.4)
        }
                        cell.lineView.isHidden = indexPath.row == titleItems.count - 1
        cell.lineView.isHidden = indexPath.row == titleItems.count - 1
                        return cell
            }
        return cell
    }
            func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
                        return titleItems.count
            }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return titleItems.count
    }
}
class HomeListenMenuTCell:UITableViewCell{
            private(set) var titleL:UILabel!
            let lineView = UIView()
    private(set) var titleL:UILabel!
    let lineView = UIView()
            override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
                        super.init(style: style, reuseIdentifier: reuseIdentifier)
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
                        titleL = UILabel()
                        titleL.textAlignment = .center
                        contentView.addSubview(titleL)
                        titleL.snp.makeConstraints { make in
                                    make.edges.equalToSuperview()
                        }
        titleL = UILabel()
        titleL.textAlignment = .center
        contentView.addSubview(titleL)
        titleL.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
                        lineView.backgroundColor = UIColor(hexStr: "#979797").withAlphaComponent(0.28)
                        contentView.addSubview(lineView)
                        lineView.snp.makeConstraints { make in
                                    make.left.bottom.right.equalToSuperview()
                                    make.height.equalTo(1)
                        }
            }
        lineView.backgroundColor = UIColor(hexStr: "#979797").withAlphaComponent(0.28)
        contentView.addSubview(lineView)
        lineView.snp.makeConstraints { make in
            make.left.bottom.right.equalToSuperview()
            make.height.equalTo(1)
        }
    }
            required init?(coder: NSCoder) {
                        fatalError("init(coder:) has not been implemented")
            }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
class HomeListenMenuCCell:UICollectionViewCell{
            private var label_week = UILabel()
            private var label_title = UILabel()
            private var label_completeCoin = UILabel()
    private var label_week = UILabel()
    private var label_title = UILabel()
    private var label_completeCoin = UILabel()
            var listenWeekModel:ListenWeekModel!{
                        didSet{
    var listenWeekModel:ListenWeekModel!{
        didSet{
                        }
            }
        }
    }
            override init(frame: CGRect) {
                        super.init(frame: frame)
    override init(frame: CGRect) {
        super.init(frame: frame)
                        contentView.jq_cornerRadius = 4
        contentView.jq_cornerRadius = 4
                        label_title.textAlignment = .center
                        label_title.textColor = .white
                        label_title.font = .systemFont(ofSize: 16, weight: .semibold)
                        contentView.addSubview(label_title)
                        label_title.snp.makeConstraints { make in
                                    make.left.right.equalToSuperview()
                                    make.centerY.equalToSuperview()
                                    make.height.equalTo(22)
                        }
        label_title.textAlignment = .center
        label_title.textColor = .white
        label_title.font = .systemFont(ofSize: 16, weight: .semibold)
        contentView.addSubview(label_title)
        label_title.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.centerY.equalToSuperview()
            make.height.equalTo(22)
        }
                        label_week.textAlignment = .center
                        label_week.textColor = .white
                        label_week.font = .systemFont(ofSize: 14, weight: .medium)
                        contentView.addSubview(label_week)
                        label_week.snp.makeConstraints { make in
                                    make.bottom.equalTo(label_title.snp.top).offset(-10)
                                    make.left.right.equalToSuperview()
                                    make.height.equalTo(20)
                        }
        label_week.textAlignment = .center
        label_week.textColor = .white
        label_week.font = .systemFont(ofSize: 14, weight: .medium)
        contentView.addSubview(label_week)
        label_week.snp.makeConstraints { make in
            make.bottom.equalTo(label_title.snp.top).offset(-10)
            make.left.right.equalToSuperview()
            make.height.equalTo(20)
        }
                        label_completeCoin.textAlignment = .center
                        label_completeCoin.textColor = .white
                        label_completeCoin.font = .systemFont(ofSize: 11, weight: .medium)
                        contentView.addSubview(label_completeCoin)
                        label_completeCoin.snp.makeConstraints { make in
                                    make.top.equalTo(label_title.snp.bottom).offset(9)
                                    make.left.right.equalToSuperview()
                                    make.height.equalTo(16)
                        }
            }
        label_completeCoin.textAlignment = .center
        label_completeCoin.textColor = .white
        label_completeCoin.font = .systemFont(ofSize: 11, weight: .medium)
        contentView.addSubview(label_completeCoin)
        label_completeCoin.snp.makeConstraints { make in
            make.top.equalTo(label_title.snp.bottom).offset(9)
            make.left.right.equalToSuperview()
            make.height.equalTo(16)
        }
    }
            func setTitle(week:String,title:String,coin:Int){
                        label_week.text = week
                        label_title.text = title
                        label_completeCoin.text = "完成后可获积分数:\(coin)"
            }
    func setTitle(week:String,title:String,coin:Int){
        label_week.text = week
        label_title.text = title
        label_completeCoin.text = "完成后可获积分数:\(coin)"
    }
            required init?(coder: NSCoder) {
                        fatalError("init(coder:) has not been implemented")
            }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}