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

#import "SearchViewController.h"
admin's avatar
admin committed
10 11 12 13 14
#import "InspectListViewController.h"
#import "RankingListViewController.h"
#import "OnLineViewController.h"
#import "PictureViewController.h"
#import "QuestionViewController.h"
admin's avatar
admin committed
15

admin's avatar
admin committed
16
#import "HomeCellItem.h"
17
#import "NoDataView.h"
admin's avatar
admin committed
18

admin's avatar
admin committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
#import "PictureTableCell.h"
#define kHomePictureListCell @"homePictureListCell"
#import "PictureStoryViewController.h"

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

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

#import "InspectListCell.h"
#define kHomeInspectListCell @"homeInspectListsCell"
#import "InspectTaskViewController.h"
#import "TaskListModel.h"

#import "SpotCheckOnLineViewController.h"

#import "LookOnLineViewController.h"

#import "StandardViewController.h"

#import "HttpClient.h"
#import <MBProgressHUD.h>

#import <MJRefresh.h>
#import "SearchViewController.h"
53
#import "PicCategoryViewController.h"
admin's avatar
admin committed
54 55 56 57

@interface SearchViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;

58
@property (nonatomic, strong) NSMutableArray *sectionArray; // section标题
admin's avatar
admin committed
59 60 61
@property (nonatomic, strong) NSMutableArray *allQuestionArray; // 问题与知识
@property (nonatomic, strong) NSMutableArray *taskListDataArray; // 问题与知识
@property (nonatomic, strong) NSMutableArray *allRankListArray;
62
@property (nonatomic, strong) NSMutableArray *allPraiseListArray;
63
@property (nonatomic, strong) NoDataView *noDataView;
64

admin's avatar
admin committed
65 66 67 68 69 70 71
@end

@implementation SearchViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
72 73 74
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.sectionArray = [NSMutableArray arrayWithObjects:@"口碑报告",@"商场风采", @"问题知识",@"口碑巡检",nil];
admin's avatar
admin committed
75
    
admin's avatar
admin committed
76 77 78 79 80 81 82 83 84 85 86 87 88
    UILabel *customLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
    [customLab setTextColor:[UIColor whiteColor]];
    [customLab setText:self.customStr];
    customLab.textAlignment = NSTextAlignmentCenter;
    customLab.font = [UIFont boldSystemFontOfSize:19];
    self.navigationItem.titleView = customLab;
    
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(0, 0, 30, 44);
    [backBtn setImage:[UIImage imageNamed:@"back_btn"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(doBack:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
    self.navigationItem.leftBarButtonItem = backItem;
admin's avatar
admin committed
89 90 91 92 93 94 95 96 97
    
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
        self.edgesForExtendedLayout = UIRectEdgeNone;
        self.extendedLayoutIncludesOpaqueBars = NO;
        self.modalPresentationCapturesStatusBarAppearance = NO;
        self.navigationController.navigationBar.translucent = NO;
    }

    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
98 99 100 101 102 103 104 105 106
    
    
    
    NSArray *permissions = [[NSUserDefaults standardUserDefaults] objectForKey:@"permissions"];
    
    // 口碑报告 商场风采 图说口碑 口碑标准  问题知识 口碑巡检
    
    if ([permissions containsObject:@"500201"]) {
        [self requestRankingList];
107 108
    } else {
        [_sectionArray removeObject:@"口碑报告"];
admin's avatar
admin committed
109 110
    }
    
111 112 113 114
    [self requestPicturePraise];
    
    if ([permissions containsObject:@"500501"] || [permissions containsObject:@"500502"]) {
        [self requestQuestionList];
115 116
    }else {
        [_sectionArray removeObject:@"问题知识"];
admin's avatar
admin committed
117 118
    }
    
119 120
    if ([permissions containsObject:@"500101"] || [permissions containsObject:@"500102"]) {
        [self requestInspectList];
121 122
    }else {
        [_sectionArray removeObject:@"口碑巡检"];
admin's avatar
admin committed
123
    }
124

125 126 127 128 129 130
    
    self.allRankListArray = [NSMutableArray array];
    self.taskListDataArray = [NSMutableArray array];
    self.allQuestionArray = [NSMutableArray array];
    self.allPraiseListArray = [NSMutableArray array];

admin's avatar
admin committed
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
}

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

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBar.hidden = NO;
    self.tabBarController.tabBar.hidden = YES;
    
}

