// // DailyReconciliationViewController.m // IBOSSmini // // Created by apple on 2017/5/4. // Copyright © 2017年 elongtian. All rights reserved. // #import "DailyReconciliationViewController.h" #import "DKWeeklyCalendarView.h" #import "DailyReconciDetailViewController.h" #import "DailyReconciliationCell.h" #import "DateFormat.h" @interface DailyReconciliationViewController (){ //TableView对象 UITableView *_vTableView; UIView *_headView; } /** 日期控件 */ @property (nonatomic, strong) DKWeeklyCalendarView* calendarView; /** 原始数据源 */ @property (strong, nonatomic) NSMutableArray *dataList; /** 转化成model数据源 */ @property (strong, nonatomic) NSMutableArray *dataNewList; /** 请求数据对象 */ @property(nonatomic,strong) ASIDownManager *mDownManager; @end static CGFloat CALENDER_VIEW_HEIGHT = 80.f; @implementation DailyReconciliationViewController #pragma mark - 公共函数 /** viewDidLoad函数 */ - (void)viewDidLoad { [super viewDidLoad]; [self showTitle:@""]; [self initUI]; } /** 修改:2017-9-26 适配机型 安全区视图发生变化 */ -(void)viewSafeAreaInsetsDidChange{ _vTableView.frame = CGRectMake(0, CGRectGetMaxY(self.calendarView.frame)+10, SCREENWIDTH, self.view.safeAreaLayoutGuide.layoutFrame.size.height-CGRectGetMaxY(self.calendarView.frame)-10); [super viewSafeAreaInsetsDidChange]; } /** didReceiveMemoryWarning函数 */ - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } #pragma mark - 数据源list属性 /** 原始数据源 @return <#return value description#> */ - (NSMutableArray *)dataList{ if(_dataList== nil){ _dataList = [NSMutableArray new]; } return _dataList; } /** 转化成model数据源 @return <#return value description#> */ - (NSMutableArray *)dataNewList{ if(_dataNewList== nil){ _dataNewList = [NSMutableArray new]; } return _dataNewList; } /** 日期控件 @return <#return value description#> */ - (DKWeeklyCalendarView *)calendarView { if(!_calendarView){ _calendarView = [[DKWeeklyCalendarView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, CALENDER_VIEW_HEIGHT)]; _calendarView.delegate = self; } return _calendarView; } #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) { // 返回值 NSDictionary *dicResult =[dic objectForKey:@"Result"]; NSArray * approvArr; NSArray * approvTotalArr; if(dicResult!=nil) { approvArr = [dicResult objectForKey:@"PivotDataTable"]; approvTotalArr = [dicResult objectForKey:@"TotalTable"]; } [self.dataList removeAllObjects]; _vTableView.tableHeaderView = nil; _vTableView.backgroundView = nil; // 返回值数组 if(approvArr!=nil) { [self.dataList addObjectsFromArray:approvArr]; if(self.dataList.count==0){ UIView *noDataView=[[UIView alloc]init]; noDataView.frame=_vTableView.bounds; UIImageView *nodataImgView=[[UIImageView alloc] initWithFrame:CGRectMake(noDataView.frame.size.width/2-16,noDataView.frame.size.height/2-16,32,32)]; [nodataImgView setImage:[UIImage imageNamed:@"icon_no_data"]]; [noDataView addSubview:nodataImgView]; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(noDataView.frame.size.width/2-16-12,CGRectGetMaxY(nodataImgView.frame)+3,70, 25)]; label.font=[UIFont systemFontOfSize:NoDataFontOfSize]; label.text = @"无数据"; label.numberOfLines = 2; label.textColor = [UIColor lightGrayColor]; [noDataView addSubview:label]; _vTableView.backgroundView =noDataView; [self showAlertViewText:@"未找到匹配结果"]; } else { NSDictionary *dicTitle =approvTotalArr[0]; _vTableView.tableHeaderView = _headView; self.lbTotalReceiptValue.text = @"¥0"; self.lbTotalReceivableValue.text = @"¥0"; if (dicTitle!=nil) { if([dicTitle objectForKey:@"ReceiptAmount"]){ self.lbTotalReceiptValue.text=[NSString stringWithFormat:@"¥%@",[dicTitle objectForKey:@"ReceiptAmount"] ]; } if([dicTitle objectForKey:@"ReceivableAmount"]){ self.lbTotalReceivableValue.text=[NSString stringWithFormat:@"¥%@",[dicTitle objectForKey:@"ReceivableAmount"]]; } } } [_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 [_dataList 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 40; } /** 单元格 @param tableView <#tableView description#> @param indexPath <#indexPath description#> @return <#return value description#> */ -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"DailyReconciliationCell"; DailyReconciliationCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell=[[DailyReconciliationCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; cell.selectionStyle=UITableViewCellSelectionStyleNone; } // DailyReconciliationCell *cell = [[ DailyReconciliationCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil]; NSDictionary *dic= _dataList[indexPath.row]; if(dic!=nil) { cell.lblOrgNameView.text=[dic objectForKey:@"OrganizationName"]; if([dic objectForKey:@"ReceiptAmount"]){ cell.lblTotalReceiptView.text=[NSString stringWithFormat:@"¥%@",[dic objectForKey:@"ReceiptAmount"] ]; }else{ cell.lblTotalReceiptView.text=@"¥0"; } if([dic objectForKey:@"ReceivableAmount"]){ cell.lblTotalReceivableView.text=[NSString stringWithFormat:@"¥%@",[dic objectForKey:@"ReceivableAmount"]]; }else{ cell.lblTotalReceivableView.text=@"¥0"; } } return cell; } /** 单元格选择事件 @param tableView <#tableView description#> @param indexPath <#indexPath description#> */ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSDictionary *dic= _dataList[indexPath.row]; if(dic!=nil) { NSString *orgID = [dic objectForKey:@"OrganizationID"]; NSString *time = [dic objectForKey:@"AccountDate"]; NSString *businessType = @"0"; self.hidesBottomBarWhenPushed=YES; DailyReconciDetailViewController *detailVC =[[DailyReconciDetailViewController alloc]init]; detailVC.organizationId = orgID; detailVC.accountDate = time; detailVC.businessType = businessType; [self.navigationController pushViewController:detailVC animated:YES]; } } /** 日期控件属性 @return <#return value description#> */ - (NSDictionary *)CLCalendarBehaviorAttributes { return @{ CLCalendarWeekStartDay : @1, //Start Day of the week, from 1-7 Mon-Sun -- default 1 // CLCalendarDayTitleTextColor : [UIColor yellowColor], // CLCalendarSelectedDatePrintColor : [UIColor greenColor], }; } /** 日期控件选择后的日期 @param date <#date description#> */ - (void)dailyCalendarViewDidSelect:(NSDate *)date { //用于格式化NSDate对象 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; //设置格式 [dateFormatter setDateFormat:@"yyyy-MM-dd"]; //NSDate转NSString NSString *currentDateString = [dateFormatter stringFromDate: date]; [self reloadData:currentDateString]; } #pragma mark - 私有函数 /** 初始化ui */ - (void)initUI { self.navigationItem.title=@"日结对账表"; self.view.backgroundColor = [UIColor whiteColor]; [self.view addSubview:self.calendarView]; //分割线 UIView *viewBackgroud = [UIView new]; viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(self.calendarView.frame), Screen_Width, 10); viewBackgroud.backgroundColor = LineBackgroundColor; [self.view addSubview:viewBackgroud]; _vTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(viewBackgroud.frame), Screen_Width, self.view.frame.size.height - CGRectGetMaxY(viewBackgroud.frame))]; _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]; //头布局 _headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_Width, 40)]; UIButton *btnHead=[UIButton buttonWithType:UIButtonTypeCustom]; btnHead.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; CGFloat titleHeight = 50; CGFloat lblx = 20; CGFloat lblwidth = 130; CGFloat fontsize = 14; //CGFloat valuex = 125; CGFloat valuey = 10; CGFloat valuewidth = 200; CGFloat valueheight = 25; CGFloat heightLine =1; //总合计================== UIView *vtotal=[UIView new]; vtotal.frame=CGRectMake(0, 0, Screen_Width, titleHeight); [_headView addSubview:vtotal]; UILabel *lbtotal = [UILabel new]; lbtotal.frame=CGRectMake(lblx, valuey, lblwidth, valueheight); lbtotal.font = [UIFont boldSystemFontOfSize:fontsize]; lbtotal.text=@"总合计"; [vtotal addSubview:lbtotal]; //分割线 viewBackgroud = [UIView new]; viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vtotal.frame), Screen_Width, heightLine); viewBackgroud.backgroundColor = LineBackgroundColor; [_headView addSubview:viewBackgroud]; //收款总额================== UIView *vtotalReceipt=[UIView new]; vtotalReceipt.frame=CGRectMake(0, CGRectGetMaxY(viewBackgroud.frame), Screen_Width, titleHeight); [_headView addSubview:vtotalReceipt]; UIImageView *imgview = [UIImageView new]; imgview.frame=CGRectMake(lblx, valuey+5, 20, 20); [imgview setImage:[UIImage imageNamed:@"day_account_total_receivable"]]; [vtotalReceipt addSubview:imgview]; UILabel *lbtotalReceipt = [UILabel new]; lbtotalReceipt.frame=CGRectMake(CGRectGetMaxX(imgview.frame)+5, valuey+3, lblwidth, valueheight); lbtotalReceipt.font = [UIFont systemFontOfSize:fontsize]; lbtotalReceipt.text=@"收款总额"; [vtotalReceipt addSubview:lbtotalReceipt]; self.lbTotalReceiptValue = [UILabel new]; self.lbTotalReceiptValue.frame=CGRectMake(Screen_Width - valuewidth - lblx, valuey+3, valuewidth, valueheight); self.lbTotalReceiptValue.font = [UIFont boldSystemFontOfSize:fontsize]; //self.lbtotalReceiptValue.text = @"¥0"; self.lbTotalReceiptValue.textAlignment = NSTextAlignmentRight; [vtotalReceipt addSubview:self.lbTotalReceiptValue]; viewBackgroud = [UIView new]; viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vtotalReceipt.frame), Screen_Width, heightLine); viewBackgroud.backgroundColor = LineBackgroundColor; [_headView addSubview:viewBackgroud]; //货款总额================== UIView *vtotalReceivable=[UIView new]; vtotalReceivable.frame=CGRectMake(0, CGRectGetMaxY(viewBackgroud.frame), Screen_Width, titleHeight); [_headView addSubview:vtotalReceivable]; UIImageView *imgviewReceivable = [UIImageView new]; imgviewReceivable.frame=CGRectMake(lblx, valuey+6, 21, 16); [imgviewReceivable setImage:[UIImage imageNamed:@"day_account_total_receipt"]]; [vtotalReceivable addSubview:imgviewReceivable]; UILabel *lbtotalReceivable = [UILabel new]; lbtotalReceivable.frame=CGRectMake(CGRectGetMaxX(imgviewReceivable.frame)+5, valuey+2, lblwidth, valueheight); lbtotalReceivable.font = [UIFont systemFontOfSize:fontsize]; lbtotalReceivable.text=@"货款总额"; [vtotalReceivable addSubview:lbtotalReceivable]; self.lbTotalReceivableValue = [UILabel new]; self.lbTotalReceivableValue.frame=CGRectMake(Screen_Width - valuewidth - lblx, valuey+2, valuewidth, valueheight); self.lbTotalReceivableValue.font = [UIFont boldSystemFontOfSize:fontsize]; //self.lbtotalReceivableValue.text = @"¥0"; self.lbTotalReceivableValue.textAlignment = NSTextAlignmentRight; [vtotalReceivable addSubview:self.lbTotalReceivableValue]; viewBackgroud = [UIView new]; viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vtotalReceivable.frame), Screen_Width, 40); viewBackgroud.backgroundColor = LineBackgroundColor; [_headView addSubview:viewBackgroud]; CGFloat backY = 8; UILabel *lblTitleReceipt = [UILabel new]; lblTitleReceipt.frame=CGRectMake(Screen_Width - 2*lblwidth - 10 - 2, backY, lblwidth, valueheight); lblTitleReceipt.font = [UIFont systemFontOfSize:fontsize]; lblTitleReceipt.text=@"收款总额"; lblTitleReceipt.textAlignment = NSTextAlignmentRight; [viewBackgroud addSubview:lblTitleReceipt]; UILabel *lblTitleReceivable = [UILabel new]; lblTitleReceivable.frame=CGRectMake(Screen_Width - lblwidth - 10, backY, lblwidth, valueheight); lblTitleReceivable.font = [UIFont systemFontOfSize:fontsize]; lblTitleReceivable.text=@"货款总额"; lblTitleReceivable.textAlignment = NSTextAlignmentRight; [viewBackgroud addSubview:lblTitleReceivable]; UILabel *lblOrg = [UILabel new]; lblOrg.frame=CGRectMake(lblx, backY, Screen_Width - CGRectGetMinX(lblTitleReceipt.frame) - lblx, valueheight); lblOrg.font = [UIFont systemFontOfSize:fontsize]; lblOrg.text=@"部门"; [viewBackgroud addSubview:lblOrg]; _headView.frame = CGRectMake(0, 0, Screen_Width, CGRectGetMaxY(viewBackgroud.frame)); _vTableView.tableHeaderView = _headView; } /** 进度条隐藏 */ - (void)Cancel { [self stopLoading]; } /** 加载数据 */ -(void)reloadData:(NSString *)date { [self startLoading]; NSString *urlStr = [NSString stringWithFormat:@"%@", ServerURL]; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:@"GetDailyReconciliationListIphone" 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:@"" forKey:@"OrganizationCode"]; [dict setObject:date forKey:@"AccountDateFrom"]; [dict setObject:date forKey:@"AccountDateTo"]; [dict setObject:@"0" forKey:@"BusinessType"]; self.mDownManager = [[ASIDownManager alloc] init]; _mDownManager.delegate = self; _mDownManager.OnImageDown = @selector(onLoadFinish:); _mDownManager.OnImageFail = @selector(onLoadFail:); [_mDownManager postHttpRequest:urlStr dic:dict path:nil fileName:nil]; } @end