HomeViewController.m 50.3 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 16 17
#import "OnLineViewController.h"
#import "PictureViewController.h"
#import "QuestionViewController.h"
admin's avatar
admin committed
18

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

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

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

44
#import "SpotCheckOnLineViewController.h"
45 46 47 48 49

#import "LookOnLineViewController.h"

#import "StandardViewController.h"

50 51 52
#import "HttpClient.h"
#import <MBProgressHUD.h>

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

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

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

admin's avatar
admin committed
69
@property (nonatomic, strong) NSMutableArray *titleArray; // section标题
admin's avatar
admin committed
70
@property (nonatomic, strong) NSArray *btnTitleArray; // section标题
admin's avatar
admin committed
71
@property (nonatomic, strong) NSArray *announeArray; // 公告内容
admin's avatar
admin committed
72 73 74 75 76 77 78 79 80

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


// rank cell
@property (nonatomic, strong) NSMutableDictionary *selectedIndexes;

81
@property (nonatomic, strong) NSMutableArray *allQuestionArray; // 问题与知识
admin's avatar
admin committed
82 83
@property (nonatomic, strong) NSMutableArray *taskListDataArray; // 问题与知识
@property (nonatomic, strong) NSMutableArray *allRankListArray;
admin's avatar
admin committed
84 85 86
@end

@implementation HomeViewController
admin's avatar
admin committed
87

admin's avatar
admin committed
88 89 90 91 92
#pragma mark - ViewDidLoad
- (void)viewDidLoad
{
    [super viewDidLoad];
    
93
    
admin's avatar
admin committed
94 95 96 97 98 99
    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
100 101
    self.titleArray = [NSMutableArray array];
    NSArray *permissions = [[NSUserDefaults standardUserDefaults] objectForKey:@"permissions"];
admin's avatar
admin committed
102
    
admin's avatar
admin committed
103 104 105 106 107
    if ([permissions containsObject:@"500101"] || [permissions containsObject:@"500102"]) {
        [self.titleArray addObject:@"口碑巡检"];
        [self requestInspectList];
    }
    
admin's avatar
admin committed
108 109 110
    if ([permissions containsObject:@"500201"]) {
        [self.titleArray addObject:@"口碑排名"];
        [self requestRankingList];
admin's avatar
admin committed
111
        
admin's avatar
admin committed
112
    }
admin's avatar
admin committed
113
    
admin's avatar
admin committed
114 115 116
    if ([permissions containsObject:@"500501"] || [permissions containsObject:@"500502"]) {
        [self.titleArray addObject:@"问题知识"];
        [self requestQuestionList];
admin's avatar
admin committed
117 118
        
    }
admin's avatar
admin committed
119
   
admin's avatar
admin committed
120 121
    
    if ([permissions containsObject:@"500301"] || [permissions containsObject:@"500302"]) {
admin's avatar
admin committed
122
        [self.titleArray addObject:@"图说口碑"];
admin's avatar
admin committed
123 124
    }
    if ([permissions containsObject:@"500401"] || [permissions containsObject:@"500402"]) {
admin's avatar
admin committed
125
         [self.titleArray addObject:@"口碑标准"];
admin's avatar
admin committed
126
    }
admin's avatar
admin committed
127
    
admin's avatar
admin committed
128
    if ([permissions containsObject:@"500701"] || [permissions containsObject:@"500702"]) {
admin's avatar
admin committed
129
        [self.titleArray addObject:@"在线抽查"];
admin's avatar
admin committed
130 131
    }
    
admin's avatar
admin committed
132
    // 初始化容器
admin's avatar
admin committed
133 134
    //self.titleArray = [NSMutableArray arrayWithObjects:@"图说口碑", @"8月口碑巡检",@"问题与知识",@"口碑任务", nil];
    self.btnTitleArray = [NSArray arrayWithObjects:@"在线抽查", @"口碑巡检",@"口碑标准",@"图说口碑",@"问题知识",@"口碑排名",@"查看抽查", nil];
admin's avatar
admin committed
135 136
    self.announeArray = [NSArray arrayWithObjects:@"关于展开10月口碑巡检的说明", @"迎2015十一大促活动启动", @"9月口碑巡检结果排名已公布", nil];
    
admin's avatar
admin committed
137 138 139 140 141
    // 初始化
    self.test1Array = [NSArray arrayWithObjects:@"【服务口碑现场】第二期",@"讲述红星人自己的故事",@"【服务口碑现场】第一期", nil];
    self.test2Array = [NSArray arrayWithObjects:@"把第一次客户投诉变成商场服务提升的契机,变成商场服务提升的契机。",@"变成商场服务提升的契机,变成商场服务提升的契机。",@"把第一次客户投诉变成商场服务提升的契机,变成商场服务提升的契机。", nil];
    self.test3Array = [NSArray arrayWithObjects:@"2015-08-26",@"2015-08-09",@"2015-07-31", nil];
    
142
    
admin's avatar
admin committed
143 144
    
    [self setupNav];
admin's avatar
admin committed
145 146
    [self setupTableView];
    
admin's avatar
admin committed
147 148 149
    // 初始化容器
    self.selectedIndexes = [[NSMutableDictionary alloc] init];
    
admin's avatar
admin committed
150 151 152 153 154 155 156 157
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    self.allRankListArray = [NSMutableArray array];
    self.taskListDataArray = [NSMutableArray array];
    self.allQuestionArray = [NSMutableArray array];

    self.tableView.tableHeaderView = self.headView;

admin's avatar
admin committed
158 159 160 161 162 163 164
    // 设置下拉刷新
    self.tableView.header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        // 进入刷新状态后会自动调用这个block
        [self refreshAllData];
        
    }];
    
