ReportViewController.m 21.4 KB
Newer Older
陈俊俊's avatar
陈俊俊 committed
1 2 3 4 5 6 7 8 9 10 11 12
//
//  ReportViewController.m
//  XFFruit
//
//  Created by 陈俊俊 on 15/11/6.
//  Copyright © 2015年 Xummer. All rights reserved.
// 报表

#import "ReportViewController.h"
#import "SaleViewController.h"
#import "PassengerViewController.h"
#import "PassgerPriceViewController.h"
陈俊俊's avatar
陈俊俊 committed
13 14 15 16
#import "GrossRateViewController.h"
#import "CustomSegView.h"
#import "FinishTimeView.h"
#import "SearchReportViewController.h"
17
#import "QueryOrder.h"
陈俊俊's avatar
陈俊俊 committed
18
#import "ReportDetailViewController.h"
陈俊俊's avatar
陈俊俊 committed
19 20 21 22 23 24
@interface ReportViewController ()<UIScrollViewDelegate,CustomSegViewDelegate,FinishTimeViewDelegate>
{
    SaleViewController *svc;
    PassengerViewController *pvc;
    PassgerPriceViewController *ppvc;
    GrossRateViewController *gvc;
25 26 27
    NSInteger _currentView;
    NSInteger _oldView;
    CGRect _currentRect;
陈俊俊's avatar
陈俊俊 committed
28
}
陈俊俊's avatar
陈俊俊 committed
29 30
@property (nonatomic,strong)UIScrollView *scrollView;
@property (nonatomic,assign)NSInteger currentPage;
陈俊俊's avatar
陈俊俊 committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
@property (nonatomic,strong)CustomSegView *segView;
@property (nonatomic,strong)NSString *dayType;
@property (nonatomic,strong)FinishTimeView *startTimeView;
@property (nonatomic,strong)NSString *scopeType;
@property (nonatomic,strong)NSString *selectDay;
@property (nonatomic,strong)NSString *selectMonth;
@property (nonatomic,strong)NSString *selectWeek;
//组织范围
@property (nonatomic,strong)NSString *orgScope;
//数据源数组
@property (nonatomic,strong)NSMutableArray *dataArr;
@property (nonatomic,strong)NSMutableArray *totalArr;
@property (nonatomic,strong)Compass *compass;
@property (nonatomic,assign)NSInteger storeCount;
@property (nonatomic,strong)NSIndexPath *currentIndex;
@property (nonatomic,strong)NSMutableArray *selectArr;
47 48


陈俊俊's avatar
陈俊俊 committed
49

陈俊俊's avatar
陈俊俊 committed
50 51 52 53 54 55 56
@end

@implementation ReportViewController

- (instancetype)init{
    self = [super init];
    if (self) {
陈俊俊's avatar
陈俊俊 committed
57 58
        //添加通知
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getNextDetailData:) name:KNOTIFICATION_GetNextDetailData object:nil];
59 60
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(goReoprtDetail:) name:KNOTIFICATION_GoReportDetail object:nil];

陈俊俊's avatar
陈俊俊 committed
61 62 63 64
    }
    return self;
}

陈俊俊's avatar
陈俊俊 committed
65 66 67 68
- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

陈俊俊's avatar
陈俊俊 committed
69 70 71
- (void)viewDidLoad {
    [super viewDidLoad];
    //布局
72
#if 1
陈俊俊's avatar
陈俊俊 committed
73 74 75
    self.dataArr = [NSMutableArray array];
    self.totalArr = [NSMutableArray array];
    self.selectArr = [NSMutableArray array];
陈俊俊's avatar
陈俊俊 committed
76
    [self bulidLayout];
陈俊俊's avatar
陈俊俊 committed
77 78 79 80 81 82 83
    UIBarButtonItem *searchItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"search"] style:UIBarButtonItemStylePlain target:self action:@selector(searchClick)];
    self.navigationItem.rightBarButtonItem = searchItem;
    
    self.dayType = @"day";
     self.scopeType = [IBTCommon stringFromDateWithFormat:[NSDate date] format:@"yyyy-MM-dd"];
    [self getDataFromServer];
