jsdw_ios/QuickLocation/Section/VipRecharge/VipRechargeVC.swift

72 lines
2.3 KiB
Swift

//
// VipRechargeVC.swift
// QuickLocation
//
// Created by on 2026/6/3.
//
import UIKit
import RxSwift
import RxCocoa
import RxDataSources
class VipRechargeVC: BaseViewController {
fileprivate var rootView: VipRechargeView!
override func loadView() {
rootView = VipRechargeView(frame: UIScreen.main.bounds)
view = rootView
}
private var viewModel = VipRechargeVM()
override func viewDidLoad() {
super.viewDidLoad()
bindViewModel()
reactiveAction()
requestRechargeInfo()
}
private func bindViewModel() {
viewModel.output.sectionedItems
.bind(to: rootView.expenseCollectionView.rx.items(dataSource: dataSource))
.disposed(by: disposeBag)
}
private func reactiveAction() {
Observable.zip(
rootView.expenseCollectionView.rx.itemSelected,
rootView.expenseCollectionView.rx.modelSelected(VipExpenseModel.self)
).subscribe(onNext: { indexPath, model in
self.viewModel.selectedIndex = indexPath.row
self.rootView.setupPayTypes(model.pay_type)
self.rootView.animatePrice(to: model.price)
self.rootView.discountLab.text = self.viewModel.discountPriceString
self.viewModel.refreshData()
})
.disposed(by: disposeBag)
}
// MARK: - dataSource
private lazy var dataSource: RxCollectionViewSectionedReloadDataSource<ExpenseListSectionModel> = {
RxCollectionViewSectionedReloadDataSource<ExpenseListSectionModel> { datasource, collectionView, indexPath, model in
let cell: ExpenseCell = collectionView.dequeueReusableCell(for: indexPath)
cell.configure(model: model, isSelected: self.viewModel.selectedIndex == indexPath.row)
return cell
}
}()
// MARK: - API
private func requestRechargeInfo() {
DLToast.showLoading()
SystemService.rechargeInfo(type: "member").subscribe(onNext: { [weak self] response in
guard let self = self else { return }
self.viewModel.loadData(list: response.list)
self.rootView.setupPayTypes(self.viewModel.payType)
self.rootView.animatePrice(to: self.viewModel.price)
self.rootView.discountLab.text = self.viewModel.discountPriceString
}).disposed(by: disposeBag)
}
}