younger_times
2023-07-24 858bd6df13a6a6415d12d8e60141575574646f58
WanPai/Root/Welfare/VC/WelfareBillListVC.swift
@@ -8,11 +8,21 @@
import UIKit
import JQTools
import QMUIKit
import RxSwift
import RxRelay
class BillViewModel:RefreshModel<BillingModel>{
    var type = BehaviorRelay<Int?>(value: nil)
    var yearMonth = BehaviorRelay<String>(value: "")
    override func api() -> (Observable<BaseResponse<[BillingModel]>>)? {
        return Services.billingList(recordType: type.value, yearMonth: yearMonth.value)
    }
}
class WelfareBillListVC: BaseVC {
    lazy private var tableView:UITableView = {
        let table = UITableView(frame: .zero, style: .plain)
    lazy private var tableView:BaseTableView = {
        let table = BaseTableView(frame: .zero, style: .plain)
        table.separatorStyle = .none
        table.delegate = self
        table.dataSource = self
@@ -23,10 +33,18 @@
        return table
    }()
    private let viewModel = BillViewModel()
    override func viewDidLoad() {
        super.viewDidLoad()
        title = "我的账单"
        viewModel.configure(tableView,needMore: false)
        viewModel.yearMonth.accept(Date().jq_format("yyyy年MM月"))
        viewModel.beginRefresh()
    }
    override func setUI() {
        tableView.jq_setEmptyView()
        view.addSubview(tableView)
        tableView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
@@ -34,19 +52,20 @@
    }
}
extension WelfareBillListVC:UITableViewDelegate{
}
extension WelfareBillListVC: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 50
        return viewModel.dataSource.value.count
    }
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
@@ -55,16 +74,30 @@
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let v = HeaderInSectionView()
        v.viewModel = viewModel
        return v
    }
}
private class HeaderInSectionView:UIView{
    fileprivate var viewModel:BillViewModel?{
        didSet{
            if let m = viewModel{
                btn_datetime.setTitle("\(m.yearMonth.value)>", for: .normal)
                if let  type = m.type.value{
                    btn_filter.setTitle(type == 1 ? "充值":"扣除", for: .normal)
                }else{
                    btn_filter.setTitle("全部记录", for: .normal)
                }
            }
        }
    }
    private lazy var btn_datetime:QMUIButton = {
        let btn = QMUIButton(type: .custom)
        btn.setTitle(Date().jq_format("yyyy年M月>"), for: .normal)
        btn.setTitleColor(UIColor(hexStr: "#0048FF"), for: .normal)
        btn.setTitleColor(UIColor.black, for: .normal)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 16, weight: .medium)
        return btn
    }()
@@ -123,14 +156,22 @@
    }
    @objc func fliterAction(){
        JQ_MenuView().show(self, tapView: btn_filter, items: ["1","2"],tableHei: 140) { index, str in
        JQ_MenuView().show(self, tapView: btn_filter, items: ["全部记录","充值","扣除"],tableHei: 140) { [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()
        }
    }
    @objc func datetimePickerAction(){
        CommonDatePickerView.show{ year, month, day in
        CommonDatePickerView.show(before: 2, after: 0, type: .YM) {[weak self] year, month,_ in
            self?.viewModel?.yearMonth.accept(String(format: "%ld年%ld月", year,month))
            self?.viewModel?.beginRefresh()
        }
    }