InspectTaskViewController.m 7.93 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
#import "HttpClient.h"
admin's avatar
admin committed
20

21 22
#import "TaskDetailModel.h"

23
#define kTaskSortCell @"InspectTaskSortCell"
admin's avatar
admin committed
24

25 26

@interface InspectTaskViewController () <UITableViewDelegate, UITableViewDataSource, InspectHeaderDelegate>
27
@property (nonatomic, strong) UITableView *tableView;
28 29 30 31

@property (nonatomic, strong) NSArray *taskData;

@property (nonatomic, strong) InspectDetailHeaderView *detailHeaderView;
admin's avatar
admin committed
32 33 34 35
@end

@implementation InspectTaskViewController

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

admin's avatar
admin committed
43 44 45
- (void)viewDidLoad {
    [super viewDidLoad];
    
46 47 48 49 50 51 52 53 54
    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;
    }
    
55 56 57 58 59 60 61 62 63
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(0, 0, 30, 44);
    [backBtn setImage:[UIImage imageNamed:@"back_btn"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(doBack:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
    self.navigationItem.leftBarButtonItem = backItem;
    
    
    
admin's avatar
admin committed
64 65 66 67 68
    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;
69
    
70
    
admin's avatar
admin committed
71 72
    // 口碑巡检明细
    [self requestRankingDetail];
admin's avatar
admin committed
73 74 75 76 77 78 79
}

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

80

81
#pragma mark - Private Methods
82 83 84 85 86 87 88 89

// 返回上一页面
- (void)doBack:(UIBarButtonItem *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}


admin's avatar
admin committed
90 91 92 93 94
- (void)requestRankingDetail
{
    NSString *url = [NSString stringWithFormat:@"%@%@%@/%@",kRedStarURL, kInspectDetailURL, self.uuid, self.store_uuid];
    
    HttpClient *httpClient = [[HttpClient alloc] initWithUrl:url];
95 96 97
    
    __block InspectTaskViewController *weakSelf = self;
    
admin's avatar
admin committed
98 99
    [httpClient getPraiseDetailWithParameters:nil completion:^(id response, NSError *error) {
        NSLog(@"口碑巡检明细PraiseDetail = %@", response);
100 101 102 103 104 105 106 107 108 109 110 111 112 113
        NSDictionary *dataDict = response[@"data"];
        TaskDetailModel *taskDetail = [TaskDetailModel taskDetailModelWithDict:dataDict];
        weakSelf.detailHeaderView.taskDetail = taskDetail;
        
        
        NSArray *dataArray = dataDict[@"categories"];
        
        NSMutableArray *tgArray = [NSMutableArray array];
        for (NSDictionary *dict in dataArray) {
            TaskGroup *taskGroup = [TaskGroup taskGroupWithDict:dict];
            [tgArray addObject:taskGroup];
        }
        
        _taskData = tgArray;
admin's avatar
admin committed
114 115 116 117 118 119
        
        self.tableView.delegate = self;
        self.tableView.dataSource = self;
    }];
}

120
#pragma mark - TableView Delegate/DataSource
121

122 123
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
124
    return _taskData.count;
125 126 127 128 129
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
130
    TaskGroup *taskGroup = _taskData[section];
131
    NSInteger count = taskGroup.isOpened ? taskGroup.answers.count : 0;
132
    return count;
133 134 135 136 137
}

// cell显示的内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
138 139 140
    InspectSortTableCell *cell=[tableView dequeueReusableCellWithIdentifier:kTaskSortCell];
    if (!cell) {
        cell = [[InspectSortTableCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kTaskSortCell];
141 142
    }
    
143
    TaskGroup *taskGroup = _taskData[indexPath.section];
144
    TaskModel *task = taskGroup.answers[indexPath.row];
145 146
    
    cell.task = task;
147
    cell.titleLabel.text = [NSString stringWithFormat:@"%d、%@", (int)(indexPath.row + 1) ,task.title];
148 149 150 151
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    return cell;
152 153 154 155
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
156 157
    InspectSettleViewController *inspectVC = [[InspectSettleViewController alloc] init];
    [self.navigationController pushViewController:inspectVC animated:YES];
158 159 160 161 162
}

// cell的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
163
    return 44;
164 165 166 167
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
168
    return 50;
169 170 171 172 173 174 175 176 177 178
}

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

// 自定义section
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
179 180 181 182
    InspectHeaderView *headView = [InspectHeaderView headViewWithTableView:tableView];
    headView.delegate = self;
    headView.taskGroup = _taskData[section];
    return headView;
183 184
}

185 186
- (void)clickHeadView
{
admin's avatar
admin committed
187
    [_tableView reloadData];
188
}
189 190 191 192 193 194 195 196
#pragma mark - lazy loading
- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _tableView.translatesAutoresizingMaskIntoConstraints = NO;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.showsHorizontalScrollIndicator = NO;
admin's avatar
admin committed
197 198
        [_tableView registerClass:[InspectSortTableCell class] forCellReuseIdentifier:kTaskSortCell];
        _tableView.tableHeaderView = self.detailHeaderView;
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
        [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;
}

216 217 218 219 220
- (InspectDetailHeaderView *)detailHeaderView
{
    if (!_detailHeaderView) {
        _detailHeaderView = [[InspectDetailHeaderView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 285)];
        
221
        
222 223 224 225 226
        _detailHeaderView.detailView.dayLabel.text = @"3";
    }
    return _detailHeaderView;
}

admin's avatar
admin committed
227 228 229 230 231 232 233 234 235 236 237
/*
#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