YMIncomeBreakdownListViewController.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. //
  2. // YMIncomeBreakdownListViewController.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/3/3.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMIncomeBreakdownListViewController.h"
  9. #import "YMIncomeBreakdownListViewModel.h"
  10. #import "YMIncomeBreakdownListSectionView.h"
  11. #import "YMIncomeBreakdownListPointsAndEarningsCell.h"
  12. #import "YMIncomeBreakdownListWithdrawalRecordsCell.h"
  13. @interface YMIncomeBreakdownListViewController ()<UITableViewDataSource, UITableViewDelegate>
  14. /// 滚动视图回调
  15. @property (nonatomic, copy) void(^scrollCallback)(UIScrollView *scrollView);
  16. /// 列表VM
  17. @property (nonatomic, strong) YMIncomeBreakdownListViewModel *viewModel;
  18. /// 内容列表
  19. @property (nonatomic, strong) UITableView *contentTableView;
  20. @end
  21. @implementation YMIncomeBreakdownListViewController
  22. @dynamic viewModel;
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. [self setNavHidden:YES];
  26. [OCNotificationCenter addObserver:self selector:@selector(changeIncomeBreakdownDateData:) name:REFRESH_HOME_NOTIFICATION object:nil];
  27. }
  28. - (void)viewWillAppear:(BOOL)animated{
  29. [super viewWillAppear:animated];
  30. }
  31. - (void)ym_setupViews{
  32. [self.view addSubview:self.contentTableView];
  33. [self.view setNeedsUpdateConstraints];
  34. [self.view updateConstraintsIfNeeded];
  35. }
  36. - (void)updateViewConstraints{
  37. [self.contentTableView mas_makeConstraints:^(MASConstraintMaker *make) {
  38. make.top.equalTo(self.view);
  39. make.left.equalTo(self.view);
  40. make.right.equalTo(self.view);
  41. make.bottom.equalTo(self.view);
  42. }];
  43. [super updateViewConstraints];
  44. }
  45. - (void)ym_bindViewModel{
  46. [self headerRefreshing];
  47. @weakify(self)
  48. [[self.viewModel.refreshUISubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id result) {
  49. @strongify(self)
  50. [self.contentTableView reloadData];
  51. switch ([result intValue]) {
  52. case YMHeaderRefresh_HasMoreData:
  53. case YMHeaderRefresh_HasNoMoreData:
  54. {
  55. [self.contentTableView.mj_header endRefreshing];
  56. [self.contentTableView.mj_footer endRefreshing];
  57. }
  58. break;
  59. case YMFooterRefresh_HasMoreData:
  60. {
  61. [self.contentTableView.mj_header endRefreshing];
  62. [self.contentTableView.mj_footer endRefreshing];
  63. if (self.contentTableView.mj_footer == self.noLoadMoreFooter) {
  64. self.contentTableView.mj_footer = self.loadMoreFooter;
  65. }
  66. }
  67. break;
  68. case YMFooterRefresh_HasNoMoreData:
  69. {
  70. [self.contentTableView.mj_header endRefreshing];
  71. [self.contentTableView.mj_footer endRefreshing];
  72. if (self.contentTableView.mj_footer == self.loadMoreFooter) {
  73. self.contentTableView.mj_footer = self.noLoadMoreFooter;
  74. }
  75. }
  76. break;
  77. case YMRefreshError: {
  78. [self.contentTableView.mj_header endRefreshing];
  79. [self.contentTableView.mj_footer endRefreshing];
  80. }
  81. break;
  82. default:
  83. break;
  84. }
  85. [self.contentTableView ym_endLoading];
  86. }];
  87. }
  88. - (void)changeIncomeBreakdownDateData:(NSNotification *)notice{
  89. [self.viewModel.changeIncomeBreakdownDateSubject sendNext:[notice.userInfo stringValueForKey:@"date" defaultValue:@""]];
  90. }
  91. - (void)headerRefreshing{
  92. [self.contentTableView ym_startLoading];
  93. self.viewModel.currentPage = 1;
  94. [self.viewModel getIncomeBreakdownListData];
  95. }
  96. - (void)footerRefreshing{
  97. [self.contentTableView ym_startLoading];
  98. self.viewModel.currentPage++;
  99. [self.viewModel getIncomeBreakdownListData];
  100. }
  101. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  102. switch (self.viewModel.categoryType) {
  103. case YMIncomeBreakdownCategoryTypePoints:
  104. case YMIncomeBreakdownCategoryTypeEarnings:
  105. {
  106. return self.viewModel.pointsAndEarningsDataArray.count;
  107. }
  108. break;
  109. case YMIncomeBreakdownCategoryTypeWithdrawalRecords:
  110. {
  111. return 1;
  112. }
  113. default:
  114. break;
  115. }
  116. }
  117. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  118. switch (self.viewModel.categoryType) {
  119. case YMIncomeBreakdownCategoryTypePoints:
  120. case YMIncomeBreakdownCategoryTypeEarnings:
  121. {
  122. return self.viewModel.pointsAndEarningsDataArray[section].rowDataArray.count;
  123. }
  124. break;
  125. case YMIncomeBreakdownCategoryTypeWithdrawalRecords:
  126. {
  127. return self.viewModel.withdrawalRecordsDataArray.count;
  128. }
  129. default:
  130. break;
  131. }
  132. }
  133. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  134. switch (self.viewModel.categoryType) {
  135. case YMIncomeBreakdownCategoryTypePoints:
  136. case YMIncomeBreakdownCategoryTypeEarnings:
  137. {
  138. YMIncomeBreakdownListPointsAndEarningsCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([YMIncomeBreakdownListPointsAndEarningsCell class])];
  139. if (!cell) {
  140. cell = [[YMIncomeBreakdownListPointsAndEarningsCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NSStringFromClass([YMIncomeBreakdownListPointsAndEarningsCell class])];
  141. }
  142. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  143. [cell ym_bindViewModel:self.viewModel.pointsAndEarningsDataArray[indexPath.section].rowDataArray[indexPath.item]];
  144. return cell;
  145. }
  146. break;
  147. case YMIncomeBreakdownCategoryTypeWithdrawalRecords:
  148. {
  149. YMIncomeBreakdownListWithdrawalRecordsCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([YMIncomeBreakdownListWithdrawalRecordsCell class])];
  150. if (!cell) {
  151. cell = [[YMIncomeBreakdownListWithdrawalRecordsCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NSStringFromClass([YMIncomeBreakdownListWithdrawalRecordsCell class])];
  152. }
  153. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  154. [cell ym_bindViewModel:self.viewModel.withdrawalRecordsDataArray[indexPath.item]];
  155. return cell;
  156. }
  157. default:
  158. break;
  159. }
  160. }
  161. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  162. switch (self.viewModel.categoryType) {
  163. case YMIncomeBreakdownCategoryTypePoints:
  164. case YMIncomeBreakdownCategoryTypeEarnings:
  165. {
  166. return adapt(90);
  167. }
  168. break;
  169. case YMIncomeBreakdownCategoryTypeWithdrawalRecords:
  170. {
  171. return adapt(180);
  172. }
  173. default:
  174. break;
  175. }
  176. }
  177. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  178. switch (self.viewModel.categoryType) {
  179. case YMIncomeBreakdownCategoryTypePoints:
  180. case YMIncomeBreakdownCategoryTypeEarnings:
  181. {
  182. if (OCStringIsEmpty(self.viewModel.pointsAndEarningsDataArray[section].sectionTitle)) {
  183. return nil;
  184. } else {
  185. YMIncomeBreakdownListSectionView *sectionHeaderView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:NSStringFromClass([YMIncomeBreakdownListSectionView class])];
  186. if(!sectionHeaderView){
  187. sectionHeaderView = [[YMIncomeBreakdownListSectionView alloc] initWithReuseIdentifier:NSStringFromClass([YMIncomeBreakdownListSectionView class])];
  188. }
  189. [sectionHeaderView ym_bindViewModel:self.viewModel.pointsAndEarningsDataArray[section]];
  190. return sectionHeaderView;
  191. }
  192. }
  193. break;
  194. case YMIncomeBreakdownCategoryTypeWithdrawalRecords:
  195. {
  196. return nil;
  197. }
  198. default:
  199. break;
  200. }
  201. }
  202. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  203. switch (self.viewModel.categoryType) {
  204. case YMIncomeBreakdownCategoryTypePoints:
  205. case YMIncomeBreakdownCategoryTypeEarnings:
  206. {
  207. if (OCStringIsEmpty(self.viewModel.pointsAndEarningsDataArray[section].sectionTitle)) {
  208. return CGFLOAT_MIN;
  209. } else {
  210. return adapt(30);
  211. }
  212. }
  213. break;
  214. case YMIncomeBreakdownCategoryTypeWithdrawalRecords:
  215. {
  216. return CGFLOAT_MIN;
  217. }
  218. default:
  219. break;
  220. }
  221. }
  222. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  223. return nil;
  224. }
  225. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  226. return CGFLOAT_MIN;
  227. }
  228. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  229. switch (self.viewModel.categoryType) {
  230. case YMIncomeBreakdownCategoryTypePoints:
  231. case YMIncomeBreakdownCategoryTypeEarnings:
  232. {
  233. if (self.viewModel.pointsAndEarningsDataArray[indexPath.section].rowDataArray[indexPath.item].userId != 0) {
  234. [self.viewModel.gotoPersonalPageSubject sendNext:@(self.viewModel.pointsAndEarningsDataArray[indexPath.section].rowDataArray[indexPath.item].userId)];
  235. }
  236. }
  237. break;
  238. case YMIncomeBreakdownCategoryTypeWithdrawalRecords:
  239. {
  240. }
  241. default:
  242. break;
  243. }
  244. }
  245. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  246. !self.scrollCallback ?: self.scrollCallback(scrollView);
  247. }
  248. #pragma mark - JXPagingViewListViewDelegate
  249. - (UIView *)listView {
  250. return self.view;
  251. }
  252. - (UIScrollView *)listScrollView {
  253. return self.contentTableView;
  254. }
  255. - (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback {
  256. self.scrollCallback = callback;
  257. }
  258. - (void)listWillAppear {
  259. // NSLog(@"%@:%@", self.title, NSStringFromSelector(_cmd));
  260. }
  261. - (void)listDidAppear {
  262. // NSLog(@"%@:%@", self.title, NSStringFromSelector(_cmd));
  263. }
  264. - (void)listWillDisappear {
  265. // NSLog(@"%@:%@", self.title, NSStringFromSelector(_cmd));
  266. }
  267. - (void)listDidDisappear {
  268. // NSLog(@"%@:%@", self.title, NSStringFromSelector(_cmd));
  269. }
  270. - (UITableView *)contentTableView{
  271. if (!_contentTableView) {
  272. _contentTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
  273. _contentTableView.delegate = self;
  274. _contentTableView.dataSource = self;
  275. _contentTableView.estimatedRowHeight = 0;
  276. _contentTableView.estimatedSectionHeaderHeight = 0;
  277. _contentTableView.estimatedSectionFooterHeight = 0;
  278. _contentTableView.showsVerticalScrollIndicator = NO;
  279. _contentTableView.showsHorizontalScrollIndicator = NO;
  280. _contentTableView.separatorColor = UIColor.clearColor;
  281. _contentTableView.backgroundColor = UIColor.whiteColor;
  282. [_contentTableView registerClass:[YMIncomeBreakdownListSectionView class] forHeaderFooterViewReuseIdentifier:NSStringFromClass([YMIncomeBreakdownListSectionView class])];
  283. [_contentTableView registerClass:[YMIncomeBreakdownListPointsAndEarningsCell class] forCellReuseIdentifier:NSStringFromClass([YMIncomeBreakdownListPointsAndEarningsCell class])];
  284. [_contentTableView registerClass:[YMIncomeBreakdownListWithdrawalRecordsCell class] forCellReuseIdentifier:NSStringFromClass([YMIncomeBreakdownListWithdrawalRecordsCell class])];
  285. _contentTableView.mj_header = self.refreshHeader;
  286. _contentTableView.mj_footer = self.noLoadMoreFooter;
  287. YMEmptyView *empty = [YMEmptyView emptyViewWithImageStr:@"ym_common_no_data_icon" titleStr:@"暂无查到相关数据" detailStr:@""];
  288. empty.imageSize = kEmptyViewSize;
  289. _contentTableView.ym_emptyView = empty;
  290. _contentTableView.ym_emptyView.autoShowEmptyView = NO;
  291. }
  292. return _contentTableView;
  293. }
  294. @end