// // OrderSaleViewController.m // IBOSSmini // // Created by apple on 2017/5/15. // Copyright © 2017年 elongtian. All rights reserved. // #import "OrderSaleViewController.h" #import "OrderSaleTotalModel.h" #import "DateFormat.h" #import "OrderSaleListModel.h" #import "OrderSalesTableViewCell.h" #import "SideSlipModel.h" #import "OrderSalesSearchModel.h" #import "OrderSalesDetailViewController.h" @interface OrderSaleViewController () @end @implementation OrderSaleViewController #pragma mark - 公共函数 /** viewDidLoad函数 */ - (void)viewDidLoad { [super viewDidLoad]; [self showTitle:@"销售单订单"]; _mEndDate= [DateFormat getCurrentDate]; _mStartDate=[DateFormat getDateBefore:7]; [self loadNavStyle]; [self initUI]; [self initSlideSlip]; _stockArr=[NSMutableArray new]; _details=[NSMutableArray new]; _correctStatus=@"1"; [self reloadData]; } /** 安全区视图发生变化 */ -(void)viewSafeAreaInsetsDidChange{ self.view.backgroundColor = [UIColor whiteColor]; _vCustomTableView.frame = self.view.safeAreaLayoutGuide.layoutFrame; [super viewSafeAreaInsetsDidChange]; } /** 抽屉初始化 */ - (void)initSlideSlip{ // 抽屉对象 __weak typeof(self) weakself=self; self.filterController = [[SideSlipFilterController alloc] initWithSponsor:self resetBlock:^(NSArray *dataList) { for (SideSlipModel *model in dataList) { model.selectedItemList = nil; model.customDict = nil; } } commitBlock:^(NSArray *dataList) { // 查询条件 SideSlipModel *model = dataList[0]; OrderSalesSearchModel *m = [model.customDict objectForKey:SEARCH_RANGE_MODEL]; _mStartDate=m.startDate; _mEndDate=m.endDate; _mCustomerName=m.customerName; _mTelephone=m.contactTelephone; _mInvoiceType=m.invoiceTypeId; _correctStatus=m.correctStatus; if(_mStartDate==nil){ [self showAlertViewText:@"请选择开始日期"]; return; } if(_mEndDate==nil){ [self showAlertViewText:@"请选择结束日期"]; return; } NSUInteger result= [DateFormat compareDate:_mStartDate withDate:_mEndDate]; if(result == -1){ [self showAlertViewText:@"开始日期不能大于结束日期"]; return; } NSDateFormatter* dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"yyyy-MM-dd"];//设定时间格式,这里可以设置成自己需要的格式 NSDate *startD =[dateFormat dateFromString:_mStartDate]; NSDate *endD = [dateFormat dateFromString:_mEndDate]; NSInteger days= [DateFormat calculateDaysFromBegin:startD end:endD]; if(days > 31){ [self showAlertViewText:@"日期间隔天数不能大于31天"]; 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 = @"OrderSalesSearchTableViewCell"; model.regionTitle = @"查询条件"; [dataArray addObject:model]; return [dataArray mutableCopy]; } #pragma mark - 代理函数 /** Sections @param tableView <#tableView description#> @return <#return value description#> */ -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1; } /** 头高 @param tableView <#tableView description#> @param section <#section description#> @return <#return value description#> */ - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 5; } /** 列表个数 @param tableView <#tableView description#> @param section <#section description#> @return <#return value description#> */ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return _details.count; } /** 行高 @param tableView <#tableView description#> @param indexPath <#indexPath description#> @return <#return value description#> */ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 134+35; } /** cell @param tableView <#tableView description#> @param indexPath <#indexPath description#> @return <#return value description#> */ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *CellIdentifier = @"OrderSalesTableViewCell"; OrderSalesTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (!cell) { cell=[[OrderSalesTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; cell.selectionStyle=UITableViewCellSelectionStyleNone; } else //当页面拉动的时候 当cell存在并且最后一个存在 把它进行删除就出来一个独特的cell我们在进行数据配置即可避免 { while ([cell.contentView.subviews lastObject] != nil) { [(UIView *)[cell.contentView.subviews lastObject] removeFromSuperview]; } } // NSString *CellIdentifier=@"OrderSalesCell"; // OrderSalesTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; // cell=[[OrderSalesTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; // cell.selectionStyle=UITableViewCellSelectionStyleNone; OrderSaleListModel *model=_details[indexPath.row]; [cell parseOrderSalesInfo:model]; return cell; } /** 单元格点击事件 @param tableView <#tableView description#> @param indexPath <#indexPath description#> */ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ self.hidesBottomBarWhenPushed=YES; OrderSalesDetailViewController *detailvc=[[OrderSalesDetailViewController alloc] init]; OrderSaleListModel *m = _details[indexPath.row]; detailvc.invoiceNo = m.invoiceNo; [self.navigationController pushViewController:detailvc animated:YES]; } #pragma mark - 私有函数 /** 初始化ui */ - (void)initUI{ self.navigationItem.title = @"订单销售单列表"; self.view.backgroundColor = [UIColor whiteColor]; _vCustomTableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0, Screen_Width, Screen_Height )]; _vCustomTableView.rowHeight = UITableViewAutomaticDimension; _vCustomTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight; _vCustomTableView.separatorStyle = UITableViewCellSeparatorStyleNone; _vCustomTableView.backgroundColor = [UIColor whiteColor]; _vCustomTableView.delegate = self; _vCustomTableView.dataSource=self; [self.view addSubview:_vCustomTableView]; // 合计 _headView = [[UIView alloc]initWithFrame:CGRectZero]; CGFloat lblx = 20; CGFloat lblwidth = 130; CGFloat valuey = 10; CGFloat valuewidth = 200; CGFloat valueheight = 25; CGFloat heightLine =1; UILabel *lbtotal = [UILabel new]; lbtotal.frame=CGRectMake(lblx, valuey, lblwidth, valueheight); lbtotal.font = reportTextFont; lbtotal.text = @"合计"; [_headView addSubview:lbtotal]; UIView *topSeparator = [UIView new]; topSeparator.frame = CGRectMake(0, CGRectGetMaxY(lbtotal.frame)+valuey, Screen_Width, heightLine); topSeparator.backgroundColor = LineBackgroundColor; [_headView addSubview:topSeparator]; UIImageView *goodsimgview = [UIImageView new]; UIImage *goodsImg= [UIImage imageNamed:@"goods_amount"]; goodsimgview.frame=CGRectMake(lblx,CGRectGetMaxY(topSeparator.frame)+valuey,goodsImg.size.width,goodsImg.size.height); [goodsimgview setImage:goodsImg]; [_headView addSubview:goodsimgview]; //货款总额 UILabel *lblTitleGoodsAmount = [UILabel new]; lblTitleGoodsAmount.frame=CGRectMake(CGRectGetMaxX(goodsimgview.frame)+5, CGRectGetMaxY(topSeparator.frame)+valuey-3, lblwidth, valueheight); lblTitleGoodsAmount.font = reportTextFont; lblTitleGoodsAmount.text = @"货款总额"; [_headView addSubview:lblTitleGoodsAmount]; _lblGoodsAmount = [UILabel new]; _lblGoodsAmount.frame=CGRectMake(Screen_Width - valuewidth - lblx, CGRectGetMaxY(topSeparator.frame)+valuey-3, valuewidth, valueheight); _lblGoodsAmount.font = reportTextFont; _lblGoodsAmount.textAlignment = NSTextAlignmentRight; [_headView addSubview:_lblGoodsAmount]; UIView *goodsSeparator = [UIView new]; goodsSeparator.frame = CGRectMake(CGRectGetMaxX(goodsimgview.frame)+5, CGRectGetMaxY(goodsimgview.frame)+valuey, Screen_Width, heightLine); goodsSeparator.backgroundColor = LineBackgroundColor; [_headView addSubview:goodsSeparator]; UIImageView *discountimgview = [UIImageView new]; UIImage *discountAmountImg= [UIImage imageNamed:@"discount_amount"]; discountimgview.frame=CGRectMake(lblx,CGRectGetMaxY(goodsSeparator.frame)+valuey,discountAmountImg.size.width,discountAmountImg.size.height); [discountimgview setImage:discountAmountImg]; [_headView addSubview:discountimgview]; // 舍零金额 UILabel *lblTitleDiscountAmount = [UILabel new]; lblTitleDiscountAmount.frame=CGRectMake(CGRectGetMaxX(discountimgview.frame)+5, CGRectGetMaxY(goodsSeparator.frame)+valuey, lblwidth, valueheight); lblTitleDiscountAmount.font = reportTextFont; lblTitleDiscountAmount.text = @"舍零金额"; [_headView addSubview:lblTitleDiscountAmount]; _lblDiscountAmount = [UILabel new]; _lblDiscountAmount.frame=CGRectMake(Screen_Width - valuewidth - lblx, CGRectGetMaxY(goodsSeparator.frame)+valuey, valuewidth, valueheight); _lblDiscountAmount.font = reportTextFont; _lblDiscountAmount.textAlignment = NSTextAlignmentRight; [_headView addSubview:_lblDiscountAmount]; UIView *discountSeparator = [UIView new]; discountSeparator.frame = CGRectMake(CGRectGetMaxX(discountimgview.frame)+5, CGRectGetMaxY(discountimgview.frame)+valuey, Screen_Width, heightLine); discountSeparator.backgroundColor = LineBackgroundColor; [_headView addSubview:discountSeparator]; //合计金额 UIImageView *totalimgview = [UIImageView new]; UIImage *totalImg= [UIImage imageNamed:@"total_amount"]; totalimgview.frame=CGRectMake(lblx,CGRectGetMaxY(discountSeparator.frame)+valuey,totalImg.size.width,totalImg.size.height); [totalimgview setImage:totalImg]; [_headView addSubview:totalimgview]; UILabel *lblTitleTotalAmount = [UILabel new]; lblTitleTotalAmount.frame=CGRectMake(CGRectGetMaxX(totalimgview.frame)+5, CGRectGetMaxY(discountSeparator.frame)+valuey-3, lblwidth, valueheight); lblTitleTotalAmount.font = reportTextFont; lblTitleTotalAmount.text = @"合计金额"; [_headView addSubview:lblTitleTotalAmount]; _lblTotalAmount = [UILabel new]; _lblTotalAmount.frame=CGRectMake(Screen_Width - valuewidth - lblx, CGRectGetMaxY(discountSeparator.frame)+valuey-3, valuewidth, valueheight); _lblTotalAmount.font = reportTextFont; _lblTotalAmount.textAlignment = NSTextAlignmentRight; [_headView addSubview:_lblTotalAmount]; UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_lblTotalAmount.frame)+5, SCREENWIDTH, 10)]; line.backgroundColor = LineBackgroundColor; [_headView addSubview:line]; _headView.frame=CGRectMake(0,0, Screen_Width, CGRectGetMaxY(line.frame)); } /** 导航菜单 */ - (void)loadNavStyle { // 右边 UIView *v = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 42, 12)]; 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 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)search{ [_filterController show]; } /** 头数据 @param md <#md description#> */ - (void)initUIData:(OrderSaleTotalModel *)md{ _lblGoodsAmount.text=[NSString stringWithFormat:@"¥%@",md.goodsAmount]; _lblDiscountAmount.text=[NSString stringWithFormat:@"¥%@",md.discountAmount]; _lblTotalAmount.text=[NSString stringWithFormat:@"¥%@",md.totalAmount]; [self loadDetailData]; } /** 加载数据 */ -(void)loadDetailData{ [self startLoading]; NSString *urlStr = ServerURL; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:@"GetOrderSalesReportListIphone" 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(_mStartDate==nil){ [dict setObject:@"" forKeyedSubscript:@"BeginTime"]; } else{ [dict setObject:_mStartDate forKeyedSubscript:@"BeginTime"]; } if(_mEndDate==nil){ [dict setObject:@"" forKeyedSubscript:@"EndTime"]; } else{ [dict setObject:_mEndDate forKeyedSubscript:@"EndTime"]; } if(_mCustomerName==nil){ [dict setObject:@"" forKeyedSubscript:@"CustomerName"]; } else{ [dict setObject:_mCustomerName forKeyedSubscript:@"CustomerName"]; } if(_mInvoiceType==nil){ [dict setObject:@"0" forKeyedSubscript:@"InvoiceType"]; } else{ [dict setObject:_mInvoiceType forKeyedSubscript:@"InvoiceType"]; } if(_mTelephone==nil){ [dict setObject:@"" forKeyedSubscript:@"Telephone"]; } else{ [dict setObject:_mTelephone forKeyedSubscript:@"Telephone"]; } [dict setObject:@"1" forKeyedSubscript:@"IsTotalFlg"]; int correctStatus; if(_correctStatus){ correctStatus=1; } else{ correctStatus=0; } [dict setObject:[NSString stringWithFormat:@"%@",_correctStatus] forKeyedSubscript:@"Status"]; _downManager = [[ASIDownManager alloc] init]; _downManager.delegate = self; _downManager.OnImageDown = @selector(onLoadDetailFinish:); _downManager.OnImageFail = @selector(onLoadDetailFail:); [_downManager postHttpRequest:urlStr dic:dict path:nil fileName:nil]; } /** 加载合集数据 */ - (void)reloadData { [self startLoading]; NSString *urlStr = [NSString stringWithFormat:@"%@", ServerURL]; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:@"GetOrderSalesReportTotalIphone" 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(_mStartDate==nil){ [dict setObject:@"" forKeyedSubscript:@"BeginTime"]; } else{ [dict setObject:_mStartDate forKeyedSubscript:@"BeginTime"]; } if(_mEndDate==nil){ [dict setObject:@"" forKeyedSubscript:@"EndTime"]; } else{ [dict setObject:_mEndDate forKeyedSubscript:@"EndTime"]; } if(_mTelephone==nil){ [dict setObject:@"" forKeyedSubscript:@"Telephone"]; } else{ [dict setObject:_mTelephone forKeyedSubscript:@"Telephone"]; } if(_mInvoiceType==nil){ [dict setObject:@"0" forKeyedSubscript:@"InvoiceType"]; } else{ [dict setObject:_mInvoiceType forKeyedSubscript:@"InvoiceType"]; } if(_mCustomerName==nil){ [dict setObject:@"" forKeyedSubscript:@"CustomerName"]; } else{ [dict setObject:_mCustomerName forKeyedSubscript:@"CustomerName"]; } [dict setObject:@"0" forKeyedSubscript:@"IsTotalFlg"]; [dict setObject:[NSString stringWithFormat:@"%@",_correctStatus] forKeyedSubscript:@"Status"]; _downManager = [[ASIDownManager alloc] init]; _downManager.delegate = self; _downManager.OnImageDown = @selector(onLoadFinish:); _downManager.OnImageFail = @selector(onLoadFail:); [_downManager postHttpRequest:urlStr dic:dict path:nil fileName:nil]; } #pragma mark - 代理函数 /** * 查询正常数据 * * @param sender <#sender description#> */ - (void)onLoadFinish:(ASIDownManager *)sender { // 服务器返回数据 NSDictionary *dic =[[NSDictionary alloc] init]; 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) { _vCustomTableView.tableHeaderView=nil; NSArray * approvArr=[dic objectForKey:@"Result"]; if(approvArr!=nil&&approvArr.count>0) { _vCustomTableView.backgroundView = nil; [_stockArr removeAllObjects]; _vCustomTableView.tableHeaderView = nil; [_stockArr addObjectsFromArray:approvArr]; [_details removeAllObjects]; [_vCustomTableView reloadData]; NSDictionary *dic=_stockArr[0]; NSInteger recount = [[dic objectForKey:@"RecCount"]integerValue]; if(recount>0){ _vCustomTableView.tableHeaderView=_headView; OrderSaleTotalModel *md = [OrderSaleTotalModel orderSaleWithDict:_stockArr[0]]; [self initUIData:md]; } else{ UIView *noDataView=[[UIView alloc]init]; noDataView.frame=_vCustomTableView.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]; _vCustomTableView.backgroundView=noDataView; [self showAlertViewText:@"未找到匹配结果"]; return; } } } // 服务器返回数据状态值异常 else if(iStatus==ActionResultStatusAuthError ||iStatus==ActionResultStatusNoLogin ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid){ [self showReLoginDialog:message]; return; } else { [_details removeAllObjects]; [_vCustomTableView reloadData]; [self showAlertViewText:message]; } } } /** * 异常数据 * * @param sender <#sender description#> */ - (void)onLoadFail:(ASIDownManager *)sender { [self cancel]; [self showAlertViewText:@"加载失败"]; } /** * 列表数据 * * @param sender <#sender description#> */ - (void)onLoadDetailFinish:(ASIDownManager *)sender { NSDictionary *dic =[[NSDictionary alloc] init]; 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) { OrderSaleListModel *md = [OrderSaleListModel orderSaleDetailWithDict:dic]; [detailArray addObject:md]; } _details = detailArray; [_vCustomTableView reloadData]; } } } // 服务器返回数据状态值异常 else if(iStatus==ActionResultStatusAuthError ||iStatus==ActionResultStatusNoLogin ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid) { [self showReLoginDialog:message]; return; } else { [self showAlertViewText:message]; } } } /** 加载失败 @param sender <#sender description#> */ - (void)onLoadDetailFail:(ASIDownManager *)sender { [self cancel]; [self showAlertViewText:@"加载失败"]; } /** * 隐藏进度条 */ - (void)cancel { [self stopLoading]; } @end