// // DailyReconciDetailViewController.m // IBOSSmini // // Created by apple on 2017/5/16. // Copyright © 2017年 elongtian. All rights reserved. // #import "DailyReconciDetailViewController.h" #import "DailyReconciliationDetailCell.h" #import "DayAccountDetailModel.h" @interface DailyReconciDetailViewController () @property(nonatomic,strong) ASIDownManager *downManager; @property(nonatomic,strong) UITableView * vTableView; @property(nonatomic,strong) NSMutableArray *dataArr; @property(nonatomic,strong) NSMutableArray *dataModelArr; /** 数据源高度数据 */ @property (strong, nonatomic) NSMutableDictionary *heights; @end @implementation DailyReconciDetailViewController #pragma mark - 公共函数 /** viewDidLoad函数 */ - (void)viewDidLoad { [super viewDidLoad]; [self showTitle:@""]; [self initUI]; [self reloadData]; } /** 修改:2017-9-26 适配机型 安全区视图发生变化 */ -(void)viewSafeAreaInsetsDidChange{ _vTableView.frame = self.view.safeAreaLayoutGuide.layoutFrame; [super viewSafeAreaInsetsDidChange]; } /** didReceiveMemoryWarning函数 */ - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } #pragma mark - 数据源list属性 /** 原始数据源 @return <#return value description#> */ - (NSMutableArray *)dataArr{ if(_dataArr== nil){ _dataArr = [NSMutableArray new]; } return _dataArr; } /** 原始Model数据源 @return <#return value description#> */ - (NSMutableArray *)dataModelArr{ if(_dataModelArr== nil){ _dataModelArr = [NSMutableArray new]; } return _dataModelArr; } /** 高度 @return <#return value description#> */ - (NSMutableDictionary *)heights{ if (_heights == nil){ _heights = [NSMutableDictionary dictionary]; } return _heights; } #pragma mark - 委托回调函数 #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) { [self.dataArr addObjectsFromArray:approvArr]; if(self.dataArr.count==0) { [self showAlertViewText:@"未找到匹配结果"]; } for (int i = 0; i < approvArr.count; i++) { NSString *str = approvArr[i]; DayAccountDetailModel *model=[DayAccountDetailModel new]; NSArray *strArr = [str componentsSeparatedByString:@" "]; if (strArr!=nil && strArr.count<3) { continue; } model.typeNo = strArr[1]; model.businessNumber = strArr[2]; model.billOperation = strArr[3]; for (int j = 0; j < strArr.count -3 -1; j++) { int count = (int) strArr.count - j -1; if ([strArr[count] rangeOfString: @"销售货款总额:"].location !=NSNotFound) { model.receivableAmount = strArr[count]; continue; } if ([strArr[count] rangeOfString:@"结算方式:"].location !=NSNotFound) { model.settleWay = strArr[count]; continue; } if ([strArr[count] rangeOfString:@"收款额:"].location !=NSNotFound) { model.receiptAmount = strArr[count]; continue; } if ([strArr[count] rangeOfString:@"使用定金:"].location !=NSNotFound) { model.earnestAmount = strArr[count]; continue; } if ([strArr[count] rangeOfString:@"使用预存:"].location !=NSNotFound) { model.depositAmount = strArr[count]; continue; } } [self.dataModelArr addObject:model]; } [_vTableView reloadData]; } } // 服务器返回数据状态值异常 else if(iStatus==ActionResultStatusAuthError ||iStatus==ActionResultStatusNoLogin ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid){ [self showReLoginDialog:message]; } else { [_vTableView reloadData]; [self showAlertViewText:message]; } } } /** 调用接口失败回调 @param sender <#sender description#> */ - (void)onLoadFail:(ASIDownManager *)sender { [self Cancel]; [_vTableView reloadData]; [self showAlertViewText:@"加载失败"]; } #pragma mark 委托tablview回调函数 /** 行数 @param tableView tableView description @param section section description @return return value description */ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [_dataArr count]; } /** Sections数 @param tableView <#tableView description#> @return <#return value description#> */ -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1; } /** 高度 @param tableView <#tableView description#> @param indexPath <#indexPath description#> @return <#return value description#> */ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return [self.heights[@(indexPath.row)] doubleValue]; } /** 估测高度 @param tableView <#tableView description#> @param indexPath <#indexPath description#> @return <#return value description#> */ - (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 300; } /** 单元格 @param tableView tableView description @param indexPath <#indexPath description#> @return return value description */ -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { DailyReconciliationDetailCell *cell = [[ DailyReconciliationDetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil]; cell.selectionStyle=UITableViewCellSelectionStyleNone; cell.dModel = [_dataModelArr objectAtIndex:indexPath.row]; // 强制布局 xib时调用 //[cell layoutIfNeeded]; // 存储高度 self.heights[@(indexPath.row)] = @(cell.height); return cell; } #pragma mark - 私有函数 /** 初始化ui */ - (void)initUI { ; self.navigationItem.title=@"日结对账表明细"; self.view.backgroundColor = [UIColor whiteColor]; _vTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, Screen_Width, Screen_Height )]; _vTableView.rowHeight = UITableViewAutomaticDimension; _vTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight; _vTableView.separatorStyle = UITableViewCellSeparatorStyleNone; _vTableView.backgroundColor = [UIColor whiteColor]; _vTableView.delegate = self; _vTableView.dataSource=self; _vTableView.tableHeaderView = nil; [self.view addSubview:_vTableView]; } /** 进度条隐藏 */ - (void)Cancel { [self stopLoading]; } /** 加载数据 */ -(void)reloadData { [self startLoading]; NSString *urlStr = [NSString stringWithFormat:@"%@", ServerURL]; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:@"GetDailyReconciliationDetailIphone" 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:_organizationId forKey:@"OrganizationID"]; [dict setObject:_accountDate forKey:@"AccountDate"]; [dict setObject:_businessType forKey:@"BusinessType"]; _downManager = [[ASIDownManager alloc] init]; _downManager.delegate = self; _downManager.OnImageDown = @selector(onLoadFinish:); _downManager.OnImageFail = @selector(onLoadFail:); [_downManager postHttpRequest:urlStr dic:dict path:nil fileName:nil]; } @end