BusinessCollectionViewController.m 5.63 KB
Newer Older
Sandy's avatar
Sandy committed
1 2 3 4 5 6 7 8 9
//
//  BusinessCollectionViewController.m
//  RealEstateManagement
//
//  Created by Z on 16/7/29.
//  Copyright © 2016年 上海勾芒信息科技. All rights reserved.
//

#import "BusinessCollectionViewController.h"
10 11
#import "BusinessFunctionModel.h"
#import "SaleInputListViewController.h"
Sandy's avatar
Sandy committed
12 13 14 15 16 17 18 19 20 21 22 23 24
@interface BusinessCollectionViewController ()

@property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *layout;
@property (nonatomic, strong) NSMutableArray *arrFunction;
@end

@implementation BusinessCollectionViewController

static NSString *const reuseIdentifier = @"Cell";

- (void)viewDidLoad
{
    [super viewDidLoad];
Sandy's avatar
Sandy committed
25
    self.tabBarController.title = @"业务";
Sandy's avatar
Sandy committed
26 27 28 29 30
    self.layout.itemSize = CGSizeMake((kWidth - 5 * 10) / 4, (kWidth - 5 * 10) / 4 + 25);
    self.layout.minimumLineSpacing = 10;
    self.layout.minimumInteritemSpacing = 10;
    self.layout.headerReferenceSize = CGSizeMake(kWidth, 40);
    self.collectionView.contentInset = UIEdgeInsetsMake(0, 0, 49, 0);
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
    
    NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"BusinessItems" ofType:@"plist"];
    NSArray *arrData = [[NSArray alloc] initWithContentsOfFile:plistPath];
    CLog(@"%@", arrData);
    self.arrFunction = [NSMutableArray array];
    for (NSDictionary *dic in arrData) {
        
        //增加菜单需要在BusinessFunctionModel里面增加枚举项
#ifdef DEBUG
        //              没有权限控制
        //        BusinessFunctionModel *model = [BusinessFunctionModel modelObjectWithDictionary:dic];
        //
        //              权限控制
        BusinessFunctionModel *model = [[BusinessFunctionModel alloc] initWithDictionaryPermissionControl:dic];
#else
        BusinessFunctionModel *model = [[BusinessFunctionModel alloc] initWithDictionaryPermissionControl:dic];
#endif
        
        
        if (model.function.count > 0) {
            [self.arrFunction addObject:model];
        }
    }
}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    UICollectionReusableView *header = nil;
    if (kind == UICollectionElementKindSectionHeader) {
        header = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"businessHeader" forIndexPath:indexPath];
    }
    
    UILabel *title = (UILabel *)[header viewWithTag:110];
    UIImageView *image = (UIImageView *)[header viewWithTag:111];
    [image.image resizableImageWithCapInsets:UIEdgeInsetsMake(0, 39, 0, 40) resizingMode:UIImageResizingModeTile];
    NSString *txt = [self.arrFunction[indexPath.section] headerTitle];
    title.text = txt;
    
    return header;
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return self.arrFunction.count;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    BusinessFunctionModel *model = self.arrFunction[section];
    return model.function.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    BusinessFunctionModel *model = self.arrFunction[indexPath.section];
    BusinessFunction *founction = model.function[indexPath.row];
    UILabel *title = (UILabel *)[cell viewWithTag:110];
    title.text = founction.functionName;
    UIImageView *img = (UIImageView *)[cell viewWithTag:111];
    img.image = [UIImage imageNamed:founction.functionPic];
    // Configure the cell
    
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    BusinessFunctionModel *functions = self.arrFunction[indexPath.section];
    BusinessFunction *function = functions.function[indexPath.row];
    switch (function.type) {
        case functionTypeSaleInput:
        {
            SaleInputListViewController *saleVC = [SaleInputListViewController viewControllerWithStoryBoardType:STORYBOARD_TYPE_SALEINPUT];
            [self.navigationController pushViewController:saleVC animated:YES];
        }
            break;
            
        default:
            break;
    }
Sandy's avatar
Sandy committed
111 112 113 114 115
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
116
    [self.navigationController setNavigationBarHidden:NO animated:NO];
Sandy's avatar
Sandy committed
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark <UICollectionViewDelegate>

/*
 // Uncomment this method to specify if the specified item should be highlighted during tracking
 - (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath {
 return YES;
 }
 */

/*
 // Uncomment this method to specify if the specified item should be selected
 - (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {
 return YES;
 }
 */

/*
 // Uncomment these methods to specify if an action menu should be displayed for the specified item, and react to actions performed on the item
 - (BOOL)collectionView:(UICollectionView *)collectionView shouldShowMenuForItemAtIndexPath:(NSIndexPath *)indexPath {
 return NO;
 }
 
 - (BOOL)collectionView:(UICollectionView *)collectionView canPerformAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
 return NO;
 }
 
 - (void)collectionView:(UICollectionView *)collectionView performAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
 
 }
 */

@end