73 lines
1.8 KiB
Swift
73 lines
1.8 KiB
Swift
//
|
|
// VipRechargeVM.swift
|
|
// QuickLocation
|
|
//
|
|
// Created by 八条 on 2026/6/3.
|
|
//
|
|
|
|
import RxSwift
|
|
import RxCocoa
|
|
import RxDataSources
|
|
import SwiftyUserDefaults
|
|
|
|
typealias ExpenseListSectionModel = SectionModel<String, VipExpenseModel>
|
|
|
|
class VipRechargeVM {
|
|
struct Input {
|
|
|
|
}
|
|
struct Output {
|
|
var sectionedItems: Observable<[ExpenseListSectionModel]>
|
|
}
|
|
|
|
let input: Input
|
|
let output: Output
|
|
var disposeBag = DisposeBag()
|
|
|
|
private let sectionedItems = PublishSubject<[ExpenseListSectionModel]>()
|
|
|
|
var selectedIndex: Int = -1
|
|
var list: [VipExpenseModel] = []
|
|
var payType: String {
|
|
guard list.count > 0 else { return "" }
|
|
return list[selectedIndex].pay_type
|
|
}
|
|
|
|
var price: String {
|
|
guard list.count > 0 else { return "" }
|
|
return list[selectedIndex].price
|
|
}
|
|
|
|
var discountPriceString: String {
|
|
guard list.count > 0 else { return "已优惠0元" }
|
|
|
|
let price = list[selectedIndex].price
|
|
let oPrice = list[selectedIndex].origin_price
|
|
|
|
guard oPrice.int >= price.int else { return "已优惠0元" }
|
|
|
|
let diff = oPrice.double - price.double
|
|
let diffStr = diff.truncatingRemainder(dividingBy: 1) == 0 ? String(format: "%.0f", diff) : String(diff)
|
|
return "已优惠\(diffStr)元"
|
|
}
|
|
|
|
// MARK: - 加载数据
|
|
func loadData(list: [VipExpenseModel]) {
|
|
self.list = list
|
|
selectedIndex = list.firstIndex(where: { $0.checked == true }) ?? 0
|
|
sectionedItems.onNext(list.mapSection())
|
|
}
|
|
|
|
func refreshData() {
|
|
sectionedItems.onNext(list.mapSection())
|
|
}
|
|
|
|
// MARK: - init
|
|
init() {
|
|
input = Input()
|
|
output = Output(
|
|
sectionedItems: sectionedItems.asObservable()
|
|
)
|
|
}
|
|
}
|