#pragma mark - Prative Methods
admin's avatar
admin committed
148 149 150
// 更多按钮点击事件
- (void)moreButtonClick:(UIButton *)sender
{
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
    NSInteger section = sender.tag - 332892;
    UINavigationController *nav;
    if ([_sectionArray[section] isEqualToString:@"在线抽查"]) {
        SpotCheckOnLineViewController *spotOnline = [[SpotCheckOnLineViewController alloc] init];
        nav = [[UINavigationController alloc] initWithRootViewController:spotOnline];
    } else if ([_sectionArray[section] isEqualToString:@"口碑巡检"]) {
        InspectListViewController *inspectListVC = [[InspectListViewController alloc] init];
        nav = [[UINavigationController alloc] initWithRootViewController:inspectListVC];
    } 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:@"问题知识"]) {
        QuestionViewController *questionVC = [[QuestionViewController alloc] init];
        nav = [[UINavigationController alloc] initWithRootViewController:questionVC];
    } 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];
admin's avatar
admin committed
179
    }
180 181 182 183 184
    
    [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
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 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
#pragma mark - 请求数据
//- (void)requestRankingList
//{
//    
//    NSString *url = [NSString stringWithFormat:@"%@%@", kRedStarURL, kRankingListURL];
//    HttpClient *httpCilent = [[HttpClient alloc] initWithUrl:url];
//    NSNumber *pageSize = [[NSUserDefaults standardUserDefaults] objectForKey:@"requestNumber"];
//
//    NSDictionary *parameters = @{@"keyword":self.customStr,
//                                 @"praiseUuid":@"",
//                                 @"statisMode":@(0),
//                                 @"pageNumber":@(0),
//                                 @"pageSize":pageSize
//                                 };
//    
//    [httpCilent getRankingListWithParameters:parameters completion:^(id response, NSError *error) {
//        NSLog(@"口碑报告response = %@", response);
//        NSDictionary *dataDict = response[@"data"];
//        NSArray *dataArray = dataDict[@"records"];
//        
//        NSMutableArray *tgArray = [NSMutableArray array];
//        
//        for (NSDictionary *ListDict in dataArray) {
//            RankListModel *rankList = [RankListModel rankListModelWithDict:ListDict];
//            [tgArray addObject:rankList];
//        }
//        _allRankListArray = (NSMutableArray *)[self sortRankListWithRankListArray:tgArray];
//        
//        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;
//            }
//        }
//        if (_allRankListArray.count != 0) {
//            [_sectionArray addObject:@"口碑报告"];
//        }
//        [self.tableView reloadData];
//        [MBProgressHUD hideHUDForView:self.view animated:YES];
//        
//        
//        
//    }];
//}
//
//- (NSArray *)sortRankListWithRankListArray:(NSMutableArray *)allRanking
//{
//    NSArray *sortedArray = [allRanking sortedArrayUsingComparator:^NSComparisonResult(RankListModel *p1, RankListModel *p2){
//        //return [p2.score compare:p1.score];
//        return [@(p2.score) compare:@(p1.score)];
//        
//    }];
//    return sortedArray;
//}
//
//
//
//- (void)requestInspectList
//{
//    
//    NSString *url = [NSString stringWithFormat:@"%@%@", kRedStarURL, kInspectListURL];
//    NSLog(@"uuuurl = %@", url);
//    HttpClient *httpCilent = [[HttpClient alloc] initWithUrl:url];
//    NSNumber *pageSize = [[NSUserDefaults standardUserDefaults] objectForKey:@"requestNumber"];
//    
//    NSDictionary *parameters = @{@"keyword":self.customStr,
//                                 @"userUuid":[[NSUserDefaults standardUserDefaults] objectForKey:@"user_uuid"],
//                                 @"queryOrders":@[@{@"field":@"lastModifyInfo", @"direction":@"desc"}],
//                                 @"pageNumber":@(0),
//                                 @"pageSize":pageSize
//                                 };
//    NSLog(@"parrrrr = %@", parameters);
//    [httpCilent getInspectListWithParameters:parameters completion:^(id response, NSError *error) {
//        
//        NSLog(@"巡检列表%@", response);
//        NSLog(@"error = %@", error);
//        NSDictionary *dataDict = response[@"data"];
//        NSArray *dataArray = dataDict[@"records"];
//        for (NSDictionary *dict in dataArray) {
//            TaskListModel *taskList = [[TaskListModel alloc] init];
//            [taskList setValuesForKeysWithDictionary:dict];
//            [_taskListDataArray addObject:taskList];
//        }
//        if (_taskListDataArray.count != 0) {
//            [_sectionArray addObject:@"口碑巡检"];
//        }
//        [self.tableView reloadData];
//        [MBProgressHUD hideHUDForView:self.view animated:YES];
//        
//    }];
//    
//}
//
//- (void)requestQuestionList
//{
//    // 初始化数组
//    // 请求地址
//    NSString *urlStr = [NSString stringWithFormat:@"%@%@", kRedStarURL, kQuestionListURL];
//    NSString *user_uuid = [[NSUserDefaults standardUserDefaults] objectForKey:@"user_uuid"];
//    NSNumber *pageSize = [[NSUserDefaults standardUserDefaults] objectForKey:@"requestNumber"];
//    NSDictionary *parameters = @{@"keyword":self.customStr,
//                                 @"user":user_uuid,
//                                 @"scope":@"all",
//                                 @"pageNumber":@(0),
//                                 @"pageSize":pageSize
//                                 };
//    // 发起请求
//    HttpClient *httpClient = [[HttpClient alloc] initWithUrl:urlStr];
//    //
//    
//    // 请求问题列表
//    [httpClient getQuestionListWithParameters:parameters completion:^(id response, NSError *error) {
//        NSDictionary *dataDict = (NSDictionary *)response[@"data"];
//        NSDictionary *recordsDict = (NSDictionary *)dataDict[@"records"];
//        NSLog(@"问题与知识列表recods = %@", response);
//        NSLog(@"error = %@", error);
//        for (NSDictionary *questionDict in recordsDict) {
//            QuestionModel *question = [[QuestionModel alloc] init];
//            [question setValuesForKeysWithDictionary:questionDict];
//            [_allQuestionArray addObject:question];
//        }
//        if (_allQuestionArray.count != 0) {
//            [_sectionArray addObject:@"问题知识"];
//        }
//        [self.tableView reloadData];
//        
//        [MBProgressHUD hideHUDForView:self.view animated:YES];
//    }];
//}
//
//- (void)requestPicturePraise
//{
//    
//    // 请求地址
//    NSString *urlStr = [NSString stringWithFormat:@"%@%@", kRedStarURL, kQueryPicturePraiseURL];
//    NSString *user_uuid = [[NSUserDefaults standardUserDefaults] objectForKey:@"user_uuid"];
//    NSNumber *pageSize = [[NSUserDefaults standardUserDefaults] objectForKey:@"requestNumber"];
//
//    NSDictionary *parameters = @{
//                                 @"keyword":self.customStr,
//                                 @"scope":@"all",
//                                 @"user":user_uuid,
//                                 @"type":@"store",
//                                 @"pageNumber":@(0),
//                                 @"pageSize":pageSize
//                                 };
//    
//    // 发起请求
//    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;
//        if (_allPraiseListArray.count != 0) {
//            [_sectionArray addObject:@"商场风采"];
//        }
//        [self.tableView reloadData];
//        [MBProgressHUD hideHUDForView:self.view animated:YES];
//    }];
//    
//}


363 364
#pragma mark - 请求数据
- (void)requestRankingList
admin's avatar
admin committed
365 366
{
    
367 368
    NSString *url = [NSString stringWithFormat:@"%@%@", kRedStarURL, kRankingListURL];
    HttpClient *httpCilent = [[HttpClient alloc] initWithUrl:url];
369 370
    NSDictionary *parameters = @{@"praiseUuid":@"",
                                 @"keyword":self.customStr,
371 372
                                 @"statisMode":@(0),
                                 @"pageNumber":@(0),
373
                                 @"pageSize":@(3)
374 375 376
                                 };
    
    [httpCilent getRankingListWithParameters:parameters completion:^(id response, NSError *error) {
377 378 379
        
        // [self requestPicturePraise];
        
380
        NSLog(@"口碑报告response = %@", response);
admin's avatar
admin committed
381 382 383
        NSDictionary *dataDict = response[@"data"];
        NSArray *dataArray = dataDict[@"records"];
        
384
        NSMutableArray *tgArray = [NSMutableArray array];
admin's avatar
admin committed
385 386 387
        
        for (NSDictionary *ListDict in dataArray) {
            RankListModel *rankList = [RankListModel rankListModelWithDict:ListDict];
388
            [tgArray addObject:rankList];
admin's avatar
admin committed
389
        }
390
        _allRankListArray = (NSMutableArray *)[self sortRankListWithRankListArray:tgArray];
admin's avatar
admin committed
391
        
392 393 394 395 396 397 398 399 400
        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;
            }
        }
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
        if (_allRankListArray.count == 0) {
            [_sectionArray removeObject:@"口碑报告"];
        }
        
        if (_sectionArray.count == 0) {
            if (_tableView) {
                [_tableView removeFromSuperview];
                _tableView = nil;
            }
            self.noDataView.backgroundColor = [UIColor whiteColor];
        } else {
            if (_noDataView) {
                [_noDataView removeFromSuperview];
                _noDataView = nil;
            }
            [self.tableView reloadData];
admin's avatar
admin committed
417
        }
418
        
admin's avatar
admin committed
419
        [MBProgressHUD hideHUDForView:self.view animated:YES];
420 421 422
        
        
        
admin's avatar
admin committed
423 424 425
    }];
}