#else
陈俊俊's avatar
陈俊俊 committed
84 85 86 87 88 89 90 91
    CGRect rect = CGRectMake(0, 200, self.view.width, 30);
    IBTUILabel *lbl = [[IBTUILabel alloc]initWithFrame:rect];
    lbl.text = @"哎呦,功能还没实现呢,下次再来看看吧。";
    lbl.textAlignment = NSTextAlignmentCenter;
    lbl.font = [UIFont systemFontOfSize:15];
    lbl.textColor = GXF_NAVIGAYION_COLOR;
    [self.view addSubview:lbl];
#endif
陈俊俊's avatar
陈俊俊 committed
92
}
陈俊俊's avatar
陈俊俊 committed
93
- (void)searchClick{
94 95 96 97
    if (self.startTimeView) {
        [self.startTimeView removeFromSuperview];
        self.startTimeView = nil;
    }
陈俊俊's avatar
陈俊俊 committed
98 99 100 101
    SearchReportViewController *srvc = [SearchReportViewController new];
    [self PushViewController:srvc animated:YES];
}

AvatarC's avatar
AvatarC committed
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
- (void)getWeekbydayFromServer {
    __weak typeof(self)weakSelf = self;
    void(^succ)(id) = ^(id data) {
        __strong __typeof(weakSelf)strongSelf = weakSelf;
        //赋值
        NSInteger success = [data[@"success"] integerValue];
        NSString *message  = data[@"message"] ;
        if (success == 1) {
             [IBTLoadingView hideHUDWithText:nil];
             self.scopeType = data[@"data"];
            [self getDataFromServer];
        }else{
            [IBTLoadingView hideHUDWithText:message];
            [IBTLoadingView showTips:data];
        }

    };
    void(^fail)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        [IBTLoadingView showTips:data];
        
    };
    [IBTLoadingView showProgressLabel:@"正在加载..."];
125 126 127 128
    
    NSDate *date ;
    if (!_selectDay) {
        self.selectDay = [[NSDate date]localYMDString];
AvatarC's avatar
AvatarC committed
129
    }
130 131
    date = [IBTCommon dateFromStringWithFormat:_selectDay format:@"yyyy-MM-dd" ];
    [[ICRHTTPController sharedController] getWeekbydayWithStringDate:[date localYMDString] success:succ failure:fail];
AvatarC's avatar
AvatarC committed
132 133
}

陈俊俊's avatar
陈俊俊 committed
134 135 136 137 138 139 140
#pragma mark - 获取上部数据
- (void)getDataFromServer{
    
    __weak typeof(self)weakSelf = self;
    void(^succ)(id) = ^(id data) {
        __strong __typeof(weakSelf)strongSelf = weakSelf;
        //赋值
陈俊俊's avatar
陈俊俊 committed
141 142 143 144 145 146 147 148 149
        NSInteger success = [data[@"success"] integerValue];
        NSString *message  = data[@"message"] ;
        if (success == 1) {
            [strongSelf prepareDataInScrollView:data];
            [strongSelf getBottomData:nil];
        }else{
            [IBTLoadingView hideHUDWithText:message];
            [IBTLoadingView showTips:data];
        }
陈俊俊's avatar
陈俊俊 committed
150 151 152 153
    };
    void(^fail)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        [IBTLoadingView showTips:data];
154

陈俊俊's avatar
陈俊俊 committed
155 156
    };
    [IBTLoadingView showProgressLabel:@"正在加载..."];
157 158 159 160 161 162 163 164
    NSMutableArray *orderArr =[NSMutableArray array];
    if (orderArr.count == 0) {
        QueryOrder *order = [QueryOrder new];
        order.field = @"orgCode";
        order.direction = @"desc";
        [orderArr addObject:[order dictForCommit]];
        
    }
