CNLiveCommuntViewController.m 10.6 KB
//
//  CNLiveCommuntViewController.m
//  AFNetworking
//
//  Created by open on 2022/2/1.
//

#import "CNLiveCommuntViewController.h"

#import "CNLiveCommuntPartyViewController.h"
#import "CNLiveCommuntConsuViewController.h"
#import "CNLiveCommuntActiviViewController.h"
#import "CNLiveCommuntServiceViewController.h"
@interface CNLiveCommuntViewController ()
@property (nonatomic, copy) NSString *nbhdId;
@end

@implementation CNLiveCommuntViewController

- (instancetype)initWithNBhdId:(NSString *)nbhdId
{
    self = [super init];
    if (self) {
        _nbhdId = nbhdId;
    }
    return self;
}
-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    NSMutableArray * tempArray = [[NSMutableArray alloc] initWithArray:self.navigationController.viewControllers];
    for (UIViewController * vc in self.navigationController.viewControllers) {
        if ([vc isKindOfClass:CNLiveCommuntyHomeListViewController.class]) {
            [tempArray removeObject:vc];
            break;
        }
    }
    self.navigationController.viewControllers = tempArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.selectColor = [UIColor colorWithHexString:@"0xCD0302"];
    self.normalColor = [UIColor colorWithHexString:@"0x979797"];
    self.hidesBottomBarWhenPushed = YES;
    self.tabBar.backgroundColor = UIColorHex(#f9f9f9);

    __weak typeof(self) weakSelf = self;
    [QMUITips showLoadingInView:self.view];
    [CNLiveCommuntViewModel requestWithCommuntyHomeNBhdAppIndexWithNBhdId:self.nbhdId CompleterBlock:^(NSArray * _Nonnull homeArray) {
        if (homeArray) {
            __block NSMutableArray * array = [[NSMutableArray alloc] init];
            for (CNLiveCommuntyHomeModel * homeModel in homeArray) {
                if ([homeModel.columnColour isNotBlank]) weakSelf.selectColor = [UIColor colorWithHexString:homeModel.columnColour];
                if ([homeModel.columnColourUncheck isNotBlank]) weakSelf.normalColor = [UIColor colorWithHexString:homeModel.columnColourUncheck];
                [weakSelf settingTabberWithImages:@[homeModel.columnImgUncheck,homeModel.columnImg] CompleterBlock:^(NSDictionary *tempDict) {
                    NSMutableDictionary * dict = [[NSMutableDictionary alloc] init];
                    [dict addEntriesFromDictionary:tempDict];
                    [dict setObject:homeModel forKey:@"model"];
                    [array addObject:dict];
                    if (array.count == homeArray.count) {
                        [QMUITips hideAllTipsInView:weakSelf.view];
                        weakSelf.tabBar.backgroundColor = [UIColor whiteColor];
                        for (NSDictionary * subDict in array) {
                            CNLiveCommuntyHomeModel * homeModel = [subDict objectForKey:@"model"];
                            UIImage *nomal_image = [[UIImage alloc] initWithData:[subDict objectForKey:@"nomal"]];
                            UIImage *select_image = [[UIImage alloc] initWithData:[subDict objectForKey:@"select"]];
                            if (homeModel.contentColumnList.count > 0) {
                                CNLiveCommuntConsuViewController * vc = [[CNLiveCommuntConsuViewController alloc] initWithHomeArray:homeModel.contentColumnList titles:homeModel.titles NBhdId:weakSelf.nbhdId];
                                vc.title = homeModel.columnName;
                                vc.view.backgroundColor = [UIColor whiteColor];
                                [weakSelf addChildViewController:vc noralImage:nomal_image selectImage:select_image];
                            }else{
                                if ([homeModel.type isEqualToString:@"3"]) {//生活服务界面 原生
                                    if ([homeModel.cmsPageType isEqualToString:@"1"]) {
                                        CNLiveCommuntActiviViewController * vc = [[CNLiveCommuntActiviViewController alloc] initWithWebUrl:homeModel.cmsPageUrl isRootVC:YES Type:@"1"];
                                        vc.title = homeModel.columnName;
                                        vc.view.backgroundColor = [UIColor whiteColor];
                                        [weakSelf addChildViewController:vc noralImage:nomal_image selectImage:select_image];
                                    }else{
                                        CNLiveCommuntServiceViewController * vc = [[CNLiveCommuntServiceViewController alloc] initWithHomeModel:homeModel isRootVC:YES isShowLocation:YES];
                                        vc.title = homeModel.columnName;
                                        vc.view.backgroundColor = [UIColor whiteColor];
                                        [weakSelf addChildViewController:vc noralImage:nomal_image selectImage:select_image];
                                    }
                                }
                                if ([homeModel.type isEqualToString:@"2"]) {
                                    CNLiveCommuntListViewController * vc = [[CNLiveCommuntListViewController alloc] initWithShowType:CNLiveCommuntListShowTypeHome NBhdId:homeModel.idStr];
                                    vc.title = homeModel.columnName;
                                    vc.view.backgroundColor = [UIColor whiteColor];
                                    [weakSelf addChildViewController:vc noralImage:nomal_image selectImage:select_image];
                                }
                                if (![homeModel.type isNotBlank] && [homeModel.cmsPageType isNotBlank] && ![homeModel.cmsPageType isEqualToString:@"4"]) {
                                    CNLiveCommuntActiviViewController * vc = [[CNLiveCommuntActiviViewController alloc] initWithWebUrl:homeModel.cmsPageUrl isRootVC:YES Type:homeModel.cmsPageType];
                                    vc.title = homeModel.columnName;
                                    vc.view.backgroundColor = [UIColor whiteColor];
                                    [weakSelf addChildViewController:vc noralImage:nomal_image selectImage:select_image];
                                }
                                if (![homeModel.type isNotBlank] && [homeModel.cmsPageType isEqualToString:@"4"]) {
                                    CNLiveCommuntServiceViewController * vc = [[CNLiveCommuntServiceViewController alloc] initWithHomeModel:homeModel isRootVC:YES isShowLocation:NO];
                                    vc.title = homeModel.columnName;
                                    vc.view.backgroundColor = [UIColor whiteColor];
                                    [weakSelf addChildViewController:vc noralImage:nomal_image selectImage:select_image];
                                }
                                if (![homeModel.type isNotBlank] && ![homeModel.cmsPageType isNotBlank] && [homeModel.cmsPageUrl isNotBlank]) {
                                    CNLiveCommuntActiviViewController * vc = [[CNLiveCommuntActiviViewController alloc] initWithWebUrl:homeModel.cmsPageUrl isRootVC:YES Type:@"1"];
                                    vc.title = homeModel.columnName;
                                    vc.view.backgroundColor = [UIColor whiteColor];
                                    [weakSelf addChildViewController:vc noralImage:nomal_image selectImage:select_image];
                                }
                            }
                        }
                    }
                }];
            }
        }else{
            NSString * nb_info =  (NSString *)[[NSUserDefaults standardUserDefaults] objectForKey:[NSString stringWithFormat:@"%@%@",kCNLiveCommuntyNBhdInfoIdentifier,[CNUserInfoManager manager].userInfoModel.uid]];
            if ([nb_info isNotBlank]) {
                CNLiveCommuntyHomeListViewController * listView = [[CNLiveCommuntyHomeListViewController alloc] init];
                [weakSelf.navigationController dsPushViewController:listView animated:YES];
            }else{
                [QMUITips hideAllTipsInView:weakSelf.view];
                [weakSelf.navigationController popViewControllerAnimated:YES];
            }
        }
    }];
}

