HomeViewController.m 64.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

#import "LookOnLineViewController.h"

#import "StandardViewController.h"
53 54 55 56 57 58 59 60 61 62
#import "LookOnLineModel.h"
#import "LookOnLineTableViewCell.h"
#define kHomeLookOnLineCell @"homeLookOnLineTableViewCell.h"

#import "SpotCheckModel.h"
#import "SpotCheckTableViewCell.h"
#define kHomeSpotCehcekCell @"homeSpotCheckCell"

#import "OnLineCompleteViewController.h"
#import "LookOnLineDetailViewController.h"
63

64 65 66
#import "HttpClient.h"
#import <MBProgressHUD.h>

admin's avatar
admin committed
67
#import <MJRefresh.h>
admin's avatar
admin committed
68
#import "SearchViewController.h"
admin's avatar
admin committed
69
#import "LookReportDetailViewController.h"
admin's avatar
admin committed
70

AvatarC's avatar
AvatarC committed
71

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

74
@interface HomeViewController () <UITableViewDelegate, UITableViewDataSource, UIScrollViewDelegate, UITextFieldDelegate, RankListHeaderDelegate>
admin's avatar
admin committed
75 76 77 78 79 80
@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
81 82 83 84
// 当前视图
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) HomeHeaderView *headView;

admin's avatar
admin committed
85
@property (nonatomic, strong) NSMutableArray *titleArray; // section标题
admin's avatar
admin committed
86
@property (nonatomic, strong) NSMutableArray *sectionArray; // section标题
admin's avatar
admin committed
87

88
@property (nonatomic, strong) NSMutableArray *allQuestionArray; // 问题与知识
admin's avatar
admin committed
89 90
@property (nonatomic, strong) NSMutableArray *taskListDataArray; // 问题与知识
@property (nonatomic, strong) NSMutableArray *allRankListArray;
admin's avatar
admin committed
91
@property (nonatomic, strong) NSMutableArray *allPraiseListArray;
92
@property (nonatomic, strong) NSMutableArray *allExcellentCaseArray; // 口碑报道
93
@property (nonatomic, strong) NSMutableArray *allPatrolReportArray; // 巡店报告
94 95
@property (nonatomic, strong) NSMutableArray *allLookOnLineList; //
@property (nonatomic, strong) NSMutableArray *allSpotCheckList; //
96

admin's avatar
admin committed
97 98 99
@end

@implementation HomeViewController
admin's avatar
admin committed
100

admin's avatar
admin committed
101 102 103 104 105
#pragma mark - ViewDidLoad
- (void)viewDidLoad
{
    [super viewDidLoad];
    
106
    
admin's avatar
admin committed
107 108 109 110 111 112
    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
113
    self.titleArray = [NSMutableArray array];
114 115 116
   // self.sectionArray = [NSMutableArray arrayWithObjects:@"口碑报告",@"口碑随手拍",@"口碑报道",@"口碑巡店", @"问题知识",@"口碑巡检",nil];
    self.sectionArray = [NSMutableArray arrayWithObjects:@"口碑报告",@"口碑报道",@"口碑巡店", @"问题知识",@"口碑巡检",nil];

admin's avatar
admin committed
117

admin's avatar
admin committed
118 119 120 121
    self.allRankListArray = [NSMutableArray array];
    self.taskListDataArray = [NSMutableArray array];
    self.allQuestionArray = [NSMutableArray array];
    self.allPraiseListArray = [NSMutableArray array];
122 123
    self.allSpotCheckList = [NSMutableArray array];
    self.allLookOnLineList = [NSMutableArray array];
admin's avatar
admin committed
124 125 126
    
    [self setupNav];
    
admin's avatar
admin committed
127
    
admin's avatar
admin committed
128
    NSArray *permissions = [[NSUserDefaults standardUserDefaults] objectForKey:@"permissions"];
admin's avatar
admin committed
129
    
130
    // 口碑报告 口碑随手拍 口碑现场 口碑标准  问题知识 口碑巡检
admin's avatar
admin committed
131
    
admin's avatar
admin committed
132
    if ([permissions containsObject:@"500201"]) {
admin's avatar
admin committed
133
        [self.titleArray addObject:@"口碑报告"];
admin's avatar
admin committed
134
        [self requestRankingList];
admin's avatar
admin committed
135 136
    } else {
        [_sectionArray removeObject:@"口碑报告"];
admin's avatar
admin committed
137
    }
admin's avatar
admin committed
138
    
139
   // [self.titleArray addObject:@"口碑随手拍"];
140 141 142
    
    NSArray *typeArray = [NSArray arrayWithObjects:@"store", @"casus",@"report",nil];
    
143
    // 口碑随手拍
144
    [self requestPicturePraiseWithType:typeArray[0]];
145
    // 口碑报道
146 147 148 149
    [self requestPicturePraiseWithType:typeArray[1]];
    // 巡店报告
    [self requestPicturePraiseWithType:typeArray[2]];

admin's avatar
admin committed
150 151
    
    if ([permissions containsObject:@"500301"] || [permissions containsObject:@"500302"]) {
152
        [self.titleArray addObject:@"口碑现场"];
admin's avatar
admin committed
153
    } else {
154
        [_sectionArray removeObject:@"口碑现场"];
admin's avatar
admin committed
155
    }
admin's avatar
admin committed
156
    
admin's avatar
admin committed
157
    if ([permissions containsObject:@"500401"] || [permissions containsObject:@"500402"]) {
admin's avatar
admin committed
158
        [self.titleArray addObject:@"口碑标准"];
admin's avatar
admin committed
159 160
    } else {
        [_sectionArray removeObject:@"口碑标准"];
admin's avatar
admin committed
161
    }
admin's avatar
admin committed
162
    
admin's avatar
admin committed
163 164
    if ([permissions containsObject:@"500501"] || [permissions containsObject:@"500502"]) {
        [self.titleArray addObject:@"问题知识"];
admin's avatar
admin committed
165 166 167
        [self requestQuestionList];
    }else {
        [_sectionArray removeObject:@"问题知识"];
admin's avatar
admin committed
168 169
    }
    
admin's avatar
admin committed
170 171
    if ([permissions containsObject:@"500101"] || [permissions containsObject:@"500102"]) {
        [self.titleArray addObject:@"口碑巡检"];
admin's avatar
admin committed
172
        [self requestInspectList];
admin's avatar
admin committed
173
    } else {
admin's avatar
admin committed
174
        [_sectionArray removeObject:@"口碑巡检"];
admin's avatar
admin committed
175 176
    }
    
177 178 179 180 181 182 183 184 185 186 187 188
    if ([permissions containsObject:@"500701"] || [permissions containsObject:@"500702"]) {
        [self.titleArray addObject:@"在线抽查"];
        
        if ([permissions containsObject:@"500701"]) {
            [self requestLookOnLineList];
        } else if ([permissions containsObject:@"500702"]){
            [self requestSpotCheckList];
        }
        
    } else {
        [_sectionArray removeObject:@"在线抽查"];
    }
admin's avatar
admin committed
189

190
    
admin's avatar
admin committed
191 192
    [self setupTableView];
    
admin's avatar
admin committed
193
    
admin's avatar
admin committed
194 195
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
admin's avatar
admin committed
196
    
admin's avatar
admin committed
197 198 199 200 201 202 203 204 205 206 207
    [[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
208 209

- (void)viewWillAppear:(BOOL)animated
admin's avatar
admin committed
210
{
admin's avatar
admin committed
211
    [super viewWillAppear:animated];
212
    self.hidesBottomBarWhenPushed = NO;
admin's avatar
admin committed
213 214
    self.tabBarController.tabBar.hidden = NO;
    self.navigationController.navigationBar.hidden = YES;
215

admin's avatar
admin committed
216
    [self.tableView.mj_header beginRefreshing];
AvatarC's avatar
AvatarC committed
217 218
    
    [MobClick beginLogPageView:@"MobClick Home"];
admin's avatar
admin committed
219 220
}

AvatarC's avatar
AvatarC committed
221

222 223 224 225 226 227 228
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    [self.tabBarController.tabBar setHidden:NO];

}
AvatarC's avatar
AvatarC committed
229 230 231 232
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"MobClick Home"];
}
admin's avatar
admin committed
233
#pragma mark - 刷新数据
admin's avatar
admin committed
234 235
- (void)refreshAllData
{
admin's avatar
admin committed
236 237 238
    [self refreshInspectList];
    [self refreshRankingList];
    [self refreshQuestionList];
admin's avatar
admin committed
239
    [self refreshPraiseList];
240 241
    [self refreshSpotCheckList];
    [self requestLookOnLineList];
admin's avatar
admin committed
242 243
}

