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

陈俊俊's avatar
陈俊俊 committed
18
#import "ICRAnnouncementViewController.h"
mei's avatar
mei committed
19

陈俊俊's avatar
陈俊俊 committed
20 21
#import "NewSurveyViewController.h"
#import "SurveyViewController.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"
zhu's avatar
zhu committed
27
#import "PurchaseNoticeViewController.h"
freecui's avatar
freecui committed
28

freecui's avatar
freecui committed
29
#import "GXFNewProcessViewController.h"
freecui's avatar
freecui committed
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 "GXFListProcessViewController.h"
freecui's avatar
freecui committed
36
#import "GXFFunctionDB.h"
37
#import "WriteFeedbackViewController.h"
管鹏飞's avatar
管鹏飞 committed
38
#import "MarketSurveyViewController.h"
freecui's avatar
freecui committed
39 40 41 42
#define ICRFUNCTION_IMG_TOP_PADDING   (25)
#define ICRFUNCTION_IMG_WIDTH         (65)
#define ICRFUNCTION_LABEL_HEIGHT      (15)
#define RIGHT_LINE_WIDTH              (0.5)
mei's avatar
mei committed
43
@interface ICRHomeViewController ()
44
<UITableViewDataSource,UITableViewDelegate,UICollectionViewDataSource,UICollectionViewDelegate,ICRFunctionBaseViewDelegate>//,UICollectionViewDelegateFlowLayout>
mei's avatar
mei committed
45

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

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

53 54


mei's avatar
mei committed
55 56 57
@end

@implementation ICRHomeViewController
freecui's avatar
freecui committed
58
static NSString *firestCellID = @"firestCell";
freecui's avatar
freecui committed
59
static NSString *secondCellID = @"secondCell";
freecui's avatar
freecui committed
60 61
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
- (void)viewWillAppear:(BOOL)animated {
 
freecui's avatar
freecui committed
72

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
    } else {
        return 44;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
freecui's avatar
freecui committed
187
    UITableViewCell *cell; //= [tableView dequeueReusableCellWithIdentifier:cellID];
mei's avatar
mei committed
188
    
freecui's avatar
freecui committed
189 190
   

freecui's avatar
freecui committed
191
        if (indexPath.section == 0) {
freecui's avatar
freecui committed
192 193 194 195 196 197
            cell = [tableView dequeueReusableCellWithIdentifier:firestCellID];
            if (!cell) {
                cell = [[GXFNoticeFunctionTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:firestCellID];
                cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
                cell.textLabel.text = @"查看行情反馈-进行中";
            }
freecui's avatar
freecui committed
198
        } else {
freecui's avatar
freecui committed
199 200 201 202 203 204 205 206 207
            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];
                }
            }
208
            [cell.contentView addSubview:_f_functionBaseView];
freecui's avatar
freecui committed
209 210 211 212 213 214 215 216 217 218 219
            NSLog(@"%@",NSStringFromCGRect(cell.frame));
        }
    
    return cell;
}

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


freecui's avatar
freecui committed
220 221 222 223 224 225
#pragma ICRFunctionBaseViewDelegate

- (void)ICRFunctionBaseView:(ICRFunctionItemControl *)imageView {
    switch (imageView.tag) {
        case kFunctionNotice://公告
        {
陈俊俊's avatar
陈俊俊 committed
226 227
            ICRAnnouncementViewController *aVC = [[ICRAnnouncementViewController alloc] init];
            [self PushViewController:aVC animated:YES];
freecui's avatar
freecui committed
228 229 230 231 232 233 234 235 236
        }
            break;
        case kFunctionNewSurvey://新建行情
        {
            NewSurveyViewController *svc = [[NewSurveyViewController alloc] init];
            svc.title = [IBTCommon localizableString:@"AddSurvey"];
            [self PushViewController:svc animated:YES];
        }
            break;
管鹏飞's avatar
管鹏飞 committed
237
        case kFunctionSeeSurvey://查看行情调研
AvatarC's avatar
AvatarC committed
238 239 240 241 242 243 244 245 246
        {
            SurveyViewController *svc = [[SurveyViewController alloc] init];
            svc.title = [IBTCommon localizableString:@"Survey"];
            svc.navigationItem.hidesBackButton = YES;
            [self PushViewController:svc animated:YES];
        }
            break;
            
        case  kFunctionFeedBackSurvey:   //填写行情反馈3
freecui's avatar
freecui committed
247
        {
管鹏飞's avatar
管鹏飞 committed
248 249 250 251 252 253
            MarketSurveyViewController *marketSurveyVC = [[MarketSurveyViewController alloc] init];
            marketSurveyVC.title = @"调研中";
            
            //WriteFeedbackViewController *svc = [[WriteFeedbackViewController alloc] init];

            [self PushViewController:marketSurveyVC animated:YES];
freecui's avatar
freecui committed
254 255 256 257 258 259 260 261 262 263 264
        }
            break;
        case kFunctionNewPurchaseNotice://新建采购通知单
        {
            NewPurchaseNoticeViewController *svc = [[NewPurchaseNoticeViewController alloc] init];
            svc.title = [IBTCommon localizableString:@"Survey2"];
            [self PushViewController:svc animated:YES];
        }
            break;
        case kFunctionSeePurchaseNotice://查看采购通知单
        {
zhu's avatar
zhu committed
265 266 267
            
            PurchaseNoticeViewController *svc =
            [[PurchaseNoticeViewController alloc] init];
freecui's avatar
freecui committed
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
            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
285 286 287 288 289 290 291 292 293
        }
            break;
        case kFunctionNewProcessing:{
            GXFNewProcessViewController *pvc = [[GXFNewProcessViewController alloc]init];
            //pvc.title = @"采购单";
            [self PushViewController:pvc animated:YES];
        }
            break;
        case kFunctionSeeProcessing:{
freecui's avatar
freecui committed
294
            GXFListProcessViewController *seeProcessVC= [[GXFListProcessViewController alloc]init];
freecui's avatar
freecui committed
295
            [self PushViewController:seeProcessVC animated:YES];
freecui's avatar
freecui committed
296 297 298 299 300
        }
            break;
        default:
            return;
            break;
mei's avatar
mei committed
301
    }
freecui's avatar
freecui committed
302 303 304
}


freecui's avatar
freecui committed
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324









//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
325 326 327 328 329 330 331 332 333 334
#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
335
    
freecui's avatar
freecui committed
336
   UICollectionViewCell *collectionCell = [collectionView dequeueReusableCellWithReuseIdentifier:collectionCellID forIndexPath:indexPath];
mei's avatar
mei committed
337
    
freecui's avatar
freecui committed
338 339 340 341 342 343 344 345 346 347
    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
348
        .origin.x = 0,
freecui's avatar
freecui committed
349 350 351 352 353 354 355 356 357 358 359 360 361
        .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
362 363
}

freecui's avatar
freecui committed
364 365 366 367 368 369 370 371
//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
372 373 374
}

@end