杨锴
2025-05-11 7453d2d0cef415b34323d1b91e6cfa4a6ba31178
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
//
//  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)
    }
}