//
|
// CourseInfoScheduleVC.swift
|
// WanPai
|
//
|
// Created by 无故事王国 on 2023/6/25.
|
//
|
|
import UIKit
|
import JQTools
|
|
class CourseInfoScheduleVC: BaseVC {
|
|
private var cellW:Double!
|
private var cellH:Double!
|
|
private var index:Int!
|
private(set) var dates = [Date]()
|
var currentSelectDate:Date?{
|
didSet{
|
weekCollectionView.reloadData()
|
}
|
}
|
|
private var clouse:((Date)->Void)?
|
|
@IBOutlet weak var weekCollectionView: UICollectionView!
|
|
required init(index:Int,clouse:@escaping (Date)->Void) {
|
super.init(nibName: nil, bundle: nil)
|
self.index = index
|
self.clouse = clouse
|
let date = Date().adding(.weekday, value: index * 7)
|
dates = date.jq_currentWeekDates
|
// print("\(dates.first!.jq_format("yyyy-MM-dd"))<---->\(dates.last!.jq_format("yyyy-MM-dd"))")
|
|
}
|
|
required init?(coder: NSCoder) {
|
fatalError("init(coder:) has not been implemented")
|
}
|
|
override func viewDidLoad() {
|
super.viewDidLoad()
|
|
}
|
|
override func setUI() {
|
weekCollectionView.register(UINib(nibName: "CourseDatetimeCCell", bundle: nil), forCellWithReuseIdentifier: "_CourseDatetimeCCell")
|
weekCollectionView.delegate = self
|
weekCollectionView.dataSource = self
|
weekCollectionView.isScrollEnabled = false
|
weekCollectionView.layer.masksToBounds = false
|
|
cellW = (JQ_ScreenW - 22 - 114 - 60) / 7
|
cellH = cellW * 1.785
|
}
|
}
|
|
extension CourseInfoScheduleVC:UICollectionViewDelegate{
|
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
currentSelectDate = dates[indexPath.row]
|
guard Date.jq_CalByDays(startDate: Date(), endDate: currentSelectDate!) >= 0 else {return}
|
if let date = currentSelectDate{
|
clouse?(date)
|
}
|
}
|
}
|
|
extension CourseInfoScheduleVC:UICollectionViewDataSource{
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
return dates.count
|
}
|
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
let cell = weekCollectionView.dequeueReusableCell(withReuseIdentifier: "_CourseDatetimeCCell", for: indexPath) as! CourseDatetimeCCell
|
let date = dates[indexPath.row]
|
cell.label_week.jq_cornerRadius = cellW / 2
|
cell.label_week.jq_masksToBounds = true
|
cell.label_week.text = date.jq_nowWeekDay().weekName
|
cell.label_time.text = date.jq_format("MM.dd")
|
cell.label_time.jq_masksToBounds = false
|
cell.layer.masksToBounds = false
|
cell.contentView.layer.masksToBounds = false
|
|
if currentSelectDate?.year == date.year && currentSelectDate?.month == date.month && currentSelectDate?.day == date.day{
|
cell.label_week.backgroundColor = Def_ThemeColor
|
cell.label_week.textColor = .white
|
}else{
|
cell.label_week.backgroundColor = UIColor(hexStr: "#DCDDDE")
|
cell.label_week.textColor = UIColor(hexStr: "#2C5064")
|
}
|
|
return cell
|
}
|
}
|
|
extension CourseInfoScheduleVC:UICollectionViewDelegateFlowLayout{
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
|
return 19
|
}
|
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
|
return CGSize(width: cellW, height: cellH)
|
}
|
}
|