//
|
// YardBookingSubListVC.swift
|
// WanPai
|
//
|
// Created by 无故事王国 on 2023/6/20.
|
//
|
|
import UIKit
|
import RxRelay
|
import RxSwift
|
|
let RefreshBooking_Noti = Notification.Name.init("RefreshBooking_Noti")
|
|
class YardBookingViewModel:RefreshModel<YardBookingModel>{
|
|
let type = BehaviorRelay<YardBookingType?>(value:nil)
|
override func api() -> (Observable<BaseResponse<[YardBookingModel]>>)? {
|
return Services.queryMySite(page: page, status: type.value)
|
}
|
}
|
|
class YardBookingSubListVC: BaseVC {
|
|
private var viewModel = YardBookingViewModel()
|
|
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: "YardBookingTCell", bundle: nil), forCellReuseIdentifier: "_YardBookingTCell")
|
return table
|
}()
|
|
required init(type:YardBookingType?) {
|
super.init(nibName: nil, bundle: nil)
|
self.viewModel.type.accept(type)
|
}
|
|
required init?(coder: NSCoder) {
|
fatalError("init(coder:) has not been implemented")
|
}
|
|
override func viewDidLoad() {
|
super.viewDidLoad()
|
|
|
viewModel.configure(tableView)
|
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(RefreshBooking_Noti).take(until: self.rx.deallocated).subscribe(onNext: {[weak self] noti in
|
guard let weakSelf = self else { return }
|
if let indexPath = noti.object as? IndexPath{
|
weakSelf.tableView.beginUpdates()
|
if weakSelf.viewModel.type.value == nil{
|
weakSelf.viewModel.dataSource.value[indexPath.row].status = .cancel
|
weakSelf.tableView.reloadRows(at: [indexPath], with: .automatic)
|
}else{
|
var tempValue = weakSelf.viewModel.dataSource.value
|
tempValue.remove(at: indexPath.row)
|
weakSelf.viewModel.dataSource.accept(tempValue)
|
weakSelf.tableView.deleteRows(at: [indexPath], with: .automatic)
|
}
|
weakSelf.tableView.endUpdates()
|
weakSelf.tableView.reloadData()
|
|
}else{
|
weakSelf.viewModel.beginRefresh()
|
}
|
}).disposed(by: disposeBag)
|
}
|
}
|
|
extension YardBookingSubListVC:UITableViewDelegate{
|
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
// let model = viewModel.dataSource.value
|
|
}
|
|
}
|
|
extension YardBookingSubListVC:UITableViewDataSource{
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
return viewModel.dataSource.value.count
|
}
|
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
let model = viewModel.dataSource.value[indexPath.row]
|
let cell = tableView.dequeueReusableCell(withIdentifier: "_YardBookingTCell") as! YardBookingTCell
|
cell.indexPath = indexPath
|
cell.yardBookingModel = model
|
return cell
|
}
|
}
|