// // ExpenseListViewController.m // IBOSS // // Created by apple on 2017/7/10. // Copyright © 2017年 沈阳东科云信软件有限公司. All rights reserved. // // 功能描述:费用明细表控制器 // #import "ExpenseListViewController.h" #import "ExpenseDetailViewController.h" #import "SideSlipModel.h" #import "ExpenseSearchModel.h" #import "ExpenseCell.h" #import "DateFormat.h" @interface ExpenseListViewController (){ //TableView对象 UITableView *_vTableView; // 头视图 UIView *_headView; } /** 原始数据源 */ @property (strong,nonatomic) NSMutableArray *dataList; /** 请求数据对象 */ @property (nonatomic,strong) ASIDownManager *downManager; /** 抽屉对象 */ @property (strong,nonatomic) SideSlipFilterController *filterController; @end @implementation ExpenseListViewController #pragma mark - 公共函数 /** viewDidLoad */ - (void)viewDidLoad { [super viewDidLoad]; [self loadNavStyle]; [self initUI]; [self initSlideSlip]; } /** 安全区视图发生变化 */ -(void)viewSafeAreaInsetsDidChange{ _vTableView.frame=self.view.safeAreaLayoutGuide.layoutFrame; [super viewSafeAreaInsetsDidChange]; } /** didReceiveMemoryWarning */ - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } #pragma mark - 数据源属性 /** 原始数据源 @return return value description */ - (NSMutableArray *)dataList{ if(_dataList == nil){ _dataList = [[NSMutableArray alloc]init]; } return _dataList; } #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; _vTableView.tableHeaderView = nil; _vTableView.backgroundView = nil; // 服务器返回数据状态值正确 if (iStatus == 0) { // 服务器返回数据结果 NSArray *approvArr = (NSArray *)resultModel.result; [self.dataList removeAllObjects]; // 是否有数据 if(approvArr != nil && approvArr.count > 0) { [self.dataList addObjectsFromArray:approvArr]; double totalFeeSumValue = 0; double totalPaySumValue = 0; _vTableView.tableHeaderView = _headView; // 合计信息 for (int i = 0; i < self.dataList.count; i++) { NSDictionary *dicValue = self.dataList[i]; totalFeeSumValue = totalFeeSumValue + [[dicValue objectForKey:@"FeeSum"] doubleValue]; totalPaySumValue = totalPaySumValue + [[dicValue objectForKey:@"PaySum"] doubleValue]; } self.lblFeeSum.text = [NSString stringWithFormat:@"¥%.2f",totalFeeSumValue]; self.lblPaySum.text = [NSString stringWithFormat:@"¥%.2f",totalPaySumValue]; // 重新刷新数据 [_vTableView reloadData]; } else{ // 无数据 // 无数据的view [_dataList removeAllObjects]; [_vTableView reloadData]; _vTableView.backgroundView = _noDataView; [self showAlertViewBackText:@"未找到匹配结果"]; } } // 服务器返回数据状态值异常 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.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 135; } /** 单元格 @param tableView <#tableView description#> @param indexPath <#indexPath description#> @return <#return value description#> */ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellIdentifier = @"ExpenseCell"; ExpenseCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; // 初始化cell if (!cell) { cell = [[ExpenseCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; cell.selectionStyle=UITableViewCellSelectionStyleNone; } NSDictionary *dic = self.dataList[indexPath.row]; if (dic) { cell.lblValueFeeDirection.text = [dic objectForKey:@"FeeDirectionName"]; cell.lblValueFeeItem.text = [dic objectForKey:@"FeeItemName"]; cell.lblValueStaff.text = [dic objectForKey:@"StaffName"]; cell.lblValueOrg.text = [dic objectForKey:@"OrganizationName"]; NSString *str = [NSString stringWithFormat:@"¥%.2f",[[dic objectForKey:@"FeeSum"]floatValue] ]; cell.lblValueFeeSum.text = str; str = [NSString stringWithFormat:@"¥%.2f",[[dic objectForKey:@"PaySum"]floatValue]]; cell.lblValuePaySum.text = str; } return cell; } /** 单元格选择进入详细界面 @param tableView <#tableView description#> @param indexPath <#indexPath description#> */ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSDictionary *dic = self.dataList[indexPath.row]; if(dic != nil) { self.hidesBottomBarWhenPushed=YES; // 格式化日期 DateFormat *df = [DateFormat new]; ExpenseDetailViewController *detailVC = [[ExpenseDetailViewController alloc]init]; detailVC.objectTypeName = [dic objectForKey:@"ObjectTypeName"]; detailVC.feeNo = [dic objectForKey:@"FeeNo"]; detailVC.objectName = [dic objectForKey:@"ObjectName"]; detailVC.accountOrganizationName = [dic objectForKey:@"AccountOrganizationName"]; detailVC.feeDirectionName = [dic objectForKey:@"FeeDirectionName"]; detailVC.feeItemName = [dic objectForKey:@"FeeItemName"]; detailVC.statusName = [dic objectForKey:@"StatusName"]; detailVC.organizationName = [dic objectForKey:@"OrganizationName"]; detailVC.staffName = [dic objectForKey:@"StaffName"]; detailVC.brandName = [dic objectForKey:@"BrandName"]; detailVC.kindName = [dic objectForKey:@"KindName"]; detailVC.seriesName = [dic objectForKey:@"SeriesName"]; detailVC.reversedFeeNo = [dic objectForKey:@"ReversedFeeNo"]; detailVC.feeSum = [NSString stringWithFormat:@"¥%.2f",[[dic objectForKey:@"FeeSum"]floatValue]]; detailVC.confirmFeeSum = [NSString stringWithFormat:@"¥%.2f",[[dic objectForKey:@"ConfirmFeeSum"]floatValue]]; detailVC.businessFunctionName = [dic objectForKey:@"BusinessFunctionName"]; detailVC.invoiceNo = [dic objectForKey:@"InvoiceNo"]; detailVC.customerCode = [dic objectForKey:@"CustomerCode"]; detailVC.customerName = [dic objectForKey:@"CustomerName"]; detailVC.feePayName = [dic objectForKey:@"FeePayName"]; detailVC.paySum = [NSString stringWithFormat:@"¥%.2f",[[dic objectForKey:@"PaySum"]floatValue]]; detailVC.checkUserName = [dic objectForKey:@"CheckUserName"]; detailVC.checkTime = [dic objectForKey:@"CheckTime"]; detailVC.suggestion = [dic objectForKey:@"Suggestion"]; detailVC.remarks = [dic objectForKey:@"Remarks"]; [self.navigationController pushViewController:detailVC animated:YES]; } } #pragma mark - 私有函数 /** 初始化ui */ - (void)initUI { CGFloat height = 170; 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 *vtotalFeeSum = [UIView new]; vtotalFeeSum.frame=CGRectMake(0, CGRectGetMaxY(viewBackgroud.frame), Screen_Width, titleHeight); [_headView addSubview:vtotalFeeSum]; UIImageView *imgview = [UIImageView new]; imgview.frame=CGRectMake(lblx, valuey + 5, 21, 16); [imgview setImage:[UIImage imageNamed:@"discount_amount"]]; [vtotalFeeSum addSubview:imgview]; UILabel *lbtotalReceipt = [UILabel new]; lbtotalReceipt.frame=CGRectMake(CGRectGetMaxX(imgview.frame)+5, valuey, lblwidth, valueheight); lbtotalReceipt.font = [UIFont systemFontOfSize:fontsize]; lbtotalReceipt.text = @"费用金额"; [vtotalFeeSum addSubview:lbtotalReceipt]; self.lblFeeSum = [UILabel new]; self.lblFeeSum.frame=CGRectMake(Screen_Width - valuewidth - lblx, valuey, valuewidth, valueheight); self.lblFeeSum.font = [UIFont systemFontOfSize:fontsize]; //lblFeeSum = @"¥0"; self.lblFeeSum.textAlignment = NSTextAlignmentRight; [vtotalFeeSum addSubview:self.lblFeeSum]; viewBackgroud = [UIView new]; viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vtotalFeeSum.frame), Screen_Width, heightLine); viewBackgroud.backgroundColor = LineBackgroundColor; [_headView addSubview:viewBackgroud]; //支付金额 ————————— UIView *vtotalPaySum = [UIView new]; vtotalPaySum.frame=CGRectMake(0, CGRectGetMaxY(viewBackgroud.frame), Screen_Width, titleHeight); [_headView addSubview:vtotalPaySum]; UIImageView *imgviewReceivable = [UIImageView new]; imgviewReceivable.frame=CGRectMake(lblx, valuey+1, 20, 20); [imgviewReceivable setImage:[UIImage imageNamed:@"order_sale_total"]]; [vtotalPaySum addSubview:imgviewReceivable]; UILabel *lbtotalReceivable = [UILabel new]; lbtotalReceivable.frame=CGRectMake(CGRectGetMaxX(imgviewReceivable.frame)+5, valuey, lblwidth, valueheight); lbtotalReceivable.font = [UIFont systemFontOfSize:fontsize]; lbtotalReceivable.text = @"支付金额"; [vtotalPaySum addSubview:lbtotalReceivable]; self.lblPaySum = [UILabel new]; self.lblPaySum.frame=CGRectMake(Screen_Width - valuewidth - lblx, valuey, valuewidth, valueheight); self.lblPaySum.font = [UIFont systemFontOfSize:fontsize]; //lblPaySum = @"¥0"; self.lblPaySum.textAlignment = NSTextAlignmentRight; [vtotalPaySum addSubview:self.lblPaySum]; viewBackgroud = [UIView new]; viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vtotalPaySum.frame), Screen_Width, 10); viewBackgroud.backgroundColor = LineBackgroundColor; _headView.frame = CGRectMake(0, 0, Screen_Width, CGRectGetMaxY(vtotalPaySum.frame)); } /** 进度条隐藏 */ - (void)cancel { [self stopLoading]; } /** 加载数据 */ - (void)reloadData { [self startLoading]; NSString *urlStr = [NSString stringWithFormat:@"%@", ServerURL]; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:@"GetExpenseDetailIphone" forKey:@"Action"]; [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"]; [dict setObject:kkUserCode forKey:@"UserCode"]; [dict setObject:kkUserPwd forKey:@"UserPassword"]; [dict setObject:kkSessionKey forKey:@"SessionKey"]; if(_departmentCode != nil){ [dict setObject:_departmentCode forKey:@"OrganizationCode"]; } if(_staffName != nil){ [dict setObject:_staffName forKey:@"StaffName"]; } if (_accountDateFrom != nil) { [dict setObject:_accountDateFrom forKey:@"AccountDateFrom"]; } if (_accountDateTo!= nil) { [dict setObject:_accountDateTo forKey:@"AccountDateTo"]; } if(_customerCode!=nil) { [dict setObject:_customerCode forKey:@"CustomerCode"]; } if(_customerName!=nil) { [dict setObject:_customerName forKey:@"CustomerName"]; } //创建日期 // if (_createDateFrom != nil) { // [dict setObject:_createDateFrom forKey:@"CreateTimeFrom"]; // } // if (_createDateTo != nil) { // [dict setObject:_createDateTo forKey:@"CreateTimeTo"]; // } _downManager = [[ASIDownManager alloc] init]; _downManager.delegate = self; _downManager.onRequestSuccess = @selector(onLoadFinish:); _downManager.onRequestFail = @selector(onLoadFail:); [_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]; ExpenseSearchModel *m = [serviceRegionModel.customDict objectForKey:EXPENSE_SEARCH_RANGE_MODEL]; self.departmentCode = m.sOrgCode; self.staffName = m.sStaffName; self.accountDateFrom = m.accountDateFrom; self.accountDateTo = m.accountDateTo; self.customerCode=m.customerCode; self.customerName=m.customerName; if(self.accountDateFrom == nil){ self.accountDateFrom = @""; } if(self.accountDateTo == nil){ self.accountDateTo = @""; } //校验账务时间是否成对选择 if (self.accountDateFrom.length<=0&&self.accountDateTo.length>0) { [self showAlertViewText:@"请选择账务开始时间"]; return; } if (self.accountDateFrom.length>0&&self.accountDateTo.length<=0) { [self showAlertViewText:@"请选择账务结束时间"]; return; } NSUInteger result= [DateFormat compareDate:self.accountDateFrom withDate:self.accountDateTo]; if(result == -1){ [self showAlertViewText:@"账务开始日期不能大于结束日期"]; return; } // NSDateFormatter* dateFormat = [[NSDateFormatter alloc] init]; // [dateFormat setDateFormat:@"yyyy-MM-dd"];//设定时间格式,这里可以设置成自己需要的格式 // // NSDate *startD = [dateFormat dateFromString:self.accountDateFrom]; // NSDate *endD = [dateFormat dateFromString:self.accountDateTo]; // NSInteger days= [DateFormat calculateDaysFromBegin:startD end:endD]; // if(days > 31){ // [self showAlertViewText:@"日期间隔天数不能大于31天"]; // return; // } //创建日期(2019-05-24) // if(self.createDateFrom == nil){ // self.createDateFrom = @""; // } // if(self.createDateTo == nil){ // self.createDateTo = @""; // } // // //校验创建时间是否成对选择 // if (self.createDateFrom.length<=0&&self.createDateTo.length>0) { // [self showAlertViewText:@"请选择创建开始时间"]; // return; // } // if (self.createDateFrom.length>0&&self.createDateTo.length<=0) { // [self showAlertViewText:@"请选择创建结束时间"]; // return; // } // NSUInteger resultCreate = [DateFormat compareDate:self.createDateFrom withDate:self.createDateTo]; // if(resultCreate == -1){ // [self showAlertViewText:@"创建开始日期不能大于结束日期"]; // return; // } [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 = @"ExpenseSearchCell"; model.regionTitle = @"查询条件"; [dataArray addObject:model]; return [dataArray mutableCopy]; } @end