ReportDetailViewController.m 11.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
@interface ReportDetailViewController ()<CustomSegViewDelegate,FinishTimeViewDelegate,UIWebViewDelegate>
陈俊俊's avatar
陈俊俊 committed
16
@property (nonatomic,strong)CustomSegView *segView;
陈俊俊's avatar
陈俊俊 committed
17
@property (nonatomic,strong)RSaleView *rsaleView;
18 19 20 21 22 23 24 25 26 27 28 29
@property (nonatomic,strong)UIWebView *rwebView;

@property (nonatomic,strong)RPassgerView *rpassgerView;
@property (nonatomic,strong)UIWebView *rpassgerWebView;

@property (nonatomic,strong)RPassgerView *rpriceView;
@property (nonatomic,strong)UIWebView *rpriceWebView;

@property (nonatomic,strong)RPassgerView *rgrossView;
@property (nonatomic,strong)UIWebView *rgrossWebView;


陈俊俊's avatar
陈俊俊 committed
30
@property (nonatomic,strong)FinishTimeView *startTimeView;
31
@property (nonatomic,strong)NSString *dayType;
陈俊俊's avatar
陈俊俊 committed
32 33 34 35
@property (nonatomic,strong)NSString *scopeType;
@property (nonatomic,strong)NSString *selectDay;
@property (nonatomic,strong)NSString *selectMonth;
@property (nonatomic,strong)NSString *selectWeek;
陈俊俊's avatar
陈俊俊 committed
36

37 38
@property (nonatomic,strong)UIScrollView *scrollView;

陈俊俊's avatar
陈俊俊 committed
39 40 41 42 43 44
@end

@implementation ReportDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
45 46 47
    //初始化数据
    self.dayType = @"day";
    self.scopeType = @"";
陈俊俊's avatar
陈俊俊 committed
48
    self.title = self.compass.orgName;
陈俊俊's avatar
陈俊俊 committed
49
    [self bulidLayout];
50
    [self getDataFromServer];
陈俊俊's avatar
陈俊俊 committed
51 52 53 54 55 56 57 58 59 60
}

#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
61
    
62 63 64 65 66 67 68 69
    
    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];
    
    //销售
70
    rect = CGRectMake(0, 0, ScreenSize.width, 145);
陈俊俊's avatar
陈俊俊 committed
71
    self.rsaleView = [[RSaleView alloc]initWithFrame:rect];
72 73
    self.rsaleView.bgImage.image = [UIImage imageNamed:@"salebg_1"];
    self.rsaleView.cenImage.image = [UIImage imageNamed:@"sale_1"];
74
    [self.scrollView addSubview:self.rsaleView];
陈俊俊's avatar
陈俊俊 committed
75 76
    
    
陈俊俊's avatar
陈俊俊 committed
77 78 79 80 81 82 83 84
    rect = CGRectMake(0, self.rsaleView.bottom, ScreenSize.width*2,  self.scrollView.height - self.rsaleView.bottom - 64);
    CLog(@"-------%f",self.scrollView.height);
    UIWebView *webView = [[UIWebView alloc]initWithFrame:CGRectMake(0,self.rsaleView.bottom, ScreenSize.width*2, self.scrollView.height)];
    webView.delegate = self;
    webView.backgroundColor = [UIColor clearColor];
    [self.scrollView addSubview:webView];
    self.rwebView = webView;

