ASCouponsListViewController.m 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. //
  2. // ASCouponsListViewController.m
  3. // Asteria
  4. //
  5. // Created by iOS on 2023/6/25.
  6. //
  7. #import "ASCouponsListViewController.h"
  8. #import "ASCouponListCell.h"
  9. #import "ASCouponsListViewModel.h"
  10. @interface ASCouponsListViewController () <UITableViewDelegate,UITableViewDataSource>
  11. @property (nonatomic, strong) UIView *colorBgV;
  12. @property (nonatomic, strong) UITableView *tableV;
  13. @property (nonatomic, assign) NSInteger page;
  14. @property (nonatomic, strong) ASCouponsListViewModel *vm;
  15. @end
  16. @implementation ASCouponsListViewController
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. self.page = 1;
  20. self.vm = [ASCouponsListViewModel new];
  21. [self loadSubVs];
  22. [self configSubVs];
  23. [self.tableV.mj_header beginRefreshing];
  24. }
  25. // MARK: - net
  26. - (void)loadNetData {
  27. [MBProgressHUD showHUDAddedTo:self.view animated:true];
  28. __weak typeof(self) weakSelf = self;
  29. [self.vm getCouponList:self.page com:^(BOOL hasNext, NSString * _Nonnull msg) {
  30. [MBProgressHUD hideHUDForView:weakSelf.view animated:true];
  31. [weakSelf.tableV.mj_header endRefreshing];
  32. if (hasNext) {
  33. [weakSelf.tableV.mj_footer endRefreshing];
  34. } else {
  35. [weakSelf.tableV.mj_footer endRefreshingWithNoMoreData];
  36. }
  37. [weakSelf.tableV reloadData];
  38. if (weakSelf.vm.couponList.count == 0) {
  39. [weakSelf showEmptyV:weakSelf.tableV];
  40. } else {
  41. [weakSelf hiddenEmpty];
  42. }
  43. }];
  44. }
  45. // MARK: - loadSubVs
  46. - (void)loadSubVs {
  47. [self.view addSubview:self.colorBgV];
  48. [self.view addSubview:self.tableV];
  49. [self.colorBgV mas_makeConstraints:^(MASConstraintMaker *make) {
  50. make.top.equalTo(self.customNavBar.mas_bottom);
  51. make.leading.trailing.bottom.equalTo(self.view);
  52. }];
  53. [self.tableV mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.top.equalTo(self.customNavBar.mas_bottom);
  55. make.leading.trailing.bottom.equalTo(self.view);
  56. }];
  57. dispatch_async(dispatch_get_main_queue(), ^{
  58. [UIView viewAddHorColorBg:self.colorBgV colorArr:@[
  59. (id)_E0FFF5.CGColor,
  60. (id)Col_FFF.CGColor
  61. ] startP:CGPointMake(0.5, 0.2) endP:CGPointMake(0.5, 1)];
  62. });
  63. }
  64. - (void)configSubVs {
  65. self.titleStr = @"Coupons";
  66. [self setNavRightSearch:^{
  67. }];
  68. self.statusBgV.backgroundColor = _E0FFF5;
  69. self.customNavBar.backgroundColor = _F0FFFA;
  70. __weak typeof(self) weakSelf = self;
  71. self.tableV.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  72. weakSelf.page = 1;
  73. [weakSelf loadNetData];
  74. }];
  75. self.tableV.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  76. weakSelf.page += 1;
  77. [weakSelf loadNetData];
  78. }];
  79. }
  80. // MARK: - subVs
  81. - (UIView *)colorBgV {
  82. if (!_colorBgV) {
  83. UIView *v = [UIView baseV];
  84. v.backgroundColor = Col_FFF;
  85. _colorBgV = v;
  86. }
  87. return _colorBgV;
  88. }
  89. - (UITableView *)tableV {
  90. if (!_tableV) {
  91. UITableView *v = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  92. [v baseSet];
  93. v.backgroundColor = UIColor.clearColor;
  94. v.delegate = self;
  95. v.dataSource = self;
  96. [v registerClass:[ASCouponListCell class] forCellReuseIdentifier:@"ASCouponListCell"];
  97. _tableV = v;
  98. }
  99. return _tableV;
  100. }
  101. // MARK: - UITableViewDelegate,UITableViewDataSource
  102. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  103. return self.vm.couponList.count;
  104. }
  105. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  106. ASCouponListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASCouponListCell" forIndexPath:indexPath];
  107. __weak typeof(self) weakSelf = self;
  108. if (self.vm.couponList.count <= indexPath.row) {
  109. return cell;
  110. }
  111. ASCouponsModel *m = self.vm.couponList[indexPath.row];
  112. [cell setData:m];
  113. [cell setCopyCallBack:^{
  114. UIPasteboard.generalPasteboard.string = m.code;
  115. [weakSelf.view makeToast:@"Code Copied"];
  116. }];
  117. return cell;
  118. }
  119. @end