426 427 428
- (NSArray *)sortRankListWithRankListArray:(NSMutableArray *)allRanking
{
    NSArray *sortedArray = [allRanking sortedArrayUsingComparator:^NSComparisonResult(RankListModel *p1, RankListModel *p2){
429
        //return [p2.score compare:p1.score];
430
        return [@(p2.score) compare:@(p1.score)];
431
        
432 433 434 435
    }];
    return sortedArray;
}

436 437 438


- (void)requestInspectList
admin's avatar
admin committed
439
{
440 441 442 443
    
    NSString *url = [NSString stringWithFormat:@"%@%@", kRedStarURL, kInspectListURL];
    HttpClient *httpCilent = [[HttpClient alloc] initWithUrl:url];
    
444 445
    
    NSDictionary *parameters = @{
446 447 448
                                 @"userUuid":[[NSUserDefaults standardUserDefaults] objectForKey:@"user_uuid"],
                                 @"queryOrders":@[@{@"field":@"lastModifyInfo", @"direction":@"desc"}],
                                 @"pageNumber":@(0),
449 450
                                 @"keyword":self.customStr,
                                 @"pageSize":@(2)
451 452 453 454 455 456 457
                                 };
    [httpCilent getInspectListWithParameters:parameters completion:^(id response, NSError *error) {
        
        NSLog(@"巡检列表%@", response);
        NSLog(@"error = %@", error);
        NSDictionary *dataDict = response[@"data"];
        NSArray *dataArray = dataDict[@"records"];
458
        NSMutableArray *tempArray = [NSMutableArray array];
459 460 461
        for (NSDictionary *dict in dataArray) {
            TaskListModel *taskList = [[TaskListModel alloc] init];
            [taskList setValuesForKeysWithDictionary:dict];
462 463 464 465 466 467
            [tempArray addObject:taskList];
        }
        _taskListDataArray = [NSMutableArray arrayWithArray:tempArray];
        
        if (_taskListDataArray.count == 0) {
            [_sectionArray removeObject:@"口碑巡检"];
468
        }
469 470 471 472 473 474 475 476 477 478 479 480
        if (_sectionArray.count == 0) {
            if (_tableView) {
                [_tableView removeFromSuperview];
                _tableView = nil;
            }
            self.noDataView.backgroundColor = [UIColor whiteColor];
        } else {
            if (_noDataView) {
                [_noDataView removeFromSuperview];
                _noDataView = nil;
            }
            [self.tableView reloadData];
481 482 483 484 485 486 487 488 489 490 491 492
        }
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        
    }];
    
}

