ASHomeViewController.m 9.4 KB

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