admin's avatar
admin committed
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
- (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) {
        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;
admin's avatar
admin committed
272
        
admin's avatar
admin committed
273 274
        [self.tableView reloadData];
        [MBProgressHUD hideHUDForView:self.view animated:YES];
admin's avatar
admin committed
275
        [self.tableView.mj_header endRefreshing];
admin's avatar
admin committed
276 277 278 279 280 281 282 283

    }];

}

// 刷新口碑任务
- (void)refreshInspectList
{
admin's avatar
admin committed
284 285 286 287
    // 口碑任务
    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
288
                                  @"queryOrders":@[@{@"field":@"lastModifyInfo", @"direction":@"desc"}],
admin's avatar
admin committed
289 290 291 292 293 294 295 296 297 298 299 300 301 302
                                  @"pageNumber":@(0),
                                  @"pageSize":@(2)
                                  };
    
    [httpCilent3 getInspectListWithParameters:parameters3 completion:^(id response, NSError *error) {
        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
303
        
admin's avatar
admin committed
304 305
        [self.tableView reloadData];
        [MBProgressHUD hideHUDForView:self.view animated:YES];
admin's avatar
admin committed
306
        [self.tableView.mj_header endRefreshing];
admin's avatar
admin committed
307 308 309
    }];

}
admin's avatar
admin committed
310

admin's avatar
admin committed
311
- (void)refreshRankingList {
admin's avatar
admin committed
312 313 314
    // 口碑巡检
    NSString *url1 = [NSString stringWithFormat:@"%@%@", kRedStarURL, kRankingListURL];
    HttpClient *httpCilent1 = [[HttpClient alloc] initWithUrl:url1];
admin's avatar
admin committed
315 316
    NSDictionary *parameters1 = @{@"praiseUuid":@"",
                                  @"statisMode":@(0),
admin's avatar
admin committed
317 318 319 320 321 322 323 324 325 326 327 328 329 330
                                  @"pageNumber":@(0),
                                  @"pageSize":@(3)
                                  };
    __block HomeViewController *weakSelf = self;
    [httpCilent1 getRankingListWithParameters:parameters1 completion:^(id response, NSError *error) {
        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
331
        
admin's avatar
admin committed
332 333
        [self.tableView reloadData];
        [MBProgressHUD hideHUDForView:self.view animated:YES];
admin's avatar
admin committed
334
        [self.tableView.mj_header endRefreshing];
admin's avatar
admin committed
335

admin's avatar
admin committed
336
    }];
admin's avatar
admin committed
337 338 339
}

- (void)refreshQuestionList {
admin's avatar
admin committed
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
    // 问题与知识
    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"];
        
        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
362
        _allQuestionArray = questionTempArr;
admin's avatar
admin committed
363
        
admin's avatar
admin committed
364 365
        [self.tableView reloadData];
        [MBProgressHUD hideHUDForView:self.view animated:YES];
admin's avatar
admin committed
366
        [self.tableView.mj_header endRefreshing];
admin's avatar
admin committed
367 368
    }];

admin's avatar
admin committed
369
}
admin's avatar
admin committed
370

admin's avatar
admin committed
371

372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393
- (void)refreshSpotCheckList
{
    HttpClient *http = [[HttpClient alloc] initWithUrl:[NSString stringWithFormat:@"%@%@", kRedStarURL, kManageSportcheckURL]];
    
    // 相关参数
    NSString *user_uuid = [[NSUserDefaults standardUserDefaults] objectForKey:@"user_uuid"];
    NSDictionary *parameters = @{@"userUuid":user_uuid,
                                 @"pageNumber":@(0),
                                 @"pageSize":@(2)
                                 };
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [http getManageSportCheckListWithParameters:parameters completion:^(id response, NSError *error) {
        NSDictionary *dataDict = response[@"data"];
        NSArray *recordsArray = dataDict[@"records"];
        NSMutableArray *tempArray = [NSMutableArray array];
        
        for (NSDictionary *dict in recordsArray) {
            SpotCheckModel *spot = [[SpotCheckModel alloc] init];
            [spot setValuesForKeysWithDictionary:dict];
            [tempArray addObject:spot];
        }
        _allSpotCheckList = [NSMutableArray arrayWithArray:tempArray];
admin's avatar
admin committed
394
        [self.tableView.mj_header endRefreshing];
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    }];
}



