123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358 |
- //
- // ASGiftCardListViewController.m
- // Asteria
- //
- // Created by iOS on 2023/11/2.
- //
- #import "ASGiftCardListViewController.h"
- #import "ASGiftCardTableView.h"
- #import "ASGiftCardListViewModel.h"
- @interface ASGiftCardListViewController ()<UIScrollViewDelegate>
- @property (nonatomic, strong) ASGiftCardListViewModel *vm;
- @property (nonatomic, assign) NSInteger unUsePage;
- @property (nonatomic, assign) NSInteger cantUsePage;
- @property (nonatomic, strong) UIView *topBgV;
- @property (nonatomic, strong) UIView *bottomBgV;
- @property (nonatomic, strong) UIButton *availabelBt;
- @property (nonatomic, strong) UIButton *usedBt;
- @property (nonatomic, strong) UIScrollView *scrollV;
- @property (nonatomic, strong) ASGiftCardTableView *allTableV;
- @property (nonatomic, strong) ASGiftCardTableView *usedTableV;
- @property (nonatomic, strong) UIView *unUseTableHeadV;
- @property (nonatomic, strong) UILabel *unUseTipLb;
- @end
- @implementation ASGiftCardListViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.vm = [ASGiftCardListViewModel new];
- self.unUsePage = 1;
- self.cantUsePage = 1;
- [self loadSubVs];
- [self configSubVs];
-
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- [self checkEmpty];
- }
- - (void)checkEmpty {
- if (_allTableV.dataArr.count == 0 && self.availabelBt.isSelected) {
- [self showEmptyV: self.allTableV];
- } else if (_usedTableV.dataArr.count == 0 && self.usedBt.isSelected) {
- [self showEmptyV: self.usedTableV];
- } else {
- [self hiddenEmpty];
- }
- }
- // MARK: - nets
- - (void)getUnuseListData {
- [MBProgressHUD showHUDAddedTo:self.view animated:true];
- __weak typeof(self) weakSelf = self;
- [self.vm getUnuseCardList:self.unUsePage com:^(BOOL hasNext, NSString * _Nonnull msg) {
- [MBProgressHUD hideHUDForView:weakSelf.view animated:true];
- [weakSelf.allTableV.mj_header endRefreshing];
- if (hasNext) {
- [weakSelf.allTableV.mj_footer endRefreshing];
- } else {
- [weakSelf.allTableV.mj_footer endRefreshingWithNoMoreData];
- }
- weakSelf.allTableV.dataArr = weakSelf.vm.unUseCardList;
- [weakSelf checkEmpty];
- [weakSelf.allTableV reloadData];
- }];
- }
- - (void)getCantUseListData {
- [MBProgressHUD showHUDAddedTo:self.view animated:true];
- __weak typeof(self) weakSelf = self;
- [self.vm getCantUseCardList:self.cantUsePage com:^(BOOL hasNext, NSString * _Nonnull msg) {
- [MBProgressHUD hideHUDForView:weakSelf.view animated:true];
- [weakSelf.usedTableV.mj_header endRefreshing];
- if (hasNext) {
- [weakSelf.usedTableV.mj_footer endRefreshing];
- } else {
- [weakSelf.usedTableV.mj_footer endRefreshingWithNoMoreData];
- }
- weakSelf.usedTableV.dataArr = weakSelf.vm.cantUseCardList;
- [weakSelf checkEmpty];
- [weakSelf.usedTableV reloadData];
- }];
- }
- // MARK: - loadSubVs
- - (void)configSubVs {
- self.view.backgroundColor = _E0FFF5;
- self.customNavBar.backgroundColor = _F0FFFA;
- self.titleStr = @"My Giftcard";
-
- __weak typeof(self) weakSelf = self;
- [self setNavRightSearch:^{
-
- }];
-
- self.allTableV.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
- weakSelf.unUsePage = 1;
- [weakSelf getUnuseListData];
- }];
- self.allTableV.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
- weakSelf.unUsePage += 1;
- [weakSelf getUnuseListData];
- }];
-
- self.usedTableV.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
- weakSelf.cantUsePage = 1;
- [weakSelf getCantUseListData];
- }];
- self.usedTableV.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
- weakSelf.cantUsePage += 1;
- [weakSelf getCantUseListData];
- }];
-
- [self.allTableV.mj_header beginRefreshing];
- [self.usedTableV.mj_header beginRefreshing];
- }
- - (void)loadSubVs {
- [self.view addSubview:self.topBgV];
- [self.view addSubview:self.bottomBgV];
-
- [self.topBgV addSubview:self.availabelBt];
- [self.topBgV addSubview:self.usedBt];
-
- [self.bottomBgV addSubview:self.scrollV];
- [self.scrollV addSubview:self.allTableV];
- [self.scrollV addSubview:self.usedTableV];
-
- [self.unUseTableHeadV addSubview:self.unUseTipLb];
-
- NSString *tipStr = @"Gift Card Will Be Applied Automatically,Go to Cart/CheckOut Page to Check.";
- CGRect rect = [tipStr boundingRectWithSize:CGSizeMake(SCREEN_WIDTH-40, CGFLOAT_MAX) options:NSStringDrawingUsesFontLeading attributes:nil context:nil];
- self.unUseTableHeadV.frame = CGRectMake(0, 0, SCREEN_WIDTH, rect.size.height + 28);
- [self.unUseTipLb mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.unUseTableHeadV).offset(8);
- make.leading.equalTo(self.unUseTableHeadV).offset(20);
- make.trailing.equalTo(self.unUseTableHeadV).offset(-20);
- make.height.equalTo(@(rect.size.height));
- }];
- self.allTableV.tableHeaderView = self.unUseTableHeadV;
-
- [self.topBgV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.customNavBar.mas_bottom);
- make.leading.trailing.equalTo(self.view);
- make.height.equalTo(@60);
- }];
-
- [self.availabelBt mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.topBgV);
- make.height.equalTo(@40);
- make.leading.equalTo(self.topBgV).offset(10);
- }];
- [self.usedBt mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.availabelBt);
- make.height.equalTo(@40);
- make.leading.equalTo(self.availabelBt.mas_trailing).offset(10);
- make.trailing.equalTo(self.topBgV).offset(-10);
- make.width.equalTo(self.availabelBt);
- }];
-
- [self.bottomBgV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.topBgV.mas_bottom);
- make.leading.trailing.bottom.equalTo(self.view);
- }];
-
- [self.scrollV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.bottomBgV).offset(10);
- make.leading.trailing.bottom.equalTo(self.bottomBgV);
- }];
-
- [self.allTableV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.leading.bottom.equalTo(self.scrollV);
- make.width.equalTo(self.bottomBgV);
- make.height.equalTo(self.bottomBgV).offset(-10);
- }];
-
- [self.usedTableV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.leading.equalTo(self.allTableV.mas_trailing);
- make.top.trailing.bottom.equalTo(self.scrollV);
- make.width.equalTo(self.bottomBgV);
- make.height.equalTo(self.bottomBgV).offset(-10);
- }];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [UIView viewAddHorColorBg:self.bottomBgV colorArr:@[
- (id)_E0FFF5.CGColor,
- (id)Col_FFF.CGColor
- ] startP:CGPointMake(0.5, 0) endP:CGPointMake(0.5, 1)];
- [self.bottomBgV bringSubviewToFront:self.scrollV];
-
- });
-
- }
- // MARK: - bt Actions
- - (void)topBtAction:(UIButton *)bt {
- if (bt == self.usedBt) {
- self.availabelBt.selected = false;
- self.usedBt.selected = true;
- [self.scrollV setContentOffset:CGPointMake(KScreenWidth, 0) animated:true];
- } else {
- self.availabelBt.selected = true;
- self.usedBt.selected = false;
- [self.scrollV setContentOffset:CGPointMake(0, 0) animated:true];
- }
- [self setBtStatus:self.availabelBt];
- [self setBtStatus:self.usedBt];
- [self checkEmpty];
- }
- - (void)setBtStatus:(UIButton *)bt {
- bt.backgroundColor = bt.isSelected ? _113632 : Col_FFF;
- bt.titleLabel.font = [UIFont fontWithName:bt.isSelected ? Rob_Bold : Rob_Regular size:16];
-
- }
- // MARK: - subvs
- - (UIView *)topBgV {
- if (!_topBgV) {
- UIView *v = [UIView baseV];
- v.backgroundColor = _E0FFF5;
- _topBgV = v;
- }
- return _topBgV;
- }
- - (UIView *)bottomBgV{
- if (!_bottomBgV) {
- UIView *v = [UIView baseV];
- v.frame = CGRectMake(0, 0, KScreenWidth, KScreenHeight);
- v.backgroundColor = UIColor.clearColor;
-
- _bottomBgV = v;
- }
- return _bottomBgV;
- }
- - (UIButton *)availabelBt {
- if (!_availabelBt) {
- UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
- [bt addTarget:self action:@selector(topBtAction:) forControlEvents:UIControlEventTouchUpInside];
- bt.selected = true;
- bt.backgroundColor = _113632;
- bt.titleLabel.font = [UIFont fontWithName:Rob_Bold size:16];
- [bt setTitleColor:Col_000 forState:UIControlStateNormal];
- bt.layer.cornerRadius = 4;
- bt.layer.masksToBounds = true;
- [bt setTitleColor:Col_FFF forState:UIControlStateSelected];
- [bt setTitle:@"AVAILABLE" forState:UIControlStateNormal];
- _availabelBt = bt;
- }
- return _availabelBt;
- }
- - (UIButton *)usedBt {
- if (!_usedBt) {
- UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
- [bt addTarget:self action:@selector(topBtAction:) forControlEvents:UIControlEventTouchUpInside];
- bt.backgroundColor = Col_FFF;
- bt.titleLabel.font = [UIFont fontWithName:Rob_Regular size:16];
- [bt setTitleColor:Col_000 forState:UIControlStateNormal];
- bt.layer.cornerRadius = 4;
- bt.layer.masksToBounds = true;
- [bt setTitleColor:Col_FFF forState:UIControlStateSelected];
- [bt setTitle:@"EXPIRED/USED" forState:UIControlStateNormal];
- _usedBt = bt;
- }
- return _usedBt;
- }
- - (UIScrollView *)scrollV {
- if (!_scrollV) {
- UIScrollView *v = [[UIScrollView alloc] init];
- v.showsVerticalScrollIndicator = false;
- v.showsHorizontalScrollIndicator = false;
- v.delegate = self;
- v.pagingEnabled = true;
- v.backgroundColor = UIColor.clearColor;
- v.alwaysBounceHorizontal = true;
- _scrollV = v;
- }
- return _scrollV;
- }
- - (ASGiftCardTableView *)allTableV {
- if (!_allTableV) {
- ASGiftCardTableView *v = [[ASGiftCardTableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
- _allTableV = v;
- }
- return _allTableV;
- }
- - (ASGiftCardTableView *)usedTableV {
- if (!_usedTableV) {
- ASGiftCardTableView *v = [[ASGiftCardTableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
- _usedTableV = v;
- }
- return _usedTableV;
- }
- - (UIView *)unUseTableHeadV {
- if (!_unUseTableHeadV) {
- UIView *v = [UIView baseV];
- v.backgroundColor = UIColor.clearColor;
- _unUseTableHeadV = v;
- }
- return _unUseTableHeadV;
- }
- - (UILabel *)unUseTipLb {
- if (!_unUseTipLb) {
- UILabel *lb = [UILabel baseLb];
- lb.numberOfLines = 0;
- lb.font = [UIFont fontWithName:Rob_Regular size:12];
- lb.textColor = Col_000;
- _unUseTipLb = lb;
- }
- return _unUseTipLb;
- }
- // MARK: - scrollview delegate
- - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
- NSInteger index = (NSInteger)(scrollView.contentOffset.x/KScreenWidth);
- self.availabelBt.selected = index == 0;
- self.usedBt.selected = index == 1;
- [self checkEmpty];
- [self setBtStatus:self.availabelBt];
- [self setBtStatus:self.usedBt];
- }
- - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
- NSInteger index = (NSInteger)(scrollView.contentOffset.x/KScreenWidth);
- self.availabelBt.selected = index == 0;
- self.usedBt.selected = index == 1;
- [self checkEmpty];
- [self setBtStatus:self.availabelBt];
- [self setBtStatus:self.usedBt];
- }
- @end
|