HomeViewController.m 48.7 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"
11
#import "RankListHeaderView.h"
admin's avatar
admin committed
12 13 14

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

admin's avatar
admin committed
20 21 22 23 24 25 26 27 28 29 30
#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"
admin's avatar
admin committed
31
#import "RankListModel.h"
32
#import "RankCommentCell.h"
admin's avatar
admin committed
33 34 35 36 37

#import "QuestionListTableCell.h"
#define kHomeQuestionListTableCell @"homeQuestionListTableCell"
#import "QuestionModel.h"
#import "QuestionDetailViewController.h"
38
#define kQuestionTag 387428
admin's avatar
admin committed
39 40 41 42

#import "InspectListCell.h"
#define kHomeInspectListCell @"homeInspectListsCell"
#import "InspectTaskViewController.h"
43
#import "TaskListModel.h"
admin's avatar
admin committed
44

admin's avatar
admin committed
45 46 47
#import "PictureTableCell.h"
#define KHomePicTableCell @"pictureTableViewCell"

48
#import "SpotCheckOnLineViewController.h"
49 50 51 52 53

#import "LookOnLineViewController.h"

#import "StandardViewController.h"

54 55 56
#import "HttpClient.h"
#import <MBProgressHUD.h>

admin's avatar
admin committed
57
#import <MJRefresh.h>
admin's avatar
admin committed
58
#import "SearchViewController.h"
admin's avatar
admin committed
59

admin's avatar
admin committed
60 61
typedef NSComparisonResult (^NSComparator)(id obj1, id obj2);

62
@interface HomeViewController () <UITableViewDelegate, UITableViewDataSource, UIScrollViewDelegate, UITextFieldDelegate, RankListHeaderDelegate>
admin's avatar
admin committed
63 64 65 66 67 68
@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
69 70 71 72
// 当前视图
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) HomeHeaderView *headView;

admin's avatar
admin committed
73
@property (nonatomic, strong) NSMutableArray *titleArray; // section标题
admin's avatar
admin committed
74
@property (nonatomic, strong) NSMutableArray *sectionArray; // section标题
admin's avatar
admin committed
75

76
@property (nonatomic, strong) NSMutableArray *allQuestionArray; // 问题与知识
admin's avatar
admin committed
77 78
@property (nonatomic, strong) NSMutableArray *taskListDataArray; // 问题与知识
@property (nonatomic, strong) NSMutableArray *allRankListArray;
admin's avatar
admin committed
79
@property (nonatomic, strong) NSMutableArray *allPraiseListArray;
admin's avatar
admin committed
80 81 82
@end

@implementation HomeViewController
admin's avatar
admin committed
83

admin's avatar
admin committed
84 85 86 87 88
#pragma mark - ViewDidLoad
- (void)viewDidLoad
{
    [super viewDidLoad];
    
89
    
admin's avatar
admin committed
90 91 92 93 94 95
    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
96
    self.titleArray = [NSMutableArray array];
admin's avatar
admin committed
97 98
    self.sectionArray = [NSMutableArray array];
    
admin's avatar
admin committed
99
    NSArray *permissions = [[NSUserDefaults standardUserDefaults] objectForKey:@"permissions"];
admin's avatar
admin committed
100
    
admin's avatar
admin committed
101
    // 口碑报告 商场风采 图说口碑 口碑标准  问题知识 口碑巡检
admin's avatar
admin committed
102
    
admin's avatar
admin committed
103
    if ([permissions containsObject:@"500201"]) {
admin's avatar
admin committed
104
        [self.titleArray addObject:@"口碑报告"];
admin's avatar
admin committed
105 106
        [self requestRankingList];
    }
admin's avatar
admin committed
107
    
admin's avatar
admin committed
108
    [self.titleArray addObject:@"商场风采"];
admin's avatar
admin committed
109
    //[self requestPicturePraise];
admin's avatar
admin committed
110 111
    
    if ([permissions containsObject:@"500301"] || [permissions containsObject:@"500302"]) {
admin's avatar
admin committed
112
        [self.titleArray addObject:@"图说口碑"];
admin's avatar
admin committed
113
    }
admin's avatar
admin committed
114
    
admin's avatar
admin committed
115
    if ([permissions containsObject:@"500401"] || [permissions containsObject:@"500402"]) {
admin's avatar
admin committed
116
        [self.titleArray addObject:@"口碑标准"];
admin's avatar
admin committed
117
    }
admin's avatar
admin committed
118
    
admin's avatar
admin committed
119 120
    if ([permissions containsObject:@"500501"] || [permissions containsObject:@"500502"]) {
        [self.titleArray addObject:@"问题知识"];
admin's avatar
admin committed
121
       // [self requestQuestionList];
admin's avatar
admin committed
122 123
    }
    
admin's avatar
admin committed
124 125
    if ([permissions containsObject:@"500101"] || [permissions containsObject:@"500102"]) {
        [self.titleArray addObject:@"口碑巡检"];
admin's avatar
admin committed
126
        //[self requestInspectList];
admin's avatar
admin committed
127 128 129 130
    }
    
    
    
admin's avatar
admin committed
131
    [[NSUserDefaults standardUserDefaults] setObject:_titleArray forKey:@"function"];
132
    
admin's avatar
admin committed
133 134
    
    [self setupNav];
admin's avatar
admin committed
135 136
    [self setupTableView];
    
admin's avatar
admin committed
137
    
admin's avatar
admin committed
138 139 140 141 142
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    self.allRankListArray = [NSMutableArray array];
    self.taskListDataArray = [NSMutableArray array];
    self.allQuestionArray = [NSMutableArray array];
admin's avatar
admin committed
143
    self.allPraiseListArray = [NSMutableArray array];
admin's avatar
admin committed
144
    
admin's avatar
admin committed
145
    
admin's avatar
admin committed
146 147 148 149 150 151 152 153 154 155 156
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(refreshInspectList)
                                                 name:kRefreshInspectPointNotification
                                               object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(refreshQuestionList)
                                                 name:kRefreshQuestionNotification
                                               object:nil];
    
}
admin's avatar
admin committed
157 158

