//
|
// RechargeRecordVC.swift
|
// WanPai
|
//
|
// Created by 无故事王国 on 2023/6/28.
|
//
|
|
import UIKit
|
import JQTools
|
import QMUIKit
|
import RxSwift
|
import RxRelay
|
|
class RechargeRecordViewModel:RefreshModel<BillingModel>{
|
var coin = BehaviorRelay<Int>(value: 0)
|
var type = BehaviorRelay<Int?>(value: nil)
|
var subType = BehaviorRelay<RechargeRecordVC.RechargeRecordType>(value: .coin)
|
var yearMonth = BehaviorRelay<String>(value: "")
|
override func api() -> (Observable<BaseResponse<[BillingModel]>>)? {
|
return Services.voucherDetail(recordType: type.value, yearMonth: yearMonth.value,page: page,pageSize: pageSize, subType: subType.value)
|
}
|
}
|
|
class RechargeRecordVC: BaseVC {
|
|
enum RechargeRecordType {
|
case coin //玩湃币
|
case integral //积分
|
}
|
|
@IBOutlet weak var view_topBg: UIView!
|
@IBOutlet weak var view_cion: JQ_RollNumberLabel!
|
@IBOutlet weak var btn_rechange: UIButton!
|
@IBOutlet weak var view_container: UIView!
|
@IBOutlet weak var tableView: BaseTableView!
|
@IBOutlet weak var btn_filter: QMUIButton!
|
@IBOutlet weak var btn_date: UIButton!
|
|
|
private let viewModel = RechargeRecordViewModel()
|
|
required init(coin:Int,subtype:RechargeRecordType) {
|
super.init(nibName: nil, bundle: nil)
|
self.viewModel.coin.accept(coin)
|
self.viewModel.subType.accept(subtype)
|
}
|
|
required init?(coder: NSCoder) {
|
fatalError("init(coder:) has not been implemented")
|
}
|
|
override func viewDidLoad() {
|
super.viewDidLoad()
|
view_cion.font = UIFont.init(name: "Impact", size: 36)!
|
view_cion.textColor = .white
|
btn_rechange.isHidden = viewModel.subType.value == .integral
|
title = viewModel.subType.value == .coin ? "充值明细":"积分明细"
|
viewModel.beginRefresh()
|
}
|
|
override func viewDidAppear(_ animated: Bool) {
|
super.viewDidAppear(animated)
|
self.view_cion.valueNumber = NSNumber(value: self.viewModel.coin.value)
|
}
|
|
|
override func setUI() {
|
btn_filter.imagePosition = .right
|
btn_filter.spacingBetweenImageAndTitle = 3
|
view_container.jq_addShadows(shadowColor: UIColor(hexStr: "#D5D5D5").withAlphaComponent(0.5), corner: 10, radius: 4, offset: CGSize(width: 0, height: 2), opacity: 1)
|
|
tableView.delegate = self
|
tableView.dataSource = self
|
tableView.separatorStyle = .none
|
tableView.showsVerticalScrollIndicator = false
|
tableView.register(UINib(nibName: "BillInfoTCell", bundle: nil), forCellReuseIdentifier:"_BillInfoTCell")
|
// tableView.jq_setEmptyView()
|
|
viewModel.yearMonth.accept(Date().jq_format("yyyy-MM"))
|
btn_date.setTitle("\(Date().jq_format("yyyy年MM月"))>", for: .normal)
|
if viewModel.subType.value == .coin{
|
viewModel.configure(tableView,needMore: true)
|
}else{
|
viewModel.configure(tableView,needMore: false)
|
}
|
|
}
|
|
override func setRx() {
|
NotificationCenter.default.rx.notification(UpdateWelfare_Noti).take(until: self.rx.deallocated).subscribe(onNext: {[weak self] noti in
|
guard let weakSelf = self else { return }
|
Services.benefitHome().subscribe(onNext: {[weak self] data in
|
if let model = data.data{
|
self?.viewModel.coin.accept(model.wpCoin)
|
self?.viewModel.beginRefresh()
|
}
|
}) { error in
|
|
}.disposed(by: weakSelf.disposeBag)
|
}).disposed(by: disposeBag)
|
}
|
|
override func viewDidLayoutSubviews() {
|
super.viewDidLayoutSubviews()
|
let colors = [UIColor(hexStr: "#FD8C02").cgColor,
|
UIColor(hexStr: "#FD7202").cgColor,]
|
view_topBg.jq_gradientColor(colorArr: colors,bounds: CGRect(x: 0, y: 0, width: JQ_ScreenW, height: JQ_ScreenW * 0.5923))
|
btn_rechange.jq_gradientNibColor(colorArr: colors, cornerRadius: 20)
|
}
|
|
@IBAction func datetimeAction(_ sender: UIButton) {
|
CommonDatePickerView.show(before: 3, after: 0, type: .YM) {[weak self] year, month, day,_,_ in
|
self?.btn_date.setTitle(String(format: "%ld年%02ld月>", year!,month!), for: .normal)
|
self?.viewModel.yearMonth.accept(String(format: "%ld-%02ld", year!,month!))
|
self?.viewModel.beginRefresh()
|
}
|
}
|
|
@IBAction func filterAction(_ sender: QMUIButton) {
|
JQ_MenuView().show(self, tapView: sender, items: ["全部记录","充值","扣除"], tableHei: 150) {[weak self] index, str in
|
self?.btn_filter.setTitle(str, for: .normal)
|
if index == 0{
|
self?.viewModel.type.accept(nil)
|
}else{
|
self?.viewModel.type.accept(index)
|
}
|
self?.viewModel.beginRefresh()
|
}
|
}
|
|
@IBAction func rechargeAction(_ sender: UIButton) {
|
let vc = RechargeCenterVC()
|
push(vc: vc)
|
}
|
}
|
|
extension RechargeRecordVC:UITableViewDelegate{
|
|
}
|
|
extension RechargeRecordVC:UITableViewDataSource{
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
let model = viewModel.dataSource.value[indexPath.row]
|
let cell = tableView.dequeueReusableCell(withIdentifier: "_BillInfoTCell") as! BillInfoTCell
|
cell.billingModel = model
|
return cell
|
}
|
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
return viewModel.dataSource.value.count
|
}
|
}
|