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

#import "ReportDetailViewController.h"
#import "CustomSegView.h"
陈俊俊's avatar
陈俊俊 committed
11
#import "RSaleView.h"
12
#import "RPassgerView.h"
陈俊俊's avatar
陈俊俊 committed
13
#import "FinishTimeView.h"
14
#import "QueryOrder.h"
陈俊俊's avatar
陈俊俊 committed
15 16


陈俊俊's avatar
陈俊俊 committed
17
@interface ReportDetailViewController ()<CustomSegViewDelegate,FinishTimeViewDelegate,UIWebViewDelegate>
陈俊俊's avatar
陈俊俊 committed
18
@property (nonatomic,strong)CustomSegView *segView;
陈俊俊's avatar
陈俊俊 committed
19 20


陈俊俊's avatar
陈俊俊 committed
21
@property (nonatomic,strong)RSaleView *rsaleView;
22
@property (nonatomic,strong)UIWebView *rwebView;
陈俊俊's avatar
陈俊俊 committed
23 24
@property (nonatomic,strong)UIActivityIndicatorView *ractivityView;

25 26 27

@property (nonatomic,strong)RPassgerView *rpassgerView;
@property (nonatomic,strong)UIWebView *rpassgerWebView;
陈俊俊's avatar
陈俊俊 committed
28 29
@property (nonatomic,strong)UIActivityIndicatorView *passActivityView;

30 31 32

@property (nonatomic,strong)RPassgerView *rpriceView;
@property (nonatomic,strong)UIWebView *rpriceWebView;
陈俊俊's avatar
陈俊俊 committed
33 34
@property (nonatomic,strong)UIActivityIndicatorView *priceActivityView;

35 36 37

@property (nonatomic,strong)RPassgerView *rgrossView;
@property (nonatomic,strong)UIWebView *rgrossWebView;
陈俊俊's avatar
陈俊俊 committed
38 39
@property (nonatomic,strong)UIActivityIndicatorView *grossActivityView;

40 41


陈俊俊's avatar
陈俊俊 committed
42
@property (nonatomic,strong)FinishTimeView *startTimeView;
43
@property (nonatomic,strong)NSString *dayType;
陈俊俊's avatar
陈俊俊 committed
44 45 46 47
@property (nonatomic,strong)NSString *scopeType;
@property (nonatomic,strong)NSString *selectDay;
@property (nonatomic,strong)NSString *selectMonth;
@property (nonatomic,strong)NSString *selectWeek;
陈俊俊's avatar
陈俊俊 committed
48

49 50
@property (nonatomic,strong)UIScrollView *scrollView;

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

@implementation ReportDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
57 58 59
    //初始化数据
    self.dayType = @"day";
    self.scopeType = @"";
陈俊俊's avatar
陈俊俊 committed
60
    self.title = self.compass.orgName;
陈俊俊's avatar
陈俊俊 committed
61
    [self bulidLayout];
62
    [self getDataFromServer];
陈俊俊's avatar
陈俊俊 committed
63 64 65 66 67 68 69 70 71 72
}

#pragma mark - 布局
- (void)bulidLayout{
    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];
陈俊俊's avatar
陈俊俊 committed
73
    
74 75 76 77 78 79
    self.scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, self.segView.bottom, ScreenSize.width, ScreenSize.height - 64 - self.segView.bottom)];
    self.scrollView.showsHorizontalScrollIndicator  = NO;
    self.scrollView.showsVerticalScrollIndicator = NO;
    self.scrollView.pagingEnabled = YES;
    [self.view addSubview:self.scrollView];
    
陈俊俊's avatar
陈俊俊 committed
80 81 82
    
  
    
83
    //销售
84
    rect = CGRectMake(0, 0, ScreenSize.width, 145);
陈俊俊's avatar
陈俊俊 committed
85
    self.rsaleView = [[RSaleView alloc]initWithFrame:rect];
86 87
    self.rsaleView.bgImage.image = [UIImage imageNamed:@"salebg_1"];
    self.rsaleView.cenImage.image = [UIImage imageNamed:@"sale_1"];
88
    [self.scrollView addSubview:self.rsaleView];
陈俊俊's avatar
陈俊俊 committed
89 90
    
    
陈俊俊's avatar
陈俊俊 committed
91
    rect = CGRectMake(0, self.rsaleView.bottom, ScreenSize.width,  self.scrollView.height - self.rsaleView.bottom - 64);
陈俊俊's avatar
陈俊俊 committed
92
    CLog(@"-------%f",self.scrollView.height);