- (void)viewWillAppear:(BOOL)animated
admin's avatar
admin committed
159
{
admin's avatar
admin committed
160 161 162 163 164
    [super viewWillAppear:animated];
    
    self.tabBarController.tabBar.hidden = NO;
    self.navigationController.navigationBar.hidden = YES;
    [self.tableView.header beginRefreshing];
admin's avatar
admin committed
165 166
}

admin's avatar
admin committed
167
#pragma mark - 刷新数据
admin's avatar
admin committed
168 169
- (void)refreshAllData
{
admin's avatar
admin committed
170 171 172
    [self refreshInspectList];
    [self refreshRankingList];
    [self refreshQuestionList];
admin's avatar
admin committed
173
    [self refreshPraiseList];
admin's avatar
admin committed
174 175
}

admin's avatar
admin committed
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
- (void)refreshPraiseList
{
    // 请求地址
    NSString *urlStr = [NSString stringWithFormat:@"%@%@", kRedStarURL, kQueryPicturePraiseURL];
    NSString *user_uuid = [[NSUserDefaults standardUserDefaults] objectForKey:@"user_uuid"];
    NSDictionary *parameters = @{
                                 @"scope":@"all",
                                 @"user":user_uuid,
                                 @"type":@"store",
                                 @"pageNumber":@(0),
                                 @"pageSize":@(2)
                                 };
    
    // 发起请求
    HttpClient *httpClient = [[HttpClient alloc] initWithUrl:urlStr];
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    // 请求问题列表
    [httpClient queryPicturePraiseWithParameters:parameters completion:^(id response, NSError *error) {
        NSLog(@"刷新!!== 图说口碑 response = %@   error = %@" , response, error);
        NSDictionary *dataDict = response[@"data"];
        NSArray *dataArray = dataDict[@"records"];
        NSMutableArray *tempArray = [NSMutableArray array];
        for (NSDictionary *dict in dataArray) {
            PictureListModel *picList = [[PictureListModel alloc] init];
            [picList setValuesForKeysWithDictionary:dict];
            [tempArray addObject:picList];
        }
        _allPraiseListArray = tempArray;
        [self.tableView reloadData];
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        [self.tableView.header endRefreshing];

    }];

}

// 刷新口碑任务
- (void)refreshInspectList
{
admin's avatar
admin committed
216 217 218 219
    // 口碑任务
    NSString *url3 = [NSString stringWithFormat:@"%@%@", kRedStarURL, kInspectListURL];
    HttpClient *httpCilent3 = [[HttpClient alloc] initWithUrl:url3];
    NSDictionary *parameters3 = @{@"userUuid":[[NSUserDefaults standardUserDefaults] objectForKey:@"user_uuid"],
admin's avatar
admin committed
220
                                  @"queryOrders":@[@{@"field":@"lastModifyInfo", @"direction":@"desc"}],
admin's avatar
admin committed
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
                                  @"pageNumber":@(0),
                                  @"pageSize":@(2)
                                  };
    
    [httpCilent3 getInspectListWithParameters:parameters3 completion:^(id response, NSError *error) {
        NSLog(@"刷新!! = 巡检列表%@", response);
        NSDictionary *dataDict = response[@"data"];
        NSArray *dataArray = dataDict[@"records"];
        NSMutableArray *inspectTempArr = [NSMutableArray array];
        for (NSDictionary *dict in dataArray) {
            TaskListModel *taskList = [[TaskListModel alloc] init];
            [taskList setValuesForKeysWithDictionary:dict];
            [inspectTempArr addObject:taskList];
        }
        _taskListDataArray = inspectTempArr;
admin's avatar
admin committed
236
        
admin's avatar
admin committed
237 238 239 240 241 242
        [self.tableView reloadData];
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        [self.tableView.header endRefreshing];
    }];

}
admin's avatar
admin committed
243

admin's avatar
admin committed
244
- (void)refreshRankingList {
admin's avatar
admin committed
245 246 247
    // 口碑巡检
    NSString *url1 = [NSString stringWithFormat:@"%@%@", kRedStarURL, kRankingListURL];
    HttpClient *httpCilent1 = [[HttpClient alloc] initWithUrl:url1];
admin's avatar
admin committed
248 249
    NSDictionary *parameters1 = @{@"praiseUuid":@"",
                                  @"statisMode":@(0),
admin's avatar
admin committed
250 251 252 253 254
                                  @"pageNumber":@(0),
                                  @"pageSize":@(3)
                                  };
    __block HomeViewController *weakSelf = self;
    [httpCilent1 getRankingListWithParameters:parameters1 completion:^(id response, NSError *error) {
admin's avatar
admin committed
255
        NSLog(@"刷新!! = 口碑报告response = %@", response);
admin's avatar
admin committed
256
        
admin's avatar
admin committed
257 258 259 260 261 262 263 264 265
        NSDictionary *dataDict = response[@"data"];
        NSArray *dataArray = dataDict[@"records"];
        
        NSMutableArray *rankTempArr = [NSMutableArray array];
        for (NSDictionary *ListDict in dataArray) {
            RankListModel *rankList = [RankListModel rankListModelWithDict:ListDict];
            [rankTempArr addObject:rankList];
        }
        weakSelf.allRankListArray = rankTempArr;
admin's avatar
admin committed
266
        
admin's avatar
admin committed
267 268
        [self.tableView reloadData];
        [MBProgressHUD hideHUDForView:self.view animated:YES];
admin's avatar
admin committed
269 270
        [self.tableView.header endRefreshing];

admin's avatar
admin committed
271
    }];
admin's avatar
admin committed
272 273 274
}

