younger_times
2023-07-20 bb4b7bdc199b81dd7e3febcfdc9bd69f6f80d633
WanPai/Root/Course/VC/CourseInfoScheduleVC.swift
@@ -13,10 +13,32 @@
    private var cellW:Double!
    private var cellH:Double!
    private let weeks = ["一","二","三","四","五","六","日"]
    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()
@@ -27,6 +49,7 @@
        weekCollectionView.delegate = self
        weekCollectionView.dataSource = self
        weekCollectionView.isScrollEnabled = false
        weekCollectionView.layer.masksToBounds = false
        cellW = (JQ_ScreenW - 22 - 114 - 60) / 7
        cellH = cellW * 1.785
@@ -34,20 +57,38 @@
}
extension CourseInfoScheduleVC:UICollectionViewDelegate{
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        currentSelectDate = dates[indexPath.row]
        if let date =  currentSelectDate{
            clouse?(date)
        }
    }
}
extension CourseInfoScheduleVC:UICollectionViewDataSource{
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return weeks.count
        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 = weeks[indexPath.row]
        cell.jq_masksToBounds = false
        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
    }
}