ICRHomeViewController.m 11.5 KB
Newer Older
mei's avatar
mei committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
//
//  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 "ICRTaskListViewController.h"
#import "ICRPatrolPlanViewController.h"
#import "ICRStoreListViewController.h"
#import "ICRStoreDetailViewController.h"
#import "ICRAnnouncementViewController.h"

#import "ICRFunctionBaseView.h"
#import "ICRFunctionEntity.h"
23

mei's avatar
mei committed
24

陈俊俊's avatar
陈俊俊 committed
25 26
#import "NewSurveyViewController.h"
#import "SurveyViewController.h"
陈俊俊's avatar
陈俊俊 committed
27
#import "AddWorkSheetViewController.h"
n22's avatar
n22 committed
28
#import "NewPurchaseViewController.h"
陈俊俊's avatar
陈俊俊 committed
29

freecui's avatar
freecui committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43


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


#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 49
@property (nonatomic, strong) UITableView *f_tableView;
@property (nonatomic, strong) NSArray *firstSectionArr;
@property (nonatomic, strong) NSArray *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 69
    
    
70 71
    
    
mei's avatar
mei committed
72
}
73

freecui's avatar
freecui committed
74 75 76 77
- (void)setupSubviews {
    [self setupRightBarBtn];
    [self setupTableView];
    [self setupColletionView];
78
    [self setupFunctionBaseView];
freecui's avatar
freecui committed
79 80 81 82 83 84 85 86 87 88
}
- (void)initData {
    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];
    self.secondSectionArr = @[dFuntionOne,dFuntionTwo];
    
    //self.firstSection =
mei's avatar
mei committed
89
}
freecui's avatar
freecui committed
90 91
- (void) setupRightBarBtn {
    UIBarButtonItem *rightBarBtn =  [[UIBarButtonItem alloc]initWithTitle:@"自定义功能" style:UIBarButtonItemStylePlain target:self action:@selector(defineFunctions)];
mei's avatar
mei committed
92

freecui's avatar
freecui committed
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
    self.navigationItem.rightBarButtonItem = rightBarBtn;
}

- (void)setupTableView {
    self.f_tableView = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStyleGrouped];
    self.f_tableView.dataSource = self;
    self.f_tableView.delegate = self;
    //[self.f_tableView dequeueReusableCellWithIdentifier ]
    [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
108
    
freecui's avatar
freecui committed
109 110 111 112 113 114 115
    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;
}
116 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 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178