- (void)refreshQuestionList {
admin's avatar
admin committed
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
    // 问题与知识
    NSString *url2 = [NSString stringWithFormat:@"%@%@", kRedStarURL, kQuestionListURL];
    NSString *user_uuid = [[NSUserDefaults standardUserDefaults] objectForKey:@"user_uuid"];
    NSDictionary *parameters2 = @{
                                  @"user":user_uuid,
                                  @"scope":@"all",
                                  @"pageNumber":@(0),
                                  @"pageSize":@(2)
                                  };
    
    HttpClient *httpClient2 = [[HttpClient alloc] initWithUrl:url2];
    [httpClient2 getQuestionListWithParameters:parameters2 completion:^(id response, NSError *error) {
        NSDictionary *dataDict = (NSDictionary *)response[@"data"];
        NSDictionary *recordsDict = (NSDictionary *)dataDict[@"records"];
        NSLog(@"刷新!! = 问题与知识列表recods = %@", response);
        
        NSMutableArray *questionTempArr = [NSMutableArray array];
        
        for (NSDictionary *questionDict in recordsDict) {
            QuestionModel *question = [[QuestionModel alloc] init];
            [question setValuesForKeysWithDictionary:questionDict];
            [questionTempArr addObject:question];
        }
admin's avatar
admin committed
298
        _allQuestionArray = questionTempArr;
admin's avatar
admin committed
299
        
admin's avatar
admin committed
300 301 302 303
        [self.tableView reloadData];
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    }];

admin's avatar
admin committed
304
}
admin's avatar
admin committed
305

admin's avatar
admin committed
306

admin's avatar
admin committed
307
#pragma mark - 请求数据
admin's avatar
admin committed
308 309 310 311 312
- (void)requestRankingList
{
    
    NSString *url = [NSString stringWithFormat:@"%@%@", kRedStarURL, kRankingListURL];
    HttpClient *httpCilent = [[HttpClient alloc] initWithUrl:url];
313
    NSDictionary *parameters = @{@"praiseUuid":@"",
admin's avatar
admin committed
314 315 316
                                 @"statisMode":@(0),
                                 @"pageNumber":@(0),
                                 @"pageSize":@(3)
admin's avatar
admin committed
317
                                 };
318

admin's avatar
admin committed
319
    [httpCilent getRankingListWithParameters:parameters completion:^(id response, NSError *error) {
admin's avatar
admin committed
320 321 322
        
        [self requestPicturePraise];

admin's avatar
admin committed
323
        NSLog(@"口碑报告response = %@", response);
admin's avatar
admin committed
324 325
        NSDictionary *dataDict = response[@"data"];
        NSArray *dataArray = dataDict[@"records"];
326 327 328
        
        NSMutableArray *tgArray = [NSMutableArray array];
        
admin's avatar
admin committed
329 330
        for (NSDictionary *ListDict in dataArray) {
            RankListModel *rankList = [RankListModel rankListModelWithDict:ListDict];
331
            [tgArray addObject:rankList];
admin's avatar
admin committed
332
        }
admin's avatar
admin committed
333
        _allRankListArray = (NSMutableArray *)[self sortRankListWithRankListArray:tgArray];
334 335 336 337 338 339 340 341 342 343
        
        for (int i = 0 ; i < _allRankListArray.count; i++) {
            RankListModel *rank = _allRankListArray[i];
            if (i == 0) {
                rank.index = i + 1;
            } else {
                RankListModel *prevRank = _allRankListArray[i-1];
                rank.index = rank.score == prevRank.score ? prevRank.index: i + 1;
            }
        }
admin's avatar
admin committed
344 345 346
        if (_allRankListArray.count != 0) {
            [_sectionArray addObject:@"口碑报告"];
        }
admin's avatar
admin committed
347 348
        [self.tableView reloadData];
        [MBProgressHUD hideHUDForView:self.view animated:YES];
admin's avatar
admin committed
349 350 351

        
        
admin's avatar
admin committed
352 353 354
    }];
}

admin's avatar
admin committed
355 356 357
- (NSArray *)sortRankListWithRankListArray:(NSMutableArray *)allRanking
{
    NSArray *sortedArray = [allRanking sortedArrayUsingComparator:^NSComparisonResult(RankListModel *p1, RankListModel *p2){
358 359 360
        //return [p2.score compare:p1.score];
        return [@(p2.score) compare:@(p1.score)];

admin's avatar
admin committed
361 362 363 364
    }];
    return sortedArray;
}

admin's avatar
admin committed
365 366 367 368 369 370