陈俊俊's avatar
陈俊俊 committed
93
    UIWebView *webView = [[UIWebView alloc]initWithFrame:CGRectMake(0,self.rsaleView.bottom, ScreenSize.width, self.scrollView.height-self.rsaleView.bottom)];
陈俊俊's avatar
陈俊俊 committed
94
    webView.delegate = self;
陈俊俊's avatar
陈俊俊 committed
95
    webView.scalesPageToFit = YES;
陈俊俊's avatar
陈俊俊 committed
96 97 98 99
    webView.backgroundColor = [UIColor clearColor];
    [self.scrollView addSubview:webView];
    self.rwebView = webView;

陈俊俊's avatar
陈俊俊 committed
100 101 102 103
    UIActivityIndicatorView *indicatorView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake((ScreenSize.width-80)/2, (webView.height-80)/2, 80, 80)];
    indicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
    [webView addSubview:indicatorView];
    self.ractivityView = indicatorView;
104
    for (int i = 1; i< 4 ; i++) {
陈俊俊's avatar
陈俊俊 committed
105
        RPassgerView *prassView = [[RPassgerView alloc]initWithFrame:CGRectMake(i*ScreenSize.width, 0, ScreenSize.width, 145) withPage:i];
106 107
        prassView.bgImage.image = [UIImage imageNamed:[NSString stringWithFormat:@"salebg_%d",(i+1)]];
        prassView.cenImage.image = [UIImage imageNamed:[NSString stringWithFormat:@"sale_%d",(i+1)]];
陈俊俊's avatar
陈俊俊 committed
108
        
陈俊俊's avatar
陈俊俊 committed
109 110
        UIWebView *web = [[UIWebView alloc]initWithFrame:CGRectMake(i*ScreenSize.width, prassView.bottom, ScreenSize.width,  self.scrollView.height-prassView.bottom)];
        web.scalesPageToFit = YES;
陈俊俊's avatar
陈俊俊 committed
111 112 113
        web.delegate = self;
        web.backgroundColor = [UIColor clearColor];
       
114 115
        [self.scrollView addSubview:prassView];
        [self.scrollView addSubview:web];
陈俊俊's avatar
陈俊俊 committed
116 117 118 119 120
        
        UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake((ScreenSize.width-80)/2, (web.height-80)/2, 80, 80)];
        indicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
        [web addSubview:indicator];
        
121 122 123
        if (i == 1) {
            self.rpassgerView = prassView;
            self.rpassgerWebView = web;
陈俊俊's avatar
陈俊俊 committed
124
            self.passActivityView = indicator;
125 126 127
        }else if (i == 2) {
            self.rpriceView = prassView;
            self.rpriceWebView = web;
陈俊俊's avatar
陈俊俊 committed
128
            self.priceActivityView = indicator;
129 130 131
        }else if (i == 3) {
            self.rgrossView = prassView;
            self.rgrossWebView = web;
陈俊俊's avatar
陈俊俊 committed
132
            self.grossActivityView = indicator;
133 134 135 136
        }
    }

    self.scrollView.contentSize = CGSizeMake(ScreenSize.width*4, ScreenSize.height - 64 - self.segView.bottom);
陈俊俊's avatar
陈俊俊 committed
137
    
陈俊俊's avatar
陈俊俊 committed
138 139 140 141 142 143
    //加载webView
    [self loadWebViewFromServer];
   
}
#pragma mark- 请求webView
- (void)loadWebViewFromServer{
AvatarC's avatar
AvatarC committed
144
    ICRUserUtil *userU = [ICRUserUtil sharedInstance];
陈俊俊's avatar
陈俊俊 committed
145
#warning 测试
AvatarC's avatar
AvatarC committed
146
    NSString *passgerUrl = [NSString stringWithFormat:@"%@/%@?enterprise=%@&dateScopeType=%@&dateScope=%@&orgUuid=%@",HTTP_REST_REPORT_BASE_URL,PassengerWebUrl,userU.orgId,self.dayType,self.compass.dataScope,self.compass.orgUuid];
陈俊俊's avatar
陈俊俊 committed
147 148
    [self.rpassgerWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:passgerUrl]]];
    
