OrderdetailsViewController.m 12.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
//
//  OrderdetailsViewController.m
//  Lighting
//
//  Created by 曹云霄 on 16/5/4.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "OrderdetailsViewController.h"
#import "OrderInformationTableViewCell.h"
#import "PersonInformationTableViewCell.h"
#import "GoodsInformationTableViewCell.h"
#import "CommodityListTableViewCell.h"
#import "AllpriceTableViewCell.h"
15
#import "SettlementViewController.h"
勾芒's avatar
勾芒 committed
16
#import "AdditionalTableViewCell.h"
勾芒's avatar
勾芒 committed
17
#import <QuickLook/QuickLook.h>
勾芒's avatar
勾芒 committed
18
#import "PDFViewController.h"
19

勾芒's avatar
勾芒 committed
20
@interface OrderdetailsViewController ()<UITableViewDelegate,UITableViewDataSource>
21

勾芒's avatar
勾芒 committed
22 23 24 25 26 27

/**
 *  订单详情数据
 */
@property (nonatomic,strong) OrderBill *orderDetails;

勾芒's avatar
勾芒 committed
28 29 30 31 32
/**
 *  本地存储地址
 */
@property (nonatomic,copy) NSString *PDFpath;

勾芒's avatar
勾芒 committed
33 34


35 36 37 38
@end

@implementation OrderdetailsViewController

勾芒's avatar
勾芒 committed
39 40 41 42




43 44 45 46
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self uiConfigAction];
勾芒's avatar
勾芒 committed
47
    [self getOrderDetailsData];
48 49 50 51 52 53 54 55 56 57 58 59 60
}



#pragma mark - UI
- (void)uiConfigAction
{
    self.orderDetailsTableview.dataSource = self;
    self.orderDetailsTableview.delegate = self;
    [self CreateTableviewHeaderView];
    [self CreateTableviewFooterView];
}

勾芒's avatar
勾芒 committed
61

勾芒's avatar
勾芒 committed
62
#pragma mark -获取订单详情
勾芒's avatar
勾芒 committed
63 64
- (void)getOrderDetailsData
{
勾芒's avatar
勾芒 committed
65
    [self CreateMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
66
    [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:[NSString stringWithFormat:@"%@%@%@",ServerAddress,@"/order/findOrder/",_orderCode] WithRequestType:1 WithParameter:nil WithReturnValueBlock:^(id returnValue) {
勾芒's avatar
勾芒 committed
67
        
勾芒's avatar
勾芒 committed
68
        [self RemoveMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
69 70
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            
勾芒's avatar
勾芒 committed
71 72
            self.orderDetails = [[OrderBill alloc]initWithDictionary:returnValue[@"data"] error:nil];
            [self.orderDetailsTableview reloadData];
勾芒's avatar
勾芒 committed
73 74 75 76 77
        }
        else
        {
            [self ErrorMBProgressView:returnValue[@"message"]];
        }
勾芒's avatar
勾芒 committed
78 79 80 81 82 83
        
    } WithErrorCodeBlock:^(id errorCodeValue) {
        
        
    } WithFailureBlock:^(id error) {
        
勾芒's avatar
勾芒 committed
84
        [self RemoveMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
85 86
    }];
}
勾芒's avatar
勾芒 committed
87 88 89 90 91





92 93 94 95 96 97 98 99 100 101 102
#pragma mark -TableviewHeader------根据不同的订单状态判断是否显示
- (void)CreateTableviewHeaderView
{
    UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 60)];
    
    //预览
    UIButton *previewButton = [UIButton buttonWithType:UIButtonTypeSystem];
    previewButton.frame = CGRectMake(50, 15, 150, 30);
    [previewButton setTitle:@"预览" forState:UIControlStateNormal];
    previewButton.titleLabel.font = [UIFont systemFontOfSize:12];
    [previewButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
曹云霄's avatar
曹云霄 committed
103
    [previewButton addTarget:self action:@selector(PreviewButtonClick:) forControlEvents:UIControlEventTouchUpInside];
104 105 106 107 108 109 110 111 112 113 114
    previewButton.backgroundColor = kMainBlueColor;
    previewButton.layer.masksToBounds = YES;
    previewButton.layer.cornerRadius = kCornerRadius;
    [headerView addSubview:previewButton];
    
    //打印
    UIButton *printButton = [UIButton buttonWithType:UIButtonTypeSystem];
    printButton.frame = CGRectMake(ScreenWidth-50-150, 15, 150, 30);
    [printButton setTitle:@"打印" forState:UIControlStateNormal];
    [printButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    printButton.titleLabel.font = [UIFont systemFontOfSize:12];
曹云霄's avatar
曹云霄 committed
115
    [printButton addTarget:self action:@selector(AirprintButtonClick:) forControlEvents:UIControlEventTouchUpInside];
116 117 118 119 120 121 122 123 124 125
    printButton.layer.masksToBounds = YES;
    printButton.layer.cornerRadius = kCornerRadius;
    printButton.backgroundColor = kMainBlueColor;
    [headerView addSubview:printButton];
    
    //横线
    UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 59, ScreenWidth, 1)];
    lineView.backgroundColor = kTCColor(193, 193, 193);
    [headerView addSubview:lineView];
    
勾芒's avatar
勾芒 committed
126 127 128 129 130
    //附加信息cell
    [self.orderDetailsTableview registerNib:[UINib nibWithNibName:@"AdditionalTableViewCell" bundle:nil] forCellReuseIdentifier:@"fifthcell"];
    
    
    
131 132 133 134 135 136 137 138 139 140 141 142 143 144
    self.orderDetailsTableview.tableHeaderView = headerView;
}