- (void)requestInspectList
{
    
    NSString *url = [NSString stringWithFormat:@"%@%@", kRedStarURL, kInspectListURL];
371
    NSLog(@"uuuurl = %@", url);
admin's avatar
admin committed
372
    HttpClient *httpCilent = [[HttpClient alloc] initWithUrl:url];
373 374 375 376
    

    NSDictionary *parameters = @{
                                 @"userUuid":[[NSUserDefaults standardUserDefaults] objectForKey:@"user_uuid"],
admin's avatar
admin committed
377
                                 @"queryOrders":@[@{@"field":@"lastModifyInfo", @"direction":@"desc"}],
admin's avatar
admin committed
378 379 380
                                 @"pageNumber":@(0),
                                 @"pageSize":@(2)
                                 };
381
    NSLog(@"parrrrr = %@", parameters);
admin's avatar
admin committed
382 383 384
    [httpCilent getInspectListWithParameters:parameters completion:^(id response, NSError *error) {
        
        NSLog(@"巡检列表%@", response);
385
        NSLog(@"error = %@", error);
admin's avatar
admin committed
386 387 388 389 390 391 392
        NSDictionary *dataDict = response[@"data"];
        NSArray *dataArray = dataDict[@"records"];
        for (NSDictionary *dict in dataArray) {
            TaskListModel *taskList = [[TaskListModel alloc] init];
            [taskList setValuesForKeysWithDictionary:dict];
            [_taskListDataArray addObject:taskList];
        }
admin's avatar
admin committed
393 394 395
        if (_taskListDataArray.count != 0) {
            [_sectionArray addObject:@"口碑巡检"];
        }
admin's avatar
admin committed
396 397 398 399 400 401 402
        [self.tableView reloadData];
        [MBProgressHUD hideHUDForView:self.view animated:YES];

    }];

}

403 404 405 406 407 408 409
- (void)requestQuestionList
{
    // 初始化数组
    // 请求地址
    NSString *urlStr = [NSString stringWithFormat:@"%@%@", kRedStarURL, kQuestionListURL];
    NSString *user_uuid = [[NSUserDefaults standardUserDefaults] objectForKey:@"user_uuid"];
    // 请求参数
admin's avatar
admin committed
410
    NSDictionary *parameters = @{@"user":user_uuid,
411 412
                                 @"scope":@"all",
                                 @"pageNumber":@(0),
admin's avatar
admin committed
413
                                 @"pageSize":@(2)
414 415 416 417 418 419 420 421
                                 };
    // 发起请求
    HttpClient *httpClient = [[HttpClient alloc] initWithUrl:urlStr];
    //
    __block HomeViewController *weakSelf = self;
    
    // 请求问题列表
    [httpClient getQuestionListWithParameters:parameters completion:^(id response, NSError *error) {
admin's avatar
admin committed
422 423 424
        
        [self requestInspectList];
        
425 426 427
        NSDictionary *dataDict = (NSDictionary *)response[@"data"];
        NSDictionary *recordsDict = (NSDictionary *)dataDict[@"records"];
        NSLog(@"问题与知识列表recods = %@", response);
428
        NSLog(@"error = %@", error);
429 430 431 432 433
        for (NSDictionary *questionDict in recordsDict) {
            QuestionModel *question = [[QuestionModel alloc] init];
            [question setValuesForKeysWithDictionary:questionDict];
            [weakSelf.allQuestionArray addObject:question];
        }
admin's avatar
admin committed
434 435 436
        if (_allQuestionArray.count != 0) {
            [_sectionArray addObject:@"问题知识"];
        }
admin's avatar
admin committed
437 438
        [self.tableView reloadData];

439 440 441 442 443
        self.tableView.tableHeaderView = self.headView;
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    }];
}

admin's avatar
admin committed
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463
- (void)requestPicturePraise
{
    
    // 请求地址
    NSString *urlStr = [NSString stringWithFormat:@"%@%@", kRedStarURL, kQueryPicturePraiseURL];
    NSString *user_uuid = [[NSUserDefaults standardUserDefaults] objectForKey:@"user_uuid"];
    NSDictionary *parameters = @{
                                 @"scope":@"all",
                                 @"user":user_uuid,
                                 @"type":@"store",
                                 @"pageNumber":@(0),
                                 @"pageSize":@(2)
                                 };
    
    // 发起请求
    HttpClient *httpClient = [[HttpClient alloc] initWithUrl:urlStr];
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    // 请求问题列表
    [httpClient queryPicturePraiseWithParameters:parameters completion:^(id response, NSError *error) {
admin's avatar
admin committed
464 465 466
        
        [self requestQuestionList];
        
admin's avatar
admin committed
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485
        NSLog(@"图说口碑 response = %@   error = %@" , response, error);
        NSDictionary *dataDict = response[@"data"];
        NSArray *dataArray = dataDict[@"records"];
        NSMutableArray *tempArray = [NSMutableArray array];
        for (NSDictionary *dict in dataArray) {
            PictureListModel *picList = [[PictureListModel alloc] init];
            [picList setValuesForKeysWithDictionary:dict];
            [tempArray addObject:picList];
        }
        _allPraiseListArray = tempArray;
        if (_allPraiseListArray.count != 0) {
            [_sectionArray addObject:@"商场风采"];
        }
        [self.tableView reloadData];
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    }];
    
}

486

admin's avatar
admin committed
487
#pragma mark - Private Methods
admin's avatar
admin committed
488 489 490 491 492 493 494
- (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];
admin's avatar
admin committed
495
    _nameLabel.text = [NSString stringWithFormat:@"%@,你好!", [[NSUserDefaults standardUserDefaults] objectForKey:@"user_name"]];
