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

#import "HomeViewController.h"
#import "HomeHeaderView.h"
admin's avatar
admin committed
11

admin's avatar
admin committed
12 13 14

#import "InspectListViewController.h"
#import "RankingListViewController.h"
15 16 17
#import "OnLineViewController.h"
#import "PictureViewController.h"
#import "QuestionViewController.h"
admin's avatar
admin committed
18

admin's avatar
admin committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
#import "HomeCellItem.h"

#import "PictureTableCell.h"
#define kHomePictureListCell @"homePictureListCell"
#import "PictureStoryViewController.h"

#import "HomeTitleTableCell.h"
#define kHomeTitleTableCell @"homeTitleTableCell"
#import "RankingListCell.h"
#define kHomeRankingListCell @"homeRankingListsCell"
#import "RankDetailViewController.h"

#import "QuestionListTableCell.h"
#define kHomeQuestionListTableCell @"homeQuestionListTableCell"
#import "QuestionModel.h"
#import "QuestionDetailViewController.h"

#import "InspectListCell.h"
#define kHomeInspectListCell @"homeInspectListsCell"
#import "InspectTaskViewController.h"
39
#import "TaskListModel.h"
admin's avatar
admin committed
40 41

@interface HomeViewController () <UITableViewDelegate, UITableViewDataSource, UIScrollViewDelegate>
admin's avatar
admin committed
42 43 44 45 46 47
@property (nonatomic, strong) UIImageView *bgImageView; // 背景
@property (nonatomic, strong) UITextField *searchTextField; // 搜索框
@property (nonatomic, strong) UILabel *shopnameLabel; // 店名
@property (nonatomic, strong) UILabel *nameLabel; // 用户姓名


admin's avatar
admin committed
48 49 50 51 52
// 当前视图
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) HomeHeaderView *headView;

@property (nonatomic, strong) NSArray *titleArray; // section标题
admin's avatar
admin committed
53
@property (nonatomic, strong) NSArray *btnTitleArray; // section标题
admin's avatar
admin committed
54
@property (nonatomic, strong) NSArray *announeArray; // 公告内容
admin's avatar
admin committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69

@property (nonatomic, strong) NSArray *test1Array; // section标题
@property (nonatomic, strong) NSArray *test2Array; // section标题
@property (nonatomic, strong) NSArray *test3Array; // section标题


@property (nonatomic, strong) NSArray *test4Array;
@property (nonatomic, strong) NSArray *test5Array;
@property (nonatomic, strong) NSArray *test6Array;
@property (nonatomic, strong) NSArray *test7Array;
@property (nonatomic, strong) NSArray *test8Array;
@property (nonatomic, strong) NSArray *test9Array;
// rank cell
@property (nonatomic, strong) NSMutableDictionary *selectedIndexes;

admin's avatar
admin committed
70 71 72 73 74 75 76 77
@end

