//
|
// HomeListenMenuVC.swift
|
// DolphinEnglishLearnStudent
|
//
|
// Created by 无故事王国 on 2024/5/23.
|
//
|
|
import UIKit
|
|
class HomeListenMenuVC: BaseVC {
|
|
|
@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 dataItems = Array<[ListenWeekModel]>(repeating: [], count: 4)
|
|
override func viewDidLoad() {
|
super.viewDidLoad()
|
getData()
|
Services.goodRecommend().subscribe(onNext: { data in
|
AwardListView.show(items: data.data ?? []) { _ in
|
|
}closeClouse: { () in
|
|
}
|
}).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()
|
|
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) {
|
let model = dataItems[selectIndexPath.row][indexPath.row]
|
|
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 }
|
if let model = data.data{
|
let quarter = weakSelf.selectIndexPath.row + 1 //季度
|
let week = model.week //周
|
let vc = HomeListenVC(quarter: quarter, week: week,studyScheduleModel: model)
|
weakSelf.push(vc: vc)
|
}
|
}).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)
|
|
return cell
|
}
|
|
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, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
|
return 23
|
}
|
|
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
|
|
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, 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)
|
}
|
|
cell.lineView.isHidden = indexPath.row == titleItems.count - 1
|
|
return cell
|
}
|
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
return titleItems.count
|
}
|
}
|
|
class HomeListenMenuTCell:UITableViewCell{
|
|
private(set) var titleL:UILabel!
|
let lineView = UIView()
|
|
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()
|
}
|
|
|
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")
|
}
|
}
|
|
class HomeListenMenuCCell:UICollectionViewCell{
|
|
private var label_week = UILabel()
|
private var label_title = UILabel()
|
private var label_completeCoin = UILabel()
|
|
var listenWeekModel:ListenWeekModel!{
|
didSet{
|
|
}
|
}
|
|
override init(frame: CGRect) {
|
super.init(frame: frame)
|
|
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_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)
|
}
|
}
|
|
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")
|
}
|
}
|