From 3e3bfd1ad307ec2ea42f66e298ccb24cec26955f Mon Sep 17 00:00:00 2001
From: younger_times <841720330@qq.com>
Date: 星期三, 26 七月 2023 18:13:33 +0800
Subject: [PATCH] 新增

---
 WanPai/Root/Course/VC/CourseBookingSubListVC.swift |   53 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 50 insertions(+), 3 deletions(-)

diff --git a/WanPai/Root/Course/VC/CourseBookingSubListVC.swift b/WanPai/Root/Course/VC/CourseBookingSubListVC.swift
index ea8a81e..0014aeb 100644
--- a/WanPai/Root/Course/VC/CourseBookingSubListVC.swift
+++ b/WanPai/Root/Course/VC/CourseBookingSubListVC.swift
@@ -7,11 +7,29 @@
 
 import UIKit
 import JQTools
+import RxSwift
+import RxRelay
+
+class CourseBookingViewModel:RefreshModel<StudentAppointModel>{
+
+    let status = BehaviorRelay<StudentAppointType?>(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(stuId: studentId.value, status: status.value,search: search.value,timeType: timeType.value)
+    }
+}
+
+let CourseBooking_Noti = Notification.Name("CourseBooking_Noti")
 
 class CourseBookingSubListVC: BaseVC {
 
-    lazy private var tableView:UITableView = {
-        let table = UITableView(frame: .zero, style: .plain)
+    let viewModel = CourseBookingViewModel()
+
+    lazy private var tableView:BaseTableView = {
+        let table = BaseTableView(frame: .zero, style: .plain)
         table.separatorStyle = .none
         table.delegate = self
         table.dataSource = self
@@ -19,9 +37,22 @@
         return table
     }()
 
+
+    required init(status:StudentAppointType?,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)
+        viewModel.beginRefresh()
     }
 
     override func setUI() {
@@ -29,6 +60,20 @@
         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)
     }
 }
 
@@ -36,11 +81,13 @@
 
 extension CourseBookingSubListVC:UITableViewDataSource{
     func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
-         return 5
+        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
     }
 }

--
Gitblit v1.7.1