- (void)refreshLookOnLineList
{
    HttpClient *http = [[HttpClient alloc] initWithUrl:[NSString stringWithFormat:@"%@%@", kRedStarURL, kStoreSportcheckURL]];
    // 相关参数
    NSString *user_uuid = [[NSUserDefaults standardUserDefaults] objectForKey:@"user_uuid"];
    
    NSDictionary *parameters = @{@"userUuid":user_uuid,
                                 @"pageNumber":@(0),
                                 @"pageSize":@(2)
                                 };
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [http getStoreSportCheckListWithParameters:parameters completion:^(id response, NSError *error) {
        NSDictionary *dataDict = response[@"data"];
        NSArray *recordsArray = dataDict[@"records"];
        NSMutableArray *tempArray = [NSMutableArray array];
        
        for (NSDictionary *dict in recordsArray) {
            LookOnLineModel *lookOnline = [[LookOnLineModel alloc] init];
            [lookOnline setValuesForKeysWithDictionary:dict];
            [tempArray addObject:lookOnline];
        }
        _allLookOnLineList = [NSMutableArray arrayWithArray:tempArray];
        
admin's avatar
admin committed
424
        [self.tableView.mj_header endRefreshing];
425
        [MBProgressHUD hideHUDForView:self.view animated:YES];
426 427 428 429 430 431 432
        [self.tableView reloadData];
        
    }];
}



admin's avatar
admin committed
433
#pragma mark - 请求数据
admin's avatar
admin committed
434 435 436 437 438
- (void)requestRankingList
{
    
    NSString *url = [NSString stringWithFormat:@"%@%@", kRedStarURL, kRankingListURL];
    HttpClient *httpCilent = [[HttpClient alloc] initWithUrl:url];
439
    NSDictionary *parameters = @{@"praiseUuid":@"",
admin's avatar
admin committed
440 441 442
                                 @"statisMode":@(0),
                                 @"pageNumber":@(0),
                                 @"pageSize":@(3)
admin's avatar
admin committed
443
                                 };
444

admin's avatar
admin committed
445
    [httpCilent getRankingListWithParameters:parameters completion:^(id response, NSError *error) {
admin's avatar
admin committed
446
        
admin's avatar
admin committed
447 448
        NSDictionary *dataDict = response[@"data"];
        NSArray *dataArray = dataDict[@"records"];
449
        NSMutableArray *tgArray = [NSMutableArray array];
admin's avatar
admin committed
450 451
        for (NSDictionary *ListDict in dataArray) {
            RankListModel *rankList = [RankListModel rankListModelWithDict:ListDict];
452
            [tgArray addObject:rankList];
admin's avatar
admin committed
453
        }
admin's avatar
admin committed
454
        _allRankListArray = (NSMutableArray *)[self sortRankListWithRankListArray:tgArray];
455 456 457 458 459 460 461 462 463 464
        
        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
465 466
        if (_allRankListArray.count == 0) {
            [_sectionArray removeObject:@"口碑报告"];
admin's avatar
admin committed
467
        }
admin's avatar
admin committed
468 469
        [self.tableView reloadData];
        [MBProgressHUD hideHUDForView:self.view animated:YES];
admin's avatar
admin committed
470 471 472

        
        
admin's avatar
admin committed
473 474 475
    }];
}

admin's avatar
admin committed
476 477 478
- (NSArray *)sortRankListWithRankListArray:(NSMutableArray *)allRanking
{
    NSArray *sortedArray = [allRanking sortedArrayUsingComparator:^NSComparisonResult(RankListModel *p1, RankListModel *p2){
479 480
        return [@(p2.score) compare:@(p1.score)];

admin's avatar
admin committed
481 482 483 484
    }];
    return sortedArray;
}

admin's avatar
admin committed
485 486 487 488 489 490 491


- (void)requestInspectList
{
    
    NSString *url = [NSString stringWithFormat:@"%@%@", kRedStarURL, kInspectListURL];
    HttpClient *httpCilent = [[HttpClient alloc] initWithUrl:url];
492 493 494 495
    

    NSDictionary *parameters = @{
                                 @"userUuid":[[NSUserDefaults standardUserDefaults] objectForKey:@"user_uuid"],
admin's avatar
admin committed
496
                                 @"queryOrders":@[@{@"field":@"lastModifyInfo", @"direction":@"desc"}],
admin's avatar
admin committed
497 498 499 500 501 502 503
                                 @"pageNumber":@(0),
                                 @"pageSize":@(2)
                                 };
    [httpCilent getInspectListWithParameters:parameters completion:^(id response, NSError *error) {
        
        NSDictionary *dataDict = response[@"data"];
        NSArray *dataArray = dataDict[@"records"];
admin's avatar
admin committed
504
        NSMutableArray *tempArray = [NSMutableArray array];
admin's avatar
admin committed
505 506 507
        for (NSDictionary *dict in dataArray) {
            TaskListModel *taskList = [[TaskListModel alloc] init];
            [taskList setValuesForKeysWithDictionary:dict];
admin's avatar
admin committed
508
            [tempArray addObject:taskList];
admin's avatar
admin committed
509
        }
admin's avatar
admin committed
510 511
        _taskListDataArray = [NSMutableArray arrayWithArray:tempArray];
        
admin's avatar
admin committed
512 513
        if (_taskListDataArray.count == 0) {
            [_sectionArray removeObject:@"口碑巡检"];
admin's avatar
admin committed
514
        }
admin's avatar
admin committed
515 516 517 518 519 520 521
        [self.tableView reloadData];
        [MBProgressHUD hideHUDForView:self.view animated:YES];

    }];

}

522 523 524 525 526 527 528
- (void)requestQuestionList
{
    // 初始化数组
    // 请求地址
    NSString *urlStr = [NSString stringWithFormat:@"%@%@", kRedStarURL, kQuestionListURL];
    NSString *user_uuid = [[NSUserDefaults standardUserDefaults] objectForKey:@"user_uuid"];
    // 请求参数
admin's avatar
admin committed
529
    NSDictionary *parameters = @{@"user":user_uuid,
530 531
                                 @"scope":@"all",
                                 @"pageNumber":@(0),
admin's avatar
admin committed
532
                                 @"pageSize":@(2)
533 534 535 536 537 538 539 540
                                 };
    // 发起请求
    HttpClient *httpClient = [[HttpClient alloc] initWithUrl:urlStr];
    
    // 请求问题列表
    [httpClient getQuestionListWithParameters:parameters completion:^(id response, NSError *error) {
        NSDictionary *dataDict = (NSDictionary *)response[@"data"];
        NSDictionary *recordsDict = (NSDictionary *)dataDict[@"records"];
admin's avatar
admin committed
541
        NSMutableArray *tempArray = [NSMutableArray array];
542 543 544
        for (NSDictionary *questionDict in recordsDict) {
            QuestionModel *question = [[QuestionModel alloc] init];
            [question setValuesForKeysWithDictionary:questionDict];
admin's avatar
admin committed
545
            [tempArray addObject:question];
546
        }
admin's avatar
admin committed
547
        _allQuestionArray = [NSMutableArray arrayWithArray:tempArray];
admin's avatar
admin committed
548 549
        if (_allQuestionArray.count == 0) {
            [_sectionArray removeObject:@"问题知识"];
admin's avatar
admin committed
550
        }
admin's avatar
admin committed
551 552
        [self.tableView reloadData];

553 554 555 556 557
        self.tableView.tableHeaderView = self.headView;
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    }];
}

