From a2589f9891509d85a873192d56e785885513e780 Mon Sep 17 00:00:00 2001
From: younger_times <841720330@qq.com>
Date: 星期二, 18 七月 2023 15:54:32 +0800
Subject: [PATCH] 新增

---
 WanPai/Root/Course/VC/CourseOnlineSubListVC.swift |   62 +++++++++++++++++++++++++++++--
 1 files changed, 58 insertions(+), 4 deletions(-)

diff --git a/WanPai/Root/Course/VC/CourseOnlineSubListVC.swift b/WanPai/Root/Course/VC/CourseOnlineSubListVC.swift
index 0b23bd2..a5577e2 100644
--- a/WanPai/Root/Course/VC/CourseOnlineSubListVC.swift
+++ b/WanPai/Root/Course/VC/CourseOnlineSubListVC.swift
@@ -6,28 +6,72 @@
 //
 
 import UIKit
+import JQTools
+import RxCocoa
+import RxSwift
+import QMUIKit
+
+class CourseOnlineViewModel:RefreshModel<VideoDetailModel>{
+    let classificationId = BehaviorRelay<Int>(value: 0)
+    let search = BehaviorRelay<String>(value: "")
+
+    override func api() -> (Observable<BaseResponse<[VideoDetailModel]>>)? {
+        Services.benefitsVideoSubList(classificationId: classificationId.value, pageNo: page, pageSize: pageSize, search: search.value)
+    }
+}
 
 class CourseOnlineSubListVC: BaseVC {
 
-    @IBOutlet weak var tableView: UITableView!
+    private var classificationId:Int?
+    private var position:Int?
+    @IBOutlet weak var tableView: BaseTableView!
+    @IBOutlet weak var tf_search: QMUITextField!
+
+    private let viewModel = CourseOnlineViewModel()
+
     override func viewDidLoad() {
         super.viewDidLoad()
 
-        // Do any additional setup after loading the view.
+            viewModel.configure(tableView)
+            viewModel.beginRefresh()
+            viewModel.classificationId.accept(classificationId!)
+
+        tableView.jq_setEmptyView()
+
     }
 
+    init(classificationId:Int) {
+        super.init(nibName: nil, bundle: nil)
+        self.classificationId = classificationId
+    }
+
+
+    override func setRx() {
+        tf_search.rx.text.orEmpty.bind(to: viewModel.search).disposed(by: disposeBag)
+    }
+
+    required init?(coder: NSCoder) {
+        fatalError("init(coder:) has not been implemented")
+    }
 
     override func setUI() {
         tableView.delegate = self
         tableView.dataSource = self
         tableView.register(UINib(nibName: "CourseOnlineTCell", bundle: nil), forCellReuseIdentifier: "_CourseOnlineTCell")
         tableView.separatorStyle = .none
+        tf_search.delegate = self
+    }
+
+    @IBAction func searchAction(_ sender: UIButton) {
+        viewModel.beginRefresh()
     }
 }
 
 extension CourseOnlineSubListVC:UITableViewDelegate{
     func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
-         let vc = CourseVideoDetailVC()
+
+        let model = viewModel.dataSource.value[indexPath.row]
+        let vc = CourseVideoDetailVC(id: model.id)
         vc.title = title
         push(vc: vc)
     }
@@ -35,11 +79,21 @@
 
 extension CourseOnlineSubListVC:UITableViewDataSource{
     func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
-         return 5
+        viewModel.dataSource.value.count
     }
 
     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
+        let model = viewModel.dataSource.value[indexPath.row]
         let cell = tableView.dequeueReusableCell(withIdentifier: "_CourseOnlineTCell") as! CourseOnlineTCell
+        cell.videoDetailModel = model
         return cell
     }
 }
+
+extension CourseOnlineSubListVC:QMUITextFieldDelegate{
+    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
+        textField.resignFirstResponder()
+        viewModel.beginRefresh()
+        return true
+    }
+}

--
Gitblit v1.7.1