陈俊俊's avatar
陈俊俊 committed
165 166
    ICRUserUtil *userUtil = [ICRUserUtil sharedInstance];
    NSDictionary *dict = @{
167 168
                           @"dataScopeType":self.dayType,
                           @"dataScope":self.scopeType,
169 170
                           @"orgUuid":userUtil.org_uuid,
                           @"fetchScope":@"owner",
171
                           @"queryOrders":orderArr,
172 173
                           @"pageNumber":@0,
                           @"pageSize":@100
陈俊俊's avatar
陈俊俊 committed
174 175 176 177 178 179 180 181 182
                           };
    [[ICRHTTPController sharedController] queryHomepageWith:dict success:succ failure:fail];
}

- (void)prepareDataInScrollView:(id)data{
    if (data) {
        NSInteger success = [data[@"success"] integerValue];
        NSString *message  = data[@"message"] ;
        if (success == 1) {
183 184 185 186 187 188 189 190 191
            NSDictionary *compassDict = data[ @"data" ][@"salesData"];
            NSArray *arr = compassDict[@"records"];
            if (arr.count > 0) {
                for (NSDictionary *comDict in arr) {
                    Compass *com = [[Compass alloc]init];
                    [com setValuesForKeysWithDictionary:comDict];
                    self.compass = com;
                }
            }
陈俊俊's avatar
陈俊俊 committed
192 193 194 195 196 197 198 199 200
            [self setValueInScrollView];
        }else{
            [IBTLoadingView showTips:message];
        }
    }else{
        [IBTLoadingView showTips:@"      无记录      "];
    }
}
- (void)setValueInScrollView{
陈俊俊's avatar
陈俊俊 committed
201 202 203 204
    [svc setValueInSale:self.compass withType:self.dayType];
    [pvc setValueInPassenger:self.compass withType:self.dayType];
    [ppvc setValueInPassgerPrice:self.compass withType:self.dayType];
    [gvc setValueInGrossRate:self.compass withType:self.dayType];
陈俊俊's avatar
陈俊俊 committed
205 206 207 208 209 210 211 212
}

//获取底部详情数据
- (void)getBottomData:(NSIndexPath *)indexPath{
    __weak typeof(self)weakSelf = self;
    void(^succ)(id) = ^(id data) {
        __strong __typeof(weakSelf)strongSelf = weakSelf;
        //赋值
213 214
        [IBTLoadingView hideHUDWithText:nil];
        [strongSelf downLoadData:data indexPath:indexPath];
陈俊俊's avatar
陈俊俊 committed
215 216 217 218 219 220 221
    };
    void(^fail)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        [IBTLoadingView showTips:data];
    };
    ICRUserUtil *userUtil = [ICRUserUtil sharedInstance];
    if (!self.orgScope) {
222 223 224 225 226 227 228 229
       self.orgScope = userUtil.org_uuid;
    }
    NSMutableArray *orderArr =[NSMutableArray array];
    if (orderArr.count == 0) {
        QueryOrder *order = [QueryOrder new];
        order.field = @"orgCode";
        order.direction = @"desc";
        [orderArr addObject:[order dictForCommit]];
陈俊俊's avatar
陈俊俊 committed
230
    }
231 232 233
    if (indexPath) {
        [IBTLoadingView showProgressLabel:@"正在加载..."];
    }
陈俊俊's avatar
陈俊俊 committed
234
    NSDictionary *dict = @{
235 236
                           @"dataScopeType":self.dayType,
                           @"dataScope":self.scopeType,
237 238
                           @"orgUuid":self.orgScope,
                           @"fetchScope":@"childs",
239
                           @"queryOrders":orderArr,
240 241
                           @"pageNumber":@0,
                           @"pageSize":@100
陈俊俊's avatar
陈俊俊 committed
242
                           };
Sandy's avatar
Sandy committed
243
    CLog(@"%@", dict);
244
    [[ICRHTTPController sharedController] queryHomepageWith:dict success:succ failure:fail];
