// // CustomerBalanceViewController.m // IBOSS // // Created by apple on 2017/5/15. // Copyright © 2017年 沈阳东科云信软件有限公司. All rights reserved. // // 功能描述:客户往来余额控制器 // #import "CustomerBalanceViewController.h" #import "CustomerBalanceDetailViewController.h" #import "CustomerBalanceSearchModel.h" #import "CustomerBalanceCell.h" @interface CustomerBalanceViewController (){ //TableView对象 UITableView *_vTableView; // 头部合计信息 UIView *_headView; } /** 数据源高度数据 */ @property (strong,nonatomic) NSMutableDictionary *heights; /** 原始数据源 */ @property (strong,nonatomic) NSMutableArray *arrDataList; /** 请求数据对象 */ @property (nonatomic,strong) ASIDownManager *downManager; @end @implementation CustomerBalanceViewController #pragma mark - 公共函数 /** viewDidLoad函数 */ - (void)viewDidLoad { [super viewDidLoad]; [self loadNavStyle]; [self initUI]; self.isBalance=@""; [self initSlideSlip]; } /** 安全区视图发生变化 */ -(void)viewSafeAreaInsetsDidChange{ _vTableView.frame = self.view.safeAreaLayoutGuide.layoutFrame; [super viewSafeAreaInsetsDidChange]; } /** didReceiveMemoryWarning函数 */ - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } /** dealloc */ - (void)dealloc{ self.arrDataList = nil; self.filterController = nil; } #pragma mark - 数据源list属性 /** 高度 @return <#return value description#> */ - (NSMutableDictionary *)heights{ if (_heights == nil){ _heights = [NSMutableDictionary dictionary]; } return _heights; } /** 原始数据源 @return <#return value description#> */ - (NSMutableArray *)arrDataList{ if(_arrDataList == nil){ _arrDataList = [[NSMutableArray alloc]init]; } return _arrDataList; } #pragma mark - 委托回调函数 #pragma mark 委托接口回调函数 /** 调用接口成功回调 @param sender <#sender description#> */ - (void)onLoadFinish:(ASIDownManager *)sender { // 取消进度条 [self cancel]; // 服务器返回数据 RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr]; // 服务器返回数据状态值 int iStatus = resultModel.status; // 服务器返回数据消息 NSString *message = resultModel.message; // 服务器返回数据状态值正确 if (iStatus == 0) { NSArray *retArr = (NSArray *)resultModel.result; [self.arrDataList removeAllObjects]; // 返回结果 if(retArr != nil) { [self.arrDataList addObjectsFromArray:retArr]; _vTableView.tableHeaderView = nil; _vTableView.backgroundView = nil; //无数据 关宏厚2017-7-6 if(self.arrDataList.count == 0) { //无数据 关宏厚2017-7-6 _vTableView.separatorStyle = UITableViewCellSeparatorStyleNone; // 有刷新数据的时候 if(self.arrDataList == nil || self.arrDataList.count == 0){ _vTableView.backgroundView =_noDataView; [self showAlertViewBackText:@"未找到匹配结果"]; } } else { _vTableView.tableHeaderView = _headView; double totalReceivableValue = 0; double totalDepositValue = 0; double totalEarnestValue = 0; for (int i = 0; i < self.arrDataList.count; i++) { NSDictionary *dicValue = self.arrDataList[i]; totalReceivableValue = totalReceivableValue + [[dicValue objectForKey:@"AccountReceivable"] doubleValue]; totalDepositValue = totalDepositValue + [[dicValue objectForKey:@"DepositReceived"] doubleValue]; totalEarnestValue = totalEarnestValue + [[dicValue objectForKey:@"Earnest"] doubleValue]; } // self.lblReceivable.text = [NSString stringWithFormat:@"¥%.2f",totalReceivableValue]; // self.lblDeposit.text = [NSString stringWithFormat:@"¥%.2f",totalDepositValue]; // self.lblEarnest.text = [NSString stringWithFormat:@"¥%.2f",totalEarnestValue]; // self.lblReceivableAndDepositAndEarnest.text = [NSString stringWithFormat:@"¥%.2f",totalReceivableValue-totalDepositValue-totalEarnestValue]; self.lblReceivable.text=[Util positiveFormat:[NSString stringWithFormat:@"%.2f",totalReceivableValue]]; self.lblDeposit.text =[Util positiveFormat:[NSString stringWithFormat:@"%.2f",totalDepositValue]]; self.lblEarnest.text=[Util positiveFormat:[NSString stringWithFormat:@"%.2f",totalEarnestValue]]; self.lblReceivableAndDepositAndEarnest.text=[Util positiveFormat:[NSString stringWithFormat:@"%.2f",totalReceivableValue-totalDepositValue-totalEarnestValue]]; } [_vTableView reloadData]; } } // 服务器返回数据状态值异常 else if(iStatus == ActionResultStatusAuthError ||iStatus == ActionResultStatusNoLogin ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){ [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 [self.arrDataList 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)]floatValue]; } /** 预估高度 @param tableView <#tableView description#> @param indexPath <#indexPath description#> @return <#return value description#> */ - (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 170; } /** 单元格 @param tableView <#tableView description#> @param indexPath <#indexPath description#> @return <#return value description#> */ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellIdentifier = @"CustomerBalanceCell"; CustomerBalanceCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; if (!cell) { cell = [[CustomerBalanceCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; cell.selectionStyle=UITableViewCellSelectionStyleNone; } else //当页面拉动的时候 当cell存在并且最后一个存在 把它进行删除就出来一个独特的cell我们在进行数据配置即可避免 { while ([cell.contentView.subviews lastObject] != nil) { [(UIView *)[cell.contentView.subviews lastObject] removeFromSuperview]; } } NSDictionary *dic= _arrDataList[indexPath.row]; [cell initUI:dic]; // 存储高度 self.heights[@(indexPath.row)] = @(cell.height); return cell; } /** 单元格选择事件 @param tableView <#tableView description#> @param indexPath <#indexPath description#> */ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSDictionary *dic= _arrDataList[indexPath.row]; if(dic != nil) { NSString *customerid = [[dic objectForKey:@"CustomerID"] stringValue]; if (customerid == nil || customerid.length == 0) { return; } self.hidesBottomBarWhenPushed=YES; CustomerBalanceDetailViewController *detailVC = [[CustomerBalanceDetailViewController alloc]init]; detailVC.sCustomerName = [dic objectForKey:@"CustomerName"]; detailVC.sChannelName = [dic objectForKey:@"ChannelName"]; detailVC.sAccountOrganizationName = [dic objectForKey:@"AccountOrganizationName"]; detailVC.sOrganizationName = [dic objectForKey:@"OrganizationName"]; detailVC.sDictionaryValue = [dic objectForKey:@"DictionaryValue"]; detailVC.sStaffName = [dic objectForKey:@"SalesManName"]; detailVC.sDistrictName = [dic objectForKey:@"DistrictName"]; detailVC.sCreditLine = [NSString stringWithFormat:@"%.f",[[dic objectForKey:@"CreditLine"]floatValue]]; detailVC.sAddress = [dic objectForKey:@"Address"]; detailVC.sTelephone = [dic objectForKey:@"Telephone"]; detailVC.sSecondaryStaffName=[dic objectForKey:@"SecondaryStaffArray"]; detailVC.sEarnest = [NSString stringWithFormat:@"%.2f",[[dic objectForKey:@"Earnest"]floatValue]]; detailVC.sAmountReceivable = [NSString stringWithFormat:@"%.2f",[[dic objectForKey:@"AccountReceivable"]floatValue]]; detailVC.sDepositReceived = [NSString stringWithFormat:@"%.2f",[[dic objectForKey:@"DepositReceived"]floatValue]]; [self.navigationController pushViewController:detailVC animated:YES]; } } #pragma mark - 私有函数 /** 初始化ui */ - (void)initUI { CGFloat height = 210; self.navigationItem.title = @"客户往来余额表"; self.view.backgroundColor = [UIColor whiteColor]; //分割线 UIView *viewBackgroud = [UIView new]; viewBackgroud.frame = CGRectMake(0, 0, Screen_Width, 0); viewBackgroud.backgroundColor = LineBackgroundColor; [self.view addSubview:viewBackgroud]; _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; _noDataView = [self noDataViewByFrame:_vTableView.bounds]; _vTableView.backgroundView =[self backGroundPromptViewByFrame:_vTableView.bounds promptStr:@"请筛选后查询"];; [self.view addSubview:_vTableView]; //头布局 _headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_Width, height)]; 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 *vtotalreceivable = [UIView new]; vtotalreceivable.frame=CGRectMake(0, CGRectGetMaxY(viewBackgroud.frame), Screen_Width, titleHeight); [_headView addSubview:vtotalreceivable]; UIImageView *imgview = [UIImageView new]; imgview.frame=CGRectMake(lblx, valuey+5, 21, 20); [imgview setImage:[UIImage imageNamed:@"balance_receivable"]]; [vtotalreceivable addSubview:imgview]; UILabel *lblText = [UILabel new]; lblText.frame=CGRectMake(CGRectGetMaxX(imgview.frame)+5, valuey+3, lblwidth, valueheight); lblText.font = [UIFont systemFontOfSize:fontsize]; lblText.text = @"应收款"; [vtotalreceivable addSubview:lblText]; self.lblReceivable = [UILabel new]; self.lblReceivable.frame=CGRectMake(Screen_Width - valuewidth - lblx, valuey+3, valuewidth, valueheight); self.lblReceivable.font = [UIFont systemFontOfSize:fontsize]; //lblreceivable = @"¥0"; self.lblReceivable.textAlignment = NSTextAlignmentRight; [vtotalreceivable addSubview:self.lblReceivable]; viewBackgroud = [UIView new]; viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vtotalreceivable.frame), Screen_Width, heightLine); viewBackgroud.backgroundColor = LineBackgroundColor; [_headView addSubview:viewBackgroud]; //预收款 ————————— UIView *vtotaldeposit = [UIView new]; vtotaldeposit.frame=CGRectMake(0, CGRectGetMaxY(viewBackgroud.frame), Screen_Width, titleHeight); [_headView addSubview:vtotaldeposit]; UIImageView *imgviewReceivable = [UIImageView new]; imgviewReceivable.frame=CGRectMake(lblx, valuey+5, 20, 20); [imgviewReceivable setImage:[UIImage imageNamed:@"balance_deposit"]]; [vtotaldeposit addSubview:imgviewReceivable]; lblText = [UILabel new]; lblText.frame=CGRectMake(CGRectGetMaxX(imgviewReceivable.frame)+5, valuey+3, lblwidth, valueheight); lblText.font = [UIFont systemFontOfSize:fontsize]; lblText.text = @"预收款"; [vtotaldeposit addSubview:lblText]; self.lblDeposit = [UILabel new]; self.lblDeposit.frame=CGRectMake(Screen_Width - valuewidth - lblx, valuey+3, valuewidth, valueheight); self.lblDeposit.font = [UIFont systemFontOfSize:fontsize]; //lbldeposit = @"¥0"; self.lblDeposit.textAlignment = NSTextAlignmentRight; [vtotaldeposit addSubview:self.lblDeposit]; viewBackgroud = [UIView new]; viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vtotaldeposit.frame), Screen_Width,heightLine); viewBackgroud.backgroundColor = LineBackgroundColor; [_headView addSubview:viewBackgroud]; //定金 ————————— UIView *vtotalearnest = [UIView new]; vtotalearnest.frame=CGRectMake(0, CGRectGetMaxY(viewBackgroud.frame), Screen_Width, titleHeight); [_headView addSubview:vtotalearnest]; UIImageView *imgviewProfit = [UIImageView new]; imgviewProfit.frame=CGRectMake(lblx, valuey+5, 20, 20); [imgviewProfit setImage:[UIImage imageNamed:@"balance_earnest"]]; [vtotalearnest addSubview:imgviewProfit]; lblText = [UILabel new]; lblText.frame=CGRectMake(CGRectGetMaxX(imgviewReceivable.frame)+5, valuey+3, lblwidth, valueheight); lblText.font = [UIFont systemFontOfSize:fontsize]; lblText.text = @"定金"; [vtotalearnest addSubview:lblText]; self.lblEarnest = [UILabel new]; self.lblEarnest.frame=CGRectMake(Screen_Width - valuewidth - lblx, valuey+3, valuewidth, valueheight); self.lblEarnest.font = [UIFont systemFontOfSize:fontsize]; //lbtotalProfitValue = @"¥0"; self.lblEarnest.textAlignment = NSTextAlignmentRight; [vtotalearnest addSubview:self.lblEarnest]; viewBackgroud = [UIView new]; viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vtotalearnest.frame), Screen_Width,heightLine); viewBackgroud.backgroundColor = LineBackgroundColor; [_headView addSubview:viewBackgroud]; // 应收款-预存款-定金 ————————— UIView *vreceivableAndDepositAndEarnest = [UIView new]; vreceivableAndDepositAndEarnest.frame=CGRectMake(0, CGRectGetMaxY(viewBackgroud.frame), Screen_Width, titleHeight); [_headView addSubview:vreceivableAndDepositAndEarnest]; imgview = [UIImageView new]; imgview.frame=CGRectMake(lblx, valuey+5, 20, 20); [imgview setImage:[UIImage imageNamed:@"order_sale_total"]]; [vreceivableAndDepositAndEarnest addSubview:imgview]; lblText = [UILabel new]; lblText.frame=CGRectMake(CGRectGetMaxX(imgviewReceivable.frame)+5, valuey+3, 200, valueheight); lblText.font = [UIFont systemFontOfSize:fontsize]; lblText.text = @"应收款-预存款-定金"; [vreceivableAndDepositAndEarnest addSubview:lblText]; self.lblReceivableAndDepositAndEarnest = [UILabel new]; self.lblReceivableAndDepositAndEarnest.frame=CGRectMake(CGRectGetMaxY(lblText.frame), valuey+3, Screen_Width - CGRectGetMaxY(lblText.frame) - lblx, valueheight); self.lblReceivableAndDepositAndEarnest.font = [UIFont systemFontOfSize:fontsize]; //lbtotalProfitValue = @"¥0"; self.lblReceivableAndDepositAndEarnest.textAlignment = NSTextAlignmentRight; [vreceivableAndDepositAndEarnest addSubview:self.lblReceivableAndDepositAndEarnest]; _headView.frame = CGRectMake(0, 0, Screen_Width, CGRectGetMaxY(vreceivableAndDepositAndEarnest.frame)); } /** 进度条隐藏 */ - (void)cancel { [self stopLoading]; } /** 加载数据 */ - (void)reloadData { [self startLoading]; NSString *urlStr = [NSString stringWithFormat:@"%@", ServerURL]; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:@"GetCustomerBalanceIphone" 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:self.sOrg forKeyedSubscript:@"OrganizationID"]; [dict setObject:self.sStaff forKeyedSubscript:@"Reporter"]; [dict setObject:self.sSummaryType forKeyedSubscript:@"SortType"]; [dict setObject:self.sCustomerAddress forKeyedSubscript:@"Address"]; [dict setObject:self.isBalance forKeyedSubscript:@"IsBalanceFee"]; [dict setObject:self.sCustomerCode forKeyedSubscript:@"CustomerCode"]; [dict setObject:self.sCustomerName forKeyedSubscript:@"CustomerName"]; [dict setObject:self.sSecondaryStaff forKeyedSubscript:@"SecondaryStaff"]; self.downManager = [[ASIDownManager alloc] init]; self.downManager.delegate = self; self.downManager.onRequestSuccess = @selector(onLoadFinish:); self.downManager.onRequestFail = @selector(onLoadFail:); [self.downManager postHttpRequest:urlStr dic:dict path:nil fileName:nil]; } /** 返回 */ - (void)goBack { [self.navigationController popViewControllerAnimated:YES]; } /** 导航按钮样式 */ - (void)loadNavStyle { //右边 UIView *v = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 42, 16)]; UIButton *btnfilter = [UIButton buttonWithType:UIButtonTypeCustom]; [btnfilter addTarget:self action:@selector(search) forControlEvents:UIControlEventTouchUpInside]; btnfilter.frame = CGRectMake(0, 0, 16, 16); [btnfilter setTitleColor:NavBarItemColor forState:UIControlStateNormal]; [btnfilter setBackgroundImage:[UIImage imageNamed:@"icon_filter_white"] forState:UIControlStateNormal]; [v addSubview:btnfilter]; UIButton *filterLbl = [[UIButton alloc]init]; filterLbl.frame=CGRectMake(CGRectGetMaxX(btnfilter.frame)+3,0,28, 16); [filterLbl setTitle:@"筛选" forState:UIControlStateNormal]; [filterLbl setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; filterLbl.titleLabel.font = [UIFont systemFontOfSize:ButtonFontOfSize]; [filterLbl addTarget:self action:@selector(search) forControlEvents:UIControlEventTouchUpInside]; [v addSubview:filterLbl]; UIBarButtonItem *menubtnAdd = [[UIBarButtonItem alloc] initWithCustomView:v]; self.navigationItem.rightBarButtonItem = menubtnAdd; //返回 UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button setImage:[UIImage imageNamed:@"icon_back"] forState:UIControlStateNormal]; [button addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside]; button.frame = CGRectMake(0, 0,45,22); UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button]; self.navigationItem.leftBarButtonItem = menuButton; } /** 抽屉弹出 */ - (void)search{ [_filterController show]; } /** 抽屉初始化 */ - (void)initSlideSlip{ // 抽屉对象 __weak typeof(self) weakself=self; self.filterController = [[SideSlipFilterController alloc] initWithSponsor:self resetBlock:^(NSArray *dataList) { for (SideSlipModel *model in dataList) { //selectedItem model.selectedItemList = nil; model.customDict = nil; } } commitBlock:^(NSArray *dataList) { // 查询条件 SideSlipModel *serviceRegionModel = dataList[0]; CustomerBalanceSearchModel *m = [serviceRegionModel.customDict objectForKey:CUSTOMER_BALANCE_SEARCH_RANGE_MODEL]; self.sOrg = m.sOrg; self.sStaff = m.sStaff; self.sSummaryType = m.sSummaryType; self.sSecondaryStaff=m.sSecondaryStaff; self.sCustomerCode=m.sCustomerCode; self.sCustomerName=m.sCustomerName; self.isBalance=m.filter; self.sCustomerAddress=m.sCustomerAddress; [weakself.filterController dismiss]; [self reloadData]; }]; _filterController.animationDuration = AnimationDuration; _filterController.hasHeadView = YES; _filterController.sideSlipLeading = UIScreenSideSlipLeading * [UIScreen mainScreen].bounds.size.width; _filterController.dataList = [self packageDataList]; } /** 数据源 @return <#return value description#> */ - (NSArray *)packageDataList { NSMutableArray *dataArray = [NSMutableArray array]; SideSlipModel *model = [[SideSlipModel alloc] init]; model.containerCellClass = @"CustomerBalanceSearchCell"; model.regionTitle = @"查询条件"; [dataArray addObject:model]; return [dataArray mutableCopy]; } @end