younger_times
2023-07-18 a2589f9891509d85a873192d56e785885513e780
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
    }
}