85
    for (int i = 1; i< 4 ; i++) {
陈俊俊's avatar
陈俊俊 committed
86
        RPassgerView *prassView = [[RPassgerView alloc]initWithFrame:CGRectMake(i*ScreenSize.width, 0, ScreenSize.width*2, 145) withPage:i];
87 88
        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
89 90 91 92 93
        
        UIWebView *web = [[UIWebView alloc]initWithFrame:CGRectMake(i*ScreenSize.width, prassView.bottom, ScreenSize.width*2,  self.scrollView.height)];
        web.delegate = self;
        web.backgroundColor = [UIColor clearColor];
       
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
        [self.scrollView addSubview:prassView];
        [self.scrollView addSubview:web];
        if (i == 1) {
            self.rpassgerView = prassView;
            self.rpassgerWebView = web;
        }else if (i == 2) {
            self.rpriceView = prassView;
            self.rpriceWebView = web;
        }else if (i == 3) {
            self.rgrossView = prassView;
            self.rgrossWebView = web;
        }
    }

    self.scrollView.contentSize = CGSizeMake(ScreenSize.width*4, ScreenSize.height - 64 - self.segView.bottom);
陈俊俊's avatar
陈俊俊 committed
109 110 111 112 113 114 115 116 117 118 119 120
    
#warning 测试
    
    [self.rpassgerWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://218.244.151.129:7580/cruiser-web/chart/surveychart.thor?enterprise=1111&surveyUuid=2222"]]];
    [self.rpriceWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://218.244.151.129:7580/cruiser-web/chart/surveychart.thor?enterprise=1111&surveyUuid=2222"]]];
    [self.rgrossWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://218.244.151.129:7580/cruiser-web/chart/surveychart.thor?enterprise=1111&surveyUuid=2222"]]];
    [self.rwebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://218.244.151.129:7580/cruiser-web/chart/surveychart.thor?enterprise=1111&surveyUuid=2222"]]];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView { //webview 自适应高度
    if (webView == self.rwebView || webView == self.rpassgerWebView || webView == self.rpriceWebView || webView == self.rgrossWebView) {
         webView.scrollView.contentSize = CGSizeMake(ScreenSize.width*3, self.scrollView.height+100);
    }
陈俊俊's avatar
陈俊俊 committed
121
}
122 123 124 125 126 127
- (void)getDataFromServer{
    __weak typeof(self)weakSelf = self;
    void(^succ)(id) = ^(id data) {
        __strong __typeof(weakSelf)strongSelf = weakSelf;
        //赋值
        [IBTLoadingView hideHUDWithText:nil];
128
        [strongSelf prepareData:data];
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
    };
    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,
146 147
                           @"orgUuid":self.compass.orgUuid,
                           @"fetchScope":@"childs",
148 149 150 151 152 153
                           @"queryOrders":orderArr,
                           @"pageNumber":@0,
                           @"pageSize":@100
                           };
    [[ICRHTTPController sharedController] queryHomepageWith:dict success:succ failure:fail];
}
陈俊俊's avatar
陈俊俊 committed
154

155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
#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];
        }else{
            [IBTLoadingView showTips:message];
        }
    }else{
        [IBTLoadingView showTips:@"      无记录      "];
    }
}
陈俊俊's avatar
陈俊俊 committed
181 182
#pragma mark -CustomSegViewDelegate
- (void)customSegOneClick:(NSString *)title{
陈俊俊's avatar
陈俊俊 committed
183 184 185 186 187 188 189 190 191 192 193 194 195
    //日周年切换
    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);
196 197
    self.dayType = dayType;
    [self getDataFromServer];
陈俊俊's avatar
陈俊俊 committed
198 199
}
- (void)customSegTwoClick:(NSString *)title{
陈俊俊's avatar
陈俊俊 committed
200 201 202 203 204 205 206 207 208
    //选择历史查看
    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
209

陈俊俊's avatar
陈俊俊 committed
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
- (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
248
}
陈俊俊's avatar
陈俊俊 committed
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
- (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;
265
    [self getDataFromServer];
陈俊俊's avatar
陈俊俊 committed
266 267 268 269 270 271 272 273 274 275 276 277
}
#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
278 279 280 281 282 283 284
- (void)viewWillDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    if (self.startTimeView) {
        [self.startTimeView removeFromSuperview];
        self.startTimeView = nil;
    }
}
陈俊俊's avatar
陈俊俊 committed
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301


- (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