558
- (void)requestPicturePraiseWithType:(NSString *)type
admin's avatar
admin committed
559 560 561 562 563 564 565 566
{
    
    // 请求地址
    NSString *urlStr = [NSString stringWithFormat:@"%@%@", kRedStarURL, kQueryPicturePraiseURL];
    NSString *user_uuid = [[NSUserDefaults standardUserDefaults] objectForKey:@"user_uuid"];
    NSDictionary *parameters = @{
                                 @"scope":@"all",
                                 @"user":user_uuid,
567
                                 @"type":type,
admin's avatar
admin committed
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585
                                 @"pageNumber":@(0),
                                 @"pageSize":@(2)
                                 };
    
    // 发起请求
    HttpClient *httpClient = [[HttpClient alloc] initWithUrl:urlStr];
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    // 请求问题列表
    [httpClient queryPicturePraiseWithParameters:parameters completion:^(id response, NSError *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];
        }
586 587 588 589
        
        if ([type isEqualToString:@"store"]) {
            _allPraiseListArray = [NSMutableArray arrayWithArray:tempArray];
            if (_allPraiseListArray.count == 0) {
590
                [_sectionArray removeObject:@"口碑随手拍"];
591 592 593 594
            }
        } else if ([type isEqualToString:@"casus"]) {
            _allExcellentCaseArray = [NSMutableArray arrayWithArray:tempArray];
            if (_allExcellentCaseArray.count == 0) {
595
                [_sectionArray removeObject:@"口碑报道"];
596 597 598 599
            }
        } else {
            _allPatrolReportArray = [NSMutableArray arrayWithArray:tempArray];
            if (_allPatrolReportArray.count == 0) {
600
                [_sectionArray removeObject:@"口碑巡店"];
601
            }
admin's avatar
admin committed
602
        }
603
        
admin's avatar
admin committed
604
        [self.tableView reloadData];
605
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
admin's avatar
admin committed
606 607 608 609
    }];
    
}

610 611 612 613 614 615 616 617 618 619 620 621
- (void)requestSpotCheckList
{
    HttpClient *http = [[HttpClient alloc] initWithUrl:[NSString stringWithFormat:@"%@%@", kRedStarURL, kManageSportcheckURL]];
    
    // 相关参数
    NSString *user_uuid = [[NSUserDefaults standardUserDefaults] objectForKey:@"user_uuid"];
    NSDictionary *parameters = @{@"userUuid":user_uuid,
                                 @"pageNumber":@(0),
                                 @"pageSize":@(2)
                                 };
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [http getManageSportCheckListWithParameters:parameters completion:^(id response, NSError *error) {
admin's avatar
admin committed
622

623 624 625 626 627 628 629 630 631 632 633 634 635
        NSDictionary *dataDict = response[@"data"];
        NSArray *recordsArray = dataDict[@"records"];
        NSMutableArray *tempArray = [NSMutableArray array];
        
        for (NSDictionary *dict in recordsArray) {
            SpotCheckModel *spot = [[SpotCheckModel alloc] init];
            [spot setValuesForKeysWithDictionary:dict];
            [tempArray addObject:spot];
        }
        _allSpotCheckList = [NSMutableArray arrayWithArray:tempArray];
        
        if (_allSpotCheckList.count == 0) {
            [_sectionArray removeObject:@"在线抽查"];
admin's avatar
admin committed
636 637 638 639
        } else {
            if (![_sectionArray containsObject:@"在线抽查"]) {
                [_sectionArray addObject:@"在线抽查"];
            }
640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669
        }
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
    }];
}



- (void)requestLookOnLineList
{
    HttpClient *http = [[HttpClient alloc] initWithUrl:[NSString stringWithFormat:@"%@%@", kRedStarURL, kStoreSportcheckURL]];
    NSString *user_uuid = [[NSUserDefaults standardUserDefaults] objectForKey:@"user_uuid"];
    
    NSDictionary *parameters = @{@"userUuid":user_uuid,
                                 @"pageNumber":@(0),
                                 @"pageSize":@(2)
                                 };
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [http getStoreSportCheckListWithParameters:parameters completion:^(id response, NSError *error) {
        NSDictionary *dataDict = response[@"data"];
        NSArray *recordsArray = dataDict[@"records"];
        NSMutableArray *tempArray = [NSMutableArray array];
        
        for (NSDictionary *dict in recordsArray) {
            LookOnLineModel *lookOnline = [[LookOnLineModel alloc] init];
            [lookOnline setValuesForKeysWithDictionary:dict];
            [tempArray addObject:lookOnline];
        }
        _allLookOnLineList = [NSMutableArray arrayWithArray:tempArray];

        if (_allLookOnLineList.count == 0) {
admin's avatar
admin committed
670 671 672 673 674 675
            [_sectionArray removeObject:@"在线抽查"];
        } else {
            if (![_sectionArray containsObject:@"在线抽查"]) {
                [_sectionArray addObject:@"在线抽查"];
            }

676 677 678 679 680 681 682 683
        }
        [self.tableView reloadData];
        
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    }];
}


684

admin's avatar
admin committed
685
#pragma mark - Private Methods
admin's avatar
admin committed
686 687 688 689 690 691 692
- (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
693
    _nameLabel.text = [NSString stringWithFormat:@"%@,你好!", [[NSUserDefaults standardUserDefaults] objectForKey:@"user_name"]];
admin's avatar
admin committed
694
    self.shopnameLabel.backgroundColor = [UIColor clearColor];
admin's avatar
admin committed
695
    _shopnameLabel.text = [NSString stringWithFormat:@"%@", [[NSUserDefaults standardUserDefaults] objectForKey:@"org_name"]];
admin's avatar
admin committed
696 697 698

}