admin's avatar
admin committed
165
    
admin's avatar
admin committed
166 167 168 169 170 171 172 173 174 175 176 177 178 179
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(refreshInspectList)
                                                 name:kRefreshInspectPointNotification
                                               object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(refreshQuestionList)
                                                 name:kRefreshQuestionNotification
                                               object:nil];
    
}
-(void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
admin's avatar
admin committed
180 181
}

admin's avatar
admin committed
182 183
- (void)refreshAllData
{
admin's avatar
admin committed
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
    [self refreshInspectList];
    [self refreshRankingList];
    [self refreshQuestionList];
}

- (void)refreshInspectList {
    // 口碑任务
    NSString *url3 = [NSString stringWithFormat:@"%@%@", kRedStarURL, kInspectListURL];
    HttpClient *httpCilent3 = [[HttpClient alloc] initWithUrl:url3];
    NSDictionary *parameters3 = @{@"userUuid":[[NSUserDefaults standardUserDefaults] objectForKey:@"user_uuid"],
                                  @"queryOrders":@[@{@"field":@"lastModifyInfo"}],
                                  @"pageNumber":@(0),
                                  @"pageSize":@(2)
                                  };
    
    [httpCilent3 getInspectListWithParameters:parameters3 completion:^(id response, NSError *error) {
        NSLog(@"刷新!! = 巡检列表%@", response);
        NSDictionary *dataDict = response[@"data"];
        NSArray *dataArray = dataDict[@"records"];
        NSMutableArray *inspectTempArr = [NSMutableArray array];
        for (NSDictionary *dict in dataArray) {
            TaskListModel *taskList = [[TaskListModel alloc] init];
            [taskList setValuesForKeysWithDictionary:dict];
            [inspectTempArr addObject:taskList];
        }
        _taskListDataArray = inspectTempArr;
        [self.tableView reloadData];
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        [self.tableView.header endRefreshing];
    }];

}
- (void)refreshRankingList {
admin's avatar
admin committed
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
    // 口碑巡检
    NSString *url1 = [NSString stringWithFormat:@"%@%@", kRedStarURL, kRankingListURL];
    HttpClient *httpCilent1 = [[HttpClient alloc] initWithUrl:url1];
    NSDictionary *parameters1 = @{
                                  @"queryOrders":@[@{@"direction":@"asc"}],
                                  @"pageNumber":@(0),
                                  @"pageSize":@(3)
                                  };
    __block HomeViewController *weakSelf = self;
    [httpCilent1 getRankingListWithParameters:parameters1 completion:^(id response, NSError *error) {
        NSLog(@"刷新!! = 口碑排名response = %@", response);
        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;
        [self.tableView reloadData];
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    }];
admin's avatar
admin committed
240 241 242
}

