ASVipCouponsViewController.m 4.1 KB

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