陈俊俊's avatar
陈俊俊 committed
245 246 247 248 249 250 251
}

- (void)downLoadData:(id)data indexPath:(NSIndexPath *)indexPath{
    if (data) {
        NSInteger success = [data[@"success"] integerValue];
        NSString *message  = data[@"message"] ;
        if (success == 1) {
252 253 254 255 256 257 258 259 260 261 262 263 264 265
            NSDictionary *recodesDict = data[ @"data" ][ @"salesData" ];
            NSArray *recodesArr = recodesDict[@"records"];
            if (!indexPath) {
                self.storeCount =[data[ @"data" ][ @"stores" ] integerValue];
                if (self.dataArr.count > 0) {
                    [self.dataArr removeAllObjects];
                }
                if (self.totalArr.count > 0) {
                    [self.totalArr removeAllObjects];
                }
                if (self.selectArr.count > 0) {
                    [self.selectArr removeAllObjects];
                }
            }
陈俊俊's avatar
陈俊俊 committed
266
            for (NSDictionary *orgDict in recodesArr) {
267
                Compass *orgCompass = [[Compass alloc]init];
陈俊俊's avatar
陈俊俊 committed
268
                [orgCompass setValuesForKeysWithDictionary:orgDict];
269 270
                if (!indexPath) {
                    [self.dataArr addObject:orgCompass]; 
陈俊俊's avatar
陈俊俊 committed
271 272 273
                }
                [self.totalArr addObject:orgCompass];
            }
274 275 276 277 278
            //刷新tableView
            [self refreshAllTable];
            if (indexPath) {
                [self actionTableView:indexPath];
            }
陈俊俊's avatar
陈俊俊 committed
279 280 281 282 283 284 285 286 287 288
        }else{
            [IBTLoadingView showTips:message];
        }
    }else{
        [IBTLoadingView showTips:@"      无记录      "];
    }
}
#pragma mark - 刷新所有的tableView
- (void)refreshAllTable{
    svc.count = self.storeCount;
Sandy's avatar
Sandy committed
289
    svc.typeStr = self.dayType;
陈俊俊's avatar
陈俊俊 committed
290
    pvc.count = self.storeCount;
陈俊俊's avatar
陈俊俊 committed
291
    pvc.typeStr = self.dayType;
陈俊俊's avatar
陈俊俊 committed
292
    ppvc.count = self.storeCount;
Sandy's avatar
Sandy committed
293
    ppvc.typeStr = self.dayType;
陈俊俊's avatar
陈俊俊 committed
294
    gvc.count = self.storeCount;
Sandy's avatar
Sandy committed
295
    gvc.typeStr = self.dayType;
陈俊俊's avatar
陈俊俊 committed
296 297 298 299 300 301 302 303 304
    svc.dataArr = self.dataArr;
    pvc.dataArr = self.dataArr;
    ppvc.dataArr = self.dataArr;
    gvc.dataArr = self.dataArr;
    [svc.tableView reloadData];
    [pvc.tableView reloadData];
    [ppvc.tableView reloadData];
    [gvc.tableView reloadData];
}
陈俊俊's avatar
陈俊俊 committed
305 306 307

#pragma mark - 布局
- (void)bulidLayout{
308

陈俊俊's avatar
陈俊俊 committed
309 310 311 312 313 314 315
    self.view.backgroundColor = [UIColor whiteColor];
    CGRect rect = CGRectMake(10, 10, ScreenSize.width - 10*2, 30);
    NSArray *arr = @[SaleDay,SaleWeek,SaleMonth];
    self.segView = [[CustomSegView alloc]initWithFrame:rect withArr:arr];
    self.segView.delegate = self;
    [self.view addSubview:self.segView];
    
Sandy's avatar
Sandy committed
316
    self.scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, self.segView.bottom, ScreenSize.width, ScreenHeight - 49 - 64- self.segView.bottom)];
