| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 | ////  ASCouponsListViewController.m//  Asteria////  Created by iOS on 2023/6/25.//#import "ASCouponsListViewController.h"#import "ASCouponListCell.h"#import "ASCouponsListViewModel.h"@interface ASCouponsListViewController () <UITableViewDelegate,UITableViewDataSource>@property (nonatomic, strong) UIView *colorBgV;@property (nonatomic, strong) UITableView *tableV;@property (nonatomic, assign) NSInteger page;@property (nonatomic, strong) ASCouponsListViewModel *vm;@end@implementation ASCouponsListViewController- (void)viewDidLoad {    [super viewDidLoad];    self.page = 1;    self.vm = [ASCouponsListViewModel new];    [self loadSubVs];    [self configSubVs];    [self.tableV.mj_header beginRefreshing];    }// MARK: - net- (void)loadNetData {    [MBProgressHUD showHUDAddedTo:self.view animated:true];    __weak typeof(self) weakSelf = self;    [self.vm getCouponList:self.page com:^(BOOL hasNext, NSString * _Nonnull msg) {        [MBProgressHUD hideHUDForView:weakSelf.view animated:true];        [weakSelf.tableV.mj_header endRefreshing];        if (hasNext) {            [weakSelf.tableV.mj_footer endRefreshing];        } else {            [weakSelf.tableV.mj_footer endRefreshingWithNoMoreData];        }        [weakSelf.tableV reloadData];        if (weakSelf.vm.couponList.count == 0) {            [weakSelf showEmptyV:weakSelf.tableV];        } else {            [weakSelf hiddenEmpty];        }    }];}// MARK: - loadSubVs- (void)loadSubVs {    [self.view addSubview:self.colorBgV];    [self.view addSubview:self.tableV];        [self.colorBgV mas_makeConstraints:^(MASConstraintMaker *make) {        make.top.equalTo(self.customNavBar.mas_bottom);        make.leading.trailing.bottom.equalTo(self.view);    }];        [self.tableV mas_makeConstraints:^(MASConstraintMaker *make) {        make.top.equalTo(self.customNavBar.mas_bottom);        make.leading.trailing.bottom.equalTo(self.view);    }];        dispatch_async(dispatch_get_main_queue(), ^{        [UIView viewAddHorColorBg:self.colorBgV colorArr:@[            (id)_E0FFF5.CGColor,            (id)Col_FFF.CGColor        ] startP:CGPointMake(0.5, 0.2) endP:CGPointMake(0.5, 1)];            });}- (void)configSubVs {    self.titleStr = @"Coupons";    [self setNavRightSearch:^{            }];    self.statusBgV.backgroundColor = _E0FFF5;    self.customNavBar.backgroundColor = _F0FFFA;        __weak typeof(self) weakSelf = self;    self.tableV.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{        weakSelf.page = 1;        [weakSelf loadNetData];    }];        self.tableV.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{        weakSelf.page += 1;        [weakSelf loadNetData];    }];    }// MARK: - subVs- (UIView *)colorBgV {    if (!_colorBgV) {        UIView *v = [UIView baseV];        v.backgroundColor = Col_FFF;        _colorBgV = v;    }    return _colorBgV;}- (UITableView *)tableV {    if (!_tableV) {        UITableView *v = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];        [v baseSet];        v.backgroundColor = UIColor.clearColor;        v.delegate  = self;        v.dataSource = self;        [v registerClass:[ASCouponListCell class] forCellReuseIdentifier:@"ASCouponListCell"];        _tableV = v;    }    return _tableV;}// MARK: - UITableViewDelegate,UITableViewDataSource- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {    return self.vm.couponList.count;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {    ASCouponListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASCouponListCell" forIndexPath:indexPath];    __weak typeof(self) weakSelf = self;    if (self.vm.couponList.count <= indexPath.row) {        return cell;    }    ASCouponsModel *m = self.vm.couponList[indexPath.row];    [cell setData:m];    [cell setCopyCallBack:^{        UIPasteboard.generalPasteboard.string = m.code;        [weakSelf.view makeToast:@"Code Copied"];    }];        return cell;}@end
 |