- (void)refreshQuestionList {
admin's avatar
admin committed
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
    // 问题与知识
    NSString *url2 = [NSString stringWithFormat:@"%@%@", kRedStarURL, kQuestionListURL];
    NSString *user_uuid = [[NSUserDefaults standardUserDefaults] objectForKey:@"user_uuid"];
    NSDictionary *parameters2 = @{
                                  @"user":user_uuid,
                                  @"scope":@"all",
                                  @"pageNumber":@(0),
                                  @"pageSize":@(2)
                                  };
    
    HttpClient *httpClient2 = [[HttpClient alloc] initWithUrl:url2];
    [httpClient2 getQuestionListWithParameters:parameters2 completion:^(id response, NSError *error) {
        NSDictionary *dataDict = (NSDictionary *)response[@"data"];
        NSDictionary *recordsDict = (NSDictionary *)dataDict[@"records"];
        NSLog(@"刷新!! = 问题与知识列表recods = %@", response);
        
        NSMutableArray *questionTempArr = [NSMutableArray array];
        
        for (NSDictionary *questionDict in recordsDict) {
            QuestionModel *question = [[QuestionModel alloc] init];
            [question setValuesForKeysWithDictionary:questionDict];
            [questionTempArr addObject:question];
        }
admin's avatar
admin committed
266
        _allQuestionArray = questionTempArr;
admin's avatar
admin committed
267 268 269 270
        [self.tableView reloadData];
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    }];

admin's avatar
admin committed
271
}
admin's avatar
admin committed
272

admin's avatar
admin committed
273 274 275 276
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
277
    self.tabBarController.tabBar.hidden = NO;
admin's avatar
admin committed
278
    self.navigationController.navigationBar.hidden = YES;
admin's avatar
admin committed
279
    [self.tableView.header beginRefreshing];
admin's avatar
admin committed
280 281 282 283 284 285
}

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

286
#pragma mark - 请求
admin's avatar
admin committed
287 288 289 290 291
- (void)requestRankingList
{
    
    NSString *url = [NSString stringWithFormat:@"%@%@", kRedStarURL, kRankingListURL];
    HttpClient *httpCilent = [[HttpClient alloc] initWithUrl:url];
admin's avatar
admin committed
292 293
    NSDictionary *parameters = @{
                                 @"queryOrders":@[@{@"direction":@"asc"}],
admin's avatar
admin committed
294 295 296 297 298
                                 @"pageNumber":@(0),
                                 @"pageSize":@(3)
                                 };
    [httpCilent getRankingListWithParameters:parameters completion:^(id response, NSError *error) {
        NSLog(@"口碑排名response = %@", response);
299
        NSLog(@"error = %@", error);
admin's avatar
admin committed
300 301
        NSDictionary *dataDict = response[@"data"];
        NSArray *dataArray = dataDict[@"records"];
302 303 304
        
        NSMutableArray *tgArray = [NSMutableArray array];
        
admin's avatar
admin committed
305 306
        for (NSDictionary *ListDict in dataArray) {
            RankListModel *rankList = [RankListModel rankListModelWithDict:ListDict];
307
            [tgArray addObject:rankList];
admin's avatar
admin committed
308
        }
admin's avatar
admin committed
309
        _allRankListArray = (NSMutableArray *)[self sortRankListWithRankListArray:tgArray];
admin's avatar
admin committed
310 311 312 313 314 315
        [self.tableView reloadData];
        [MBProgressHUD hideHUDForView:self.view animated:YES];
            
    }];
}

admin's avatar
admin committed
316 317 318 319 320 321 322 323
- (NSArray *)sortRankListWithRankListArray:(NSMutableArray *)allRanking
{
    NSArray *sortedArray = [allRanking sortedArrayUsingComparator:^NSComparisonResult(RankListModel *p1, RankListModel *p2){
        return [p2.score compare:p1.score];
    }];
    return sortedArray;
}

admin's avatar
admin committed
324 325 326 327 328 329


- (void)requestInspectList
{
    
    NSString *url = [NSString stringWithFormat:@"%@%@", kRedStarURL, kInspectListURL];
330
    NSLog(@"uuuurl = %@", url);
admin's avatar
admin committed
331
    HttpClient *httpCilent = [[HttpClient alloc] initWithUrl:url];
332 333 334 335
    

    NSDictionary *parameters = @{
                                 @"userUuid":[[NSUserDefaults standardUserDefaults] objectForKey:@"user_uuid"],
admin's avatar
admin committed
336 337 338 339
                                 @"queryOrders":@[@{@"field":@"lastModifyInfo"}],
                                 @"pageNumber":@(0),
                                 @"pageSize":@(2)
                                 };
340
    NSLog(@"parrrrr = %@", parameters);
admin's avatar
admin committed
341 342 343
    [httpCilent getInspectListWithParameters:parameters completion:^(id response, NSError *error) {
        
        NSLog(@"巡检列表%@", response);
344
        NSLog(@"error = %@", error);
admin's avatar
admin committed
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
        NSDictionary *dataDict = response[@"data"];
        NSArray *dataArray = dataDict[@"records"];
        for (NSDictionary *dict in dataArray) {
            TaskListModel *taskList = [[TaskListModel alloc] init];
            [taskList setValuesForKeysWithDictionary:dict];
            [_taskListDataArray addObject:taskList];
        }
        [self.tableView reloadData];
        [MBProgressHUD hideHUDForView:self.view animated:YES];

    }];

}