admin's avatar
admin committed
496
    self.shopnameLabel.backgroundColor = [UIColor clearColor];
admin's avatar
admin committed
497
    _shopnameLabel.text = [NSString stringWithFormat:@"%@", [[NSUserDefaults standardUserDefaults] objectForKey:@"org_name"]];
admin's avatar
admin committed
498 499 500

}

admin's avatar
admin committed
501 502
- (void)setupTableView
{
admin's avatar
admin committed
503
    self.headView = [[HomeHeaderView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 115)];
admin's avatar
admin committed
504
    
admin's avatar
admin committed
505 506
    self.headView.scrollView.contentSize = CGSizeMake(2 * kScreenWidth, 86);
    CGFloat itemW = kScreenWidth / 4;
admin's avatar
admin committed
507
    CGFloat itemH = self.headView.scrollView.frame.size.height;
admin's avatar
admin committed
508 509 510
    NSMutableArray *titleArray = [[NSUserDefaults standardUserDefaults] objectForKey:@"function"];

    for (int i = 0; i < titleArray.count; i++) {
admin's avatar
admin committed
511 512
        HomeCellItem *item = [[HomeCellItem alloc] init];
        item.frame = CGRectMake(i * itemW, 0, itemW, itemH);
admin's avatar
admin committed
513
        NSString *nameStr = titleArray[i];
admin's avatar
admin committed
514
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%@", nameStr]];
admin's avatar
admin committed
515 516
        [item setImage:image forState:UIControlStateNormal];
        [item setTitleColor:kPictureCellDetailsColor forState:UIControlStateNormal];
admin's avatar
admin committed
517
        [item setTitle:nameStr forState:UIControlStateNormal];
admin's avatar
admin committed
518 519 520
        [item addTarget:self action:@selector(itemClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.headView.scrollView addSubview:item];
    }
admin's avatar
admin committed
521 522 523 524 525 526 527 528 529
    
    self.tableView.tableHeaderView = self.headView;
    
    // 设置下拉刷新
    self.tableView.header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        // 进入刷新状态后会自动调用这个block
        [self refreshAllData];
        
    }];
admin's avatar
admin committed
530 531
}

