ASCouponsListViewController.m 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. }];
  39. }
  40. // MARK: - loadSubVs
  41. - (void)loadSubVs {
  42. [self.view addSubview:self.colorBgV];
  43. [self.view addSubview:self.tableV];
  44. [self.colorBgV mas_makeConstraints:^(MASConstraintMaker *make) {
  45. make.top.equalTo(self.customNavBar.mas_bottom);
  46. make.leading.trailing.bottom.equalTo(self.view);
  47. }];
  48. [self.tableV mas_makeConstraints:^(MASConstraintMaker *make) {
  49. make.top.equalTo(self.customNavBar.mas_bottom);
  50. make.leading.trailing.bottom.equalTo(self.view);
  51. }];
  52. dispatch_async(dispatch_get_main_queue(), ^{
  53. [UIView viewAddHorColorBg:self.colorBgV colorArr:@[
  54. (id)_E0FFF5.CGColor,
  55. (id)Col_FFF.CGColor
  56. ] startP:CGPointMake(0.5, 0.2) endP:CGPointMake(0.5, 1)];
  57. });
  58. }
  59. - (void)configSubVs {
  60. self.titleStr = @"Coupons";
  61. [self setNavRightSearch:^{
  62. }];
  63. self.statusBgV.backgroundColor = _E0FFF5;
  64. self.customNavBar.backgroundColor = _F0FFFA;
  65. __weak typeof(self) weakSelf = self;
  66. self.tableV.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  67. weakSelf.page = 1;
  68. [weakSelf loadNetData];
  69. }];
  70. self.tableV.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  71. weakSelf.page += 1;
  72. [weakSelf loadNetData];
  73. }];
  74. }
  75. // MARK: - subVs
  76. - (UIView *)colorBgV {
  77. if (!_colorBgV) {
  78. UIView *v = [UIView baseV];
  79. v.backgroundColor = Col_FFF;
  80. _colorBgV = v;
  81. }
  82. return _colorBgV;
  83. }
  84. - (UITableView *)tableV {
  85. if (!_tableV) {
  86. UITableView *v = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  87. [v baseSet];
  88. v.backgroundColor = UIColor.clearColor;
  89. v.delegate = self;
  90. v.dataSource = self;
  91. [v registerClass:[ASCouponListCell class] forCellReuseIdentifier:@"ASCouponListCell"];
  92. _tableV = v;
  93. }
  94. return _tableV;
  95. }
  96. // MARK: - UITableViewDelegate,UITableViewDataSource
  97. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  98. return self.vm.couponList.count;
  99. }
  100. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  101. ASCouponListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASCouponListCell" forIndexPath:indexPath];
  102. __weak typeof(self) weakSelf = self;
  103. [cell setCopyCallBack:^{
  104. [weakSelf.view makeToast:@"Code Copied"];
  105. }];
  106. return cell;
  107. }
  108. @end