ICRHomeViewController.m 12.1 KB
Newer Older
mei's avatar
mei committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
//
//  ICRHomeViewController.m
//  XFFruit
//
//  Created by Xummer on 3/24/15.
//  Copyright (c) 2015 Xummer. All rights reserved.
//

#define M_HEAD_IMG_VIEW_HEIGHT               (190)
#define M_HEAD_VIEW_TITLE_LABEL_HEIGHT       (30)
#define M_HEAD_IMG_HEIGHT_WIDTH_PROPORTION   190.0f/320.0f

#import "ICRHomeViewController.h"

#import "ICRFunctionBaseView.h"
#import "ICRFunctionEntity.h"
17

mei's avatar
mei committed
18

陈俊俊's avatar
陈俊俊 committed
19 20
#import "NewSurveyViewController.h"
#import "SurveyViewController.h"
陈俊俊's avatar
陈俊俊 committed
21
#import "AddWorkSheetViewController.h"
n22's avatar
n22 committed
22
#import "NewPurchaseViewController.h"
freecui's avatar
freecui committed
23 24 25 26
#import "NewPurchaseNoticeViewController.h"
#import "SeePurchaseNoticeViewController.h"
#import "NewPurchaseViewController.h"
#import "PurchaseViewController.h"
freecui's avatar
freecui committed
27 28 29 30 31 32 33 34 35


#import "GXFFunctionsViewController.h"
#import "GXFDisplayFunction.h"
#import "GXFFunction.h"
#import "GXFNoticeFunctionTableViewCell.h"
#import "GXFFunctionCollectionViewCell.h"


freecui's avatar
freecui committed
36

freecui's avatar
freecui committed
37 38
#import "GXFFunctionDB.h"

freecui's avatar
freecui committed
39 40 41 42 43
#define ICRFUNCTION_IMG_TOP_PADDING   (25)
#define ICRFUNCTION_IMG_WIDTH         (65)
#define ICRFUNCTION_LABEL_HEIGHT      (15)
#define ICRFUNCTION_INNER_GAP         (5)
#define RIGHT_LINE_WIDTH              (0.5)
mei's avatar
mei committed
44
@interface ICRHomeViewController ()
45
<UITableViewDataSource,UITableViewDelegate,UICollectionViewDataSource,UICollectionViewDelegate,ICRFunctionBaseViewDelegate>//,UICollectionViewDelegateFlowLayout>
mei's avatar
mei committed
46

freecui's avatar
freecui committed
47 48
@property (nonatomic, strong) UITableView *f_tableView;
@property (nonatomic, strong) NSArray *firstSectionArr;
freecui's avatar
freecui committed
49
@property (nonatomic, strong) NSMutableArray *secondSectionArr;
50 51

@property (nonatomic, strong) ICRFunctionBaseView *f_functionBaseView;
freecui's avatar
freecui committed
52
@property (nonatomic, strong) UICollectionView *f_collectionView;
mei's avatar
mei committed
53

54 55


mei's avatar
mei committed
56 57 58
@end

@implementation ICRHomeViewController
freecui's avatar
freecui committed
59 60 61
static NSString *cellID = @"cell";
static NSString *collectionCellID = @"collectionCell";
//static CGFloat  colletionCellHeight [UIScreen mainScreen].bounds.size.width / 3.0
mei's avatar
mei committed
62 63 64 65
#pragma mark - Life Cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
freecui's avatar
freecui committed
66
    [self initData];
mei's avatar
mei committed
67
    [self setupSubviews];
freecui's avatar
freecui committed
68
    
mei's avatar
mei committed
69
}
freecui's avatar
freecui committed
70 71 72
- (void)viewWillAppear:(BOOL)animated {
 
    
73

freecui's avatar
freecui committed
74
}
freecui's avatar
freecui committed
75 76 77
- (void)setupSubviews {
    [self setupRightBarBtn];
    [self setupTableView];
freecui's avatar
freecui committed
78
   // [self setupColletionView];
79
    [self setupFunctionBaseView];
freecui's avatar
freecui committed
80 81
}
- (void)initData {
freecui's avatar
freecui committed
82 83


freecui's avatar
freecui committed
84 85 86 87 88
    NSDictionary *dictOne = @{@"Id":@(1),@"functionName":@"新建行情反馈",@"imgName":@"RefreshBtn",@"isSelected":@(0)};
    NSDictionary *dictTwo = @{@"Id":@(2),@"functionName":@"查询行情反馈",@"imgName":@"RefreshBtn",@"isSelected":@(1)};
    GXFDisplayFunction *dFuntionOne = [[GXFDisplayFunction alloc]initWithDictionary:dictOne];
    GXFDisplayFunction *dFuntionTwo = [[GXFDisplayFunction alloc]initWithDictionary:dictTwo];
    self.firstSectionArr = @[dFuntionOne,dFuntionTwo];
freecui's avatar
freecui committed
89
    self.secondSectionArr = [NSMutableArray array];
freecui's avatar
freecui committed
90
    
freecui's avatar
freecui committed
91 92 93 94
    [self.secondSectionArr addObjectsFromArray:[[GXFFunctionDB sharedInstance]isSelectedDisplayFunctions]];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeSecondSectionArr) name:KNOTIFICATION_changeIsSelectedFunctions object:nil];
    }
