ICRHomeViewController.m 13.2 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

freecui's avatar
freecui committed
28
#import "GXFNewProcessViewController.h"
freecui's avatar
freecui committed
29 30 31 32 33 34

#import "GXFFunctionsViewController.h"
#import "GXFDisplayFunction.h"
#import "GXFFunction.h"
#import "GXFNoticeFunctionTableViewCell.h"
#import "GXFFunctionCollectionViewCell.h"
freecui's avatar
freecui committed
35
#import "GXFSeeProcessViewController.h"
freecui's avatar
freecui committed
36

freecui's avatar
freecui committed
37

freecui's avatar
freecui committed
38

freecui's avatar
freecui committed
39 40
#import "GXFFunctionDB.h"

freecui's avatar
freecui committed
41 42 43 44 45
#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
46
@interface ICRHomeViewController ()
47
<UITableViewDataSource,UITableViewDelegate,UICollectionViewDataSource,UICollectionViewDelegate,ICRFunctionBaseViewDelegate>//,UICollectionViewDelegateFlowLayout>
mei's avatar
mei committed
48

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

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

56 57


mei's avatar
mei committed
58 59 60
@end

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

76

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


freecui's avatar
freecui committed
87 88 89 90 91
    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
92
    self.secondSectionArr = [NSMutableArray array];
freecui's avatar
freecui committed
93
    
freecui's avatar
freecui committed
94 95 96 97
    [self.secondSectionArr addObjectsFromArray:[[GXFFunctionDB sharedInstance]isSelectedDisplayFunctions]];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeSecondSectionArr) name:KNOTIFICATION_changeIsSelectedFunctions object:nil];
    }
freecui's avatar
freecui committed
98 99
- (void) setupRightBarBtn {
    UIBarButtonItem *rightBarBtn =  [[UIBarButtonItem alloc]initWithTitle:@"自定义功能" style:UIBarButtonItemStylePlain target:self action:@selector(defineFunctions)];
mei's avatar
mei committed
100

freecui's avatar
freecui committed
101 102 103 104
    self.navigationItem.rightBarButtonItem = rightBarBtn;
}

- (void)setupTableView {
freecui's avatar
freecui committed
105 106 107 108 109 110 111
    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
112 113 114 115 116 117 118 119 120
    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
121
    
freecui's avatar
freecui committed
122 123 124 125 126 127 128
    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;
}
129 130 131

- (void)setupFunctionBaseView {
    NSMutableArray *funtionEntitlesArr = [NSMutableArray array];
freecui's avatar
freecui committed
132
    for (GXFDisplayFunction *displayFunction in _secondSectionArr) {
133
        ICRFunctionEntity *functionEntity = [[ICRFunctionEntity alloc]init];
freecui's avatar
freecui committed
134 135
        functionEntity.functionName = displayFunction.functionName;
        functionEntity.iconName = displayFunction.functionImgName;
freecui's avatar
freecui committed
136
        functionEntity.functionItemTag = displayFunction.functionItemTag;
137 138 139 140 141 142 143 144
        [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
145
        .size.height = _f_functionBaseView.height};//CGRectGetHeight(self.view.frame),};
146 147 148 149
    _f_functionBaseView.backgroundColor = [UIColor clearColor];
    _f_functionBaseView.m_delegate = self;
    
}
freecui's avatar
freecui committed
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164

#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
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
- (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
180
    
freecui's avatar
freecui committed
181 182 183
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 1) {
freecui's avatar
freecui committed
184
        return _f_functionBaseView.height ;
freecui's avatar
freecui committed
185 186 187 188 189
    } else {
        return 44;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
freecui's avatar
freecui committed
190
    UITableViewCell *cell; //= [tableView dequeueReusableCellWithIdentifier:cellID];
mei's avatar
mei committed
191
    
freecui's avatar
freecui committed
192 193
   

freecui's avatar
freecui committed
194
        if (indexPath.section == 0) {
freecui's avatar
freecui committed
195 196 197 198 199 200
            cell = [tableView dequeueReusableCellWithIdentifier:firestCellID];
            if (!cell) {
                cell = [[GXFNoticeFunctionTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:firestCellID];
                cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
                cell.textLabel.text = @"查看行情反馈-进行中";
            }
freecui's avatar
freecui committed
201
        } else {
freecui's avatar
freecui committed
202 203 204 205 206 207 208 209 210
            cell = [tableView dequeueReusableCellWithIdentifier:secondCellID];
            if (!cell) {
                cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:secondCellID];
               
            } else {
                while ([cell.contentView.subviews lastObject] != nil) {
                    [(UIView *)[cell.contentView.subviews lastObject]removeFromSuperview];
                }
            }
211
            [cell.contentView addSubview:_f_functionBaseView];
freecui's avatar
freecui committed
212 213 214 215 216 217 218 219 220 221 222
            NSLog(@"%@",NSStringFromCGRect(cell.frame));
        }
    
    return cell;
}

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


freecui's avatar
freecui committed
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 267 268 269 270 271 272 273 274 275
#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];
freecui's avatar
freecui committed
276 277 278 279 280 281 282 283 284
        }
            break;
        case kFunctionNewProcessing:{
            GXFNewProcessViewController *pvc = [[GXFNewProcessViewController alloc]init];
            //pvc.title = @"采购单";
            [self PushViewController:pvc animated:YES];
        }
            break;
        case kFunctionSeeProcessing:{
freecui's avatar
freecui committed
285 286
            GXFSeeProcessViewController *seeProcessVC= [[GXFSeeProcessViewController alloc]init];
            [self PushViewController:seeProcessVC animated:YES];
freecui's avatar
freecui committed
287 288 289 290 291
        }
            break;
        default:
            return;
            break;
mei's avatar
mei committed
292
    }
freecui's avatar
freecui committed
293 294 295
}


freecui's avatar
freecui committed
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315









//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
316 317 318 319 320 321 322 323 324 325
#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
326
    
freecui's avatar
freecui committed
327
   UICollectionViewCell *collectionCell = [collectionView dequeueReusableCellWithReuseIdentifier:collectionCellID forIndexPath:indexPath];
mei's avatar
mei committed
328
    
freecui's avatar
freecui committed
329 330 331 332 333 334 335 336 337 338
    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
339
        .origin.x = 0,
freecui's avatar
freecui committed
340 341 342 343 344 345 346 347 348 349 350 351 352
        .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
353 354
}

freecui's avatar
freecui committed
355 356 357 358 359 360 361 362
//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
363 364 365
}

@end