InspectTaskViewController.m 7.19 KB
Newer Older
admin's avatar
admin committed
1 2 3 4 5 6 7 8 9
//
//  InspectTaskViewController.m
//  redstar
//
//  Created by admin on 15/10/27.
//  Copyright © 2015年 ZWF. All rights reserved.
//

#import "InspectTaskViewController.h"
10
#import "InspectSettleViewController.h"
11 12 13 14 15 16 17 18
#import "InspectDetailView.h"
#import "InspectSortTableCell.h"

#import "InspectDetailHeaderView.h"

#import "TaskGroup.h"
#import "TaskModel.h"
#import "InspectHeaderView.h"
admin's avatar
admin committed
19

20
#define kTaskSortCell @"InspectTaskSortCell"
admin's avatar
admin committed
21

22 23

@interface InspectTaskViewController () <UITableViewDelegate, UITableViewDataSource, InspectHeaderDelegate>
24
@property (nonatomic, strong) UITableView *tableView;
25 26 27 28

@property (nonatomic, strong) NSArray *taskData;

@property (nonatomic, strong) InspectDetailHeaderView *detailHeaderView;
admin's avatar
admin committed
29 30 31 32
@end

@implementation InspectTaskViewController

admin's avatar
admin committed
33 34 35 36 37 38 39
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBar.hidden = NO;
}

admin's avatar
admin committed
40 41 42
- (void)viewDidLoad {
    [super viewDidLoad];
    
43 44 45 46 47 48 49 50 51
    self.view.backgroundColor = kSectionBackGroundColor;
    
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
        self.edgesForExtendedLayout = UIRectEdgeNone;
        self.extendedLayoutIncludesOpaqueBars = NO;
        self.modalPresentationCapturesStatusBarAppearance = NO;
        self.navigationController.navigationBar.translucent = NO;
    }
    
admin's avatar
admin committed
52 53 54 55 56
    UILabel *customLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 40, 30)];
    [customLab setTextColor:[UIColor whiteColor]];
    [customLab setText:@"口碑巡检任务"];
    customLab.font = [UIFont boldSystemFontOfSize:19];
    self.navigationItem.titleView = customLab;
57
    
58 59 60 61 62
    self.tableView.tableHeaderView = self.detailHeaderView;

    
    [self setupTableView];
    
63

admin's avatar
admin committed
64 65 66 67 68 69 70
}

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

71

72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
#pragma mark - Private Methods
- (void)setupTableView
{
    [self.tableView registerClass:[InspectSortTableCell class] forCellReuseIdentifier:kTaskSortCell];

    NSURL *url = [[NSBundle mainBundle] URLForResource:@"classfiy.plist" withExtension:nil];
    NSArray *tempArray = [NSArray arrayWithContentsOfURL:url];
    
    NSMutableArray *tgArray = [NSMutableArray array];
    for (NSDictionary *dict in tempArray) {
        TaskGroup *taskGroup = [TaskGroup taskGroupWithDict:dict];
        [tgArray addObject:taskGroup];
    }
    
    _taskData = tgArray;
}

89
#pragma mark - TableView Delegate/DataSource
90

91 92
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
93
    return _taskData.count;
94 95 96 97 98
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
99 100 101
    TaskGroup *taskGroup = _taskData[section];
    NSInteger count = taskGroup.isOpened ? taskGroup.classfiy.count : 0;
    return count;
102 103 104 105 106
}

// cell显示的内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
107 108 109
    InspectSortTableCell *cell=[tableView dequeueReusableCellWithIdentifier:kTaskSortCell];
    if (!cell) {
        cell = [[InspectSortTableCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kTaskSortCell];
110 111
    }
    
112 113 114 115
    TaskGroup *taskGroup = _taskData[indexPath.section];
    TaskModel *task = taskGroup.classfiy[indexPath.row];
    
    cell.task = task;
116
    cell.titleLabel.text = [NSString stringWithFormat:@"%d、%@", (int)(indexPath.row + 1) ,task.intro];
117 118 119 120
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    return cell;
121 122 123 124
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
125 126
    InspectSettleViewController *inspectVC = [[InspectSettleViewController alloc] init];
    [self.navigationController pushViewController:inspectVC animated:YES];
127 128 129 130 131
}

// cell的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
132
    return 44;
133 134 135 136
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
137
    return 50;
138 139 140 141 142 143 144 145 146 147
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return CGFLOAT_MIN;
}

// 自定义section
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
148 149 150 151
    InspectHeaderView *headView = [InspectHeaderView headViewWithTableView:tableView];
    headView.delegate = self;
    headView.taskGroup = _taskData[section];
    return headView;
152 153
}

154 155 156 157
- (void)clickHeadView
{
    [self.tableView reloadData];
}
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
#pragma mark - lazy loading
- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _tableView.translatesAutoresizingMaskIntoConstraints = NO;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.showsHorizontalScrollIndicator = NO;
        [self.view addSubview:_tableView];
        
        NSLayoutConstraint *tableTop = [NSLayoutConstraint constraintWithItem:_tableView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1.0 constant:0];
        [self.view addConstraint:tableTop];
        
        NSLayoutConstraint *tableLeft = [NSLayoutConstraint constraintWithItem:_tableView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
        [self.view addConstraint:tableLeft];
        
        NSLayoutConstraint *tableRight = [NSLayoutConstraint constraintWithItem:_tableView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeRight multiplier:1.0 constant:0];
        [self.view addConstraint:tableRight];
        
        NSLayoutConstraint *tableBottom = [NSLayoutConstraint constraintWithItem:_tableView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
        [self.view addConstraint:tableBottom];
    }
    return _tableView;
}

185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
- (InspectDetailHeaderView *)detailHeaderView
{
    if (!_detailHeaderView) {
        _detailHeaderView = [[InspectDetailHeaderView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 285)];
        
        _detailHeaderView.detailView.multiplier = self.multiplier;
        _detailHeaderView.detailView.progressState = self.progressState;
        _detailHeaderView.detailView.alreadyLabel.text = self.alreadyNumber;
        _detailHeaderView.detailView.allLabel.text = self.allNumber;
        _detailHeaderView.detailView.shopnameLabel.text = @"上海真北店";
        _detailHeaderView.detailView.startDateLabel.text = @"2015-09-30";
        _detailHeaderView.detailView.overDateLabel.text = @"2015-09-30";
        _detailHeaderView.detailView.dayLabel.text = @"3";
    }
    return _detailHeaderView;
}

admin's avatar
admin committed
202 203 204 205 206 207 208 209 210 211 212
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end