freecui's avatar
freecui committed
95 96
- (void) setupRightBarBtn {
    UIBarButtonItem *rightBarBtn =  [[UIBarButtonItem alloc]initWithTitle:@"自定义功能" style:UIBarButtonItemStylePlain target:self action:@selector(defineFunctions)];
mei's avatar
mei committed
97

freecui's avatar
freecui committed
98 99 100 101
    self.navigationItem.rightBarButtonItem = rightBarBtn;
}

- (void)setupTableView {
freecui's avatar
freecui committed
102 103 104 105 106 107 108
    self.f_tableView = [[UITableView alloc]initWithFrame:(CGRect){
        .origin.x = 0,
        .origin.y =0,
        .size.width = self.view.width,
        .size.height = self.view.height - 80}
    style:UITableViewStyleGrouped];
    
freecui's avatar
freecui committed
109 110 111 112 113 114 115 116 117
    self.f_tableView.dataSource = self;
    self.f_tableView.delegate = self;
    [self.view addSubview:_f_tableView];
}

- (void)setupColletionView {
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
   // [flowLayout setItemSize:CGSizeMake(MODULE_VIEW_WIDTH, MODULE_VIEW_WIDTH)];
mei's avatar
mei committed
118
    
freecui's avatar
freecui committed
119 120 121 122 123 124 125
    self.f_collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, self.view.width, 600) collectionViewLayout:flowLayout];
    //self.f_collectionView.collectionViewLayout = flowLayout;
    [self.f_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:collectionCellID];
    _f_collectionView.backgroundColor = [UIColor whiteColor];
    self.f_collectionView.dataSource = self;
    self.f_collectionView.delegate = self;
}
126 127 128

- (void)setupFunctionBaseView {
    NSMutableArray *funtionEntitlesArr = [NSMutableArray array];
freecui's avatar
freecui committed
129
    for (GXFDisplayFunction *displayFunction in _secondSectionArr) {
130
        ICRFunctionEntity *functionEntity = [[ICRFunctionEntity alloc]init];
freecui's avatar
freecui committed
131 132
        functionEntity.functionName = displayFunction.functionName;
        functionEntity.iconName = displayFunction.functionImgName;
freecui's avatar
freecui committed
133
        functionEntity.functionItemTag = displayFunction.functionItemTag;
134 135 136 137 138 139 140 141
        [funtionEntitlesArr addObject:functionEntity];
    }
    
    self.f_functionBaseView = [ICRFunctionBaseView initWithFunctionData:funtionEntitlesArr];
    _f_functionBaseView.frame = (CGRect){
        .origin.x = 0,
        .origin.y =0,
        .size.width = CGRectGetWidth(self.view.frame),
freecui's avatar
freecui committed
142
        .size.height = _f_functionBaseView.height};//CGRectGetHeight(self.view.frame),};
143 144 145 146
    _f_functionBaseView.backgroundColor = [UIColor clearColor];
    _f_functionBaseView.m_delegate = self;
    
}
freecui's avatar
freecui committed
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161

#pragma Notification
- (void)changeSecondSectionArr {
    if (_secondSectionArr.count ) {
        [_secondSectionArr removeAllObjects];
        [self.secondSectionArr addObjectsFromArray:[[GXFFunctionDB sharedInstance]isSelectedDisplayFunctions]];
    }
    if (_f_functionBaseView) {
        [_f_functionBaseView removeFromSuperview];
        _f_functionBaseView = nil;
        [self setupFunctionBaseView];
    }
    [_f_tableView reloadData];
}
#pragma rightBarButton Action
freecui's avatar
freecui committed
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
- (void)defineFunctions {
    GXFFunctionsViewController *functionsVc = [[GXFFunctionsViewController alloc]init];
    [self PushViewController:functionsVc animated:YES];
}

#pragma UITablewViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return _firstSectionArr.count;
    } else {
        return 1;
    }
mei's avatar
mei committed
177
    