- (void)requestQuestionList
{
    // 初始化数组
    // 请求地址
    NSString *urlStr = [NSString stringWithFormat:@"%@%@", kRedStarURL, kQuestionListURL];
admin's avatar
admin committed
493
    NSString *user_uuid = [[NSUserDefaults standardUserDefaults] objectForKey:@"user_uuid"];
494 495
    // 请求参数
    NSDictionary *parameters = @{@"user":user_uuid,
496 497
                                 @"scope":@"all",
                                 @"pageNumber":@(0),
498 499
                                 @"keyword":self.customStr,
                                 @"pageSize":@(2)
500 501 502 503 504 505
                                 };
    // 发起请求
    HttpClient *httpClient = [[HttpClient alloc] initWithUrl:urlStr];
    
    // 请求问题列表
    [httpClient getQuestionListWithParameters:parameters completion:^(id response, NSError *error) {
506 507 508
        
        // [self requestInspectList];
        
admin's avatar
admin committed
509 510 511
        NSDictionary *dataDict = (NSDictionary *)response[@"data"];
        NSDictionary *recordsDict = (NSDictionary *)dataDict[@"records"];
        NSLog(@"问题与知识列表recods = %@", response);
512
        NSLog(@"error = %@", error);
513
        NSMutableArray *tempArray = [NSMutableArray array];
admin's avatar
admin committed
514 515 516
        for (NSDictionary *questionDict in recordsDict) {
            QuestionModel *question = [[QuestionModel alloc] init];
            [question setValuesForKeysWithDictionary:questionDict];
517
            [tempArray addObject:question];
admin's avatar
admin committed
518
        }
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534
        _allQuestionArray = [NSMutableArray arrayWithArray:tempArray];
        if (_allQuestionArray.count == 0) {
            [_sectionArray removeObject:@"问题知识"];
        }
        if (_sectionArray.count == 0) {
            if (_tableView) {
                [_tableView removeFromSuperview];
                _tableView = nil;
            }
            self.noDataView.backgroundColor = [UIColor whiteColor];
        } else {
            if (_noDataView) {
                [_noDataView removeFromSuperview];
                _noDataView = nil;
            }
            [self.tableView reloadData];
admin's avatar
admin committed
535 536 537 538 539
        }
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    }];
}