陈俊俊's avatar
陈俊俊 committed
317 318 319 320
    self.scrollView.delegate = self;
    self.scrollView.showsHorizontalScrollIndicator  = NO;
    self.scrollView.showsVerticalScrollIndicator = NO;
    self.scrollView.pagingEnabled = YES;
321
    [self.view addSubview:self.scrollView];
陈俊俊's avatar
陈俊俊 committed
322
    
陈俊俊's avatar
陈俊俊 committed
323
    svc = [SaleViewController new];
陈俊俊's avatar
陈俊俊 committed
324 325
    [self addChildViewController:svc];
    
陈俊俊's avatar
陈俊俊 committed
326
    pvc = [PassengerViewController new];
陈俊俊's avatar
陈俊俊 committed
327 328
    [self addChildViewController:pvc];
    
陈俊俊's avatar
陈俊俊 committed
329
    ppvc = [PassgerPriceViewController new];
陈俊俊's avatar
陈俊俊 committed
330 331
    [self addChildViewController:ppvc];
    
陈俊俊's avatar
陈俊俊 committed
332 333
    gvc = [GrossRateViewController new];
    [self addChildViewController:gvc];
陈俊俊's avatar
陈俊俊 committed
334
    
Sandy's avatar
Sandy committed
335
    rect = CGRectMake(0, 0, ScreenSize.width, ScreenHeight - 49 - 64- self.segView.bottom);
陈俊俊's avatar
陈俊俊 committed
336
    svc.view.frame = rect;
337
    [self.scrollView addSubview:svc.view];
陈俊俊's avatar
陈俊俊 committed
338
    
Sandy's avatar
Sandy committed
339
    rect = CGRectMake(self.scrollView.width,0 , ScreenSize.width, ScreenHeight - 49 - 64- self.segView.bottom);
陈俊俊's avatar
陈俊俊 committed
340
    pvc.view.frame = rect;
341
    [self.scrollView addSubview:pvc.view];
陈俊俊's avatar
陈俊俊 committed
342 343 344
    
    rect = CGRectMake(self.scrollView.width*2, 0, ScreenSize.width, self.scrollView.height);
    ppvc.view.frame = rect;
345
    [self.scrollView addSubview:ppvc.view];
陈俊俊's avatar
陈俊俊 committed
346
    
陈俊俊's avatar
陈俊俊 committed
347 348
    rect = CGRectMake(self.scrollView.width*3, 0, ScreenSize.width, self.scrollView.height);
    gvc.view.frame = rect;
349
    [self.scrollView addSubview:gvc.view];
陈俊俊's avatar
陈俊俊 committed
350
    
351
    self.scrollView.contentSize = CGSizeMake(self.scrollView.width * 4, self.scrollView.height);
陈俊俊's avatar
陈俊俊 committed
352 353
}

