Robert
59 分钟以前 c547797c9267e2f3e3c24c7acb31502517f3b6e6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
//
//  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
                }
}