540 541 542 543 544 545 546 547 548 549
- (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",
550
                                 @"keyword":self.customStr,
551
                                 @"pageNumber":@(0),
552
                                 @"pageSize":@(2)
553 554 555 556 557 558 559 560
                                 };
    
    // 发起请求
    HttpClient *httpClient = [[HttpClient alloc] initWithUrl:urlStr];
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    // 请求问题列表
    [httpClient queryPicturePraiseWithParameters:parameters completion:^(id response, NSError *error) {
561
        // [self requestQuestionList];
562 563 564 565 566 567 568 569
        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];
        }
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585
        _allPraiseListArray = [NSMutableArray arrayWithArray:tempArray];
        if (_allPraiseListArray.count == 0) {
            [_sectionArray removeObject:@"商场风采"];
        }
        if (_sectionArray.count == 0) {
            if (_tableView) {
                [_tableView removeFromSuperview];
                _tableView = nil;
            }
            self.noDataView.backgroundColor = [UIColor whiteColor];
        } else {
            if (_noDataView) {
                [_noDataView removeFromSuperview];
                _noDataView = nil;
            }
            [self.tableView reloadData];
586 587 588 589 590
        }
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    }];
    
}
admin's avatar
admin committed
591 592 593 594 595 596 597

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

admin's avatar
admin committed
598

599
#pragma mark - TableView Delegate/DataSource
admin's avatar
admin committed
600 601 602
#pragma mark - TableView Delegate/DataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
603
    return _sectionArray.count;