陈俊俊's avatar
陈俊俊 committed
354 355
#pragma mark - segViewDelegate
- (void)customSegOneClick:(NSString *)title{
356 357 358
    NSDate *date ;
    if (!_selectDay) {
        self.selectDay = [[NSDate date]localYMDString];
Sandy's avatar
Sandy committed
359
        //
360 361
    }
    date = [IBTCommon dateFromStringWithFormat:_selectDay format:@"yyyy-MM-dd" ];
Sandy's avatar
Sandy committed
362
    //    NSString *strDate = [_selectDay substringToIndex:_selectDay.length - 3];
陈俊俊's avatar
陈俊俊 committed
363 364
    //日周年切换
    NSString *dayType = @"";
AvatarC's avatar
AvatarC committed
365 366
    if ([title isEqualToString:SaleWeek]) {
        dayType = @"week";
AvatarC's avatar
AvatarC committed
367 368
        self.dayType = dayType;
        self.orgScope = nil;
AvatarC's avatar
AvatarC committed
369
        [self getWeekbydayFromServer];
AvatarC's avatar
AvatarC committed
370
        return;
AvatarC's avatar
AvatarC committed
371
    }
Sandy's avatar
Sandy committed
372
    
陈俊俊's avatar
陈俊俊 committed
373 374
    if ([title isEqualToString:SaleDay]) {
        dayType = @"day";
375
        self.scopeType = _selectDay;//[IBTCommon stringFromDateWithFormat:[NSDate date] format:@"yyyy-MM-dd"];
Sandy's avatar
Sandy committed
376 377 378
        //    }else if ([title isEqualToString:SaleWeek]) {
        //        dayType = @"week";
        //        self.scopeType = [IBTCommon getWeekFromDateWithDate:date];
陈俊俊's avatar
陈俊俊 committed
379 380
    }else if ([title isEqualToString:SaleMonth]) {
        dayType = @"month";
Sandy's avatar
Sandy committed
381
        //        date = [IBTCommon dateFromStringWithFormat:strDate format:@"yyyy-MM" ];
382
        self.scopeType = [IBTCommon stringFromDateWithFormat:date format:@"yyyy-MM"];
AvatarC's avatar
AvatarC committed
383 384
    } else {
        return;
陈俊俊's avatar
陈俊俊 committed
385 386 387
    }
    CLog(@"-------%@",self.scopeType);
    self.dayType = dayType;
388
    self.orgScope = nil;
陈俊俊's avatar
陈俊俊 committed
389
    [self getDataFromServer];
AvatarC's avatar
AvatarC committed
390
    
Sandy's avatar
Sandy committed
391
    
陈俊俊's avatar
陈俊俊 committed
392
}
AvatarC's avatar
AvatarC committed
393

陈俊俊's avatar
陈俊俊 committed
394 395 396 397 398 399 400 401 402 403 404
- (void)customSegTwoClick:(NSString *)title{
    //选择历史查看
    if ([title isEqualToString:SaleDay]) {
        [self startDatePickView:SaleEnDay];
    }else if ([title isEqualToString:SaleWeek]) {
        [self startDatePickView:SaleEnWeek];
    }else if ([title isEqualToString:SaleMonth]) {
        [self startDatePickView:SaleEnMonth];
    }
}