admin's avatar
admin committed
699 700
- (void)setupTableView
{
admin's avatar
admin committed
701
    self.headView = [[HomeHeaderView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 115)];
admin's avatar
admin committed
702
    
admin's avatar
admin committed
703 704
    self.headView.scrollView.contentSize = CGSizeMake(2 * kScreenWidth, 86);
    CGFloat itemW = kScreenWidth / 4;
admin's avatar
admin committed
705
    CGFloat itemH = self.headView.scrollView.frame.size.height;
admin's avatar
admin committed
706

admin's avatar
admin committed
707
    for (int i = 0; i < _titleArray.count; i++) {
admin's avatar
admin committed
708 709
        HomeCellItem *item = [[HomeCellItem alloc] init];
        item.frame = CGRectMake(i * itemW, 0, itemW, itemH);
admin's avatar
admin committed
710
        NSString *nameStr = _titleArray[i];
admin's avatar
admin committed
711
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%@", nameStr]];
admin's avatar
admin committed
712 713
        [item setImage:image forState:UIControlStateNormal];
        [item setTitleColor:kPictureCellDetailsColor forState:UIControlStateNormal];
admin's avatar
admin committed
714
        [item setTitle:nameStr forState:UIControlStateNormal];
admin's avatar
admin committed
715 716 717
        [item addTarget:self action:@selector(itemClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.headView.scrollView addSubview:item];
    }
admin's avatar
admin committed
718 719 720 721
    
    self.tableView.tableHeaderView = self.headView;
    
    // 设置下拉刷新
admin's avatar
admin committed
722
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
admin's avatar
admin committed
723 724 725 726
        // 进入刷新状态后会自动调用这个block
        [self refreshAllData];
        
    }];
admin's avatar
admin committed
727 728
    [self.tableView reloadData];

admin's avatar
admin committed
729 730
}

731
// 更多按钮点击事件
admin's avatar
admin committed
732 733
- (void)moreButtonClick:(UIButton *)sender
{
admin's avatar
admin committed
734 735
    NSArray *permissions = [[NSUserDefaults standardUserDefaults] objectForKey:@"permissions"];

admin's avatar
admin committed
736
    NSInteger section = sender.tag - 332892;
737
    UINavigationController *nav;
admin's avatar
admin committed
738
    if ([_sectionArray[section] isEqualToString:@"在线抽查"]) {
admin's avatar
admin committed
739 740 741 742 743 744 745 746
        
        if ([permissions containsObject:@"500701"]) {
            SpotCheckOnLineViewController *spotOnline = [[SpotCheckOnLineViewController alloc] init];
            nav = [[UINavigationController alloc] initWithRootViewController:spotOnline];
        } else if ([permissions containsObject:@"500702"]){
            LookOnLineViewController *lookOnLine = [[LookOnLineViewController alloc] init];
            nav = [[UINavigationController alloc] initWithRootViewController:lookOnLine];
        }
admin's avatar
admin committed
747
    } else if ([_sectionArray[section] isEqualToString:@"口碑巡检"]) {
admin's avatar
admin committed
748 749
        InspectListViewController *inspectListVC = [[InspectListViewController alloc] init];
        nav = [[UINavigationController alloc] initWithRootViewController:inspectListVC];
admin's avatar
admin committed
750 751 752
    } else if ([_sectionArray[section] isEqualToString:@"口碑标准"]) {
        StandardViewController *standardVC = [[StandardViewController alloc] init];
        nav = [[UINavigationController alloc] initWithRootViewController:standardVC];
753
    } else if ([_sectionArray[section] isEqualToString:@"口碑现场"]) {
admin's avatar
admin committed
754 755 756
        PicCategoryViewController *pictureVC = [[PicCategoryViewController alloc] init];
        nav = [[UINavigationController alloc] initWithRootViewController:pictureVC];
    } else if ([_sectionArray[section] isEqualToString:@"问题知识"]) {
757 758
        QuestionViewController *questionVC = [[QuestionViewController alloc] init];
        nav = [[UINavigationController alloc] initWithRootViewController:questionVC];
admin's avatar
admin committed
759 760 761
    } else if ([_sectionArray[section] isEqualToString:@"口碑报告"]){
        RankingListViewController *rankingListVC = [[RankingListViewController alloc] init];
        nav = [[UINavigationController alloc] initWithRootViewController:rankingListVC];
762
    } else if ([_sectionArray[section] isEqualToString:@"口碑随手拍"]) {
admin's avatar
admin committed
763 764
        PictureViewController *pic = [[PictureViewController alloc] init];
        pic.come = @"首页";
765
        pic.titleStr = @"口碑随手拍";
admin's avatar
admin committed
766 767
        pic.category = @"store";
        nav = [[UINavigationController alloc] initWithRootViewController:pic];
768
    } else if ([_sectionArray[section] isEqualToString:@"口碑报道"]) {
769 770
        PictureViewController *pic = [[PictureViewController alloc] init];
        pic.come = @"首页";
771
        pic.titleStr = @"口碑报道";
772 773
        pic.category = @"casus";
        nav = [[UINavigationController alloc] initWithRootViewController:pic];
774
    } else if ([_sectionArray[section] isEqualToString:@"口碑巡店"]) {
775 776
        PictureViewController *pic = [[PictureViewController alloc] init];
        pic.come = @"首页";
777
        pic.titleStr = @"口碑巡店";
778 779
        pic.category = @"report";
        nav = [[UINavigationController alloc] initWithRootViewController:pic];
780 781 782 783 784
    }
    
    [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
785
    
admin's avatar
admin committed
786 787
}

admin's avatar
admin committed
788
- (void)itemClick:(HomeCellItem *)sender
admin's avatar
admin committed
789
{
admin's avatar
admin committed
790 791 792
    NSArray *permissions = [[NSUserDefaults standardUserDefaults] objectForKey:@"permissions"];

    
admin's avatar
admin committed
793 794 795
    HomeCellItem *item = (HomeCellItem *)sender;
    UINavigationController *nav;
    if ([item.titleLabel.text isEqualToString:@"在线抽查"]) {
admin's avatar
admin committed
796 797 798 799 800 801 802 803 804
        
        if ([permissions containsObject:@"500701"]) {
            SpotCheckOnLineViewController *spotOnline = [[SpotCheckOnLineViewController alloc] init];
            nav = [[UINavigationController alloc] initWithRootViewController:spotOnline];
        } else if ([permissions containsObject:@"500702"]){
            LookOnLineViewController *lookOnLine = [[LookOnLineViewController alloc] init];
            nav = [[UINavigationController alloc] initWithRootViewController:lookOnLine];
            
        }
805
        
admin's avatar
admin committed
806
    } else if ([item.titleLabel.text isEqualToString:@"口碑巡检"]) {
admin's avatar
admin committed
807 808 809
        InspectListViewController *inspectListVC = [[InspectListViewController alloc] init];
        nav = [[UINavigationController alloc] initWithRootViewController:inspectListVC];
    } else if ([item.titleLabel.text isEqualToString:@"口碑标准"]) {
admin's avatar
admin committed
810 811
        StandardViewController *standardVC = [[StandardViewController alloc] init];
        nav = [[UINavigationController alloc] initWithRootViewController:standardVC];
812
    } else if ([item.titleLabel.text isEqualToString:@"口碑现场"]) {
admin's avatar
admin committed
813
        PicCategoryViewController *pictureVC = [[PicCategoryViewController alloc] init];
admin's avatar
admin committed
814
        nav = [[UINavigationController alloc] initWithRootViewController:pictureVC];
admin's avatar
admin committed
815
    } else if ([item.titleLabel.text isEqualToString:@"问题知识"]) {
admin's avatar
admin committed
816 817
        QuestionViewController *questionVC = [[QuestionViewController alloc] init];
        nav = [[UINavigationController alloc] initWithRootViewController:questionVC];
admin's avatar
admin committed
818
    } else if ([item.titleLabel.text isEqualToString:@"口碑报告"]){
admin's avatar
admin committed
819 820
        RankingListViewController *rankingListVC = [[RankingListViewController alloc] init];
        nav = [[UINavigationController alloc] initWithRootViewController:rankingListVC];
821
    } else if ([item.titleLabel.text isEqualToString:@"口碑随手拍"]) {
admin's avatar
admin committed
822 823 824
        PictureViewController *pic = [[PictureViewController alloc] init];
        pic.come = @"首页";
        pic.category = @"store";
825
        pic.titleStr = @"口碑随手拍";
admin's avatar
admin committed
826
        nav = [[UINavigationController alloc] initWithRootViewController:pic];
admin's avatar
admin committed
827
    }
admin's avatar
admin committed
828
    
admin's avatar
admin committed
829 830 831
    [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
832 833 834 835 836 837 838 839
}




#pragma mark - TableView Delegate/DataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
admin's avatar
admin committed
840
    return _sectionArray.count;
admin's avatar
admin committed
841 842 843 844 845
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
admin's avatar
admin committed
846 847 848
    NSArray *permissions = [[NSUserDefaults standardUserDefaults] objectForKey:@"permissions"];

    
admin's avatar
admin committed
849
    NSUInteger s2 = [_sectionArray indexOfObject:@"口碑报告"];
850
    NSUInteger s4 = [_sectionArray indexOfObject:@"口碑随手拍"];
admin's avatar
admin committed
851 852
    NSUInteger s3 = [_sectionArray indexOfObject:@"问题知识"];
    NSUInteger s1 = [_sectionArray indexOfObject:@"口碑巡检"];
853 854
    NSUInteger s5 = [_sectionArray indexOfObject:@"口碑报道"];
    NSUInteger s6 = [_sectionArray indexOfObject:@"口碑巡店"];
855
    NSUInteger s7 = [_sectionArray indexOfObject:@"在线抽查"];
admin's avatar
admin committed
856
    //NSUInteger s8 = [_sectionArray indexOfObject:@"在线抽查"];
admin's avatar
admin committed
857 858 859 860 861 862 863
    
    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;
864
    } else if ([_sectionArray[section] isEqualToString:@"口碑随手拍"] && section == s4) {
admin's avatar
admin committed
865
        return _allPraiseListArray.count;
866
    } else if ([_sectionArray[section] isEqualToString:@"口碑报道"] && section == s5) {
867
        return _allExcellentCaseArray.count;
868
    } else if ([_sectionArray[section] isEqualToString:@"口碑巡店"] && section == s6) {
869
        return _allPatrolReportArray.count;
870
    } else if ([_sectionArray[section] isEqualToString:@"在线抽查"] && section == s7) {
admin's avatar
admin committed
871 872 873 874 875 876 877
        if ([permissions containsObject:@"500701"]) {
            return _allSpotCheckList.count;
        } else if ([permissions containsObject:@"500702"]){
            return _allLookOnLineList.count;
        } else {
            return 0;
        }
admin's avatar
admin committed
878 879 880
    } else {
        return 0;
    }
admin's avatar
admin committed
881 882
}