admin's avatar
admin committed
604 605 606 607 608
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
609 610 611 612 613 614
    NSUInteger s2 = [_sectionArray indexOfObject:@"口碑报告"];
    NSUInteger s4 = [_sectionArray indexOfObject:@"商场风采"];
    NSUInteger s3 = [_sectionArray indexOfObject:@"问题知识"];
    NSUInteger s1 = [_sectionArray indexOfObject:@"口碑巡检"];
    
    if ([_sectionArray[section] isEqualToString:@"口碑巡检"] && section == s1) {
admin's avatar
admin committed
615
        return _taskListDataArray.count;
616
    } else if ([_sectionArray[section] isEqualToString:@"口碑报告"] && section == s2) {
admin's avatar
admin committed
617
        return _allRankListArray.count + 1;
618
    } else if ([_sectionArray[section] isEqualToString:@"问题知识"] && section == s3) {
admin's avatar
admin committed
619
        return _allQuestionArray.count;
620 621
    } else if ([_sectionArray[section] isEqualToString:@"商场风采"] && section == s4) {
        return _allPraiseListArray.count;
admin's avatar
admin committed
622 623 624 625 626 627 628 629 630
    } else {
        return 0;
    }
}


// cell显示的内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
631 632 633 634
    NSUInteger s2 = [_sectionArray indexOfObject:@"口碑报告"];
    NSUInteger s4 = [_sectionArray indexOfObject:@"商场风采"];
    NSUInteger s3 = [_sectionArray indexOfObject:@"问题知识"];
    NSUInteger s1 = [_sectionArray indexOfObject:@"口碑巡检"];
admin's avatar
admin committed
635
    
636
    if ([_sectionArray[indexPath.section] isEqualToString:@"口碑巡检"] && indexPath.section == s1) {
admin's avatar
admin committed
637 638 639 640 641 642 643 644 645 646 647 648
        InspectListCell *cell=[tableView dequeueReusableCellWithIdentifier:kHomeInspectListCell];
        if (!cell) {
            cell = [[InspectListCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kHomeInspectListCell];
        }
        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;
649
    } else if ([_sectionArray[indexPath.section] isEqualToString:@"口碑报告"] && indexPath.section == s2) {
admin's avatar
admin committed
650 651 652 653 654 655 656 657 658 659 660 661
        if (indexPath.row == 0) {
            HomeTitleTableCell *cell=[tableView dequeueReusableCellWithIdentifier:kHomeTitleTableCell];
            if (!cell) {
                cell = [[HomeTitleTableCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kHomeTitleTableCell];
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        } else {
            RankingListCell *cell = [tableView dequeueReusableCellWithIdentifier:kHomeRankingListCell];
            if (!cell) {
                cell = [[RankingListCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kHomeRankingListCell];
            }
662 663
            RankListModel *rankList = _allRankListArray[indexPath.row - 1];
            cell.rankList = rankList;
664
            cell.gradeImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"medal_0%d", rankList.index]];
admin's avatar
admin committed
665 666 667
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }
668
    } else if ([_sectionArray[indexPath.section] isEqualToString:@"问题知识"] && indexPath.section == s3) {
admin's avatar
admin committed
669 670 671 672 673 674 675 676 677
        // 问题与知识
        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;
678 679 680 681 682 683 684
    } else if ([_sectionArray[indexPath.section] isEqualToString:@"商场风采"] && indexPath.section == s4) {
        PictureTableCell *cell=[tableView dequeueReusableCellWithIdentifier:kHomePictureListCell];
        if (!cell) {
            cell = [[PictureTableCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kHomePictureListCell];
        }
        cell.pictureList = _allPraiseListArray[indexPath.row];
        return cell;
admin's avatar
admin committed
685 686 687
    } else {
        return nil;
    }
688 689 690 691
    
    
    
    
admin's avatar
admin committed
692 693 694 695 696
}

// cell点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
697 698 699 700 701 702 703 704 705 706 707 708 709 710 711
    NSUInteger s2 = [_sectionArray indexOfObject:@"口碑报告"];
    NSUInteger s4 = [_sectionArray indexOfObject:@"商场风采"];
    NSUInteger s3 = [_sectionArray indexOfObject:@"问题知识"];
    NSUInteger s1 = [_sectionArray indexOfObject:@"口碑巡检"];
    if ([_sectionArray[indexPath.section] isEqualToString:@"口碑巡检"] && indexPath.section == s1) {
        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];
    } else if ([_sectionArray[indexPath.section] isEqualToString:@"口碑报告"] && indexPath.section == s2) {
        if (indexPath.row == 0) {
            return;
admin's avatar
admin committed
712
        }
713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733
        RankListModel *rankList = _allRankListArray[indexPath.row - 1];
        RankDetailViewController *rankDetailVC = [[RankDetailViewController alloc] init];
        rankDetailVC.indexRow = rankList.index;
        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];
    } else if ([_sectionArray[indexPath.section] isEqualToString:@"问题知识"] && indexPath.section == s3) {
        QuestionDetailViewController *questionDetailVC = [[QuestionDetailViewController alloc] init];
        QuestionModel *question = self.allQuestionArray[indexPath.row];
        questionDetailVC.questionUuid = question.uuid;
        self.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:questionDetailVC animated:YES];
    } 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