@implementation HomeViewController
#pragma mark - ViewDidLoad
- (void)viewDidLoad
{
    [super viewDidLoad];
    
78
    
admin's avatar
admin committed
79 80 81 82 83 84 85
    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;
    
    // 初始化容器
admin's avatar
admin committed
86 87
    self.titleArray = [NSArray arrayWithObjects:@"图说口碑", @"8月口碑巡检",@"问题与知识",@"口碑任务", nil];
    self.btnTitleArray = [NSArray arrayWithObjects:@"在线抽查", @"口碑报告",@"口碑标准",@"图说口碑",@"问题与知识",@"优秀案例", nil];
admin's avatar
admin committed
88 89
    self.announeArray = [NSArray arrayWithObjects:@"关于展开10月口碑巡检的说明", @"迎2015十一大促活动启动", @"9月口碑巡检结果排名已公布", nil];
    
admin's avatar
admin committed
90 91 92 93 94 95 96 97 98 99 100 101 102
    // 初始化
    self.test1Array = [NSArray arrayWithObjects:@"【服务口碑现场】第二期",@"讲述红星人自己的故事",@"【服务口碑现场】第一期", nil];
    self.test2Array = [NSArray arrayWithObjects:@"把第一次客户投诉变成商场服务提升的契机,变成商场服务提升的契机。",@"变成商场服务提升的契机,变成商场服务提升的契机。",@"把第一次客户投诉变成商场服务提升的契机,变成商场服务提升的契机。", nil];
    self.test3Array = [NSArray arrayWithObjects:@"2015-08-26",@"2015-08-09",@"2015-07-31", nil];
    
    self.test7Array = [NSArray arrayWithObjects:@"2015年9月口碑巡检",@"2015年9月卫生专项巡检",@"2015年9月真北店安全临时巡检",@"2015年10月卫生专项巡检",@"2015年10月设备安全巡检", nil];
    self.test8Array = [NSArray arrayWithObjects:@"2015-09-01 10:28:52",@"2015-09-08 12:47:32",@"2015-10-21 07:58:22",@"2015-10-09 19:08:52",@"2015-09-01 14:19:52", nil];
    self.test9Array = [NSArray arrayWithObjects:@"2015-09-03",@"2015-09-15",@"2015-10-22",@"2015-11-02",@"2015-11-05", nil];
    self.test4Array = [NSArray arrayWithObjects:@"2",@"3",@"1",@"2",@"1", nil];
    self.test5Array = [NSArray arrayWithObjects:@(5),@(12),@(0),@(8),@(20), nil];
    self.test6Array = [NSArray arrayWithObjects:@(16),@(25),@(20),@(100),@(20), nil];
    
    [self setupNav];
admin's avatar
admin committed
103 104
    [self setupTableView];
    
admin's avatar
admin committed
105 106 107
    // 初始化容器
    self.selectedIndexes = [[NSMutableDictionary alloc] init];
    
admin's avatar
admin committed
108 109 110 111 112 113
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
114
    self.tabBarController.tabBar.hidden = NO;
admin's avatar
admin committed
115
    self.navigationController.navigationBar.hidden = YES;
admin's avatar
admin committed
116 117 118 119 120 121 122
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - Private Methods
admin's avatar
admin committed
123 124 125 126 127 128 129 130 131 132 133 134 135
- (void)setupNav
{
    UIEdgeInsets insets = UIEdgeInsetsMake( 0, 199, 0, 175);
    UIImage *image = [[UIImage imageNamed:@"home_title"] resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch];
    self.bgImageView.image = image;
    self.searchTextField.backgroundColor = [UIColor clearColor];
    self.nameLabel.backgroundColor = [UIColor clearColor];
    _nameLabel.text = @"东方明珠,你好!";
    self.shopnameLabel.backgroundColor = [UIColor clearColor];
    _shopnameLabel.text = @"上海真北店";

}

admin's avatar
admin committed
136 137
- (void)setupTableView
{
admin's avatar
admin committed
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
    self.headView = [[HomeHeaderView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 115)];
    
    self.headView.scrollView.contentSize = CGSizeMake(2 * kScreenWidth, 85);
    CGFloat itemW = kScreenWidth / 4;
    CGFloat itemH = self.headView.scrollView.frame.size.height;
    
    for (int i = 0; i < 6; i++) {
        HomeCellItem *item = [[HomeCellItem alloc] init];
        item.frame = CGRectMake(i * itemW, 0, itemW, itemH);
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"task_0%d", i]];
        [item setImage:image forState:UIControlStateNormal];
        [item setTitleColor:kPictureCellDetailsColor forState:UIControlStateNormal];
        [item setTitle:[NSString stringWithFormat:@"%@", self.btnTitleArray[i]] forState:UIControlStateNormal];
        [item addTarget:self action:@selector(itemClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.headView.scrollView addSubview:item];
    }
    
    
admin's avatar
admin committed
156 157 158
    self.tableView.tableHeaderView = self.headView;
}

admin's avatar
admin committed
159 160


admin's avatar
admin committed
161 162 163 164 165
- (void)moreButtonClick:(UIButton *)sender
{
    NSLog(@"查看全部公告···");
}

admin's avatar
admin committed
166
- (void)itemClick:(HomeCellItem *)sender
admin's avatar
admin committed
167
{
admin's avatar
admin committed
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
    HomeCellItem *item = (HomeCellItem *)sender;
    UINavigationController *nav;
    if ([item.titleLabel.text isEqualToString:@"在线抽查"]) {
        return;
    } else if ([item.titleLabel.text isEqualToString:@"口碑报告"]) {
        InspectListViewController *inspectListVC = [[InspectListViewController alloc] init];
        nav = [[UINavigationController alloc] initWithRootViewController:inspectListVC];
    } else if ([item.titleLabel.text isEqualToString:@"口碑标准"]) {
        return;
    } else if ([item.titleLabel.text isEqualToString:@"图说口碑"]) {
        PictureViewController *pictureVC = [[PictureViewController alloc] init];
        nav = [[UINavigationController alloc] initWithRootViewController:pictureVC];
    } else if ([item.titleLabel.text isEqualToString:@"问题与知识"]) {
        QuestionViewController *questionVC = [[QuestionViewController alloc] init];
        nav = [[UINavigationController alloc] initWithRootViewController:questionVC];
    } else if ([item.titleLabel.text isEqualToString:@"优秀案例"]) {
        RankingListViewController *rankingListVC = [[RankingListViewController alloc] init];
        nav = [[UINavigationController alloc] initWithRootViewController:rankingListVC];
    } else {
        return;
    }
admin's avatar
admin committed
189
    
admin's avatar
admin committed
190 191 192
    [nav.navigationBar setBarTintColor:kNavigationBarColor];
    [nav.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]];
    [self presentViewController:nav animated:YES completion:nil];