admin's avatar
admin committed
883

admin's avatar
admin committed
884 885 886
// cell显示的内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
admin's avatar
admin committed
887 888 889 890
    
    NSArray *permissions = [[NSUserDefaults standardUserDefaults] objectForKey:@"permissions"];

    
admin's avatar
admin committed
891
    NSUInteger s2 = [_sectionArray indexOfObject:@"口碑报告"];
892
    NSUInteger s4 = [_sectionArray indexOfObject:@"口碑随手拍"];
admin's avatar
admin committed
893 894
    NSUInteger s3 = [_sectionArray indexOfObject:@"问题知识"];
    NSUInteger s1 = [_sectionArray indexOfObject:@"口碑巡检"];
895 896
    NSUInteger s5 = [_sectionArray indexOfObject:@"口碑报道"];
    NSUInteger s6 = [_sectionArray indexOfObject:@"口碑巡店"];
897
    NSUInteger s7 = [_sectionArray indexOfObject:@"在线抽查"];
admin's avatar
admin committed
898
    //NSUInteger s8 = [_sectionArray indexOfObject:@"在线抽查"];
admin's avatar
admin committed
899

admin's avatar
admin committed
900
    if ([_sectionArray[indexPath.section] isEqualToString:@"口碑巡检"] && indexPath.section == s1) {
admin's avatar
admin committed
901 902 903
        InspectListCell *cell=[tableView dequeueReusableCellWithIdentifier:kHomeInspectListCell];
        if (!cell) {
            cell = [[InspectListCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kHomeInspectListCell];
admin's avatar
admin committed
904
        }
admin's avatar
admin committed
905 906 907 908 909 910 911 912
        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
913
    } else if ([_sectionArray[indexPath.section] isEqualToString:@"口碑报告"] && indexPath.section == s2) {
admin's avatar
admin committed
914 915
        if (indexPath.row == 0) {
            HomeTitleTableCell *cell=[tableView dequeueReusableCellWithIdentifier:kHomeTitleTableCell];
admin's avatar
admin committed
916
            if (!cell) {
admin's avatar
admin committed
917
                cell = [[HomeTitleTableCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kHomeTitleTableCell];
admin's avatar
admin committed
918 919 920 921
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        } else {
admin's avatar
admin committed
922
            RankingListCell *cell = [tableView dequeueReusableCellWithIdentifier:kHomeRankingListCell];
admin's avatar
admin committed
923
            if (!cell) {
admin's avatar
admin committed
924
                cell = [[RankingListCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kHomeRankingListCell];
admin's avatar
admin committed
925
            }
admin's avatar
admin committed
926 927 928 929 930 931 932 933 934
            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;
                }
            }
935 936
            RankListModel *rankList = _allRankListArray[indexPath.row - 1];
            cell.rankList = rankList;
admin's avatar
admin committed
937
            cell.gradeImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"medal_0%d", rankList.index]];
admin's avatar
admin committed
938 939
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
admin's avatar
admin committed
940
        }
admin's avatar
admin committed
941
    } else if ([_sectionArray[indexPath.section] isEqualToString:@"问题知识"] && indexPath.section == s3) {
admin's avatar
admin committed
942 943 944 945 946 947 948 949 950
        // 问题与知识
        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;
951
    } else if ([_sectionArray[indexPath.section] isEqualToString:@"口碑随手拍"] && indexPath.section == s4) {
admin's avatar
admin committed
952 953 954 955 956 957
        PictureTableCell *cell=[tableView dequeueReusableCellWithIdentifier:KHomePicTableCell];
        if (!cell) {
            cell = [[PictureTableCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:KHomePicTableCell];
        }
        cell.pictureList = _allPraiseListArray[indexPath.row];
        return cell;
958
    } else if ([_sectionArray[indexPath.section] isEqualToString:@"口碑报道"] && indexPath.section == s5) {
959 960 961 962 963 964
        PictureTableCell *cell=[tableView dequeueReusableCellWithIdentifier:KHomePicTableCell];
        if (!cell) {
            cell = [[PictureTableCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:KHomePicTableCell];
        }
        cell.pictureList = _allExcellentCaseArray[indexPath.row];
        return cell;
965
    } else if ([_sectionArray[indexPath.section] isEqualToString:@"口碑巡店"] && indexPath.section == s6) {
966 967 968 969 970 971
        PictureTableCell *cell=[tableView dequeueReusableCellWithIdentifier:KHomePicTableCell];
        if (!cell) {
            cell = [[PictureTableCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:KHomePicTableCell];
        }
        cell.pictureList = _allPatrolReportArray[indexPath.row];
        return cell;
972 973
    } else if ([_sectionArray[indexPath.section] isEqualToString:@"在线抽查"] && indexPath.section == s7) {
        
admin's avatar
admin committed
974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991
        if ([permissions containsObject:@"500701"]) {
            SpotCheckTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:kHomeSpotCehcekCell];
            if (!cell) {
                cell = [[SpotCheckTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kHomeSpotCehcekCell];
            }
            cell.spotCheck = _allSpotCheckList[indexPath.row];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        } else if ([permissions containsObject:@"500702"]){
            LookOnLineTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:kHomeLookOnLineCell];
            if (!cell) {
                cell = [[LookOnLineTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kHomeLookOnLineCell];
            }
            cell.lookOnLine = _allLookOnLineList[indexPath.row];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        } else {
            return nil;
992 993
        }
    }  else {
admin's avatar
admin committed
994
        return nil;
admin's avatar
admin committed
995
    }
admin's avatar
admin committed
996 997 998 999 1000
}

// cell点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
admin's avatar
admin committed
1001 1002
    NSArray *permissions = [[NSUserDefaults standardUserDefaults] objectForKey:@"permissions"];

admin's avatar
admin committed
1003
    NSUInteger s2 = [_sectionArray indexOfObject:@"口碑报告"];
1004
    NSUInteger s4 = [_sectionArray indexOfObject:@"口碑随手拍"];
admin's avatar
admin committed
1005 1006
    NSUInteger s3 = [_sectionArray indexOfObject:@"问题知识"];
    NSUInteger s1 = [_sectionArray indexOfObject:@"口碑巡检"];
1007 1008
    NSUInteger s5 = [_sectionArray indexOfObject:@"口碑报道"];
    NSUInteger s6 = [_sectionArray indexOfObject:@"口碑巡店"];
1009
    NSUInteger s7 = [_sectionArray indexOfObject:@"在线抽查"];
admin's avatar
admin committed
1010
    //NSUInteger s8 = [_sectionArray indexOfObject:@"在线抽查"];
admin's avatar
admin committed
1011
    if ([_sectionArray[indexPath.section] isEqualToString:@"口碑巡检"] && indexPath.section == s1) {
admin's avatar
admin committed
1012 1013 1014 1015 1016 1017 1018
        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
1019
    } else if ([_sectionArray[indexPath.section] isEqualToString:@"口碑报告"] && indexPath.section == s2) {
1020 1021 1022
        if (indexPath.row == 0) {
            return;
        }
admin's avatar
admin committed
1023 1024
        RankListModel *rankList = _allRankListArray[indexPath.row - 1];
        RankDetailViewController *rankDetailVC = [[RankDetailViewController alloc] init];
1025
        rankDetailVC.indexRow = rankList.index;
admin's avatar
admin committed
1026 1027 1028 1029
        rankDetailVC.uuid = rankList.uuid;
        rankDetailVC.store_uuid = rankList.store_uuid;
        rankDetailVC.storeAddress = rankList.storeAddress;
        rankDetailVC.storePictures = rankList.storePictures;
admin's avatar
admin committed
1030
        rankDetailVC.commentId = rankList.commentId;
admin's avatar
admin committed
1031 1032
        self.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:rankDetailVC animated:YES];
admin's avatar
admin committed
1033
    } else if ([_sectionArray[indexPath.section] isEqualToString:@"问题知识"] && indexPath.section == s3) {
admin's avatar
admin committed
1034 1035 1036 1037 1038
        QuestionDetailViewController *questionDetailVC = [[QuestionDetailViewController alloc] init];
        QuestionModel *question = self.allQuestionArray[indexPath.row];
        questionDetailVC.questionUuid = question.uuid;
        self.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:questionDetailVC animated:YES];
1039
    } else if ([_sectionArray[indexPath.section] isEqualToString:@"口碑随手拍"] && indexPath.section == s4) {
admin's avatar
admin committed
1040 1041 1042
        PictureListModel *picList = _allPraiseListArray[indexPath.row];
        PictureStoryViewController *storyVC = [[PictureStoryViewController alloc] init];
        storyVC.uuid = picList.uuid;
1043
        storyVC.titleStr = @"口碑随手拍";
1044 1045
        self.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:storyVC animated:YES];
