123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 |
- //
- // ASHomeViewController.m
- // Asteria
- //
- // Created by iOS on 2023/6/5.
- //
- #import "ASHomeViewController.h"
- #import "ASHomeBannerCell.h"
- #import "ASCategaryListCell.h"
- #import "ASHomeTipCell.h"
- #import "ASHomeBestSellCell.h"
- #import "ASHomeNewInCellTableViewCell.h"
- #import "ASHomeImgCell.h"
- #import "ASHomeFlashDealCell.h"
- #import "ASHomeLookingCell.h"
- #import "ASHomeActiveView.h"
- #import "ASProductListViewController.h"
- @interface ASHomeViewController ()<UITableViewDelegate,UITableViewDataSource>
- @property (nonatomic, strong) UITableView *tableV;
- @property (nonatomic, strong) NSArray <ASHomeMainListModel*>*listArr;
- @property (nonatomic, strong) NSArray <ASHomeBannerModel *>*topLinkArr;
- @property (nonatomic, strong, nullable) ASHomeActiveView *activeV;
- @end
- @implementation ASHomeViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- __block typeof(self) wSelf = self;
- [self ucHomeStyle:^{
- // TODO: 跳转搜索模块
- }];
- [self addSubV];
- [self demoData];
- [self.tableV reloadData];
-
- if (self.topLinkArr.count > 0) {
- self.activeV = [[ASHomeActiveView alloc] initWithFrame:CGRectZero];
- self.activeV.tapBlock = ^(ASHomeBannerModel * _Nullable m) {
-
- };
- self.tableV.tableHeaderView = self.activeV;
- [self.activeV setData:self.topLinkArr];
-
- } else {
- self.activeV.tapBlock = nil;
- self.activeV = nil;
- self.tableV.tableHeaderView = nil;
- }
- }
- - (void)demoData {
- _listArr = [ASHomeMainListModel homeDemoDatas];
- NSMutableArray *tempArr = [NSMutableArray array];
- for (int i=0;i < (arc4random()%6); i++) {
- ASHomeBannerModel *m = [ASHomeBannerModel demoModelWithType:i%3+1];
- [tempArr addObject:m];
- }
- self.topLinkArr = tempArr;
- }
- - (void)addSubV {
- [self.view addSubview:self.tableV];
- [self.tableV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.customNavBar.mas_bottom);
- make.leading.trailing.equalTo(self.view);
- make.bottom.equalTo(self.view);
- }];
- self.tableV.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1), dispatch_get_main_queue(), ^{
- [self.tableV.mj_header endRefreshing];
- [self.tableV reloadData];
- });
- }];
- }
- // MARK: - UITableViewDelegate
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if (indexPath.section == 0) { // banner
- return;
- }
-
- }
- // MARK: - UITableViewDataSource
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return self.listArr.count + 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
-
- switch (section) {
- default:
- return 1;
- }
- return 1;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- if (indexPath.section == 0) { // banner
- ASHomeBannerCell *bcell = [tableView dequeueReusableCellWithIdentifier:@"ASHomeBannerCell" forIndexPath:indexPath];
- @weakify(self);
- bcell.selectCallBack = ^(NSInteger index, NSString * _Nonnull title, NSString * _Nonnull typeId, id _Nonnull model) {
- if (model == nil || ![model isKindOfClass:[ASHomeBannerModel class]]) {
- return;
- }
- ASHomeBannerModel *m = (ASHomeBannerModel *)model;
- if (m.type == 1) {
- // [self goto_WKM_GoodsDetailsC:m.tapUrl];
- return;
- }
- if (m.type == 2) {
- // NSString *typeId = m.tapUrl;
- // [self pushToProductList:@"Products" typeid:typeId];
- return;
- }
- if ([m.tapUrl.lowercaseString hasPrefix:@"http"]) {
- // [self toWebVC:m.tapUrl name:@"Alipearl"];
- }
- };
- NSMutableArray *arr = [NSMutableArray array];
- for (int i=0; i<6; i++) {
- ASHomeBannerModel *m = [ASHomeBannerModel demoModelWithType:i%3];
- [arr addObject:m];
- }
- [bcell showData:arr];
- return bcell;
- }
- if (self.listArr.count <= indexPath.row) {
- return [UITableViewCell new];
- }
- ASHomeMainListModel *m = self.listArr[indexPath.section-1];
- switch (m.showType) {
- case 1: { // 分类
- ASCategaryListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASCategaryListCell" forIndexPath:indexPath];
- cell.arr = m.titleArr;
- cell.selectCategory = ^(ASHomeCategoryModel * _Nonnull model, NSIndexPath * _Nonnull index) {
- // TODO: - to productlist
- [self pushToProductList:model.typeId title:model.title];
- };
- return cell;
- }
- case 2: { // tips
- ASHomeTipCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASHomeTipCell" forIndexPath:indexPath];
- return cell;
- }
- case 3: {// bestSell
- ASHomeBestSellCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASHomeBestSellCell" forIndexPath:indexPath];
- cell.productClick = ^(NSInteger i, ASProductBaseModel * _Nonnull m) {
- [ASNetTools login];
- };
- cell.model = m;
- return cell;
- }
- case 4: {
- ASHomeNewInCellTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASHomeNewInCellTableViewCell" forIndexPath:indexPath];
- [cell setData:m];
- return cell;
- }
- case 5: {
- ASHomeImgCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASHomeImgCell" forIndexPath:indexPath];
- cell.tapImgBlock = ^{
- // TODO: -
- };
- [cell setImgStr:m.imgUrl];
- return cell;
- }
- case 6: {
- ASHomeFlashDealCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASHomeFlashDealCell" forIndexPath:indexPath];
- cell.productClick = ^(NSInteger i, ASProductBaseModel * _Nonnull m) {
-
- };
- cell.proAddCartClick = ^(NSInteger i, ASProductBaseModel * _Nonnull m) {
-
- };
- cell.model = m;
- return cell;
- }
- case 7: {
- ASHomeLookingCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASHomeLookingCell" forIndexPath:indexPath];
- cell.itemClick = ^(NSInteger i, ASHomeCategoryModel * _Nonnull m) {
-
- };
- cell.model = m;
- return cell;
- }
- default:
- break;
- }
-
- return [UITableViewCell new];
-
- }
- - (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
- return 40;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- return UITableViewAutomaticDimension;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
- return 0.01;
-
- }
- -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
-
- UIView *footer = [[UIView alloc] initWithFrame:CGRectZero];
- footer.backgroundColor = [UIColor clearColor];
- return footer;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
- return 0.01;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
- UIView *footer = [[UIView alloc] initWithFrame:CGRectZero];
- footer.backgroundColor = [UIColor clearColor];
- return footer;
- }
- -(void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
-
- }
- // MARK: - nextViews
- - (void)pushToProductList:(NSString *)typeId title:(NSString *)title {
- ASProductListViewController *vc = [ASProductListViewController new];
- vc.titleStr = title;
- [self.navigationController pushViewController:vc animated:true];
- }
- // MARK: - subVs
- -(UITableView *)tableV {
- if (!_tableV) {
- UITableView *tabV = [[UITableView alloc] initWithFrame:self.view.bounds];
- tabV.delegate = self;
- tabV.dataSource = self;
- [tabV baseSet];
- tabV.backgroundColor = UIColor.whiteColor;
- tabV.separatorStyle = UITableViewCellSeparatorStyleNone;
- [tabV registerClass:[ASHomeBannerCell class] forCellReuseIdentifier:@"ASHomeBannerCell"];
- [tabV registerClass:[ASCategaryListCell class] forCellReuseIdentifier:@"ASCategaryListCell"];
- [tabV registerClass:[ASHomeTipCell class] forCellReuseIdentifier:@"ASHomeTipCell"];
- [tabV registerClass:[ASHomeBestSellCell class] forCellReuseIdentifier:@"ASHomeBestSellCell"];
- [tabV registerClass:[ASHomeNewInCellTableViewCell class] forCellReuseIdentifier:@"ASHomeNewInCellTableViewCell"];
- [tabV registerClass:[ASHomeImgCell class] forCellReuseIdentifier:@"ASHomeImgCell"];
- [tabV registerClass:[ASHomeFlashDealCell class] forCellReuseIdentifier:@"ASHomeFlashDealCell"];
- [tabV registerClass:[ASHomeLookingCell class] forCellReuseIdentifier:@"ASHomeLookingCell"];
- _tableV = tabV;
- }
- return _tableV;
- }
- @end
|