admin's avatar
admin committed
193 194 195
}


admin's avatar
admin committed
196 197 198 199 200
// rank Cell
- (BOOL)cellIsSelected:(NSIndexPath *)indexPath {
    // Return whether the cell at the specified index path is selected or not
    NSNumber *selectedIndex = [_selectedIndexes objectForKey:indexPath];
    return selectedIndex == nil ? FALSE : [selectedIndex boolValue];
admin's avatar
admin committed
201 202
}

admin's avatar
admin committed
203
- (void)loadMoreInfo:(UIButton *)sender
admin's avatar
admin committed
204
{
admin's avatar
admin committed
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 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 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
    RankingListCell * cell = (RankingListCell *)[[sender superview] superview];
    cell.isDrop = !cell.isDrop;
    NSIndexPath * path = [self.tableView indexPathForCell:cell];
    
    [_tableView deselectRowAtIndexPath:path animated:TRUE];
    
    BOOL isSelected = ![self cellIsSelected:path];
    
    NSNumber *selectedIndex = [NSNumber numberWithBool:isSelected];
    [_selectedIndexes setObject:selectedIndex forKey:path];
    
    if (cell.isDrop) {
        
        [UIView animateWithDuration:0.2 animations:^{
            cell.arrowImageView.transform = CGAffineTransformIdentity;
            cell.arrowImageView.transform = CGAffineTransformMakeRotation(M_PI / 2);
        }];
        
        
        cell.someoneLabel = [[UILabel alloc] init];
        cell.someoneLabel.text = @"集团领导某总";
        cell.someoneLabel.font = [UIFont systemFontOfSize:15.0];
        cell.someoneLabel.textAlignment = NSTextAlignmentCenter;
        cell.someoneLabel.textColor = kRankHeadTitleTextColor;
        cell.someoneLabel.translatesAutoresizingMaskIntoConstraints = NO;
        [cell.contentView addSubview:cell.someoneLabel];
        
        cell.dateLabel = [[UILabel alloc] init];
        cell.dateLabel.text = @"2015-09-25 12:12:09";
        cell.dateLabel.font = [UIFont systemFontOfSize:15.0];
        cell.dateLabel.textAlignment = NSTextAlignmentCenter;
        cell.dateLabel.textColor = kRankHeadTitleTextColor;
        cell.dateLabel.translatesAutoresizingMaskIntoConstraints = NO;
        [cell.contentView addSubview:cell.dateLabel];
        
        cell.remarkLabel = [[UILabel alloc] init];
        cell.remarkLabel.translatesAutoresizingMaskIntoConstraints = NO;
        cell.remarkLabel.text = @"评语:该店进步非常大,值得大家一起学习!";
        cell.remarkLabel.font = [UIFont systemFontOfSize:15.0];
        cell.remarkLabel.textColor = kRankHeadTitleTextColor;
        [cell.contentView addSubview:cell.remarkLabel];
        
        NSLayoutConstraint *someoneTop = [NSLayoutConstraint constraintWithItem:cell.someoneLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:cell.shopNameButton attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
        [cell.contentView addConstraint:someoneTop];
        
        NSLayoutConstraint *someoneCenterX = [NSLayoutConstraint constraintWithItem:cell.someoneLabel attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:cell.shopNameButton attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:5];
        [cell.contentView addConstraint:someoneCenterX];
        
        NSLayoutConstraint *someoneWidth = [NSLayoutConstraint constraintWithItem:cell.someoneLabel attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:100];
        [cell.contentView addConstraint:someoneWidth];
        
        NSLayoutConstraint *someoneHeight = [NSLayoutConstraint constraintWithItem:cell.someoneLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:25];
        [cell.contentView addConstraint:someoneHeight];
        
        //
        NSLayoutConstraint *dateTop = [NSLayoutConstraint constraintWithItem:cell.dateLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:cell.shopNameButton attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
        [cell.contentView addConstraint:dateTop];
        
        NSLayoutConstraint *dateLeft = [NSLayoutConstraint constraintWithItem:cell.dateLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:cell.someoneLabel attribute:NSLayoutAttributeRight multiplier:1.0 constant:10];
        [cell.contentView addConstraint:dateLeft];
        
        NSLayoutConstraint *dateRight = [NSLayoutConstraint constraintWithItem:cell.dateLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:cell.contentView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-20];
        [cell.contentView addConstraint:dateRight];
        
        NSLayoutConstraint *dateHeight = [NSLayoutConstraint constraintWithItem:cell.dateLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:25];
        [cell.contentView addConstraint:dateHeight];
        
        //
        NSLayoutConstraint *remarkTop = [NSLayoutConstraint constraintWithItem:cell.remarkLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:cell.someoneLabel attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
        [cell.contentView addConstraint:remarkTop];
        
        NSLayoutConstraint *remarkLeft = [NSLayoutConstraint constraintWithItem:cell.remarkLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:cell.someoneLabel attribute:NSLayoutAttributeLeft multiplier:1.0 constant:5];
        [cell.contentView addConstraint:remarkLeft];
        
        NSLayoutConstraint *remarkRight = [NSLayoutConstraint constraintWithItem:cell.remarkLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:cell.contentView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-20];
        [cell.contentView addConstraint:remarkRight];
        
        NSLayoutConstraint *remarkHeight = [NSLayoutConstraint constraintWithItem:cell.remarkLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:25];
        [cell.contentView addConstraint:remarkHeight];
        
    } else {
        
        [UIView animateWithDuration:0.2 animations:^{
            cell.arrowImageView.transform = CGAffineTransformIdentity;
            cell.arrowImageView.transform = CGAffineTransformMakeRotation(0);
        }];
        
        if (cell.someoneLabel) {
            [cell.someoneLabel removeFromSuperview];
            cell.someoneLabel = nil;
        }
        
        if (cell.dateLabel) {
            [cell.dateLabel removeFromSuperview];
            cell.dateLabel = nil;
        }
        
        if (cell.remarkLabel) {
            [cell.remarkLabel removeFromSuperview];
            cell.remarkLabel = nil;
        }
    }
    
    [_tableView beginUpdates];
    [_tableView endUpdates];
admin's avatar
admin committed
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
}





#pragma mark - TableView Delegate/DataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return _titleArray.count;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
admin's avatar
admin committed
325 326
    if (section == 1) {
        return 4;
admin's avatar
admin committed
327
    } else {
admin's avatar
admin committed
328
        return 2;
admin's avatar
admin committed
329 330 331 332 333 334
    }
}

// cell显示的内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
admin's avatar
admin committed
335
    
admin's avatar
admin committed
336
    if (indexPath.section == 0) {
admin's avatar
admin committed
337 338 339 340
        
        // 图说口碑
        
        PictureTableCell *cell=[tableView dequeueReusableCellWithIdentifier:kHomePictureListCell];
admin's avatar
admin committed
341
        if (!cell) {
admin's avatar
admin committed
342
            cell = [[PictureTableCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kHomePictureListCell];
admin's avatar
admin committed
343 344
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
admin's avatar
admin committed
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
        cell.titleLabel.text = _test1Array[indexPath.row];
        cell.detailsLabel.text = _test2Array[indexPath.row];
        cell.dateLabel.text = [NSString stringWithFormat:@"发布时间: %@", _test3Array[indexPath.row]];
        [cell.thumbBtn setTitle:@"220" forState:UIControlStateNormal];
        [cell.commentBtn setTitle:@"18" forState:UIControlStateNormal];
        return cell;
    } else if (indexPath.section == 1) {
        
        // 口碑巡检
        
        if (indexPath.row == 0) {
            HomeTitleTableCell *cell=[tableView dequeueReusableCellWithIdentifier:kHomeTitleTableCell];
            if (!cell) {
                cell = [[HomeTitleTableCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kHomeTitleTableCell];
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        } else {
            RankingListCell *cell=[tableView dequeueReusableCellWithIdentifier:kHomeRankingListCell];
            if (!cell) {
                cell = [[RankingListCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kHomeRankingListCell];
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.scoreState = ScoreStateHigh;
            NSString *imageName = [NSString stringWithFormat:@"medal_0%ld", (long)(indexPath.row)];
            cell.gradeImageView.image = [UIImage imageNamed:imageName];
            [cell.shopNameButton setTitle:@"上海真北店" forState:UIControlStateNormal];
            cell.scoreLabel.text = @"98";
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            // 添加点击事件
            [cell.shopNameButton addTarget:self action:@selector(loadMoreInfo:) forControlEvents:UIControlEventTouchUpInside];
            return cell;
        }
    } else if (indexPath.section == 2) {
        QuestionListTableCell *cell = [tableView dequeueReusableCellWithIdentifier:kHomeQuestionListTableCell];
        if (!cell) {
            cell = [[QuestionListTableCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kHomeQuestionListTableCell];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        QuestionModel *question = [[QuestionModel alloc] init];
        question.content = @"OMS系统不能执行15分钟退货程序处理,应该添加";
        question.feedback = @"启动线下“30天无理由退货”程序处理OMS系统的相关问题";
        question.categoryName = @"送货跟单-送货跟单";
        question.submitTime = @"2015-09-11 10:23:12";
        cell.question = question;
admin's avatar
admin committed
390 391 392
        return cell;

    } else {
admin's avatar
admin committed
393
        InspectListCell *cell=[tableView dequeueReusableCellWithIdentifier:kHomeInspectListCell];
admin's avatar
admin committed
394
        if (!cell) {
admin's avatar
admin committed
395
            cell = [[InspectListCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kHomeInspectListCell];
admin's avatar
admin committed
396
        }
397 398 399 400
        TaskListModel *taskList = [[TaskListModel alloc] init];
        taskList.reportCount = 10;
        taskList.questionCount = 13;
        cell.taskList = taskList;
admin's avatar
admin committed
401
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
admin's avatar
admin committed
402 403 404
        cell.titleLabel.text = [NSString stringWithFormat:@"%@", _test7Array[indexPath.row]];
        cell.startDate.text = [NSString stringWithFormat:@"起始时间:%@", _test8Array[indexPath.row]];
        cell.overDate.text = [NSString stringWithFormat:@"截止时间:%@", _test9Array[indexPath.row]];
405
        
admin's avatar
admin committed
406 407
        cell.alreadyLabel.text = [NSString stringWithFormat:@"%@", _test5Array[indexPath.row]];
        cell.allLabel.text = [NSString stringWithFormat:@"/%@", _test6Array[indexPath.row]];
408 409 410
//        CGFloat already = [_test5Array[indexPath.row] floatValue];
//        CGFloat all = [_test6Array[indexPath.row] floatValue];
//        cell.multiplier = already / all;
admin's avatar
admin committed
411 412
        cell.allView.backgroundColor = kProgressViewAllBackColor;
        cell.alreadyView.backgroundColor = kProgressViewAlreadyBackColor;
admin's avatar
admin committed
413 414
        return cell;
    }
admin's avatar
admin committed
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447
}

// cell点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        PictureStoryViewController *storyVC = [[PictureStoryViewController alloc] init];
        [self.navigationController pushViewController:storyVC animated:YES];
    } else if (indexPath.section == 1) {
        if (indexPath.row != 0) {
            RankDetailViewController *rankDetailVC = [[RankDetailViewController alloc] init];
            rankDetailVC.indexRow = indexPath.row - 1;
            [self.navigationController pushViewController:rankDetailVC animated:YES];
        }
    } else if (indexPath.section == 2) {
        QuestionDetailViewController *questionDetailVC = [[QuestionDetailViewController alloc] init];
        QuestionModel *question = [[QuestionModel alloc] init];
        question.content = @"OMS系统不能执行15分钟退货程序处理,应该添加";
        question.feedback = @"启动线下“30天无理由退货”程序处理OMS系统的相关问题";
        question.categoryName = @"送货跟单-送货跟单";
        question.submitTime = @"2015-09-11 10:23:12";
        questionDetailVC.question = question;
        [self.navigationController pushViewController:questionDetailVC animated:YES];

    } else {
        InspectListCell *cell = (InspectListCell *)[self tableView:_tableView cellForRowAtIndexPath:indexPath];
        InspectTaskViewController *inspectTaskVC = [[InspectTaskViewController alloc] init];
        inspectTaskVC.multiplier = cell.multiplier;
        inspectTaskVC.alreadyNumber = cell.alreadyLabel.text;
        inspectTaskVC.allNumber = cell.allLabel.text;
        [self.navigationController pushViewController:inspectTaskVC animated:YES];
        
    }
admin's avatar
admin committed
448 449 450 451 452 453
}

// cell的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
admin's avatar
admin committed
454 455 456 457 458 459 460 461 462 463 464 465
        return 123;
    } else if (indexPath.section == 1) {
        if (indexPath.row == 0) {
            return 40;
        } else {
            if([self cellIsSelected:indexPath]) {
                return 108;
            }
            return 50;
        }
    } else if (indexPath.section == 2) {
        return 120;
admin's avatar
admin committed
466
    } else {
admin's avatar
admin committed
467
        return 145;
admin's avatar
admin committed
468 469 470 471 472 473 474 475 476 477 478
    }
}

// section高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 36;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
admin's avatar
admin committed
479
    return 10;
admin's avatar
admin committed
480 481 482 483 484
}

// 自定义section
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
admin's avatar
admin committed
485 486 487 488
   
    
    
    
admin's avatar
admin committed
489 490 491
    // 创建sectionView
    UIView *sectionView = [[UIView alloc] init];
    sectionView.userInteractionEnabled = YES;
admin's avatar
admin committed
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510
    sectionView.backgroundColor = [UIColor whiteColor];
    
    UIView *lineView = [[UIView alloc] init];
    lineView.translatesAutoresizingMaskIntoConstraints = NO;
    lineView.backgroundColor = kSeparateLineColor;
    [sectionView addSubview:lineView];
    
    NSLayoutConstraint *lineTop = [NSLayoutConstraint constraintWithItem:lineView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:sectionView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0];
    [sectionView addConstraint:lineTop];
    
    NSLayoutConstraint *lineLeft = [NSLayoutConstraint constraintWithItem:lineView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:sectionView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
    [sectionView addConstraint:lineLeft];
    
    NSLayoutConstraint *lineRight = [NSLayoutConstraint constraintWithItem:lineView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:sectionView attribute:NSLayoutAttributeRight multiplier:1.0 constant:0];
    [sectionView addConstraint:lineRight];
    
    NSLayoutConstraint *lineHeight = [NSLayoutConstraint constraintWithItem:lineView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:0.5];
    [sectionView addConstraint:lineHeight];
    
admin's avatar
admin committed
511 512 513
    // 创建标题label
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
admin's avatar
admin committed
514
    titleLabel.textColor = kPictureCellDetailsColor;
admin's avatar
admin committed
515 516 517 518
    titleLabel.font = [UIFont systemFontOfSize:17.0];
    titleLabel.text = _titleArray[section];
    [sectionView addSubview:titleLabel];
    
admin's avatar
admin committed
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534
    
    // 查看更多按钮
    UIButton *moreButton = [[UIButton alloc] init];
    moreButton.translatesAutoresizingMaskIntoConstraints = NO;
    [moreButton setTitle:@"更多" forState:UIControlStateNormal];
    [moreButton setTitleColor:kMoreButtonTextColor forState:UIControlStateNormal];
    [moreButton addTarget:self action:@selector(moreButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    moreButton.titleLabel.font = [UIFont systemFontOfSize:13.0];
    [sectionView addSubview:moreButton];
    
    // 箭头Iamge
    UIImageView *arrowIamgeView = [[UIImageView alloc] init];
    arrowIamgeView.image = [UIImage imageNamed:@"arrow_right"];
    arrowIamgeView.translatesAutoresizingMaskIntoConstraints = NO;
    [sectionView addSubview:arrowIamgeView];
    
admin's avatar
admin committed
535 536 537 538 539 540
    NSLayoutConstraint *titleLabelTop = [NSLayoutConstraint constraintWithItem:titleLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:sectionView attribute:NSLayoutAttributeTop multiplier:1.0 constant:3];
    [sectionView addConstraint:titleLabelTop];
    
    NSLayoutConstraint *titleLabelLeft = [NSLayoutConstraint constraintWithItem:titleLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:sectionView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:20];
    [sectionView addConstraint:titleLabelLeft];
    
admin's avatar
admin committed
541 542
    NSLayoutConstraint *titleLabelRight = [NSLayoutConstraint constraintWithItem:titleLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:moreButton attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
    [sectionView addConstraint:titleLabelRight];
admin's avatar
admin committed
543 544 545 546 547
    
    NSLayoutConstraint *titleLabelBottom = [NSLayoutConstraint constraintWithItem:titleLabel attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:sectionView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
    [sectionView addConstraint:titleLabelBottom];
    
    
admin's avatar
admin committed
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623
    
    
    
    // moreButton布局
    NSLayoutConstraint *moreButtonTop = [NSLayoutConstraint constraintWithItem:moreButton attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:sectionView attribute:NSLayoutAttributeTop multiplier:1.0 constant:3];
    [sectionView addConstraint:moreButtonTop];
    
    NSLayoutConstraint *moreButtonRight = [NSLayoutConstraint constraintWithItem:moreButton attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:arrowIamgeView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
    [sectionView addConstraint:moreButtonRight];
    
    NSLayoutConstraint *moreButtonWidth = [NSLayoutConstraint constraintWithItem:moreButton attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:35];
    [sectionView addConstraint:moreButtonWidth];
    
    NSLayoutConstraint *moreButtonBottom = [NSLayoutConstraint constraintWithItem:moreButton attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:sectionView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
    [sectionView addConstraint:moreButtonBottom];
    
    // arrowIamgeView布局
    NSLayoutConstraint *arrowIamgeViewTop = [NSLayoutConstraint constraintWithItem:arrowIamgeView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:sectionView attribute:NSLayoutAttributeTop multiplier:1.0 constant:13];
    [sectionView addConstraint:arrowIamgeViewTop];
    
    NSLayoutConstraint *arrowIamgeViewRight = [NSLayoutConstraint constraintWithItem:arrowIamgeView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:sectionView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-20];
    [sectionView addConstraint:arrowIamgeViewRight];
    
    NSLayoutConstraint *arrowIamgeViewWidth = [NSLayoutConstraint constraintWithItem:arrowIamgeView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:7];
    [sectionView addConstraint:arrowIamgeViewWidth];
    
    NSLayoutConstraint *arrowIamgeViewHeight = [NSLayoutConstraint constraintWithItem:arrowIamgeView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:12];
    [sectionView addConstraint:arrowIamgeViewHeight];
    
    
    return sectionView;
}

#pragma mark - lazy loading
- (UIImageView *)bgImageView
{
    if (!_bgImageView) {
        _bgImageView = [[UIImageView alloc] init];
        _bgImageView.translatesAutoresizingMaskIntoConstraints = NO;
        _bgImageView.userInteractionEnabled = YES;
        [self.view addSubview:_bgImageView];
        
        NSLayoutConstraint *bgImageTop = [NSLayoutConstraint constraintWithItem:_bgImageView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1.0 constant:0];
        [self.view addConstraint:bgImageTop];
        
        NSLayoutConstraint *bgImageLeft = [NSLayoutConstraint constraintWithItem:_bgImageView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
        [self.view addConstraint:bgImageLeft];
        
        NSLayoutConstraint *bgImageHeight = [NSLayoutConstraint constraintWithItem:_bgImageView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:95];
        [self.view addConstraint:bgImageHeight];
        
        NSLayoutConstraint *bgImageRight = [NSLayoutConstraint constraintWithItem:_bgImageView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeRight multiplier:1.0 constant:0];
        [self.view addConstraint:bgImageRight];
    }
    return _bgImageView;
}

- (UITextField *)searchTextField
{
    if (!_searchTextField) {
        _searchTextField = [[UITextField alloc] init];
        _searchTextField.translatesAutoresizingMaskIntoConstraints = NO;
        _searchTextField.font = [UIFont systemFontOfSize:13.0];
        _searchTextField.textAlignment = NSTextAlignmentCenter;
        _searchTextField.layer.cornerRadius = 4.0;
        _searchTextField.textColor = [UIColor whiteColor];
        _searchTextField.layer.borderColor = [[UIColor whiteColor] CGColor];
        _searchTextField.layer.borderWidth = 0.5;
        _searchTextField.placeholder = @"查询";
        [_searchTextField setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];
        UIImageView *imageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"search"]];
        imageV.contentMode = UIViewContentModeCenter;
        imageV.width += 10;
        _searchTextField.rightView = imageV;
        _searchTextField.rightViewMode = UITextFieldViewModeAlways;
        [self.bgImageView addSubview:_searchTextField];
admin's avatar
admin committed
624
        
admin's avatar
admin committed
625 626
        NSLayoutConstraint *bgImageTop = [NSLayoutConstraint constraintWithItem:_searchTextField attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.bgImageView attribute:NSLayoutAttributeTop multiplier:1.0 constant:35];
        [self.bgImageView addConstraint:bgImageTop];
admin's avatar
admin committed
627
        
admin's avatar
admin committed
628 629
        NSLayoutConstraint *bgImageRight = [NSLayoutConstraint constraintWithItem:_searchTextField attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.bgImageView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-20];
        [self.bgImageView addConstraint:bgImageRight];
admin's avatar
admin committed
630
        
admin's avatar
admin committed
631 632
        NSLayoutConstraint *bgImageHeight = [NSLayoutConstraint constraintWithItem:_searchTextField attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:28];
        [self.bgImageView addConstraint:bgImageHeight];
admin's avatar
admin committed
633
        
admin's avatar
admin committed
634 635 636 637 638 639 640 641 642 643 644 645 646 647 648
        NSLayoutConstraint *bgImageWidth = [NSLayoutConstraint constraintWithItem:_searchTextField attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:100];
        [self.bgImageView addConstraint:bgImageWidth];
    }
    return _searchTextField;
}

- (UILabel *)nameLabel
{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc] init];
        _nameLabel.translatesAutoresizingMaskIntoConstraints = NO;
        _nameLabel.font = [UIFont systemFontOfSize:13.0];
        _nameLabel.textAlignment = NSTextAlignmentRight;
        _nameLabel.textColor = [UIColor whiteColor];
        [self.bgImageView addSubview:_nameLabel];
admin's avatar
admin committed
649
        
admin's avatar
admin committed
650 651
        NSLayoutConstraint *bgImageTop = [NSLayoutConstraint constraintWithItem:_nameLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.searchTextField attribute:NSLayoutAttributeBottom multiplier:1.0 constant:3];
        [self.bgImageView addConstraint:bgImageTop];
admin's avatar
admin committed
652
        
admin's avatar
admin committed
653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673
        NSLayoutConstraint *bgImageRight = [NSLayoutConstraint constraintWithItem:_nameLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.bgImageView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-20];
        [self.bgImageView addConstraint:bgImageRight];
        
        NSLayoutConstraint *bgImageBottom = [NSLayoutConstraint constraintWithItem:_nameLabel attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.bgImageView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
        [self.bgImageView addConstraint:bgImageBottom];
        
        NSLayoutConstraint *bgImageWidth = [NSLayoutConstraint constraintWithItem:_nameLabel attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:95];
        [self.bgImageView addConstraint:bgImageWidth];
    }
    return _nameLabel;
}

- (UILabel *)shopnameLabel
{
    if (!_shopnameLabel) {
        _shopnameLabel = [[UILabel alloc] init];
        _shopnameLabel.translatesAutoresizingMaskIntoConstraints = NO;
        _shopnameLabel.font = [UIFont systemFontOfSize:13.0];
        _shopnameLabel.textAlignment = NSTextAlignmentRight;
        _shopnameLabel.textColor = [UIColor whiteColor];
        [self.bgImageView addSubview:_shopnameLabel];
admin's avatar
admin committed
674
        
admin's avatar
admin committed
675 676
        NSLayoutConstraint *bgImageTop = [NSLayoutConstraint constraintWithItem:_shopnameLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.searchTextField attribute:NSLayoutAttributeBottom multiplier:1.0 constant:3];
        [self.bgImageView addConstraint:bgImageTop];
admin's avatar
admin committed
677
        
admin's avatar
admin committed
678 679
        NSLayoutConstraint *bgImageRight = [NSLayoutConstraint constraintWithItem:_shopnameLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.nameLabel attribute:NSLayoutAttributeLeft multiplier:1.0 constant:-10];
        [self.bgImageView addConstraint:bgImageRight];
admin's avatar
admin committed
680
        
admin's avatar
admin committed
681 682
        NSLayoutConstraint *bgImageBottom = [NSLayoutConstraint constraintWithItem:_shopnameLabel attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.bgImageView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
        [self.bgImageView addConstraint:bgImageBottom];
admin's avatar
admin committed
683
        
admin's avatar
admin committed
684 685
        NSLayoutConstraint *bgImageLeft = [NSLayoutConstraint constraintWithItem:_shopnameLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.bgImageView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:20];
        [self.bgImageView addConstraint:bgImageLeft];
admin's avatar
admin committed
686
    }
admin's avatar
admin committed
687
    return _shopnameLabel;
admin's avatar
admin committed
688 689
}

admin's avatar
admin committed
690

admin's avatar
admin committed
691 692 693 694 695 696 697 698 699
- (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;
admin's avatar
admin committed
700 701 702 703 704 705
        
        [_tableView registerClass:[PictureTableCell class] forCellReuseIdentifier:kHomePictureListCell];
        [_tableView registerClass:[HomeTitleTableCell class] forCellReuseIdentifier:kHomeTitleTableCell];
        [_tableView registerClass:[RankingListCell class] forCellReuseIdentifier:kHomeRankingListCell];
        [_tableView registerClass:[QuestionListTableCell class] forCellReuseIdentifier:kHomeQuestionListTableCell];

admin's avatar
admin committed
706 707
        [self.view addSubview:_tableView];
        
admin's avatar
admin committed
708
        NSLayoutConstraint *tableTop = [NSLayoutConstraint constraintWithItem:_tableView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1.0 constant:95];
admin's avatar
admin committed
709 710 711 712 713 714 715 716
        [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];
        
admin's avatar
admin committed
717
        NSLayoutConstraint *tableBottom = [NSLayoutConstraint constraintWithItem:_tableView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-40];
admin's avatar
admin committed
718 719 720 721 722 723
        [self.view addConstraint:tableBottom];
    }
    return _tableView;
}

@end