532
// 更多按钮点击事件
admin's avatar
admin committed
533 534
- (void)moreButtonClick:(UIButton *)sender
{
admin's avatar
admin committed
535
    NSInteger section = sender.tag - 332892;
536
    UINavigationController *nav;
admin's avatar
admin committed
537 538 539 540
    if ([_sectionArray[section] isEqualToString:@"在线抽查"]) {
        SpotCheckOnLineViewController *spotOnline = [[SpotCheckOnLineViewController alloc] init];
        nav = [[UINavigationController alloc] initWithRootViewController:spotOnline];
    } else if ([_sectionArray[section] isEqualToString:@"口碑巡检"]) {
admin's avatar
admin committed
541 542
        InspectListViewController *inspectListVC = [[InspectListViewController alloc] init];
        nav = [[UINavigationController alloc] initWithRootViewController:inspectListVC];
admin's avatar
admin committed
543 544 545 546 547 548 549
    } else if ([_sectionArray[section] isEqualToString:@"口碑标准"]) {
        StandardViewController *standardVC = [[StandardViewController alloc] init];
        nav = [[UINavigationController alloc] initWithRootViewController:standardVC];
    } else if ([_sectionArray[section] isEqualToString:@"图说口碑"]) {
        PicCategoryViewController *pictureVC = [[PicCategoryViewController alloc] init];
        nav = [[UINavigationController alloc] initWithRootViewController:pictureVC];
    } else if ([_sectionArray[section] isEqualToString:@"问题知识"]) {
550 551
        QuestionViewController *questionVC = [[QuestionViewController alloc] init];
        nav = [[UINavigationController alloc] initWithRootViewController:questionVC];
admin's avatar
admin committed
552 553 554 555 556 557 558 559 560 561 562
    } else if ([_sectionArray[section] isEqualToString:@"口碑报告"]){
        RankingListViewController *rankingListVC = [[RankingListViewController alloc] init];
        nav = [[UINavigationController alloc] initWithRootViewController:rankingListVC];
    } else if ([_sectionArray[section] isEqualToString:@"查看抽查"]){
        LookOnLineViewController *lookOnLine = [[LookOnLineViewController alloc] init];
        nav = [[UINavigationController alloc] initWithRootViewController:lookOnLine];
    } else if ([_sectionArray[section] isEqualToString:@"商场风采"]) {
        PictureViewController *pic = [[PictureViewController alloc] init];
        pic.come = @"首页";
        pic.category = @"store";
        nav = [[UINavigationController alloc] initWithRootViewController:pic];
563 564 565 566 567
    }
    
    [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
568
    
admin's avatar
admin committed
569 570
}

admin's avatar
admin committed
571
- (void)itemClick:(HomeCellItem *)sender
admin's avatar
admin committed
572
{
admin's avatar
admin committed
573 574 575
    HomeCellItem *item = (HomeCellItem *)sender;
    UINavigationController *nav;
    if ([item.titleLabel.text isEqualToString:@"在线抽查"]) {
576 577
        SpotCheckOnLineViewController *spotOnline = [[SpotCheckOnLineViewController alloc] init];
        nav = [[UINavigationController alloc] initWithRootViewController:spotOnline];
admin's avatar
admin committed
578
    } else if ([item.titleLabel.text isEqualToString:@"口碑巡检"]) {
admin's avatar
admin committed
579 580 581
        InspectListViewController *inspectListVC = [[InspectListViewController alloc] init];
        nav = [[UINavigationController alloc] initWithRootViewController:inspectListVC];
    } else if ([item.titleLabel.text isEqualToString:@"口碑标准"]) {
admin's avatar
admin committed
582 583
        StandardViewController *standardVC = [[StandardViewController alloc] init];
        nav = [[UINavigationController alloc] initWithRootViewController:standardVC];
admin's avatar
admin committed
584
    } else if ([item.titleLabel.text isEqualToString:@"图说口碑"]) {
admin's avatar
admin committed
585
        PicCategoryViewController *pictureVC = [[PicCategoryViewController alloc] init];
admin's avatar
admin committed
586
        nav = [[UINavigationController alloc] initWithRootViewController:pictureVC];
admin's avatar
admin committed
587
    } else if ([item.titleLabel.text isEqualToString:@"问题知识"]) {
admin's avatar
admin committed
588 589
        QuestionViewController *questionVC = [[QuestionViewController alloc] init];
        nav = [[UINavigationController alloc] initWithRootViewController:questionVC];
admin's avatar
admin committed
590
    } else if ([item.titleLabel.text isEqualToString:@"口碑报告"]){
admin's avatar
admin committed
591 592
        RankingListViewController *rankingListVC = [[RankingListViewController alloc] init];
        nav = [[UINavigationController alloc] initWithRootViewController:rankingListVC];
593 594 595
    } else if ([item.titleLabel.text isEqualToString:@"查看抽查"]){
        LookOnLineViewController *lookOnLine = [[LookOnLineViewController alloc] init];
        nav = [[UINavigationController alloc] initWithRootViewController:lookOnLine];
admin's avatar
admin committed
596 597 598 599 600
    } else if ([item.titleLabel.text isEqualToString:@"商场风采"]) {
        PictureViewController *pic = [[PictureViewController alloc] init];
        pic.come = @"首页";
        pic.category = @"store";
        nav = [[UINavigationController alloc] initWithRootViewController:pic];
admin's avatar
admin committed
601
    }
admin's avatar
admin committed
602
    
admin's avatar
admin committed
603 604 605
    [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
606 607 608 609 610 611 612 613
}




#pragma mark - TableView Delegate/DataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
admin's avatar
admin committed
614
    return _sectionArray.count;
admin's avatar
admin committed
615 616 617 618 619
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
admin's avatar
admin committed
620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635
    NSUInteger s2 = [_sectionArray indexOfObject:@"口碑报告"];
    NSUInteger s4 = [_sectionArray indexOfObject:@"商场风采"];
    NSUInteger s3 = [_sectionArray indexOfObject:@"问题知识"];
    NSUInteger s1 = [_sectionArray indexOfObject:@"口碑巡检"];
    
    if ([_sectionArray[section] isEqualToString:@"口碑巡检"] && section == s1) {
        return _taskListDataArray.count;
    } else if ([_sectionArray[section] isEqualToString:@"口碑报告"] && section == s2) {
        return _allRankListArray.count + 1;
    } else if ([_sectionArray[section] isEqualToString:@"问题知识"] && section == s3) {
        return _allQuestionArray.count;
    } else if ([_sectionArray[section] isEqualToString:@"商场风采"] && section == s4) {
        return _allPraiseListArray.count;
    } else {
        return 0;
    }
admin's avatar
admin committed
636 637
}

admin's avatar
admin committed
638

admin's avatar
admin committed
639 640 641
// cell显示的内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
admin's avatar
admin committed
642 643 644 645
    NSUInteger s2 = [_sectionArray indexOfObject:@"口碑报告"];
    NSUInteger s4 = [_sectionArray indexOfObject:@"商场风采"];
    NSUInteger s3 = [_sectionArray indexOfObject:@"问题知识"];
    NSUInteger s1 = [_sectionArray indexOfObject:@"口碑巡检"];
admin's avatar
admin committed
646

admin's avatar
admin committed
647
    if ([_sectionArray[indexPath.section] isEqualToString:@"口碑巡检"] && indexPath.section == s1) {
admin's avatar
admin committed
648 649 650
        InspectListCell *cell=[tableView dequeueReusableCellWithIdentifier:kHomeInspectListCell];
        if (!cell) {
            cell = [[InspectListCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kHomeInspectListCell];
admin's avatar
admin committed
651
        }
admin's avatar
admin committed
652 653 654 655 656 657 658 659
        TaskListModel *taskList = _taskListDataArray[indexPath.row];
        cell.taskList = taskList;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.allView.backgroundColor = kProgressViewAllBackColor;
        UIImage *image = [UIImage imageNamed:@"progress-bar"];
        image = [image resizableImageWithCapInsets:UIEdgeInsetsZero resizingMode:UIImageResizingModeTile];
        cell.alreadyView.image = image;
        return cell;
admin's avatar
admin committed
660
    } else if ([_sectionArray[indexPath.section] isEqualToString:@"口碑报告"] && indexPath.section == s2) {
admin's avatar
admin committed
661 662
        if (indexPath.row == 0) {
            HomeTitleTableCell *cell=[tableView dequeueReusableCellWithIdentifier:kHomeTitleTableCell];
admin's avatar
admin committed
663
            if (!cell) {
admin's avatar
admin committed
664
                cell = [[HomeTitleTableCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kHomeTitleTableCell];
admin's avatar
admin committed
665 666 667 668
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        } else {
admin's avatar
admin committed
669
            RankingListCell *cell = [tableView dequeueReusableCellWithIdentifier:kHomeRankingListCell];
admin's avatar
admin committed
670
            if (!cell) {
admin's avatar
admin committed
671
                cell = [[RankingListCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kHomeRankingListCell];
admin's avatar
admin committed
672
            }
673 674
            RankListModel *rankList = _allRankListArray[indexPath.row - 1];
            cell.rankList = rankList;
admin's avatar
admin committed
675
            cell.gradeImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"medal_0%d", rankList.index+ 1]];
admin's avatar
admin committed
676 677
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
admin's avatar
admin committed
678
        }
admin's avatar
admin committed
679
    } else if ([_sectionArray[indexPath.section] isEqualToString:@"问题知识"] && indexPath.section == s3) {
admin's avatar
admin committed
680 681 682 683 684 685 686 687 688
        // 问题与知识
        QuestionListTableCell *cell = [tableView dequeueReusableCellWithIdentifier:kHomeQuestionListTableCell];
        if (!cell) {
            cell = [[QuestionListTableCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kHomeQuestionListTableCell];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        QuestionModel *question = _allQuestionArray[indexPath.row];
        cell.question = question;
        return cell;
admin's avatar
admin committed
689 690 691 692 693 694 695
    } else if ([_sectionArray[indexPath.section] isEqualToString:@"商场风采"] && indexPath.section == s4) {
        PictureTableCell *cell=[tableView dequeueReusableCellWithIdentifier:KHomePicTableCell];
        if (!cell) {
            cell = [[PictureTableCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:KHomePicTableCell];
        }
        cell.pictureList = _allPraiseListArray[indexPath.row];
        return cell;
admin's avatar
admin committed
696 697
    } else {
        return nil;
admin's avatar
admin committed
698
    }
admin's avatar
admin committed
699
    
admin's avatar
admin committed
700 701 702
    

    
admin's avatar
admin committed
703 704 705 706 707
}

// cell点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
admin's avatar
admin committed
708 709 710 711 712
    NSUInteger s2 = [_sectionArray indexOfObject:@"口碑报告"];
    NSUInteger s4 = [_sectionArray indexOfObject:@"商场风采"];
    NSUInteger s3 = [_sectionArray indexOfObject:@"问题知识"];
    NSUInteger s1 = [_sectionArray indexOfObject:@"口碑巡检"];
    if ([_sectionArray[indexPath.section] isEqualToString:@"口碑巡检"] && indexPath.section == s1) {
admin's avatar
admin committed
713 714 715 716 717 718 719
        InspectTaskViewController *inspectTaskVC = [[InspectTaskViewController alloc] init];
        TaskListModel *taskList = self.taskListDataArray[indexPath.row];
        inspectTaskVC.uuid = taskList.uuid;
        inspectTaskVC.store_uuid = taskList.store_uuid;
        inspectTaskVC.multiplier = (CGFloat)taskList.reportCount / taskList.questionCount ;
        self.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:inspectTaskVC animated:YES];
admin's avatar
admin committed
720
    } else if ([_sectionArray[indexPath.section] isEqualToString:@"口碑报告"] && indexPath.section == s2) {
721 722 723
        if (indexPath.row == 0) {
            return;
        }
admin's avatar
admin committed
724 725
        RankListModel *rankList = _allRankListArray[indexPath.row - 1];
        RankDetailViewController *rankDetailVC = [[RankDetailViewController alloc] init];
726
        rankDetailVC.indexRow = rankList.index;
admin's avatar
admin committed
727 728 729 730 731 732
        rankDetailVC.uuid = rankList.uuid;
        rankDetailVC.store_uuid = rankList.store_uuid;
        rankDetailVC.storeAddress = rankList.storeAddress;
        rankDetailVC.storePictures = rankList.storePictures;
        self.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:rankDetailVC animated:YES];
admin's avatar
admin committed
733
    } else if ([_sectionArray[indexPath.section] isEqualToString:@"问题知识"] && indexPath.section == s3) {
admin's avatar
admin committed
734 735 736 737 738
        QuestionDetailViewController *questionDetailVC = [[QuestionDetailViewController alloc] init];
        QuestionModel *question = self.allQuestionArray[indexPath.row];
        questionDetailVC.questionUuid = question.uuid;
        self.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:questionDetailVC animated:YES];
admin's avatar
admin committed
739 740 741 742 743 744
    } else if ([_sectionArray[indexPath.section] isEqualToString:@"商场风采"] && indexPath.section == s4) {
        PictureListModel *picList = _allPraiseListArray[indexPath.row];
        PictureStoryViewController *storyVC = [[PictureStoryViewController alloc] init];
        storyVC.uuid = picList.uuid;
        self.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:storyVC animated:YES];
admin's avatar
admin committed
745
    } else {
admin's avatar
admin committed
746
        return;
admin's avatar
admin committed
747
    }
admin's avatar
admin committed
748 749 750 751 752 753
}


