123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348 |
- //
- // 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"
- #import "ASProductListViewModel.h"
- #import "ASHomeViewModel.h"
- @interface ASHomeViewController ()<UITableViewDelegate,UITableViewDataSource>
- @property (nonatomic, strong) ASProductListViewModel *topVm;
- @property (nonatomic, strong) ASHomeViewModel *vm;
- @property (nonatomic, strong) UITableView *tableV;
- @property (nonatomic, strong, nullable) ASHomeActiveView *activeV;
- @end
- @implementation ASHomeViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.vm = [ASHomeViewModel new];
- self.topVm = [ASProductListViewModel new];
-
- __block typeof(self) wSelf = self;
- [self ucHomeStyle:^{
- // TODO: 跳转搜索模块
- }];
- [self addSubV];
- [self.tableV.mj_header beginRefreshing];
-
- [self updateTopLinkData];
- }
- - (void)getTopLinkData {
- __weak typeof(self) weakSelf = self;
- [self.topVm getTopLinkList:^{
- [weakSelf updateTopLinkData];
- }];
- }
- - (void)getHomeListData {
- __weak typeof(self) weakSelf = self;
- [self.vm getHomeListData:^{
- [weakSelf.tableV.mj_header endRefreshing];
- [weakSelf.tableV reloadData];
- }];
- }
- - (void)getHomeTopData {
- __weak typeof(self) weakSelf = self;
- [self.vm getHomeTopData:^{
- [weakSelf.tableV reloadData];
- }];
- }
- - (void)updateTopLinkData {
- if (self.topVm.topLinks.count > 0) {
- self.activeV = [[ASHomeActiveView alloc] initWithFrame:CGRectZero];
- __weak typeof(self) weakSelf = self;
- [self.activeV setTapTopBlock:^(KWSearchHotKeyModel * _Nullable m) {
- NSLog(@"---toplink:-%@--", m.code);
- [weakSelf jumpWithModel:[m toJumpM]];
- }];
- self.tableV.tableHeaderView = self.activeV;
- [self.activeV setTopData:self.topVm.topLinks];
-
- } else {
- self.activeV.tapBlock = nil;
- self.activeV = nil;
- self.tableV.tableHeaderView = nil;
- }
- }
- - (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);
- }];
- __weak typeof(self) weakSelf = self;
- self.tableV.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
- [weakSelf getTopLinkData];
- [weakSelf getHomeTopData];
- [weakSelf getHomeListData];
-
- }];
- }
- // MARK: - UITableViewDelegate
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if (indexPath.section == 0) { // banner
- return;
- }
-
- }
- // MARK: - UITableViewDataSource
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return self.vm.listData.count + 3;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
-
- switch (section) {
- case 0:// banner
- return self.vm.banners.count > 0 ? 1 : 0;
- break;
- case 1:// category
- return self.vm.categorys.count > 0 ? 1 : 0;
- break;
- case 2:// tips
- return 1;
- default:
- {
- if (self.vm.listData.count < section-3) {
- return 0;
- }
- ASHomeMainListModel *m = self.vm.listData[section-3];
- NSInteger showtype = m.showType;
- switch (showtype) {
- case 1:// best seller
- return m.productList.count > 0 ? 1 : 0;
- case 2:// new in
- return m.productList.count > 0 ? 1 : 0;
- case 3://
- return m.imgUrl.length > 0 ? 1 : 0;
- case 4:// New Arrivals
- return m.productList.count > 0 ? 1 : 0;
- case 5:// 单图活动
- return m.imgUrl.length > 0 ? 1 : 0;
- case 6:// shop by looking
- return m.titleArr.count > 0 ? 1 : 0;
- case 7:// memship
- return m.imgUrl.length > 0 ? 1 : 0;
- // case 8:// video Active
- // return m.videoUrl.length > 0 ? 1 : 0;
- // case 9:// You may also like
- // return m.productList.count > 0 ? 1 : 0;
- // case 10:// today deals
- // return m.productList.count > 0 ? 1 : 0;
- // case 11: // 带背景色和图片的 cycle cell
- // return m.productList.count > 0 ? 1 : 0;
- default:
- return 0;
- }
- 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:[ASJumpModel class]]) {
- return;
- }
- ASJumpModel *m = (ASJumpModel *)model;
- [weak_self jumpWithModel:m];
- };
-
- [bcell showData:self.vm.banners];
- return bcell;
- }
- if (indexPath.section == 1) { // category
- ASCategaryListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASCategaryListCell" forIndexPath:indexPath];
- cell.arr = self.vm.categorys;
- cell.selectCategory = ^(ASJumpModel * _Nonnull model, NSIndexPath * _Nonnull index) {
- // TODO: - to productlist
- [self jumpWithModel:model];
- };
- return cell;
- }
- if (indexPath.section == 2) {
- ASHomeTipCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASHomeTipCell" forIndexPath:indexPath];
- return cell;
- }
- if (self.vm.listData.count <= indexPath.section-3) {
- return [UITableViewCell new];
- }
- ASHomeMainListModel *m = self.vm.listData[indexPath.section-3];
- __weak typeof(self) weakSelf = self;
- switch (m.showType) {
- case 1: {// bestSell
- ASHomeBestSellCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASHomeBestSellCell" forIndexPath:indexPath];
- cell.productClick = ^(NSInteger i, ASProductBaseModel * _Nonnull m) {
- [weakSelf goto_WKM_GoodsDetailsC:m.Id];
- };
- cell.model = m;
- return cell;
- }
- case 2: {
- ASHomeNewInCellTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASHomeNewInCellTableViewCell" forIndexPath:indexPath];
- cell.productClick = ^(NSInteger i, ASProductBaseModel * _Nonnull model) {
- [weakSelf goto_WKM_GoodsDetailsC: model.Id];
- };
- cell.addCartBlock = ^(NSInteger i, ASProductBaseModel * _Nonnull model) {
- [weakSelf action_GoodsSizeC: model.Id];
- };
- [cell setData:m];
- return cell;
- }
- case 3: {
- ASHomeImgCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASHomeImgCell" forIndexPath:indexPath];
- cell.tapImgBlock = ^{
- [weakSelf jumpWithModel:[m toJumpM]];
- };
- [cell setImgStr:m.imgUrl];
- return cell;
- }
- case 5: {
- ASHomeImgCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASHomeImgCell" forIndexPath:indexPath];
- cell.tapImgBlock = ^{
- [weakSelf jumpWithModel:[m toJumpM]];
- };
- [cell setImgStr:m.imgUrl];
- return cell;
- }
- case 7: {
- ASHomeImgCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASHomeImgCell" forIndexPath:indexPath];
- cell.tapImgBlock = ^{
- [weakSelf jumpWithModel:[m toJumpM]];
- };
- [cell setImgStr:m.imgUrl];
- return cell;
- }
- case 4: {
- ASHomeFlashDealCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASHomeFlashDealCell" forIndexPath:indexPath];
- cell.productClick = ^(NSInteger i, ASProductBaseModel * _Nonnull model) {
- [weakSelf goto_WKM_GoodsDetailsC:model.Id];
- };
- cell.proAddCartClick = ^(NSInteger i, ASProductBaseModel * _Nonnull model) {
- [weakSelf action_GoodsSizeC:model.Id];
- };
- cell.model = m;
- return cell;
- }
- case 6: {
- ASHomeLookingCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASHomeLookingCell" forIndexPath:indexPath];
- cell.itemClick = ^(NSInteger i, ASHomeCategoryModel * _Nonnull model) {
- [weakSelf jumpWithModel:[model toJumpM]];
- };
- 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
|