Sandy's avatar
Sandy committed
405
//日期选择器开始的初始时间
陈俊俊's avatar
陈俊俊 committed
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430
- (void)startDatePickView:(NSString *)type{
    if (!self.startTimeView) {
        
        NSString *currentStr  = @"";
        if ([type isEqualToString:SaleEnDay]) {
            if (self.selectDay) {
                currentStr =  self.selectDay;
            }else{
                currentStr = [IBTCommon stringFromDateWithFormat:[NSDate date] format:@"yyyy-MM-dd"];
            }
            
        }else if([type isEqualToString:SaleEnMonth]){
            if (self.selectMonth) {
                currentStr =  self.selectMonth;
            }else{
                currentStr = [IBTCommon stringFromDateWithFormat:[NSDate date] format:@"yyyy-MM"];
            }
        }else{
            if (self.selectWeek) {
                currentStr =  self.selectWeek;
            }else{
                currentStr = [IBTCommon getWeekFromDate];
            }
        }

Sandy's avatar
Sandy committed
431
        self.startTimeView = [[FinishTimeView alloc] initWithFrame:CGRectMake(0, ScreenHeight, ScreenSize.width, ScreenHeight - 64) withDate:currentStr type:type];
陈俊俊's avatar
陈俊俊 committed
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459
        self.startTimeView.delegate = self;
        self.startTimeView.backgroundColor        = RGBA(0, 0, 0 ,0.5);
        [AppWindow addSubview:self.startTimeView];
        
        [UIView animateWithDuration:0.15 animations:^{
            CGRect startFrame =  self.startTimeView.frame;
            startFrame.origin.y =  64;
            self.startTimeView.frame = startFrame;
        } completion:^(BOOL finished) {
            
        }];
    }
}
- (void)cancelTimeView{
    [self clearDatePickView];
}
- (void)okTimeView:(NSString *)time withType:(NSString *)type{
    CLog(@"--------%@",time);
    // 关闭选择器
    [self clearDatePickView];
    if ([type isEqualToString:SaleEnDay]) {
        self.selectDay = time;
    }else if ([type isEqualToString:SaleEnWeek]) {
        self.selectWeek = time;
    }else if ([type isEqualToString:SaleEnMonth]) {
        self.selectMonth = time;
    }
    self.scopeType = time;
460
    self.orgScope = nil;
陈俊俊's avatar
陈俊俊 committed
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476
    [self getDataFromServer];
}
#pragma mark - 取消
- (void)clearDatePickView{
    [UIView animateWithDuration:0.15 animations:^{
        CGRect startFrame =  self.startTimeView.frame;
        startFrame.origin.y = ScreenSize.height;
        self.startTimeView.frame = startFrame;
    } completion:^(BOOL finished) {
        [self.startTimeView removeFromSuperview];
        self.startTimeView = nil;
    }];
}
- (void)getNextDetailData:(NSNotification *)fication{
    NSDictionary *dict = fication.userInfo;
    NSIndexPath *indexPath = dict[@"indexPath"];
477
        Compass *parentCompass = [self.dataArr objectAtIndex:indexPath.row];
陈俊俊's avatar
陈俊俊 committed
478
        //如果当前点击的不是删除,则要先获取数据在进行插入
陈俊俊's avatar
陈俊俊 committed
479
        if (![self isHaveIndexPath:parentCompass.orgUuid]) {
陈俊俊's avatar
陈俊俊 committed
480
            if (parentCompass.isLeaf) {
陈俊俊's avatar
陈俊俊 committed
481 482 483
                //如果是子节点就不用进行网络请求
                return;
            }//不是子节点进行网络请求
484 485
            self.orgScope = parentCompass.orgUuid;
            [self getBottomData:indexPath];
陈俊俊's avatar
陈俊俊 committed
486 487 488 489 490
            return;
        }
    [self actionTableView:indexPath];
}
- (void)actionTableView:(NSIndexPath *)indexPath{
491
    Compass *parentCompass = [self.dataArr objectAtIndex:indexPath.row];
陈俊俊's avatar
陈俊俊 committed
492 493 494 495
    NSInteger startPosition = indexPath.row+1;
    NSInteger endPosition = startPosition;
    BOOL expand = NO;
    for (int i=0; i<self.totalArr.count; i++) {
496
        Compass *node = [self.totalArr objectAtIndex:i];
497
        if ([node.upperUuid isEqualToString:parentCompass.orgUuid]) {
陈俊俊's avatar
陈俊俊 committed
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517
            //修改二级节点的属性为为原属性相反属性
            node.expand = !node.expand;
            if (node.expand) {
                [self.dataArr insertObject:node atIndex:endPosition];
                expand = YES;
                endPosition++;
            }else{
                expand = NO;
                endPosition = [self removeAllNodesAtParentNode:parentCompass];
                break;
            }
        }
    }
    
    //获得需要修正的indexPath
    NSMutableArray *indexPathArray = [NSMutableArray array];
    for (NSInteger i=startPosition; i<endPosition; i++) {
        NSIndexPath *tempIndexPath = [NSIndexPath indexPathForRow:i inSection:0];
        [indexPathArray addObject:tempIndexPath];
    }
陈俊俊's avatar
陈俊俊 committed
518
    
陈俊俊's avatar
陈俊俊 committed
519 520
    //插入或者删除相关节点
    if (expand) {
陈俊俊's avatar
陈俊俊 committed
521
        [self.selectArr addObject:parentCompass.orgUuid];
陈俊俊's avatar
陈俊俊 committed
522 523 524 525 526
        [self insertDataWithTable:svc.tableView arr:indexPathArray];
        [self insertDataWithTable:ppvc.tableView arr:indexPathArray];
        [self insertDataWithTable:pvc.tableView arr:indexPathArray];
        [self insertDataWithTable:gvc.tableView arr:indexPathArray];
    }else{
陈俊俊's avatar
陈俊俊 committed
527
        [self.selectArr removeObject:parentCompass.orgUuid];
陈俊俊's avatar
陈俊俊 committed
528 529 530 531 532 533 534
        [self deleteDataWithTable:svc.tableView arr:indexPathArray];
        [self deleteDataWithTable:pvc.tableView arr:indexPathArray];
        [self deleteDataWithTable:ppvc.tableView arr:indexPathArray];
        [self deleteDataWithTable:gvc.tableView arr:indexPathArray];
    }
    [self refreshAllTable];

陈俊俊's avatar
陈俊俊 committed
535 536
}