AvatarC's avatar
AvatarC committed
149 150 151 152 153 154 155 156 157 158
//    NSString *priceUrl = [NSString stringWithFormat:@"%@/%@?enterprise=%@&dateScopeType=%@&dateScope=%@&orgUuid=%@",HTTP_REST_REPORT_BASE_URL,PriceWebUrl,[ICRUserUtil sharedInstance].orgId,self.dayType,self.scopeType,self.compass.orgUuid];
//    [self.rpriceWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:priceUrl]]];
//    
//    NSString *grossUrl = [NSString stringWithFormat:@"%@/%@?enterprise=%@&dateScopeType=%@&dateScope=%@&orgUuid=%@",HTTP_REST_REPORT_BASE_URL,GrossWebUrl,[ICRUserUtil sharedInstance].orgId,self.dayType,self.scopeType,self.compass.orgUuid];
//    [self.rgrossWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:grossUrl]]];
//    
//    NSString *saleUrl = [NSString stringWithFormat:@"%@/%@?enterprise=%@&dateScopeType=%@&dateScope=%@&orgUuid=%@",HTTP_REST_REPORT_BASE_URL,SaleWebUrl,[ICRUserUtil sharedInstance].orgId,self.dayType,self.scopeType,self.compass.orgUuid];
//    [self.rwebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:saleUrl]]];
    
    NSString *priceUrl = [NSString stringWithFormat:@"%@/%@?enterprise=%@&dateScopeType=%@&dateScope=%@&orgUuid=%@",HTTP_REST_REPORT_BASE_URL,PriceWebUrl,userU.orgId,self.dayType,self.compass.dataScope,self.compass.orgUuid];
陈俊俊's avatar
陈俊俊 committed
159 160
    [self.rpriceWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:priceUrl]]];
    
AvatarC's avatar
AvatarC committed
161
    NSString *grossUrl = [NSString stringWithFormat:@"%@/%@?enterprise=%@&dateScopeType=%@&dateScope=%@&orgUuid=%@",HTTP_REST_REPORT_BASE_URL,GrossWebUrl,[ICRUserUtil sharedInstance].orgId,self.dayType,self.compass.dataScope,self.compass.orgUuid];
陈俊俊's avatar
陈俊俊 committed
162 163
    [self.rgrossWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:grossUrl]]];
    
AvatarC's avatar
AvatarC committed
164
    NSString *saleUrl = [NSString stringWithFormat:@"%@/%@?enterprise=%@&dateScopeType=%@&dateScope=%@&orgUuid=%@",HTTP_REST_REPORT_BASE_URL,SaleWebUrl,[ICRUserUtil sharedInstance].orgId,self.dayType,self.compass.dataScope,self.compass.orgUuid];
陈俊俊's avatar
陈俊俊 committed
165
    [self.rwebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:saleUrl]]];
陈俊俊's avatar
陈俊俊 committed
166
}
陈俊俊's avatar
陈俊俊 committed
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184


- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
    if (webView == self.rwebView) {
        [self.ractivityView startAnimating];
        
    }else if (webView == self.rpassgerWebView) {
        [self.passActivityView startAnimating];
        
    }else if (webView == self.rpriceWebView) {
        [self.priceActivityView startAnimating];
        
    }else if (webView == self.rgrossWebView) {
        [self.grossActivityView startAnimating];
    }
    return YES;
}

陈俊俊's avatar
陈俊俊 committed
185
- (void)webViewDidFinishLoad:(UIWebView *)webView { //webview 自适应高度
陈俊俊's avatar
陈俊俊 committed
186 187 188 189 190 191 192 193 194 195 196
    if (webView == self.rwebView) {
        [self.ractivityView stopAnimating];
        
    }else if (webView == self.rpassgerWebView) {
        [self.passActivityView stopAnimating];
        
    }else if (webView == self.rpriceWebView) {
        [self.priceActivityView stopAnimating];
        
    }else if (webView == self.rgrossWebView) {
        [self.grossActivityView stopAnimating];
陈俊俊's avatar
陈俊俊 committed
197
    }
陈俊俊's avatar
陈俊俊 committed
198
}
陈俊俊's avatar
陈俊俊 committed
199 200


201 202 203 204 205 206
- (void)getDataFromServer{
    __weak typeof(self)weakSelf = self;
    void(^succ)(id) = ^(id data) {
        __strong __typeof(weakSelf)strongSelf = weakSelf;
        //赋值
        [IBTLoadingView hideHUDWithText:nil];
207
        [strongSelf prepareData:data];
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
    };
    void(^fail)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        [IBTLoadingView showTips:data];
        
    };
    [IBTLoadingView showProgressLabel:@"正在加载..."];
    NSMutableArray *orderArr =[NSMutableArray array];
    if (orderArr.count == 0) {
        QueryOrder *order = [QueryOrder new];
        order.field = @"orgCode";
        order.direction = @"desc";
        [orderArr addObject:[order dictForCommit]];
    }
    NSDictionary *dict = @{
                           @"dataScopeType":self.dayType,
                           @"dataScope":self.scopeType,
225 226
                           @"orgUuid":self.compass.orgUuid,
                           @"fetchScope":@"childs",
227 228 229 230 231 232
                           @"queryOrders":orderArr,
                           @"pageNumber":@0,
                           @"pageSize":@100
                           };
    [[ICRHTTPController sharedController] queryHomepageWith:dict success:succ failure:fail];
}
陈俊俊's avatar
陈俊俊 committed
233

