ASHomeViewController.m 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. //
  2. // ASHomeViewController.m
  3. // Asteria
  4. //
  5. // Created by iOS on 2023/6/5.
  6. //
  7. #import "ASHomeViewController.h"
  8. #import "ASHomeBannerCell.h"
  9. #import "ASCategaryListCell.h"
  10. #import "ASHomeTipCell.h"
  11. #import "ASHomeBestSellCell.h"
  12. #import "ASHomeNewInCellTableViewCell.h"
  13. #import "ASHomeImgCell.h"
  14. #import "ASHomeFlashDealCell.h"
  15. #import "ASHomeLookingCell.h"
  16. #import "ASHomeActiveView.h"
  17. #import "ASProductListViewController.h"
  18. @interface ASHomeViewController ()<UITableViewDelegate,UITableViewDataSource>
  19. @property (nonatomic, strong) UITableView *tableV;
  20. @property (nonatomic, strong) NSArray <ASHomeMainListModel*>*listArr;
  21. @property (nonatomic, strong) NSArray <ASHomeBannerModel *>*topLinkArr;
  22. @property (nonatomic, strong, nullable) ASHomeActiveView *activeV;
  23. @end
  24. @implementation ASHomeViewController
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. __block typeof(self) wSelf = self;
  28. [self ucHomeStyle:^{
  29. // TODO: 跳转搜索模块
  30. }];
  31. [self addSubV];
  32. [self demoData];
  33. [self.tableV reloadData];
  34. if (self.topLinkArr.count > 0) {
  35. self.activeV = [[ASHomeActiveView alloc] initWithFrame:CGRectZero];
  36. self.activeV.tapBlock = ^(ASHomeBannerModel * _Nullable m) {
  37. };
  38. self.tableV.tableHeaderView = self.activeV;
  39. [self.activeV setData:self.topLinkArr];
  40. } else {
  41. self.activeV.tapBlock = nil;
  42. self.activeV = nil;
  43. self.tableV.tableHeaderView = nil;
  44. }
  45. }
  46. - (void)demoData {
  47. _listArr = [ASHomeMainListModel homeDemoDatas];
  48. NSMutableArray *tempArr = [NSMutableArray array];
  49. for (int i=0;i < (arc4random()%6); i++) {
  50. ASHomeBannerModel *m = [ASHomeBannerModel demoModelWithType:i%3+1];
  51. [tempArr addObject:m];
  52. }
  53. self.topLinkArr = tempArr;
  54. }
  55. - (void)addSubV {
  56. [self.view addSubview:self.tableV];
  57. [self.tableV mas_makeConstraints:^(MASConstraintMaker *make) {
  58. make.top.equalTo(self.customNavBar.mas_bottom);
  59. make.leading.trailing.equalTo(self.view);
  60. make.bottom.equalTo(self.view);
  61. }];
  62. self.tableV.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  63. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1), dispatch_get_main_queue(), ^{
  64. [self.tableV.mj_header endRefreshing];
  65. [self.tableV reloadData];
  66. });
  67. }];
  68. }
  69. // MARK: - UITableViewDelegate
  70. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  71. {
  72. if (indexPath.section == 0) { // banner
  73. return;
  74. }
  75. }
  76. // MARK: - UITableViewDataSource
  77. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  78. {
  79. return self.listArr.count + 1;
  80. }
  81. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  82. {
  83. switch (section) {
  84. default:
  85. return 1;
  86. }
  87. return 1;
  88. }
  89. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  90. if (indexPath.section == 0) { // banner
  91. ASHomeBannerCell *bcell = [tableView dequeueReusableCellWithIdentifier:@"ASHomeBannerCell" forIndexPath:indexPath];
  92. @weakify(self);
  93. bcell.selectCallBack = ^(NSInteger index, NSString * _Nonnull title, NSString * _Nonnull typeId, id _Nonnull model) {
  94. if (model == nil || ![model isKindOfClass:[ASHomeBannerModel class]]) {
  95. return;
  96. }
  97. ASHomeBannerModel *m = (ASHomeBannerModel *)model;
  98. if (m.type == 1) {
  99. // [self goto_WKM_GoodsDetailsC:m.tapUrl];
  100. return;
  101. }
  102. if (m.type == 2) {
  103. // NSString *typeId = m.tapUrl;
  104. // [self pushToProductList:@"Products" typeid:typeId];
  105. return;
  106. }
  107. if ([m.tapUrl.lowercaseString hasPrefix:@"http"]) {
  108. // [self toWebVC:m.tapUrl name:@"Alipearl"];
  109. }
  110. };
  111. NSMutableArray *arr = [NSMutableArray array];
  112. for (int i=0; i<6; i++) {
  113. ASHomeBannerModel *m = [ASHomeBannerModel demoModelWithType:i%3];
  114. [arr addObject:m];
  115. }
  116. [bcell showData:arr];
  117. return bcell;
  118. }
  119. if (self.listArr.count <= indexPath.row) {
  120. return [UITableViewCell new];
  121. }
  122. ASHomeMainListModel *m = self.listArr[indexPath.section-1];
  123. switch (m.showType) {
  124. case 1: { // 分类
  125. ASCategaryListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASCategaryListCell" forIndexPath:indexPath];
  126. cell.arr = m.titleArr;
  127. cell.selectCategory = ^(ASHomeCategoryModel * _Nonnull model, NSIndexPath * _Nonnull index) {
  128. // TODO: - to productlist
  129. [self pushToProductList:model.typeId title:model.title];
  130. };
  131. return cell;
  132. }
  133. case 2: { // tips
  134. ASHomeTipCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASHomeTipCell" forIndexPath:indexPath];
  135. return cell;
  136. }
  137. case 3: {// bestSell
  138. ASHomeBestSellCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASHomeBestSellCell" forIndexPath:indexPath];
  139. cell.productClick = ^(NSInteger i, ASProductBaseModel * _Nonnull m) {
  140. };
  141. cell.model = m;
  142. return cell;
  143. }
  144. case 4: {
  145. ASHomeNewInCellTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASHomeNewInCellTableViewCell" forIndexPath:indexPath];
  146. [cell setData:m];
  147. return cell;
  148. }
  149. case 5: {
  150. ASHomeImgCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASHomeImgCell" forIndexPath:indexPath];
  151. cell.tapImgBlock = ^{
  152. // TODO: -
  153. };
  154. [cell setImgStr:m.imgUrl];
  155. return cell;
  156. }
  157. case 6: {
  158. ASHomeFlashDealCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASHomeFlashDealCell" forIndexPath:indexPath];
  159. cell.productClick = ^(NSInteger i, ASProductBaseModel * _Nonnull m) {
  160. };
  161. cell.proAddCartClick = ^(NSInteger i, ASProductBaseModel * _Nonnull m) {
  162. };
  163. cell.model = m;
  164. return cell;
  165. }
  166. case 7: {
  167. ASHomeLookingCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASHomeLookingCell" forIndexPath:indexPath];
  168. cell.itemClick = ^(NSInteger i, ASHomeCategoryModel * _Nonnull m) {
  169. };
  170. cell.model = m;
  171. return cell;
  172. }
  173. default:
  174. break;
  175. }
  176. return [UITableViewCell new];
  177. }
  178. - (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
  179. return 40;
  180. }
  181. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  182. return UITableViewAutomaticDimension;
  183. }
  184. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  185. return 0.01;
  186. }
  187. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  188. UIView *footer = [[UIView alloc] initWithFrame:CGRectZero];
  189. footer.backgroundColor = [UIColor clearColor];
  190. return footer;
  191. }
  192. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  193. return 0.01;
  194. }
  195. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  196. UIView *footer = [[UIView alloc] initWithFrame:CGRectZero];
  197. footer.backgroundColor = [UIColor clearColor];
  198. return footer;
  199. }
  200. -(void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  201. }
  202. // MARK: - nextViews
  203. - (void)pushToProductList:(NSString *)typeId title:(NSString *)title {
  204. ASProductListViewController *vc = [ASProductListViewController new];
  205. vc.titleStr = title;
  206. [self.navigationController pushViewController:vc animated:true];
  207. }
  208. // MARK: - subVs
  209. -(UITableView *)tableV {
  210. if (!_tableV) {
  211. UITableView *tabV = [[UITableView alloc] initWithFrame:self.view.bounds];
  212. tabV.delegate = self;
  213. tabV.dataSource = self;
  214. [tabV baseSet];
  215. tabV.backgroundColor = UIColor.whiteColor;
  216. tabV.separatorStyle = UITableViewCellSeparatorStyleNone;
  217. [tabV registerClass:[ASHomeBannerCell class] forCellReuseIdentifier:@"ASHomeBannerCell"];
  218. [tabV registerClass:[ASCategaryListCell class] forCellReuseIdentifier:@"ASCategaryListCell"];
  219. [tabV registerClass:[ASHomeTipCell class] forCellReuseIdentifier:@"ASHomeTipCell"];
  220. [tabV registerClass:[ASHomeBestSellCell class] forCellReuseIdentifier:@"ASHomeBestSellCell"];
  221. [tabV registerClass:[ASHomeNewInCellTableViewCell class] forCellReuseIdentifier:@"ASHomeNewInCellTableViewCell"];
  222. [tabV registerClass:[ASHomeImgCell class] forCellReuseIdentifier:@"ASHomeImgCell"];
  223. [tabV registerClass:[ASHomeFlashDealCell class] forCellReuseIdentifier:@"ASHomeFlashDealCell"];
  224. [tabV registerClass:[ASHomeLookingCell class] forCellReuseIdentifier:@"ASHomeLookingCell"];
  225. _tableV = tabV;
  226. }
  227. return _tableV;
  228. }
  229. @end