734
    } else {
735
        return;
admin's avatar
admin committed
736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781
    }
}


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

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

// 自定义section
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    
    // 创建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];
782
    titleLabel.text = _sectionArray[section];
admin's avatar
admin committed
783 784 785 786 787 788 789 790 791 792 793 794 795 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 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 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883
    
    
    [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];
    
    
    
    
    
    // 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;
}


- (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;
        _tableView.rowHeight = UITableViewAutomaticDimension;
        _tableView.estimatedRowHeight = 300.0;
        _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 40)];
        [_tableView registerClass:[PictureTableCell class] forCellReuseIdentifier:kHomePictureListCell];
        [_tableView registerClass:[HomeTitleTableCell class] forCellReuseIdentifier:kHomeTitleTableCell];
        [_tableView registerClass:[RankingListCell class] forCellReuseIdentifier:kHomeRankingListCell];
        [_tableView registerClass:[QuestionListTableCell class] forCellReuseIdentifier:kHomeQuestionListTableCell];
        
        [self.view addSubview:_tableView];
        
        NSLayoutConstraint *tableTop = [NSLayoutConstraint constraintWithItem:_tableView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1.0 constant:0];
        [self.view addConstraint:tableTop];
        
        NSLayoutConstraint *tableLeft = [NSLayoutConstraint constraintWithItem:_tableView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
        [self.view addConstraint:tableLeft];
        
        NSLayoutConstraint *tableRight = [NSLayoutConstraint constraintWithItem:_tableView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeRight multiplier:1.0 constant:0];
        [self.view addConstraint:tableRight];
        
        NSLayoutConstraint *tableBottom = [NSLayoutConstraint constraintWithItem:_tableView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
        [self.view addConstraint:tableBottom];
    }
    return _tableView;
}
884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907


- (NoDataView *)noDataView
{
    if (!_noDataView) {
        _noDataView = [[NoDataView alloc] init];
        _noDataView.translatesAutoresizingMaskIntoConstraints = NO;
        [self.view addSubview:_noDataView];
        
        NSLayoutConstraint *tableTop = [NSLayoutConstraint constraintWithItem:_noDataView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1.0 constant:45];
        [self.view addConstraint:tableTop];
        
        NSLayoutConstraint *tableLeft = [NSLayoutConstraint constraintWithItem:_noDataView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
        [self.view addConstraint:tableLeft];
        
        NSLayoutConstraint *tableRight = [NSLayoutConstraint constraintWithItem:_noDataView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeRight multiplier:1.0 constant:0];
        [self.view addConstraint:tableRight];
        
        NSLayoutConstraint *tableBottom = [NSLayoutConstraint constraintWithItem:_noDataView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
        [self.view addConstraint:tableBottom];
    }
    return _noDataView;
}

admin's avatar
admin committed
908 909 910 911 912 913 914 915 916 917 918
/*
#pragma mark - Navigation

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

@end