234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
#pragma mark- 成功之后的操作
- (void)prepareData:(id)data{
    if (data) {
        NSInteger success = [data[@"success"] integerValue];
        NSString *message  = data[@"message"] ;
        if (success == 1) {
            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;
                }
            }
            [self.rsaleView setValueInSaleView:self.compass];
            [self.rpassgerView setPassengerWithCompass:self.compass];
            [self.rpriceView setPersalesWithCompass:self.compass];
            [self.rgrossView setGrossprofitWithCompass:self.compass];
陈俊俊's avatar
陈俊俊 committed
253 254 255 256
            self.rsaleView.weekLabelStr = self.dayType;
            self.rpassgerView.weekLabelStr = self.dayType;
            self.rpriceView.weekLabelStr = self.dayType;
            self.rsaleView.weekLabelStr = self.dayType;
257 258 259 260 261 262 263
        }else{
            [IBTLoadingView showTips:message];
        }
    }else{
        [IBTLoadingView showTips:@"      无记录      "];
    }
}
陈俊俊's avatar
陈俊俊 committed
264 265
#pragma mark -CustomSegViewDelegate
- (void)customSegOneClick:(NSString *)title{
陈俊俊's avatar
陈俊俊 committed
266 267 268 269 270 271 272 273 274 275 276 277 278
    //日周年切换
    NSString *dayType = @"";
    if ([title isEqualToString:SaleDay]) {
        dayType = @"day";
        self.scopeType = [IBTCommon stringFromDateWithFormat:[NSDate date] format:@"yyyy-MM-dd"];
    }else if ([title isEqualToString:SaleWeek]) {
        dayType = @"week";
        self.scopeType = [IBTCommon getWeekFromDate];
    }else if ([title isEqualToString:SaleMonth]) {
        dayType = @"month";
        self.scopeType = [IBTCommon stringFromDateWithFormat:[NSDate date] format:@"yyyy-MM"];
    }
    CLog(@"-------%@",self.scopeType);
279 280
    self.dayType = dayType;
    [self getDataFromServer];
陈俊俊's avatar
陈俊俊 committed
281 282 283
    //加载webView
    [self loadWebViewFromServer];

陈俊俊's avatar
陈俊俊 committed
284 285
}
- (void)customSegTwoClick:(NSString *)title{
陈俊俊's avatar
陈俊俊 committed
286 287 288 289 290 291 292 293 294
    //选择历史查看
    if ([title isEqualToString:SaleDay]) {
        [self startDatePickView:SaleEnDay];
    }else if ([title isEqualToString:SaleWeek]) {
        [self startDatePickView:SaleEnWeek];
    }else if ([title isEqualToString:SaleMonth]) {
        [self startDatePickView:SaleEnMonth];
    }
}
陈俊俊's avatar
陈俊俊 committed
295

陈俊俊's avatar
陈俊俊 committed
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
- (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];
            }
        }
        
        self.startTimeView = [[FinishTimeView alloc] initWithFrame:CGRectMake(0, ScreenSize.height, ScreenSize.width, ScreenSize.height - 64) withDate:currentStr type:type];
        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) {
            
        }];
    }
陈俊俊's avatar
陈俊俊 committed
334
}
陈俊俊's avatar
陈俊俊 committed
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
- (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;
351
    [self getDataFromServer];
陈俊俊's avatar
陈俊俊 committed
352 353 354
    //加载webView
    [self loadWebViewFromServer];

陈俊俊's avatar
陈俊俊 committed
355 356 357 358 359 360 361 362 363 364 365 366
}
#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;
    }];
}
陈俊俊's avatar
陈俊俊 committed
367 368 369 370 371 372 373
- (void)viewWillDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    if (self.startTimeView) {
        [self.startTimeView removeFromSuperview];
        self.startTimeView = nil;
    }
}
陈俊俊's avatar
陈俊俊 committed
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390


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

/*
#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