// section高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
admin's avatar
admin committed
754
    return 36;
admin's avatar
admin committed
755 756 757 758
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
admin's avatar
admin committed
759
    return 10;
admin's avatar
admin committed
760 761 762 763 764
}

// 自定义section
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
admin's avatar
admin committed
765
    
766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792
        // 创建sectionView
        UIView *sectionView = [[UIView alloc] init];
        sectionView.userInteractionEnabled = YES;
        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];
        
        // 创建标题label
        UILabel *titleLabel = [[UILabel alloc] init];
        titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
        titleLabel.textColor = kPictureCellDetailsColor;
        titleLabel.font = [UIFont systemFontOfSize:17.0];
admin's avatar
admin committed
793

admin's avatar
admin committed
794
        titleLabel.text = _sectionArray[section];
admin's avatar
admin committed
795

admin's avatar
admin committed
796
    
797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827
        [sectionView addSubview:titleLabel];
        
        
        // 查看更多按钮
        UIButton *moreButton = [[UIButton alloc] init];
        moreButton.tag = 332892 + section;
        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];
        
        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];
        
        NSLayoutConstraint *titleLabelRight = [NSLayoutConstraint constraintWithItem:titleLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:moreButton attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
        [sectionView addConstraint:titleLabelRight];
        
        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
828
    
829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859
        
        
        // 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;
}
admin's avatar
admin committed
860