1046
    } else if ([_sectionArray[indexPath.section] isEqualToString:@"口碑报道"] && indexPath.section == s5) {
1047 1048 1049
        PictureListModel *picList = _allExcellentCaseArray[indexPath.row];
        PictureStoryViewController *storyVC = [[PictureStoryViewController alloc] init];
        storyVC.uuid = picList.uuid;
1050
        storyVC.titleStr = @"口碑报道";
1051 1052
        self.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:storyVC animated:YES];
1053
    } else if ([_sectionArray[indexPath.section] isEqualToString:@"口碑巡店"] && indexPath.section == s6) {
1054 1055 1056
        PictureListModel *picList = _allPatrolReportArray[indexPath.row];
        PictureStoryViewController *storyVC = [[PictureStoryViewController alloc] init];
        storyVC.uuid = picList.uuid;
1057
        storyVC.titleStr = @"口碑巡店";
admin's avatar
admin committed
1058 1059
        self.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:storyVC animated:YES];
1060
    } else if ([_sectionArray[indexPath.section] isEqualToString:@"在线抽查"] && indexPath.section == s7) {
admin's avatar
admin committed
1061 1062 1063 1064 1065 1066 1067 1068 1069
        
        
        
        if ([permissions containsObject:@"500701"]) {
            SpotCheckModel *spot = _allSpotCheckList[indexPath.row];
            OnLineCompleteViewController *completeVC = [[OnLineCompleteViewController alloc] init];
            completeVC.uuid = spot.uuid;
            self.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:completeVC animated:YES];
admin's avatar
admin committed
1070
            
admin's avatar
admin committed
1071 1072
        } else if ([permissions containsObject:@"500702"]){
            LookOnLineModel *lookOnLine = _allLookOnLineList[indexPath.row];
admin's avatar
admin committed
1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090
//            LookOnLineDetailViewController *lookDetailVC = [[LookOnLineDetailViewController alloc] init];
//            lookDetailVC.lookOnLine = lookOnLine;
//            self.hidesBottomBarWhenPushed = YES;
//            [self.navigationController pushViewController:lookDetailVC animated:YES];
            
            if ([lookOnLine.state isEqualToString:@"initial"]) {
                LookOnLineDetailViewController *lookDetailVC = [[LookOnLineDetailViewController alloc] init];
                // lookDetailVC.delegate = self;
                lookDetailVC.lookOnLine = lookOnLine;
                self.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:lookDetailVC animated:YES];
            } else {
                LookReportDetailViewController *lookReportVC = [[LookReportDetailViewController alloc] init];
                lookReportVC.lookOnLine = lookOnLine;
                self.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:lookReportVC animated:YES];
            }
            