- (void)setupFunctionBaseView {
    NSMutableArray *funtionEntitlesArr = [NSMutableArray array];
    
    NSArray *functionImageNames = @[ @"AnnouncementIcon",@"create_surver",@"watch_surver",@"create_surver_result",@"create_needs",@"watch_needs",@"create_purchase",@"watch_purchase",@"review_purchase",@"create_transport",@"watch_transort",@"create_process"];
    NSArray *functionNames = @[ [IBTCommon localizableString:@"Announcement"],
                               [IBTCommon localizableString:@"AddSurvey"],
                               [IBTCommon localizableString:@"Survey"],
                               [IBTCommon localizableString:@"Survey1"],
                               [IBTCommon localizableString:@"Survey2"],
                               [IBTCommon localizableString:@"Survey3"],
                               [IBTCommon localizableString:@"Survey4"],
                               [IBTCommon localizableString:@"Survey5"],
                               [IBTCommon localizableString:@"Survey6"],
                               [IBTCommon localizableString:@"Survey7"],
                               [IBTCommon localizableString:@"Survey8"],[IBTCommon localizableString:@"Survey9"],
                               ];
    NSArray *functionTags = @[ @(kFunctionNotice),
                               //公告
                               @(kFunctionNewSurvey),
                               //新建行情调研
                               @(kFunctionSeeSurvey),
                               //查看行情调研
                               @(kFunctionFeeBackSurvey),
                               //填写行情反馈
                               @(kFunctionNewPurchaseNotice),
                               //新建采购通知
                               @(kFunctionSeePurchaseNotice),
                               //查看采购通知
                               @(kFunctionNewPurchase),
                               //新建采购单
                               @(kFunctionSeePurchase),
                               //查看采购单
                               @(kFunctionExaminePurchas),
                               //审核采购单
                               @(kFunctionNewShipment),
                               //新建发运单
                               @(kFunctionSeeShipment),
                               //查看发运单
                               @(kFunctionNewProcessing)];
    //新建加工单
    
    int i = 0;
    for (NSString *functionName in functionNames) {
        ICRFunctionEntity *functionEntity = [[ICRFunctionEntity alloc]init];
        functionEntity.functionName = functionName;
        functionEntity.iconName = functionImageNames[i];
        // functionEntity.functionItemTag = []
        
        [funtionEntitlesArr addObject:functionEntity];
        i++;
    }
    
    self.f_functionBaseView = [ICRFunctionBaseView initWithFunctionData:funtionEntitlesArr];
    _f_functionBaseView.frame = (CGRect){
        .origin.x = 0,
        .origin.y =0,
        .size.width = CGRectGetWidth(self.view.frame),
        .size.height = CGRectGetHeight(self.view.frame),};
    _f_functionBaseView.backgroundColor = [UIColor clearColor];
    _f_functionBaseView.m_delegate = self;
    
}
freecui's avatar
freecui committed
179 180 181 182
#pragma BarButton Action
- (void)defineFunctions {
    GXFFunctionsViewController *functionsVc = [[GXFFunctionsViewController alloc]init];
    [self PushViewController:functionsVc animated:YES];
183

mei's avatar
mei committed
184
    
freecui's avatar
freecui committed
185 186 187 188 189 190 191 192 193 194 195 196
}

#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
197
    
freecui's avatar
freecui committed
198 199 200 201 202 203 204 205 206 207
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 1) {
        return 900;
    } else {
        return 44;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
mei's avatar
mei committed
208
    
freecui's avatar
freecui committed
209 210 211 212
    if (!cell) {
        if (indexPath.section == 0) {
            cell = [[GXFNoticeFunctionTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
213
            cell.textLabel.text = @"查看行情反馈-进行中";
freecui's avatar
freecui committed
214 215 216
        } else {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"secondCell"];
            //self.f_collectionView.size =
217
           // [cell.contentView addSubview:_f_collectionView];
freecui's avatar
freecui committed
218
      
219
            [cell.contentView addSubview:_f_functionBaseView];
freecui's avatar
freecui committed
220 221 222 223 224
            NSLog(@"%@",NSStringFromCGRect(cell.frame));
        }
    }
    
   // cell.selectionStyle = UITableViewCellSelectionStyleNone;
mei's avatar
mei committed
225
    
freecui's avatar
freecui committed
226 227 228 229 230 231 232 233 234 235 236 237
    return cell;
}

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


#pragma 给cell的内容赋值
- (void)p_contentToTableViewCell: (UITableViewCell *)cell andArray: (NSArray *)array {
    for (int count = 0; count < array.count; count ++) {
        GXFDisplayFunction *dFunction = (GXFDisplayFunction *)array[count];
238
        cell.imageView.image = [UIImage imageNamed:dFunction.functionSmallImgName];
freecui's avatar
freecui committed
239
        cell.textLabel.text = dFunction.functionName;
mei's avatar
mei committed
240
    }
freecui's avatar
freecui committed
241 242 243 244 245 246 247 248 249 250 251 252 253
}


#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
254
    
freecui's avatar
freecui committed
255
   UICollectionViewCell *collectionCell = [collectionView dequeueReusableCellWithReuseIdentifier:collectionCellID forIndexPath:indexPath];
mei's avatar
mei committed
256
    
freecui's avatar
freecui committed
257 258 259 260 261 262 263 264 265 266
    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
267
        .origin.x = 0,
freecui's avatar
freecui committed
268 269 270 271 272 273 274 275 276 277 278 279 280
        .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
281 282
}

freecui's avatar
freecui committed
283 284 285 286 287 288 289 290
//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
291 292 293
}

@end