ASPointDetailViewController.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. //
  2. // ASPointDetailViewController.m
  3. // Asteria
  4. //
  5. // Created by iOS on 2023/6/24.
  6. //
  7. #import "ASPointDetailViewController.h"
  8. #import "ASPointDetailTableView.h"
  9. #import "ASPointsViewModel.h"
  10. @interface ASPointDetailViewController () <UIScrollViewDelegate>
  11. @property (nonatomic, strong) ASPointsViewModel *vm;
  12. @property (nonatomic, assign) NSInteger allPage;
  13. @property (nonatomic, assign) NSInteger usedPage;
  14. @property (nonatomic, strong) UIView *topBgV;
  15. @property (nonatomic, strong) UIView *bottomBgV;
  16. @property (nonatomic, strong) UIButton *allBt;
  17. @property (nonatomic, strong) UIButton *usedBt;
  18. @property (nonatomic, strong) UIScrollView *scrollV;
  19. @property (nonatomic, strong) ASPointDetailTableView *allTableV;
  20. @property (nonatomic, strong) ASPointDetailTableView *usedTableV;
  21. @end
  22. @implementation ASPointDetailViewController
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. self.vm = [ASPointsViewModel new];
  26. self.allPage = 1;
  27. self.usedPage = 1;
  28. [self loadSubVs];
  29. [self configSubVs];
  30. }
  31. - (void)viewWillAppear:(BOOL)animated {
  32. [super viewWillAppear:animated];
  33. [self checkEmpty];
  34. }
  35. - (void)checkEmpty {
  36. if (_allTableV.dataArr.count == 0 && self.allBt.isSelected) {
  37. [self showEmptyV: self.allTableV];
  38. } else if (_usedTableV.dataArr.count == 0 && self.usedBt.isSelected) {
  39. [self showEmptyV: self.usedTableV];
  40. } else {
  41. [self hiddenEmpty];
  42. }
  43. }
  44. // MARK: - nets
  45. - (void)getAllListData {
  46. [MBProgressHUD showHUDAddedTo:self.view animated:true];
  47. __weak typeof(self) weakSelf = self;
  48. [self.vm getAllList:self.allPage com:^(BOOL hasNext, NSString * _Nonnull msg) {
  49. [MBProgressHUD hideHUDForView:weakSelf.view animated:true];
  50. [weakSelf.allTableV.mj_header endRefreshing];
  51. if (hasNext) {
  52. [weakSelf.allTableV.mj_footer endRefreshing];
  53. } else {
  54. [weakSelf.allTableV.mj_footer endRefreshingWithNoMoreData];
  55. }
  56. weakSelf.allTableV.dataArr = weakSelf.vm.allList;
  57. [weakSelf checkEmpty];
  58. [weakSelf.allTableV reloadData];
  59. }];
  60. }
  61. - (void)getUsedListData {
  62. [MBProgressHUD showHUDAddedTo:self.view animated:true];
  63. __weak typeof(self) weakSelf = self;
  64. [self.vm getUsedList:self.usedPage com:^(BOOL hasNext, NSString * _Nonnull msg) {
  65. [MBProgressHUD hideHUDForView:weakSelf.view animated:true];
  66. [weakSelf.usedTableV.mj_header endRefreshing];
  67. if (hasNext) {
  68. [weakSelf.usedTableV.mj_footer endRefreshing];
  69. } else {
  70. [weakSelf.usedTableV.mj_footer endRefreshingWithNoMoreData];
  71. }
  72. weakSelf.usedTableV.dataArr = weakSelf.vm.usedList;
  73. [weakSelf checkEmpty];
  74. [weakSelf.usedTableV reloadData];
  75. }];
  76. }
  77. // MARK: - loadSubVs
  78. - (void)configSubVs {
  79. self.view.backgroundColor = _E0FFF5;
  80. self.customNavBar.backgroundColor = _F0FFFA;
  81. self.titleStr = @"Points Details";
  82. __weak typeof(self) weakSelf = self;
  83. [self setNavRightSearch:^{
  84. }];
  85. self.allTableV.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  86. weakSelf.allPage = 1;
  87. [weakSelf getAllListData];
  88. }];
  89. self.allTableV.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  90. weakSelf.allPage += 1;
  91. [weakSelf getAllListData];
  92. }];
  93. self.usedTableV.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  94. weakSelf.usedPage = 1;
  95. [weakSelf getUsedListData];
  96. }];
  97. self.usedTableV.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  98. weakSelf.usedPage += 1;
  99. [weakSelf getUsedListData];
  100. }];
  101. [self.allTableV.mj_header beginRefreshing];
  102. [self.usedTableV.mj_header beginRefreshing];
  103. }
  104. - (void)loadSubVs {
  105. [self.view addSubview:self.topBgV];
  106. [self.view addSubview:self.bottomBgV];
  107. [self.topBgV addSubview:self.allBt];
  108. [self.topBgV addSubview:self.usedBt];
  109. [self.bottomBgV addSubview:self.scrollV];
  110. [self.scrollV addSubview:self.allTableV];
  111. [self.scrollV addSubview:self.usedTableV];
  112. [self.topBgV mas_makeConstraints:^(MASConstraintMaker *make) {
  113. make.top.equalTo(self.customNavBar.mas_bottom);
  114. make.leading.trailing.equalTo(self.view);
  115. make.height.equalTo(@60);
  116. }];
  117. [self.allBt mas_makeConstraints:^(MASConstraintMaker *make) {
  118. make.centerY.equalTo(self.topBgV);
  119. make.height.equalTo(@40);
  120. make.leading.equalTo(self.topBgV).offset(10);
  121. }];
  122. [self.usedBt mas_makeConstraints:^(MASConstraintMaker *make) {
  123. make.centerY.equalTo(self.allBt);
  124. make.height.equalTo(@40);
  125. make.leading.equalTo(self.allBt.mas_trailing).offset(10);
  126. make.trailing.equalTo(self.topBgV).offset(-10);
  127. make.width.equalTo(self.allBt);
  128. }];
  129. [self.bottomBgV mas_makeConstraints:^(MASConstraintMaker *make) {
  130. make.top.equalTo(self.topBgV.mas_bottom);
  131. make.leading.trailing.bottom.equalTo(self.view);
  132. }];
  133. [self.scrollV mas_makeConstraints:^(MASConstraintMaker *make) {
  134. make.top.equalTo(self.bottomBgV).offset(10);
  135. make.leading.trailing.bottom.equalTo(self.bottomBgV);
  136. }];
  137. [self.allTableV mas_makeConstraints:^(MASConstraintMaker *make) {
  138. make.top.leading.bottom.equalTo(self.scrollV);
  139. make.width.equalTo(self.bottomBgV);
  140. make.height.equalTo(self.bottomBgV).offset(-10);
  141. }];
  142. [self.usedTableV mas_makeConstraints:^(MASConstraintMaker *make) {
  143. make.leading.equalTo(self.allTableV.mas_trailing);
  144. make.top.trailing.bottom.equalTo(self.scrollV);
  145. make.width.equalTo(self.bottomBgV);
  146. make.height.equalTo(self.bottomBgV).offset(-10);
  147. }];
  148. }
  149. // MARK: - bt Actions
  150. - (void)topBtAction:(UIButton *)bt {
  151. if (bt == self.usedBt) {
  152. self.allBt.selected = false;
  153. self.usedBt.selected = true;
  154. [self.scrollV setContentOffset:CGPointMake(KScreenWidth, 0) animated:true];
  155. } else {
  156. self.allBt.selected = true;
  157. self.usedBt.selected = false;
  158. [self.scrollV setContentOffset:CGPointMake(0, 0) animated:true];
  159. }
  160. [self setBtStatus:self.allBt];
  161. [self setBtStatus:self.usedBt];
  162. [self checkEmpty];
  163. }
  164. - (void)setBtStatus:(UIButton *)bt {
  165. bt.backgroundColor = bt.isSelected ? _113632 : Col_FFF;
  166. bt.titleLabel.font = [UIFont fontWithName:bt.isSelected ? Rob_Bold : Rob_Regular size:16];
  167. }
  168. // MARK: - subvs
  169. - (UIView *)topBgV {
  170. if (!_topBgV) {
  171. UIView *v = [UIView baseV];
  172. v.backgroundColor = _E0FFF5;
  173. _topBgV = v;
  174. }
  175. return _topBgV;
  176. }
  177. - (UIView *)bottomBgV{
  178. if (!_bottomBgV) {
  179. UIView *v = [UIView baseV];
  180. v.frame = CGRectMake(0, 0, KScreenWidth, KScreenHeight);
  181. v.backgroundColor = Col_FFF;
  182. // 左上和右上为圆角
  183. UIBezierPath *cornerRadiusPath = [UIBezierPath bezierPathWithRoundedRect:v.bounds byRoundingCorners:UIRectCornerTopRight | UIRectCornerTopLeft cornerRadii:CGSizeMake(16, 16)];
  184. CAShapeLayer *cornerRadiusLayer = [ [CAShapeLayer alloc ] init];
  185. cornerRadiusLayer.frame = v.bounds;
  186. cornerRadiusLayer.path = cornerRadiusPath.CGPath;
  187. v.layer.mask = cornerRadiusLayer;
  188. _bottomBgV = v;
  189. }
  190. return _bottomBgV;
  191. }
  192. - (UIButton *)allBt {
  193. if (!_allBt) {
  194. UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
  195. [bt addTarget:self action:@selector(topBtAction:) forControlEvents:UIControlEventTouchUpInside];
  196. bt.selected = true;
  197. bt.backgroundColor = _113632;
  198. bt.titleLabel.font = [UIFont fontWithName:Rob_Bold size:16];
  199. [bt setTitleColor:Col_000 forState:UIControlStateNormal];
  200. bt.layer.cornerRadius = 4;
  201. bt.layer.masksToBounds = true;
  202. [bt setTitleColor:Col_FFF forState:UIControlStateSelected];
  203. [bt setTitle:@"ALL" forState:UIControlStateNormal];
  204. _allBt = bt;
  205. }
  206. return _allBt;
  207. }
  208. - (UIButton *)usedBt {
  209. if (!_usedBt) {
  210. UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
  211. [bt addTarget:self action:@selector(topBtAction:) forControlEvents:UIControlEventTouchUpInside];
  212. bt.backgroundColor = Col_FFF;
  213. bt.titleLabel.font = [UIFont fontWithName:Rob_Regular size:16];
  214. [bt setTitleColor:Col_000 forState:UIControlStateNormal];
  215. bt.layer.cornerRadius = 4;
  216. bt.layer.masksToBounds = true;
  217. [bt setTitleColor:Col_FFF forState:UIControlStateSelected];
  218. [bt setTitle:@"USED" forState:UIControlStateNormal];
  219. _usedBt = bt;
  220. }
  221. return _usedBt;
  222. }
  223. - (UIScrollView *)scrollV {
  224. if (!_scrollV) {
  225. UIScrollView *v = [[UIScrollView alloc] init];
  226. v.showsVerticalScrollIndicator = false;
  227. v.showsHorizontalScrollIndicator = false;
  228. v.delegate = self;
  229. v.pagingEnabled = true;
  230. v.backgroundColor = UIColor.clearColor;
  231. v.alwaysBounceHorizontal = true;
  232. _scrollV = v;
  233. }
  234. return _scrollV;
  235. }
  236. - (ASPointDetailTableView *)allTableV {
  237. if (!_allTableV) {
  238. ASPointDetailTableView *v = [[ASPointDetailTableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  239. v.estimatedRowHeight = 50;
  240. _allTableV = v;
  241. }
  242. return _allTableV;
  243. }
  244. - (ASPointDetailTableView *)usedTableV {
  245. if (!_usedTableV) {
  246. ASPointDetailTableView *v = [[ASPointDetailTableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  247. v.estimatedRowHeight = 50;
  248. _usedTableV = v;
  249. }
  250. return _usedTableV;
  251. }
  252. // MARK: - scrollview delegate
  253. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
  254. NSInteger index = (NSInteger)(scrollView.contentOffset.x/KScreenWidth);
  255. self.allBt.selected = index == 0;
  256. self.usedBt.selected = index == 1;
  257. [self setBtStatus:self.allBt];
  258. [self setBtStatus:self.usedBt];
  259. [self checkEmpty];
  260. }
  261. - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
  262. NSInteger index = (NSInteger)(scrollView.contentOffset.x/KScreenWidth);
  263. self.allBt.selected = index == 0;
  264. self.usedBt.selected = index == 1;
  265. [self setBtStatus:self.allBt];
  266. [self setBtStatus:self.usedBt];
  267. [self checkEmpty];
  268. }
  269. @end