admin's avatar
admin committed
1091 1092 1093 1094 1095
        } else {
            return;
        }
        
    } else {
admin's avatar
admin committed
1096
        return;
admin's avatar
admin committed
1097
    }
admin's avatar
admin committed
1098 1099 1100 1101 1102 1103
}


// section高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
admin's avatar
admin committed
1104
    return 36;
admin's avatar
admin committed
1105 1106 1107 1108
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
admin's avatar
admin committed
1109
    return 10;
admin's avatar
admin committed
1110 1111 1112 1113 1114
}

// 自定义section
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
admin's avatar
admin committed
1115
    
1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142
        // 创建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
1143

admin's avatar
admin committed
1144
        titleLabel.text = _sectionArray[section];
admin's avatar
admin committed
1145

admin's avatar
admin committed
1146
    
1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177
        [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
1178
    
1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209
        
        
        // 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
1210

admin's avatar
admin committed
1211

admin's avatar
admin committed
1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248

#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
1249
        _searchTextField.delegate = self;
admin's avatar
admin committed
1250
        [_searchTextField setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];
admin's avatar
admin committed
1251 1252 1253 1254
        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
1255 1256 1257 1258 1259
        imageV.contentMode = UIViewContentModeCenter;
        imageV.width += 10;
        _searchTextField.rightView = imageV;
        _searchTextField.rightViewMode = UITextFieldViewModeAlways;
        [self.bgImageView addSubview:_searchTextField];
admin's avatar
admin committed
1260
        
admin's avatar
admin committed
1261 1262
        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
1263
        
admin's avatar
admin committed
1264 1265
        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
1266
        
admin's avatar
admin committed
1267 1268
        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
1269
        
admin's avatar
admin committed
1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284
        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
1285
        
admin's avatar
admin committed
1286 1287
        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
1288
        
admin's avatar
admin committed
1289 1290 1291 1292 1293 1294
        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
1295
        NSLayoutConstraint *bgImageWidth = [NSLayoutConstraint constraintWithItem:_nameLabel attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:110];
admin's avatar
admin committed
1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309
        [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
1310
        
admin's avatar
admin committed
1311 1312
        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
1313
        
admin's avatar
admin committed
1314 1315
        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
1316
        
admin's avatar
admin committed
1317 1318
        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
1319
        
admin's avatar
admin committed
1320 1321
        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
1322
    }
admin's avatar
admin committed
1323
    return _shopnameLabel;
admin's avatar
admin committed
1324 1325
}

admin's avatar
admin committed
1326

admin's avatar
admin committed
1327 1328 1329 1330 1331 1332 1333 1334 1335
- (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;
1336 1337
        _tableView.rowHeight = UITableViewAutomaticDimension;
        _tableView.estimatedRowHeight = 300.0;
1338
        _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 40)];
admin's avatar
admin committed
1339 1340
        [_tableView registerClass:[PictureTableCell class] forCellReuseIdentifier:kHomePictureListCell];
        [_tableView registerClass:[HomeTitleTableCell class] forCellReuseIdentifier:kHomeTitleTableCell];
admin's avatar
admin committed
1341
        [_tableView registerClass:[RankingListCell class] forCellReuseIdentifier:kHomeRankingListCell];
admin's avatar
admin committed
1342
        [_tableView registerClass:[QuestionListTableCell class] forCellReuseIdentifier:kHomeQuestionListTableCell];
1343 1344
        [_tableView registerClass:[SpotCheckTableViewCell class] forCellReuseIdentifier:kHomeSpotCehcekCell];
        [_tableView registerClass:[LookOnLineTableViewCell class] forCellReuseIdentifier:kHomeLookOnLineCell];
admin's avatar
admin committed
1345

admin's avatar
admin committed
1346 1347
        [self.view addSubview:_tableView];
        
admin's avatar
admin committed
1348
        NSLayoutConstraint *tableTop = [NSLayoutConstraint constraintWithItem:_tableView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1.0 constant:95];
admin's avatar
admin committed
1349 1350 1351 1352 1353 1354 1355 1356
        [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];
        
1357
        NSLayoutConstraint *tableBottom = [NSLayoutConstraint constraintWithItem:_tableView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
admin's avatar
admin committed
1358 1359 1360 1361 1362
        [self.view addConstraint:tableBottom];
    }
    return _tableView;
}

admin's avatar
admin committed
1363

admin's avatar
admin committed
1364 1365
- (void)searchClick:(UIButton *)sender
{
admin's avatar
admin committed
1366
    if (![_searchTextField.text isEqualToString:@""]) {
admin's avatar
admin committed
1367 1368
        SearchViewController *searchVC = [[SearchViewController alloc] init];
        searchVC.customStr = _searchTextField.text;
admin's avatar
admin committed
1369
        self.hidesBottomBarWhenPushed = YES;
admin's avatar
admin committed
1370 1371 1372 1373 1374
        [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
1375
    [_searchTextField resignFirstResponder];
admin's avatar
admin committed
1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389
}

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

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

1390 1391 1392 1393 1394
- (void)clickHeadView
{
    [_tableView reloadData];
}

admin's avatar
admin committed
1395 1396 1397 1398 1399
-(void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

admin's avatar
admin committed
1400
@end