#pragma mark -TableviewFooterView------根据不同的订单状态判断支付按钮是否显示
- (void)CreateTableviewFooterView
{
    UIView *footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 100)];
    
    //支付
    UIButton *payButton = [UIButton buttonWithType:UIButtonTypeSystem];
    payButton.frame = CGRectMake((ScreenWidth-150)/2, 30, 150, 40);
    [payButton setTitle:@"支付" forState:UIControlStateNormal];
    payButton.titleLabel.font = [UIFont systemFontOfSize:12];
    [payButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
145
    [payButton addTarget:self action:@selector(PayButtonClick) forControlEvents:UIControlEventTouchUpInside];
146 147 148 149 150 151 152 153
    payButton.backgroundColor = kMainBlueColor;
    payButton.layer.masksToBounds = YES;
    payButton.layer.cornerRadius = kCornerRadius;
    [footerView addSubview:payButton];
    self.orderDetailsTableview.tableFooterView = footerView;
}


154 155 156 157 158


#pragma mark -调出支付框
- (void)PayButtonClick
{
勾芒's avatar
勾芒 committed
159
    
160 161
    SettlementViewController *settlement = [[SettlementViewController alloc]init];
    settlement.preferredContentSize = CGSizeMake(380, 500);
勾芒's avatar
勾芒 committed
162
    settlement.goodsArray = self.orderDetails.orderdetailList;
勾芒's avatar
勾芒 committed
163
    settlement.orderCode = _orderCode;
164 165 166 167 168 169 170 171
    settlement.modalPresentationStyle = UIModalPresentationFormSheet;
    UIPopoverPresentationController *pop = settlement.popoverPresentationController;
    pop.sourceView = settlement.view;
    pop.permittedArrowDirections = UIPopoverArrowDirectionAny;
    [self presentViewController:settlement animated:YES completion:nil];
}


172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    switch (section) {
        case 0:
        {
            return 1;
        }
            break;
        case 1:
        {
            return 1;
        }
            break;
        case 2:
        {
            return 1;
        }
            break;
        case 3:
        {
勾芒's avatar
勾芒 committed
193
            return self.orderDetails.orderdetailList.count+1;
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
        }
            break;
        case 4:
        {
           return 1;
        }
            break;
            
        default:
            break;
    }
    return 0;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
勾芒's avatar
勾芒 committed
211
    NSLog(@"%ld",indexPath.section);
212 213 214 215
    switch (indexPath.section) {
        case 0://订单信息
        {
            OrderInformationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"firstcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
216
            cell.model = self.orderDetails;
217 218 219 220 221 222
            return cell;
        }
            break;
        case 1://客户信息
        {
            PersonInformationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"secondcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
223
            cell.model = self.orderDetails.consumer;
224 225 226 227 228 229
            return cell;
        }
            break;
        case 2://收货信息
        {
            GoodsInformationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"thirdcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
230
            cell.model = self.orderDetails.order;
231 232 233 234 235
            return cell;
        }
            break;
        case 3://商品清单
        {
勾芒's avatar
勾芒 committed
236
            if (indexPath.row == self.orderDetails.orderdetailList.count) {
237 238 239
                
                //商品总计
                AllpriceTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"sixthcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
240
                cell.goodsArray = self.orderDetails.orderdetailList;
241 242 243 244 245 246
                return cell;
                
            }else
            {
                //单个商品
                CommodityListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"fourthcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
247
                cell.orderDetailslist = [self.orderDetails.orderdetailList objectAtIndex_opple:indexPath.row];
248 249 250 251 252 253
                return cell;
            }
        }
            break;
        case 4://附件信息
        {
勾芒's avatar
勾芒 committed
254 255 256 257
            //是否显示
            if (_isShowattachment) {
             
                AdditionalTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"fifthcell" forIndexPath:indexPath];
勾芒's avatar
勾芒 committed
258
                cell.model = self.orderDetails.order;
勾芒's avatar
勾芒 committed
259 260
                return cell;
            }
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
        }
            break;
        default:
            break;
    }
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.section) {
        case 0:
        {
            return 84;
        }
            break;
        case 1:
        {
勾芒's avatar
勾芒 committed
279
            return 135;
280 281 282 283
        }
            break;
        case 2:
        {
勾芒's avatar
勾芒 committed
284
            return 90;
285 286 287 288 289
        }
            break;
        case 3:
        {
            //商品总计
勾芒's avatar
勾芒 committed
290
            if (indexPath.row == self.orderDetails.orderdetailList.count) {
291 292 293 294 295 296 297 298 299 300 301 302
                
                return 50;
            }
            else
            {
            //单个商品
               return 80;
            }
        }
            break;
        case 4:
        {
勾芒's avatar
勾芒 committed
303 304 305 306 307
            //是否显示附件信息
            if (!_isShowattachment) {
                
                return 0;
            }
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323
            return 75;
        }
            break;
            
        default:
            break;
    }
    return 100;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    
        
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 44)];
    //区头文字