freecui's avatar
freecui committed
178 179 180
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 1) {
freecui's avatar
freecui committed
181
        return _f_functionBaseView.height ;
freecui's avatar
freecui committed
182 183 184 185 186 187
    } else {
        return 44;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
mei's avatar
mei committed
188
    
freecui's avatar
freecui committed
189 190 191 192
    if (!cell) {
        if (indexPath.section == 0) {
            cell = [[GXFNoticeFunctionTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
193
            cell.textLabel.text = @"查看行情反馈-进行中";
freecui's avatar
freecui committed
194 195
        } else {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"secondCell"];
196
            [cell.contentView addSubview:_f_functionBaseView];
freecui's avatar
freecui committed
197 198 199 200 201 202 203 204 205 206 207 208
            NSLog(@"%@",NSStringFromCGRect(cell.frame));
        }
    }
    
    return cell;
}

#pragma UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}


freecui's avatar
freecui committed
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
#pragma ICRFunctionBaseViewDelegate

- (void)ICRFunctionBaseView:(ICRFunctionItemControl *)imageView {
    switch (imageView.tag) {
        case kFunctionNotice://公告
        {
//            ICRAnnouncementViewController *aVC = [[ICRAnnouncementViewController alloc] init];
//            [self PushViewController:aVC animated:YES];
        }
            break;
        case kFunctionNewSurvey://新建行情
        {
            NewSurveyViewController *svc = [[NewSurveyViewController alloc] init];
            svc.title = [IBTCommon localizableString:@"AddSurvey"];
            [self PushViewController:svc animated:YES];
        }
            break;
        case kFunctionSeeSurvey://查看行情
        {
            SurveyViewController *svc = [[SurveyViewController alloc] init];
            svc.title = [IBTCommon localizableString:@"Survey"];
            svc.navigationItem.hidesBackButton = YES;
            [self PushViewController:svc animated:YES];
        }
            break;
        case kFunctionNewPurchaseNotice://新建采购通知单
        {
            NewPurchaseNoticeViewController *svc = [[NewPurchaseNoticeViewController alloc] init];
            svc.title = [IBTCommon localizableString:@"Survey2"];
            [self PushViewController:svc animated:YES];
        }
            break;
        case kFunctionSeePurchaseNotice://查看采购通知单
        {
            SeePurchaseNoticeViewController *svc =
            [[SeePurchaseNoticeViewController alloc] init];
            svc.title = [IBTCommon localizableString:@"Survey3"];
            [self PushViewController:svc animated:YES];
        }
            break;
            
        case kFunctionNewPurchase://新建采购单
        {
            NewPurchaseViewController *nvc = [[NewPurchaseViewController alloc]init];
            nvc.title = @"新建采购单";
            [self PushViewController:nvc animated:YES];
            
        }
            break;
        case kFunctionSeePurchase:{
            PurchaseViewController *pvc = [[PurchaseViewController alloc]init];
            pvc.title = @"采购单";
            [self PushViewController:pvc animated:YES];
        }
            break;
        default:
            return;
            break;
mei's avatar
mei committed
267
    }
freecui's avatar
freecui committed
268 269 270
}


freecui's avatar
freecui committed
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290









//UICollectionView
//#pragma 给cell的内容赋值
//- (void)p_contentToTableViewCell: (UITableViewCell *)cell andArray: (NSArray *)array {
//    for (int count = 0; count < array.count; count ++) {
//        GXFDisplayFunction *dFunction = (GXFDisplayFunction *)array[count];
//        cell.imageView.image = [UIImage imageNamed:dFunction.functionSmallImgName];
//        cell.textLabel.text = dFunction.functionName;
//    }
//}


freecui's avatar
freecui committed
291 292 293 294 295 296 297 298 299 300
#pragma UICollectionViewDataSource,UICollectionViewDelegate

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 6;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
mei's avatar
mei committed
301
    
freecui's avatar
freecui committed
302
   UICollectionViewCell *collectionCell = [collectionView dequeueReusableCellWithReuseIdentifier:collectionCellID forIndexPath:indexPath];
mei's avatar
mei committed
303
    
freecui's avatar
freecui committed
304 305 306 307 308 309 310 311 312 313
    UIImageView *functionImg =[[UIImageView alloc]initWithFrame:(CGRect){
        .origin.x = (CGRectGetWidth(collectionCell.frame) - ICRFUNCTION_IMG_WIDTH)/2,
        .origin.y = ICRFUNCTION_IMG_TOP_PADDING,
        .size.width = ICRFUNCTION_IMG_WIDTH,
        .size.height = ICRFUNCTION_IMG_WIDTH
    }];
    functionImg.image = [UIImage imageNamed:@"create_purchase"];
    [collectionCell.contentView addSubview:functionImg];
    
    UILabel *lbl = [[UILabel alloc]initWithFrame:(CGRect){
mei's avatar
mei committed
314
        .origin.x = 0,
freecui's avatar
freecui committed
315 316 317 318 319 320 321 322 323 324 325 326 327
        .origin.y = CGRectGetMaxY(functionImg.frame) + ICRFUNCTION_INNER_GAP,
        .size.width = collectionCell.width,
        .size.height = ICRFUNCTION_LABEL_HEIGHT
  
    }];
    lbl.textAlignment = NSTextAlignmentCenter;
    lbl.tintColor = [UIColor blackColor];
    lbl.text = @"kkk";
    [collectionCell.contentView addSubview:lbl];


    //collectionCell.backgroundColor = [UIColor yellowColor];
    return collectionCell;
mei's avatar
mei committed
328 329
}

freecui's avatar
freecui committed
330 331 332 333 334 335 336 337
//UICollectionViewDelegateFlowLayout是UICollectionViewDelegate的子协议
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    CGFloat width = self.view.width / 3.0;
     return CGSizeMake((self.view.width - 30) / 3.0,width);
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    //top, CGFloat left, CGFloat bottom, CGFloat right
    return UIEdgeInsetsMake(0, 5, 0, 5);
mei's avatar
mei committed
338 339 340
}

@end