ASHomeViewController.m 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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. [ASNetTools login];
  141. };
  142. cell.model = m;
  143. return cell;
  144. }
  145. case 4: {
  146. ASHomeNewInCellTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASHomeNewInCellTableViewCell" forIndexPath:indexPath];
  147. [cell setData:m];
  148. return cell;
  149. }
  150. case 5: {
  151. ASHomeImgCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASHomeImgCell" forIndexPath:indexPath];
  152. cell.tapImgBlock = ^{
  153. // TODO: -
  154. };
  155. [cell setImgStr:m.imgUrl];
  156. return cell;
  157. }
  158. case 6: {
  159. ASHomeFlashDealCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASHomeFlashDealCell" forIndexPath:indexPath];
  160. cell.productClick = ^(NSInteger i, ASProductBaseModel * _Nonnull m) {
  161. };
  162. cell.proAddCartClick = ^(NSInteger i, ASProductBaseModel * _Nonnull m) {
  163. };
  164. cell.model = m;
  165. return cell;
  166. }
  167. case 7: {
  168. ASHomeLookingCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASHomeLookingCell" forIndexPath:indexPath];
  169. cell.itemClick = ^(NSInteger i, ASHomeCategoryModel * _Nonnull m) {
  170. };
  171. cell.model = m;
  172. return cell;
  173. }
  174. default:
  175. break;
  176. }
  177. return [UITableViewCell new];
  178. }
  179. - (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
  180. return 40;
  181. }
  182. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  183. return UITableViewAutomaticDimension;
  184. }
  185. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  186. return 0.01;
  187. }
  188. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  189. UIView *footer = [[UIView alloc] initWithFrame:CGRectZero];
  190. footer.backgroundColor = [UIColor clearColor];
  191. return footer;
  192. }
  193. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  194. return 0.01;
  195. }
  196. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  197. UIView *footer = [[UIView alloc] initWithFrame:CGRectZero];
  198. footer.backgroundColor = [UIColor clearColor];
  199. return footer;
  200. }
  201. -(void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  202. }
  203. // MARK: - nextViews
  204. - (void)pushToProductList:(NSString *)typeId title:(NSString *)title {
  205. ASProductListViewController *vc = [ASProductListViewController new];
  206. vc.titleStr = title;
  207. [self.navigationController pushViewController:vc animated:true];
  208. }
  209. // MARK: - subVs
  210. -(UITableView *)tableV {
  211. if (!_tableV) {
  212. UITableView *tabV = [[UITableView alloc] initWithFrame:self.view.bounds];
  213. tabV.delegate = self;
  214. tabV.dataSource = self;
  215. [tabV baseSet];
  216. tabV.backgroundColor = UIColor.whiteColor;
  217. tabV.separatorStyle = UITableViewCellSeparatorStyleNone;
  218. [tabV registerClass:[ASHomeBannerCell class] forCellReuseIdentifier:@"ASHomeBannerCell"];
  219. [tabV registerClass:[ASCategaryListCell class] forCellReuseIdentifier:@"ASCategaryListCell"];
  220. [tabV registerClass:[ASHomeTipCell class] forCellReuseIdentifier:@"ASHomeTipCell"];
  221. [tabV registerClass:[ASHomeBestSellCell class] forCellReuseIdentifier:@"ASHomeBestSellCell"];
  222. [tabV registerClass:[ASHomeNewInCellTableViewCell class] forCellReuseIdentifier:@"ASHomeNewInCellTableViewCell"];
  223. [tabV registerClass:[ASHomeImgCell class] forCellReuseIdentifier:@"ASHomeImgCell"];
  224. [tabV registerClass:[ASHomeFlashDealCell class] forCellReuseIdentifier:@"ASHomeFlashDealCell"];
  225. [tabV registerClass:[ASHomeLookingCell class] forCellReuseIdentifier:@"ASHomeLookingCell"];
  226. _tableV = tabV;
  227. }
  228. return _tableV;
  229. }
  230. @end