// // OrderSalesDetailViewController.m // IBOSSmini // // Created by guan hong hou on 2017/5/26. // Copyright © 2017年 elongtian. All rights reserved. // #import "OrderSalesDetailViewController.h" #import "OrderSaleListDetailModel.h" #import "OrderSalesDetailTableViewCell.h" @interface OrderSalesDetailViewController () @end @implementation OrderSalesDetailViewController /** viewDidLoad */ - (void)viewDidLoad { [super viewDidLoad]; [self showTitle:@"订单销售单商品明细"]; [self loadNavStyle]; [self initUI]; _details=[NSMutableArray new]; [self reloadData]; } /** 安全区视图发生变化 */ -(void)viewSafeAreaInsetsDidChange{ _customTableView.frame = CGRectMake(10, 0, self.view.frame.size.width-20,self.view.safeAreaLayoutGuide.layoutFrame.size.height); [super viewSafeAreaInsetsDidChange]; } #pragma mark - 代理函数 /** * 查询正常数据 * * @param sender sender description */ - (void)onLoadFinish:(ASIDownManager *)sender { // 服务器返回数据 NSDictionary *dic = [sender.mWebStr JSONValue]; [self cancel]; // 服务器返回数据是否正确 if (dic && [dic isKindOfClass:[NSDictionary class]]) { // 服务器返回数据状态值 int iStatus = [[dic objectForKey:@"Status"] intValue]; // 服务器返回数据消息 NSString *message=[dic objectForKey:@"Message"]; // 服务器返回数据状态值正确 if (iStatus == 0) { NSArray * approvArr=[dic objectForKey:@"Result"]; if(approvArr!=nil) { [_details removeAllObjects]; if(approvArr.count==0) { [self showAlertViewText:@"未找到匹配结果"]; } else { NSMutableArray *detailArray = [NSMutableArray array]; for (NSDictionary *dic in approvArr) { OrderSaleListDetailModel *md = [OrderSaleListDetailModel orderSaleDetailWithDict:dic]; [detailArray addObject:md]; } _details = detailArray; [_customTableView reloadData]; } } } // 服务器返回数据状态值异常 else if(iStatus==ActionResultStatusAuthError ||iStatus==ActionResultStatusNoLogin ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid) { [self showReLoginDialog:message]; return; } else { [self showAlertViewText:message]; } } } /** * 异常数据 * * @param sender sender description */ - (void)onLoadFail:(ASIDownManager *)sender { [self cancel]; [self showAlertViewText:@"加载失败"]; } #pragma mark - tableView代理函数 /** Sections @param tableView <#tableView description#> @return <#return value description#> */ -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return _details.count; } /** numberOfRowsInSection @param tableView <#tableView description#> @param section <#section description#> @return <#return value description#> */ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return 1; } /** 头高度 @param tableView tableView description @param section section description @return <#return value description#> */ - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 10; } /** 头布局 @param tableView <#tableView description#> @param section <#section description#> @return <#return value description#> */ - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView* myView =[[UIView alloc]init]; myView.backgroundColor = [UIColor clearColor]; return myView; } /** 单元格高度 @param tableView <#tableView description#> @param indexPath <#indexPath description#> @return <#return value description#> */ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 770; } /** cell @param tableView <#tableView description#> @param indexPath <#indexPath description#> @return <#return value description#> */ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ NSString *cellIdentifier=@"OrderSalesCell"; OrderSalesDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; cell=[[OrderSalesDetailTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; OrderSaleListDetailModel *model=_details[indexPath.section]; [cell parseOrderSalesDetailInfo:model]; return cell; } #pragma mark - 私有函数 /** UITableView初始化 */ -(void)initUI{ _customTableView = [[UITableView alloc] initWithFrame:CGRectMake(10, 0, self.view.frame.size.width-20, self.view.frame.size.height-10)]; _customTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight; _customTableView.separatorStyle=UITableViewCellSeparatorStyleNone; _customTableView.backgroundColor=[UIColor clearColor]; _customTableView.delegate = self; _customTableView.dataSource=self; _customTableView.showsVerticalScrollIndicator = NO; [self.view addSubview:_customTableView]; } /** 加载数据 */ -(void)reloadData { [self startLoading]; NSString *urlStr = ServerURL; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:@"GetOrderSalesReportListDetailIphone" forKey:@"Action"]; [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"]; [dict setObject:kkUserCode forKey:@"UserCode"]; [dict setObject:kkUserPwd forKey:@"UserPassword"]; [dict setObject:kkSessionKey forKey:@"SessionKey"]; [dict setObject:_invoiceNo forKey:@"InvoiceNo"]; _downManager = [[ASIDownManager alloc] init]; _downManager.delegate = self; _downManager.OnImageDown = @selector(onLoadFinish:); _downManager.OnImageFail = @selector(onLoadFail:); [_downManager postHttpRequest:urlStr dic:dict path:nil fileName:nil]; } /** * 隐藏进度条 */ - (void)cancel { [self stopLoading]; } /** 导航栏 */ - (void)loadNavStyle { //返回 UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button setBackgroundImage:[UIImage imageNamed:@"icon_back"] forState:UIControlStateNormal]; [button addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside]; button.frame = CGRectMake(0, 0, 15, 18); UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button]; self.navigationItem.leftBarButtonItem = menuButton; } /** 返回 */ - (void)goBack { [self.navigationController popViewControllerAnimated:YES]; } @end