勾芒's avatar
勾芒 committed
324 325
    UILabel *Titlelabe = [[UILabel alloc]initWithFrame:CGRectMake(30, 0, 100, 44)];
    Titlelabe.text = [self.sectionTitle objectAtIndex_opple:section];
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
    Titlelabe.font = [UIFont systemFontOfSize:13];
    [view addSubview:Titlelabe];
    return view;
}



- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 44;
}



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
勾芒's avatar
勾芒 committed
342
    return self.sectionTitle.count;
343 344
}

曹云霄's avatar
曹云霄 committed
345 346 347 348 349 350 351 352





#pragma mark -打印订单
- (void)AirprintButtonClick:(UIButton *)button
{
勾芒's avatar
勾芒 committed
353
    [self DownloadPDF:^(id returnValue) {
勾芒's avatar
勾芒 committed
354
        
勾芒's avatar
勾芒 committed
355 356 357 358 359
        [self callAirprintWithdata:returnValue SuccessBlock:^{
            [self SuccessMBProgressView:@"打印成功"];
        } ErrorBlock:^{
            [self ErrorMBProgressView:@"打印失败"];
        }];
勾芒's avatar
勾芒 committed
360
    }];
曹云霄's avatar
曹云霄 committed
361 362 363
}


勾芒's avatar
勾芒 committed
364 365
#pragma mark -下载PDF
- (void)DownloadPDF:(void(^)(id returnValue))success
曹云霄's avatar
曹云霄 committed
366 367
{
    
勾芒's avatar
勾芒 committed
368
    [self CreateMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
369
    [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:[NSString stringWithFormat:@"%@%@%@",ServerAddress,@"/order/UrlOfprintPDF/",_orderCode] WithRequestType:1 WithParameter:nil WithReturnValueBlock:^(id returnValue) {
勾芒's avatar
勾芒 committed
370
        
勾芒's avatar
勾芒 committed
371 372 373
        NSString *url = [NSString stringWithFormat:@"%@%@",PDFSERADDRESS,returnValue[@"data"]];
        self.PDFpath = url;
        [[NetworkRequestClassManager Manager] DownloadPDFdatasWithURL:url WithReturnValueBlock:^(id returnValue) {
勾芒's avatar
勾芒 committed
374 375 376 377 378 379 380 381 382 383 384 385 386 387
            
            [self RemoveMBProgressHUDLoding];
            success(returnValue);
            
        } WithErrorCodeBlock:^(id errorCodeValue) {
            
        } WithFailureBlock:^(id error) {
            [self RemoveMBProgressHUDLoding];
        }];
    } WithErrorCodeBlock:^(id errorCodeValue) {
        
    } WithFailureBlock:^(id error) {
        [self RemoveMBProgressHUDLoding];
    }];
曹云霄's avatar
曹云霄 committed
388 389
}

勾芒's avatar
勾芒 committed
390 391 392 393 394 395 396 397 398

#pragma mark -预览订单
- (void)PreviewButtonClick:(UIButton *)button
{
    
    [self DownloadPDF:^(id returnValue) {
        

        PDFViewController *pdfVc = [[PDFViewController alloc]init];
勾芒's avatar
勾芒 committed
399
        pdfVc.pdfURLString = self.PDFpath;
勾芒's avatar
勾芒 committed
400 401 402
        [self presentViewController:pdfVc animated:YES completion:nil];
    }];
}
曹云霄's avatar
曹云霄 committed
403 404 405 406 407 408






勾芒's avatar
勾芒 committed
409

410 411 412 413 414 415
#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.
勾芒's avatar
勾芒 committed
416
    
417
}
勾芒's avatar
勾芒 committed
418

419 420 421 422 423 424 425 426

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


@end