-(void)settingTabberWithImages:(NSArray *)images CompleterBlock:(void(^)(NSDictionary * tempDict))completerBlock
{
    __block NSMutableDictionary * tempDict = [[NSMutableDictionary alloc] init];
    for (int i = 0; i < images.count; i++) {
        NSString * imageUrl = images[i];
        if ([imageUrl isNotBlank]) {
            [SDWebImageManager.sharedManager loadImageWithURL:[NSURL URLWithString:imageUrl] options:SDWebImageRetryFailed progress:NULL completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
                [tempDict setObject:UIImagePNGRepresentation(image) forKey:[images indexOfObject:imageURL.absoluteString] == 0 ? @"nomal" : @"select"];
                if (tempDict.count == images.count && completerBlock) completerBlock(tempDict);
            }];
        }
    }
}

-(void)settingTabBar
{
    //带分页的显示界面的
    CNLiveCommuntConsuViewController * vc02 = [[CNLiveCommuntConsuViewController alloc] init];
    vc02.title = @"权威资讯";
    vc02.view.backgroundColor = [UIColor whiteColor];
    [self addChildViewController:vc02 noralImage:[CNLiveCommuntTools cCommunt_setImageWithName:@"c_community_consu_nomal"] selectImage:[CNLiveCommuntTools cCommunt_setImageWithName:@"c_community_consu_select"]];
    
    //准备放WebView的
    CNLiveCommuntPartyViewController * vc01 = [[CNLiveCommuntPartyViewController alloc] init];
    vc01.title = @"数字党建";
    vc01.view.backgroundColor = [UIColor whiteColor];
    [self addChildViewController:vc01 noralImage:[CNLiveCommuntTools cCommunt_setImageWithName:@"c_community_party_nomal"] selectImage:[CNLiveCommuntTools cCommunt_setImageWithName:@"c_community_party_select"]];
    
    CNLiveCommuntActiviViewController * vc03 = [[CNLiveCommuntActiviViewController alloc] init];
    vc03.title = @"公益活动";
    vc03.view.backgroundColor = [UIColor whiteColor];
    [self addChildViewController:vc03 noralImage:[CNLiveCommuntTools cCommunt_setImageWithName:@"c_community_public_nomal"] selectImage:[CNLiveCommuntTools cCommunt_setImageWithName:@"c_community_public_select"]];
    
    //块状结构的
    CNLiveCommuntServiceViewController * vc04 = [[CNLiveCommuntServiceViewController alloc] init];
    vc04.title = @"生活服务";
    vc04.view.backgroundColor = [UIColor whiteColor];
    [self addChildViewController:vc04 noralImage:[CNLiveCommuntTools cCommunt_setImageWithName:@"c_community_service_nomal"] selectImage:[CNLiveCommuntTools cCommunt_setImageWithName:@"c_community_service_select"]];
}


@end