陈俊俊's avatar
陈俊俊 committed
537 538 539 540 541
- (void)insertDataWithTable:(UITableView *)tableView arr:(NSMutableArray *)arr{
    [tableView insertRowsAtIndexPaths:arr withRowAnimation:UITableViewRowAnimationFade];
}
- (void)deleteDataWithTable:(UITableView *)tableView arr:(NSMutableArray *)arr{
    [tableView deleteRowsAtIndexPaths:arr withRowAnimation:UITableViewRowAnimationFade];
陈俊俊's avatar
陈俊俊 committed
542
}
陈俊俊's avatar
陈俊俊 committed
543 544 545 546 547 548 549
/**
 *  删除该父节点下的所有子节点(包括孙子节点)
 *
 *  @param parentNode 父节点
 *
 *  @return 该父节点下一个相邻的统一级别的节点的位置
 */
550
-(NSUInteger)removeAllNodesAtParentNode : (Compass *)parentNode{
陈俊俊's avatar
陈俊俊 committed
551 552 553
    NSUInteger startPosition = [self.dataArr indexOfObject:parentNode];
    NSUInteger endPosition = startPosition;
        for (NSUInteger i=startPosition+1; i<self.dataArr.count; i++) {
554
            Compass *node = [self.dataArr objectAtIndex:i];
陈俊俊's avatar
陈俊俊 committed
555 556 557 558 559 560 561 562 563 564 565 566 567
            endPosition++;
            if (node.level <= parentNode.level) {
                break;
            }
            if(endPosition == self.dataArr.count-1){
                endPosition++;
                node.expand = NO;
                break;
            }
            node.expand = NO;
        }
        if (endPosition>startPosition) {
            for (NSInteger i = startPosition+1; i < endPosition; i++) {
568 569 570
                Compass *parentCompass = self.dataArr[i];
                for (Compass *orgCompass in self.totalArr) {
                    if (parentCompass.orgUuid == orgCompass.orgUuid) {
陈俊俊's avatar
陈俊俊 committed
571 572 573 574 575 576 577 578 579 580
                        [self.totalArr removeObject:orgCompass];
                        break;
                    }
                }
            }
            [self.dataArr removeObjectsInRange:NSMakeRange(startPosition+1, endPosition-startPosition-1)];
        }
    return endPosition;
}

陈俊俊's avatar
陈俊俊 committed
581 582 583
- (BOOL)isHaveIndexPath:(NSString *)orgUuid{
    for (NSString *selectoUuid in self.selectArr) {
        if ([selectoUuid isEqualToString:orgUuid]) {
陈俊俊's avatar
陈俊俊 committed
584 585 586 587 588 589
            return YES;
        }
    }
    return NO;
}

590 591
#pragma mark - 详情页面跳转
- (void)goReoprtDetail:(NSNotification *)finication{
592 593
    NSDictionary *dict = finication.userInfo;
    Compass *compass = dict[@"compass"];
陈俊俊's avatar
陈俊俊 committed
594
    ReportDetailViewController *rvc = [ReportDetailViewController new];
595 596
    rvc.compass = compass;
    rvc.title = compass.orgName;
陈俊俊's avatar
陈俊俊 committed
597
    [self PushViewController:rvc animated:YES];
598
}
陈俊俊's avatar
陈俊俊 committed
599 600 601 602 603 604

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

@end