杨锴
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
//
//  CourseBookingDetailVC.swift
//  WanPai
//
//  Created by 无故事王国 on 2023/6/27.
//
 
import UIKit
import JQTools
import RxSwift
import RxRelay
 
class CourseBookingViewModel:RefreshModel<StudentAppointModel>{
 
    let status = BehaviorRelay<StudentAppointTypeList?>(value: nil)
    let search = BehaviorRelay<String>(value: "")
    let studentId = BehaviorRelay<Int>(value: 0)
    let timeType = BehaviorRelay<StudentAppointDateType>(value: .all)
 
    override func api() -> (Observable<BaseResponse<[StudentAppointModel]>>)? {
        Services.studentAppointList(page:page,stuId: studentId.value, status: status.value,search: search.value,timeType: timeType.value)
    }
}
 
let CourseBooking_Noti = Notification.Name("CourseBooking_Noti")
 
class CourseBookingSubListVC: BaseVC {
 
    let viewModel = CourseBookingViewModel()
 
    lazy private var tableView:BaseTableView = {
        let table = BaseTableView(frame: .zero, style: .plain)
        table.separatorStyle = .none
        table.delegate = self
        table.dataSource = self
        table.register(UINib(nibName: "CourseBooking_1_TCell", bundle: nil), forCellReuseIdentifier: "_CourseBooking_1_TCell")
        return table
    }()
 
 
    required init(status:StudentAppointTypeList?,studentId:Int) {
        super.init(nibName: nil, bundle: nil)
        viewModel.status.accept(status)
        viewModel.studentId.accept(studentId)
    }
 
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
 
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .white
        viewModel.configure(tableView,needMore: true)
        viewModel.beginRefresh()
    }
 
    override func setUI() {
        view.addSubview(tableView)
        tableView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
//        tableView.jq_setEmptyView()
    }
 
    override func setRx() {
        NotificationCenter.default.rx.notification(CourseBooking_Noti).take(until: self.rx.deallocated).subscribe(onNext: {[weak self] noti in
            guard let weakSelf = self else { return }
            if let obj = noti.object as? IndexPath{
                let model = weakSelf.viewModel.dataSource.value[obj.row]
                model.status = .cancel
                weakSelf.tableView.beginUpdates()
                weakSelf.tableView.reloadRows(at: [obj], with: .automatic)
                weakSelf.tableView.endUpdates()
            }
        }).disposed(by: disposeBag)
    }
}
 
extension CourseBookingSubListVC:UITableViewDelegate{}
 
extension CourseBookingSubListVC:UITableViewDataSource{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return viewModel.dataSource.value.count
    }
 
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "_CourseBooking_1_TCell") as! CourseBooking_1_TCell
        cell.indexPath = indexPath
        cell.studentAppointModel = viewModel.dataSource.value[indexPath.row]
        return cell
    }
}