360 361 362 363 364 365 366
- (void)requestQuestionList
{
    // 初始化数组
    // 请求地址
    NSString *urlStr = [NSString stringWithFormat:@"%@%@", kRedStarURL, kQuestionListURL];
    NSString *user_uuid = [[NSUserDefaults standardUserDefaults] objectForKey:@"user_uuid"];
    // 请求参数
admin's avatar
admin committed
367
    NSDictionary *parameters = @{@"user":user_uuid,
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
                                 @"scope":@"all",
                                 @"pageNumber":@(0),
                                 @"pageSize":@(2)
                                 };
    
    // 发起请求
    HttpClient *httpClient = [[HttpClient alloc] initWithUrl:urlStr];
    //
    __block HomeViewController *weakSelf = self;
    
    // 请求问题列表
    [httpClient getQuestionListWithParameters:parameters completion:^(id response, NSError *error) {
        NSDictionary *dataDict = (NSDictionary *)response[@"data"];
        NSDictionary *recordsDict = (NSDictionary *)dataDict[@"records"];
        NSLog(@"问题与知识列表recods = %@", response);
383
        NSLog(@"error = %@", error);
384 385 386 387 388
        for (NSDictionary *questionDict in recordsDict) {
            QuestionModel *question = [[QuestionModel alloc] init];
            [question setValuesForKeysWithDictionary:questionDict];
            [weakSelf.allQuestionArray addObject:question];
        }
admin's avatar
admin committed
389 390
        [self.tableView reloadData];

391 392 393 394 395 396
        self.tableView.tableHeaderView = self.headView;
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    }];
}


admin's avatar
admin committed
397
#pragma mark - Private Methods
admin's avatar
admin committed
398 399 400 401 402 403 404
- (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
405
    _nameLabel.text = [NSString stringWithFormat:@"%@,你好!", [[NSUserDefaults standardUserDefaults] objectForKey:@"user_name"]];
admin's avatar
admin committed
406
    self.shopnameLabel.backgroundColor = [UIColor clearColor];
admin's avatar
admin committed
407
    _shopnameLabel.text = [NSString stringWithFormat:@"%@", [[NSUserDefaults standardUserDefaults] objectForKey:@"org_name"]];
admin's avatar
admin committed
408 409 410

}