admin's avatar
admin committed
861

admin's avatar
admin committed
862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898

#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 = @"查询";
admin's avatar
admin committed
899
        _searchTextField.delegate = self;
admin's avatar
admin committed
900
        [_searchTextField setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];
admin's avatar
admin committed
901 902 903 904
        UIButton *imageV = [[UIButton alloc] init];
        imageV.frame = CGRectMake(0, 0, 28, 28);
        [imageV setImage:[UIImage imageNamed:@"search"] forState:UIControlStateNormal];
        [imageV addTarget:self action:@selector(searchClick:) forControlEvents:UIControlEventTouchUpInside];
admin's avatar
admin committed
905 906 907 908 909
        imageV.contentMode = UIViewContentModeCenter;
        imageV.width += 10;
        _searchTextField.rightView = imageV;
        _searchTextField.rightViewMode = UITextFieldViewModeAlways;
        [self.bgImageView addSubview:_searchTextField];
admin's avatar
admin committed
910
        
admin's avatar
admin committed
911 912
        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
913
        
admin's avatar
admin committed
914 915
        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
916
        
admin's avatar
admin committed
917 918
        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
919
        
admin's avatar
admin committed
920 921 922 923 924 925 926 927 928 929 930 931 932 933 934
        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
935
        
admin's avatar
admin committed
936 937
        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
938
        
admin's avatar
admin committed
939 940 941 942 943 944
        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];
        
admin's avatar
admin committed
945
        NSLayoutConstraint *bgImageWidth = [NSLayoutConstraint constraintWithItem:_nameLabel attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:110];
admin's avatar
admin committed
946 947 948 949 950 951 952 953 954 955 956 957 958 959
        [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
960
        
admin's avatar
admin committed
961 962
        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
963
        
admin's avatar
admin committed
964 965
        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
966
        
admin's avatar
admin committed
967 968
        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
969
        
admin's avatar
admin committed
970 971
        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
972
    }
admin's avatar
admin committed
973
    return _shopnameLabel;
admin's avatar
admin committed
974 975
}

admin's avatar
admin committed
976

admin's avatar
admin committed
977 978 979 980 981 982 983 984 985
- (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;
986 987
        _tableView.rowHeight = UITableViewAutomaticDimension;
        _tableView.estimatedRowHeight = 300.0;
988
        _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 40)];
admin's avatar
admin committed
989 990
        [_tableView registerClass:[PictureTableCell class] forCellReuseIdentifier:kHomePictureListCell];
        [_tableView registerClass:[HomeTitleTableCell class] forCellReuseIdentifier:kHomeTitleTableCell];
admin's avatar
admin committed
991
        [_tableView registerClass:[RankingListCell class] forCellReuseIdentifier:kHomeRankingListCell];
admin's avatar
admin committed
992 993
        [_tableView registerClass:[QuestionListTableCell class] forCellReuseIdentifier:kHomeQuestionListTableCell];

admin's avatar
admin committed
994 995
        [self.view addSubview:_tableView];
        
admin's avatar
admin committed
996
        NSLayoutConstraint *tableTop = [NSLayoutConstraint constraintWithItem:_tableView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1.0 constant:95];
admin's avatar
admin committed
997 998 999 1000 1001 1002 1003 1004
        [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];
        
1005
        NSLayoutConstraint *tableBottom = [NSLayoutConstraint constraintWithItem:_tableView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
admin's avatar
admin committed
1006 1007 1008 1009 1010
        [self.view addConstraint:tableBottom];
    }
    return _tableView;
}

admin's avatar
admin committed
1011

admin's avatar
admin committed
1012 1013
- (void)searchClick:(UIButton *)sender
{
admin's avatar
admin committed
1014
    if (![_searchTextField.text isEqualToString:@""]) {
admin's avatar
admin committed
1015 1016
        SearchViewController *searchVC = [[SearchViewController alloc] init];
        searchVC.customStr = _searchTextField.text;
admin's avatar
admin committed
1017
        self.hidesBottomBarWhenPushed = YES;
admin's avatar
admin committed
1018 1019 1020 1021 1022
        [self.navigationController pushViewController:searchVC animated:YES];
    } else {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请输入关键字!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
        [alert show];
    }
admin's avatar
admin committed
1023
    [_searchTextField resignFirstResponder];
admin's avatar
admin committed
1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:YES];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if ([textField resignFirstResponder]) {
        return YES;
    }
    return NO;
}

1038 1039 1040 1041 1042
- (void)clickHeadView
{
    [_tableView reloadData];
}

admin's avatar
admin committed
1043 1044 1045 1046 1047
-(void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

admin's avatar
admin committed
1048
@end