admin's avatar
admin committed
411 412
- (void)setupTableView
{
admin's avatar
admin committed
413
    self.headView = [[HomeHeaderView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 115)];
admin's avatar
admin committed
414
    
admin's avatar
admin committed
415 416
    self.headView.scrollView.contentSize = CGSizeMake(2 * kScreenWidth, 86);
    CGFloat itemW = kScreenWidth / 4;
admin's avatar
admin committed
417 418
    CGFloat itemH = self.headView.scrollView.frame.size.height;
    
admin's avatar
admin committed
419
    for (int i = 0; i < _titleArray.count; i++) {
admin's avatar
admin committed
420 421
        HomeCellItem *item = [[HomeCellItem alloc] init];
        item.frame = CGRectMake(i * itemW, 0, itemW, itemH);
admin's avatar
admin committed
422 423
        NSString *nameStr = _titleArray[i];
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%@", nameStr]];
admin's avatar
admin committed
424 425
        [item setImage:image forState:UIControlStateNormal];
        [item setTitleColor:kPictureCellDetailsColor forState:UIControlStateNormal];
admin's avatar
admin committed
426
        [item setTitle:nameStr forState:UIControlStateNormal];
admin's avatar
admin committed
427 428 429
        [item addTarget:self action:@selector(itemClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.headView.scrollView addSubview:item];
    }
admin's avatar
admin committed
430 431
}

432
// 更多按钮点击事件
admin's avatar
admin committed
433 434
- (void)moreButtonClick:(UIButton *)sender
{
admin's avatar
admin committed
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451
    
    if (_titleArray.count == 5) {
        UIButton *button = (UIButton *)sender;
        UINavigationController *nav;
        
        if (button.tag - 332892 == 0) {
            InspectListViewController *inspectListVC = [[InspectListViewController alloc] init];
            nav = [[UINavigationController alloc] initWithRootViewController:inspectListVC];
        } else  {
            QuestionViewController *questionVC = [[QuestionViewController alloc] init];
            nav = [[UINavigationController alloc] initWithRootViewController:questionVC];
        }
        [nav.navigationBar setBarTintColor:kNavigationBarColor];
        [nav.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]];
        [self presentViewController:nav animated:YES completion:nil];
    } else {
    
452 453 454 455
    UIButton *button = (UIButton *)sender;
    UINavigationController *nav;

    if (button.tag - 332892 == 0) {
admin's avatar
admin committed
456 457 458
        InspectListViewController *inspectListVC = [[InspectListViewController alloc] init];
        nav = [[UINavigationController alloc] initWithRootViewController:inspectListVC];
    } else if (button.tag - 332892 == 1) {
459 460
        RankingListViewController *rankingListVC = [[RankingListViewController alloc] init];
        nav = [[UINavigationController alloc] initWithRootViewController:rankingListVC];
admin's avatar
admin committed
461 462
        
    } else {
463 464 465
        QuestionViewController *questionVC = [[QuestionViewController alloc] init];
        nav = [[UINavigationController alloc] initWithRootViewController:questionVC];

admin's avatar
admin committed
466
      
467 468 469 470 471
    }
    
    [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
472
    }
admin's avatar
admin committed
473 474
}

admin's avatar
admin committed
475
- (void)itemClick:(HomeCellItem *)sender
admin's avatar
admin committed
476
{
admin's avatar
admin committed
477 478 479
    HomeCellItem *item = (HomeCellItem *)sender;
    UINavigationController *nav;
    if ([item.titleLabel.text isEqualToString:@"在线抽查"]) {
480 481
        SpotCheckOnLineViewController *spotOnline = [[SpotCheckOnLineViewController alloc] init];
        nav = [[UINavigationController alloc] initWithRootViewController:spotOnline];
admin's avatar
admin committed
482
    } else if ([item.titleLabel.text isEqualToString:@"口碑巡检"]) {
admin's avatar
admin committed
483 484 485
        InspectListViewController *inspectListVC = [[InspectListViewController alloc] init];
        nav = [[UINavigationController alloc] initWithRootViewController:inspectListVC];
    } else if ([item.titleLabel.text isEqualToString:@"口碑标准"]) {
486 487
        StandardViewController *standardVC = [[StandardViewController alloc] init];
        nav = [[UINavigationController alloc] initWithRootViewController:standardVC];
admin's avatar
admin committed
488 489 490
    } else if ([item.titleLabel.text isEqualToString:@"图说口碑"]) {
        PictureViewController *pictureVC = [[PictureViewController alloc] init];
        nav = [[UINavigationController alloc] initWithRootViewController:pictureVC];
admin's avatar
admin committed
491
    } else if ([item.titleLabel.text isEqualToString:@"问题知识"]) {
admin's avatar
admin committed
492 493
        QuestionViewController *questionVC = [[QuestionViewController alloc] init];
        nav = [[UINavigationController alloc] initWithRootViewController:questionVC];
494
    } else if ([item.titleLabel.text isEqualToString:@"口碑排名"]){
admin's avatar
admin committed
495 496
        RankingListViewController *rankingListVC = [[RankingListViewController alloc] init];
        nav = [[UINavigationController alloc] initWithRootViewController:rankingListVC];
497 498 499
    } else if ([item.titleLabel.text isEqualToString:@"查看抽查"]){
        LookOnLineViewController *lookOnLine = [[LookOnLineViewController alloc] init];
        nav = [[UINavigationController alloc] initWithRootViewController:lookOnLine];
admin's avatar
admin committed
500
    }
admin's avatar
admin committed
501
    
admin's avatar
admin committed
502 503 504
    [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
505 506 507 508 509 510 511 512
}




#pragma mark - TableView Delegate/DataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
admin's avatar
admin committed
513
    if (_titleArray.count == 1) {
admin's avatar
admin committed
514
        return _titleArray.count;
admin's avatar
admin committed
515 516 517 518
    } else if (_titleArray.count == 5){
        return 2;
    } else {
        return 3;
admin's avatar
admin committed
519
    }
admin's avatar
admin committed
520 521 522 523 524
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
admin's avatar
admin committed
525
    
admin's avatar
admin committed
526 527 528 529 530 531 532 533
    if (_titleArray.count == 5) {
        if (section == 0) {
            return _taskListDataArray.count;
        } else {
            return _allQuestionArray.count;
        }
    } else {
    
admin's avatar
admin committed
534
    if (section == 0) {
admin's avatar
admin committed
535 536
        return _taskListDataArray.count;

admin's avatar
admin committed
537
    } else if (section == 1 ) {
admin's avatar
admin committed
538 539
        return _allRankListArray.count + 1;

540
    } else {
admin's avatar
admin committed
541 542
        return _allQuestionArray.count;

admin's avatar
admin committed
543
    }
admin's avatar
admin committed
544
    }
admin's avatar
admin committed
545 546
}

admin's avatar
admin committed
547

admin's avatar
admin committed
548 549 550
// cell显示的内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
admin's avatar
admin committed
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575
    if (_titleArray.count == 5) {
        if (indexPath.section == 0) {
            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;
        } else  {
            // 问题与知识
            QuestionListTableCell *cell = [tableView dequeueReusableCellWithIdentifier:kHomeQuestionListTableCell];
            if (!cell) {
                cell = [[QuestionListTableCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kHomeQuestionListTableCell];
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            QuestionModel *question = _allQuestionArray[indexPath.row];
            cell.question = question;
            return cell;
            
admin's avatar
admin committed
576
        }
admin's avatar
admin committed
577 578 579
    } else {
        if (indexPath.section == 0) {
            InspectListCell *cell=[tableView dequeueReusableCellWithIdentifier:kHomeInspectListCell];
admin's avatar
admin committed
580
            if (!cell) {
admin's avatar
admin committed
581
                cell = [[InspectListCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kHomeInspectListCell];
admin's avatar
admin committed
582
            }
admin's avatar
admin committed
583 584
            TaskListModel *taskList = _taskListDataArray[indexPath.row];
            cell.taskList = taskList;
admin's avatar
admin committed
585
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
admin's avatar
admin committed
586 587 588 589
            cell.allView.backgroundColor = kProgressViewAllBackColor;
            UIImage *image = [UIImage imageNamed:@"progress-bar"];
            image = [image resizableImageWithCapInsets:UIEdgeInsetsZero resizingMode:UIImageResizingModeTile];
            cell.alreadyView.image = image;
admin's avatar
admin committed
590
            return cell;
admin's avatar
admin committed
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615
        } else if (indexPath.section == 1) {
            
            
            
            if (indexPath.row == 0) {
                HomeTitleTableCell *cell=[tableView dequeueReusableCellWithIdentifier:kHomeTitleTableCell];
                if (!cell) {
                    cell = [[HomeTitleTableCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kHomeTitleTableCell];
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                return cell;
            } else {
                RankingListCell *cell = [tableView dequeueReusableCellWithIdentifier:kHomeRankingListCell];
                if (!cell) {
                    cell = [[RankingListCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kHomeRankingListCell];
                }
                cell.rankList = _allRankListArray[indexPath.row - 1];
                cell.gradeImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"medal_0%d", (int)indexPath.row]];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                return cell;
            }
            
            
            
            
admin's avatar
admin committed
616
        } else {
admin's avatar
admin committed
617 618 619 620
            
            
            // 问题与知识
            QuestionListTableCell *cell = [tableView dequeueReusableCellWithIdentifier:kHomeQuestionListTableCell];
admin's avatar
admin committed
621
            if (!cell) {
admin's avatar
admin committed
622
                cell = [[QuestionListTableCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kHomeQuestionListTableCell];
admin's avatar
admin committed
623 624
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
admin's avatar
admin committed
625 626
            QuestionModel *question = _allQuestionArray[indexPath.row];
            cell.question = question;
admin's avatar
admin committed
627
            return cell;
admin's avatar
admin committed
628 629
            
            
admin's avatar
admin committed
630
        }
admin's avatar
admin committed
631

admin's avatar
admin committed
632
    }
admin's avatar
admin committed
633
    
admin's avatar
admin committed
634 635 636 637 638
}

// cell点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
admin's avatar
admin committed
639 640 641 642 643 644 645 646 647
    if (_titleArray.count == 5) {
        if (indexPath.section == 0) {
            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
648
        } else {
admin's avatar
admin committed
649 650 651
            QuestionDetailViewController *questionDetailVC = [[QuestionDetailViewController alloc] init];
            QuestionModel *question = self.allQuestionArray[indexPath.row];
            questionDetailVC.questionUuid = question.uuid;
admin's avatar
admin committed
652
            self.hidesBottomBarWhenPushed = YES;
admin's avatar
admin committed
653
            [self.navigationController pushViewController:questionDetailVC animated:YES];
admin's avatar
admin committed
654
        }
admin's avatar
admin committed
655
    } else {
admin's avatar
admin committed
656
        
admin's avatar
admin committed
657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692
        if (indexPath.section == 0) {
            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 (indexPath.section == 1) {
            
            if (indexPath.row == 0) {
                NSLog(@"不能点击");
            } else {
                RankListModel *rankList = _allRankListArray[indexPath.row - 1];
                RankDetailViewController *rankDetailVC = [[RankDetailViewController alloc] init];
                rankDetailVC.indexRow = indexPath.section - 2;
                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 {
            QuestionDetailViewController *questionDetailVC = [[QuestionDetailViewController alloc] init];
            QuestionModel *question = self.allQuestionArray[indexPath.row];
            questionDetailVC.questionUuid = question.uuid;
            self.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:questionDetailVC animated:YES];
            
            
            
        }
admin's avatar
admin committed
693
    }
admin's avatar
admin committed
694 695 696 697 698 699
}


// section高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
admin's avatar
admin committed
700
    return 36;
admin's avatar
admin committed
701 702 703 704
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
admin's avatar
admin committed
705
    return 10;
admin's avatar
admin committed
706 707 708 709 710
}

// 自定义section
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
admin's avatar
admin committed
711
    
712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738
        // 创建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
739
        titleLabel.text = _titleArray[section];
admin's avatar
admin committed
740

admin's avatar
admin committed
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 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805
        [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;
}
admin's avatar
admin committed
806

admin's avatar
admin committed
807 808 809 810 811 812 813 814 815 816 817 818 819
//- (void)pushclick:(UIButton *)sender
//{
//    NSInteger section = sender.tag - kPushTag;
//    
//    RankListModel *rankList = _rankData[section-2];
//    
//    RankDetailViewController *rankDetailVC = [[RankDetailViewController alloc] init];
//    rankDetailVC.indexRow = section;
//    rankDetailVC.uuid = rankList.uuid;
//    rankDetailVC.store_uuid = rankList.store_uuid;
//    self.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:rankDetailVC animated:YES];
//}
admin's avatar
admin committed
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

#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
857
        _searchTextField.delegate = self;
admin's avatar
admin committed
858
        [_searchTextField setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];
admin's avatar
admin committed
859 860 861 862
        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
863 864 865 866 867
        imageV.contentMode = UIViewContentModeCenter;
        imageV.width += 10;
        _searchTextField.rightView = imageV;
        _searchTextField.rightViewMode = UITextFieldViewModeAlways;
        [self.bgImageView addSubview:_searchTextField];
admin's avatar
admin committed
868
        
admin's avatar
admin committed
869 870
        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
871
        
admin's avatar
admin committed
872 873
        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
874
        
admin's avatar
admin committed
875 876
        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
877
        
admin's avatar
admin committed
878 879 880 881 882 883 884 885 886 887 888 889 890 891 892
        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
893
        
admin's avatar
admin committed
894 895
        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
896
        
admin's avatar
admin committed
897 898 899 900 901 902
        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
903
        NSLayoutConstraint *bgImageWidth = [NSLayoutConstraint constraintWithItem:_nameLabel attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:110];
admin's avatar
admin committed
904 905 906 907 908 909 910 911 912 913 914 915 916 917
        [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
918
        
admin's avatar
admin committed
919 920
        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
921
        
admin's avatar
admin committed
922 923
        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
924
        
admin's avatar
admin committed
925 926
        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
927
        
admin's avatar
admin committed
928 929
        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
930
    }
admin's avatar
admin committed
931
    return _shopnameLabel;
admin's avatar
admin committed
932 933
}

admin's avatar
admin committed
934

admin's avatar
admin committed
935 936 937 938 939 940 941 942 943
- (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;
944 945
        _tableView.rowHeight = UITableViewAutomaticDimension;
        _tableView.estimatedRowHeight = 300.0;
946
        _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 40)];
admin's avatar
admin committed
947 948
        [_tableView registerClass:[PictureTableCell class] forCellReuseIdentifier:kHomePictureListCell];
        [_tableView registerClass:[HomeTitleTableCell class] forCellReuseIdentifier:kHomeTitleTableCell];
admin's avatar
admin committed
949
        [_tableView registerClass:[RankingListCell class] forCellReuseIdentifier:kHomeRankingListCell];
admin's avatar
admin committed
950 951
        [_tableView registerClass:[QuestionListTableCell class] forCellReuseIdentifier:kHomeQuestionListTableCell];

admin's avatar
admin committed
952 953
        [self.view addSubview:_tableView];
        
admin's avatar
admin committed
954
        NSLayoutConstraint *tableTop = [NSLayoutConstraint constraintWithItem:_tableView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1.0 constant:95];
admin's avatar
admin committed
955 956 957 958 959 960 961 962
        [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];
        
963
        NSLayoutConstraint *tableBottom = [NSLayoutConstraint constraintWithItem:_tableView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
admin's avatar
admin committed
964 965 966 967 968
        [self.view addConstraint:tableBottom];
    }
    return _tableView;
}

admin's avatar
admin committed
969

admin's avatar
admin committed
970 971
- (void)searchClick:(UIButton *)sender
{
admin's avatar
admin committed
972 973
    NSLog(@"_searchTextField.text = %@", _searchTextField.text);
    if (![_searchTextField.text isEqualToString:@""]) {
admin's avatar
admin committed
974 975 976 977 978 979 980
        SearchViewController *searchVC = [[SearchViewController alloc] init];
        searchVC.customStr = _searchTextField.text;
        [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
981
}
admin's avatar
admin committed
982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070
//- (void)searchClick:(UIButton *)sender
//{
//    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
//    // 口碑巡检
//    NSString *url1 = [NSString stringWithFormat:@"%@%@", kRedStarURL, kRankingListURL];
//    HttpClient *httpCilent1 = [[HttpClient alloc] initWithUrl:url1];
//    NSDictionary *parameters1 = @{
//                                 @"keyword":_searchTextField.text,
//                                 @"queryOrders":@[@{@"direction":@"asc"}],
//                                 @"pageNumber":@(0),
//                                 @"pageSize":@(3)
//                                 };
//    __block HomeViewController *weakSelf = self;
//    [httpCilent1 getRankingListWithParameters:parameters1 completion:^(id response, NSError *error) {
//        NSLog(@"口碑排名response = %@", response);
//        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;
//        [self.tableView reloadData];
//        [MBProgressHUD hideHUDForView:self.view animated:YES];
//    }];
//
//    
//    // 问题与知识
//    NSString *url2 = [NSString stringWithFormat:@"%@%@", kRedStarURL, kQuestionListURL];
//    NSString *user_uuid = [[NSUserDefaults standardUserDefaults] objectForKey:@"user_uuid"];
//    NSDictionary *parameters2 = @{
//                                 @"keyword":_searchTextField.text,
//                                 @"user":user_uuid,
//                                 @"scope":@"all",
//                                 @"pageNumber":@(0),
//                                 @"pageSize":@(2)
//                                 };
//    
//    HttpClient *httpClient2 = [[HttpClient alloc] initWithUrl:url2];
//    [httpClient2 getQuestionListWithParameters:parameters2 completion:^(id response, NSError *error) {
//        NSDictionary *dataDict = (NSDictionary *)response[@"data"];
//        NSDictionary *recordsDict = (NSDictionary *)dataDict[@"records"];
//        NSLog(@"问题与知识列表recods = %@", response);
//        
//        NSMutableArray *questionTempArr = [NSMutableArray array];
//        
//        for (NSDictionary *questionDict in recordsDict) {
//            QuestionModel *question = [[QuestionModel alloc] init];
//            [question setValuesForKeysWithDictionary:questionDict];
//            [questionTempArr addObject:question];
//        }
//        weakSelf.allQuestionArray = questionTempArr;
//        [self.tableView reloadData];
//        [MBProgressHUD hideHUDForView:self.view animated:YES];
//    }];
//
//    
//    // 口碑任务
//    NSString *url3 = [NSString stringWithFormat:@"%@%@", kRedStarURL, kInspectListURL];
//    HttpClient *httpCilent3 = [[HttpClient alloc] initWithUrl:url3];
//    NSDictionary *parameters3 = @{
//                                 @"keyword":_searchTextField.text,
//                                 @"userUuid":@"",
//                                 @"queryOrders":@[@{@"field":@"lastModifyInfo"}],
//                                 @"pageNumber":@(0),
//                                 @"pageSize":@(2)
//                                 };
//    
//    [httpCilent3 getInspectListWithParameters:parameters3 completion:^(id response, NSError *error) {
//        NSLog(@"巡检列表%@", response);
//        NSDictionary *dataDict = response[@"data"];
//        NSArray *dataArray = dataDict[@"records"];
//        NSMutableArray *inspectTempArr = [NSMutableArray array];
//        for (NSDictionary *dict in dataArray) {
//            TaskListModel *taskList = [[TaskListModel alloc] init];
//            [taskList setValuesForKeysWithDictionary:dict];
//            [inspectTempArr addObject:taskList];
//        }
//        _taskListDataArray = inspectTempArr;
//        [self.tableView reloadData];
//        [MBProgressHUD hideHUDForView:self.view animated:YES];
//        
//    }];
//    
//    [self.searchTextField resignFirstResponder];
//
//}
admin's avatar
admin committed
1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083

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

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

1084 1085 1086 1087 1088
- (void)clickHeadView
{
    [_tableView reloadData];
}

admin's avatar
admin committed
1089
@end