// ReceiptDetailViewController // IOBSS 2.0 // // Created by 刘瀚璘 on 2017.7.18 // Copyright 2017 沈阳东科云信软件有限公司. All rights reserved. // // 系统名称: // 功能描述:定制品回执详细 #import "ReceiptDetailViewController.h" #import "ReceiptDetailModel.h" #import "CustomerReceiptDetailCell.h" #import "AlbumPhotoCollectionViewCell.h" #import "XHImageViewer.h" @interface ReceiptDetailViewController (){ /** 安排单号 */ UILabel *_lblArrangementNo; /** 回执类型 */ UILabel *_lblRecReceiptType; /** 客户名称 */ UILabel *_lblCustomerName; /** 联系人 */ UILabel *_lblContacts; /** 送货单号 */ UILabel *_lblDeliveryNo; /** 送货地址 */ UILabel *_lblDeliveryAddress; /** 应收金额 */ UILabel *_lblReceivables; /** 已回执金额 */ UILabel *_lblCompleteReceivables; /** 回执金额 */ UILabel *_lblReceiptAmount; /** 应收方式 */ UILabel *_lblReceivablesType; /** 单据回收标示 */ UILabel *_lblRecoverFlag; /** 回执状态 */ UILabel *_lblReceiptStatus; /** 记录cell的高度的数组 */ NSMutableDictionary *_dicCellHeight; /** 圆角布局 */ UIView *_content; /** scrollView */ UIScrollView *_scrollView; /** 位置 */ UIView *_positionImage; /** 位置 */ UILabel *_lblPosition; /** 位置 */ NSString *_strPosition; } @end @implementation ReceiptDetailViewController #pragma mark - 公共函数 /** 公共函数 */ - (void)viewDidLoad { [super viewDidLoad]; [self initUI]; [self reloadData]; } /** 安全区视图发生变化 */ -(void)viewSafeAreaInsetsDidChange{ _scrollView.frame = self.view.safeAreaLayoutGuide.layoutFrame; [super viewSafeAreaInsetsDidChange]; } #pragma mark - 请求数据 /** 请求数据 */ - (void)reloadData { _dicCellHeight = [NSMutableDictionary dictionary]; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:@"GetFixedReceiptDetailIphone" 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:_deliveryID forKey:@"FixedID"]; [dict setObject:_arrangementID forKey:@"ArrangementID"]; [dict setObject:_receiptNo forKey:@"ReceiptNo"]; _downManager = [[ASIDownManager alloc] init]; _downManager.delegate = self; _downManager.onRequestSuccess = @selector(onLoadFinish:); _downManager.onRequestFail = @selector(onLoadFail:); [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil]; } #pragma mark - 数据回调 /** 数据回调成功 @param sender */ - (void)onLoadFinish:(ASIDownManager *)sender { // 服务器返回数据 RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr]; // 服务器返回数据状态值 int iStatus = resultModel.status; // 服务器返回数据消息 NSString *message = resultModel.message; // 服务器返回数据状态值正确 if (iStatus == 0){ NSDictionary *dic = (NSDictionary *)resultModel.result; if(dic != nil){ NSArray *array = [dic objectForKey:@"Table"]; for (int i = 0; i < array.count; i++) { NSDictionary *dic = array[i]; if([dic objectForKey:@"ArrangementNo"]){ _lblArrangementNo.text = [NSString stringWithFormat:@"安排单号:%@",[dic objectForKey:@"ArrangementNo"]]; } if([dic objectForKey:@"recReceiptType"]){ if([[dic objectForKey:@"recReceiptType"]boolValue]){ _lblRecReceiptType.text = [NSString stringWithFormat:@"回执类型:%@",@"撤销回执"]; }else { _lblRecReceiptType.text = [NSString stringWithFormat:@"回执类型:%@",@"回执"]; } } if([dic objectForKey:@"CustomerName"]){ _lblCustomerName.text = [NSString stringWithFormat:@"客户名称:%@",[dic objectForKey:@"CustomerName"]];; } if([dic objectForKey:@"Contacts"]){ _lblContacts.text = [NSString stringWithFormat:@"联 系 人:%@",[dic objectForKey:@"Contacts"]];; } if([dic objectForKey:@"FixedNo"]){ _lblDeliveryNo.text = [NSString stringWithFormat:@"售前单号:%@",[dic objectForKey:@"FixedNo"]];; } if([dic objectForKey:@"Receivables"]){ NSString *str = [NSString stringWithFormat:@"%0.2f",[[dic objectForKey:@"Receivables"] doubleValue]]; _lblReceivables.text = [NSString stringWithFormat:@"应收金额:%@",str];; } if([dic objectForKey:@"CompleteReceivables"]){ NSString *str = [NSString stringWithFormat:@"%0.2f",[[dic objectForKey:@"CompleteReceivables"] doubleValue]]; _lblCompleteReceivables.text = [NSString stringWithFormat:@"已回执金额:%@",str]; } if([dic objectForKey:@"ReceiptAmount"]){ NSString *str = [NSString stringWithFormat:@"%0.2f",[[dic objectForKey:@"ReceiptAmount"] doubleValue]]; _lblReceiptAmount.text = [NSString stringWithFormat:@"回执金额:%@",str]; } if([dic objectForKey:@"ReceivablesType"]){ _lblReceivablesType.text = [NSString stringWithFormat:@"应收方式:%@",[dic objectForKey:@"ReceivablesType"]]; } if([[dic objectForKey:@"ReceiptStatus"] boolValue]){ _lblReceiptStatus.text = [NSString stringWithFormat:@"回执状态:%@",@"完成"]; }else{ _lblReceiptStatus.text = [NSString stringWithFormat:@"回执状态:%@",@"再次安排"]; } } NSArray *arrImage = [dic objectForKey:@"ImagePath"]; if(arrImage){ _arrImagePaths = [[NSMutableArray alloc] init]; [_arrImagePaths addObjectsFromArray:arrImage]; } NSArray *arrPosition = [dic objectForKey:@"Position"]; if(arrPosition.count != 0) { //共一条数据 NSDictionary * dicPositon = arrPosition[0]; _strPosition = [dicPositon objectForKey:@"Position"]; } _arrData = [[NSMutableArray alloc] init]; NSArray *arrTable1 = [dic objectForKey:@"Table1"]; for (int i = 0; i < arrTable1.count; i++) { NSDictionary *dic = arrTable1[i]; ReceiptDetailModel *model = [ReceiptDetailModel dk_modelWithDictionary:dic]; [_arrData insertObject:model atIndex:0]; if([model.receiptRemarks isEqualToString:@""]){ //不加空格计算不出备注的高度 model.receiptRemarks = @" "; } _dicCellHeight[@(arrTable1.count - 1 - i)] = @([model.receiptRemarks sizeWithFont:[UIFont systemFontOfSize:13] constrainedToSize:CGSizeMake(SCREENWIDTH-110, MAXFLOAT)].height + 389); } CGFloat tableViewHeight; for (int i = 0; i < _dicCellHeight.count; i++) { tableViewHeight = tableViewHeight + [_dicCellHeight[@(i)] floatValue]; } _tableView.frame = CGRectMake(0,CGRectGetMaxY(_content.frame)+10, SCREENWIDTH, tableViewHeight+10); [_tableView reloadData]; [_collectionView reloadData]; } } else if(iStatus == ActionResultStatusAuthError ||iStatus == ActionResultStatusNoLogin ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){ [self showReLoginDialog:message]; } else{ // [self.tableView reloadData]; [self showAlertViewText:message]; } } /** 数据回调失败 @param sender */ - (void)onLoadFail:(ASIDownManager *)sender { //[self.tableView reloadData]; [self showAlertViewText:@"网络异常"]; } #pragma mark - 自定义方法 /** 刷新ScrollView高度 */ - (void)refreshHeight { _scrollView.contentSize = CGSizeMake(SCREENWIDTH, CGRectGetMaxY(_tableView.frame)+10); _collectionView.frame = CGRectMake(0, CGRectGetMaxY(_tableView.frame) , SCREENWIDTH,[Util getPhotoCollectionViewHeightWithPhotos :_arrImagePaths]); _scrollView.contentSize = CGSizeMake(SCREENWIDTH, CGRectGetMaxY(_collectionView.frame)+10); [_collectionView reloadData]; if(_strPosition == nil){ _positionImage.hidden = YES; }else{ _positionImage.hidden = NO; _positionImage.frame = CGRectMake(0, CGRectGetMaxY(_collectionView.frame)+8, Screen_Width,30); _lblPosition.text = _strPosition; _scrollView.contentSize = CGSizeMake(SCREENWIDTH, CGRectGetMaxY(_positionImage.frame)+10); } } #pragma mark - tableView实现的方法 /** 组数 @param tableView @return */ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1; } /** 返回cell @param tableView @param indexPath @return */ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *str = @"CustomerReceiptDetailCell"; CustomerReceiptDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:str]; if(cell == nil){ NSArray *nibs = [[NSBundle mainBundle]loadNibNamed:@"CustomerReceiptDetailCell" owner:nil options:nil]; cell = [nibs lastObject]; } ReceiptDetailModel *model = [_arrData objectAtIndex:indexPath.row]; cell.model = model; [cell loadCell]; return cell; } /** 每组多少行 @param tableView @param section @return */ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return _arrData.count; } /** 预估高度 @param tableView tableView @param indexPath 组数,行数的封装 @return 预估高度值 */ - (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 170; } /** tableview将要加载完 @param tableView @param cell @param indexPath */ - (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { if([indexPath row] == ((NSIndexPath*)[[tableView indexPathsForVisibleRows] lastObject]).row){ [self refreshHeight]; } } #pragma mark - collectionviewdelegate collectionviewdatasource /** 个数 @param collectionView @param section @return */ - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ return _arrImagePaths.count; } /** 返回cell @param collectionView @param indexPath @return */ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ static NSString *PhotoCollectionViewCellIdentifier = @"PhotoCollectionViewCellIdentifier"; AlbumPhotoCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:PhotoCollectionViewCellIdentifier forIndexPath:indexPath]; NSArray *followInfoarray = _arrImagePaths; cell.indexPath = indexPath; //Image *image1 = [followInfoarray objectAtIndex:indexPath.row]; NSString *imagepath = [[followInfoarray objectAtIndex:indexPath.row]objectForKey:@"ImagePath"]; if(imagepath != nil&&[imagepath length]>0){ NSString *imageUrl= [NSString stringWithFormat:@"http://%@:%@/WebService/%@",kkServerUrl,kkServerPort,imagepath]; NSURL *url = [NSURL URLWithString:imageUrl]; [cell.photoImageView setImageWithURL:url placeholderImage:nil]; } return cell; } /** 点击图片 @param collectionView @param indexPath */ - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ AlbumPhotoCollectionViewCell *cell = (AlbumPhotoCollectionViewCell *)[self.collectionView cellForItemAtIndexPath:indexPath]; NSMutableArray *imageViews = [NSMutableArray array]; NSArray *visibleCell = [self.collectionView visibleCells]; NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:@"indexPath" ascending:YES]; visibleCell = [visibleCell sortedArrayUsingDescriptors:[NSArray arrayWithObject:sort]]; [visibleCell enumerateObjectsUsingBlock:^(AlbumPhotoCollectionViewCell *cell, NSUInteger idx, BOOL *stop) { [imageViews addObject:[[cell.contentView subviews] lastObject]]; }]; XHImageViewer *imageViewer = [[XHImageViewer alloc] init]; [imageViewer showWithImageViews:imageViews selectedView:[[cell.contentView subviews] lastObject]]; } - (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath{ return YES; } #pragma mark - 初始化布局 /** 初始化布局 */ - (void)initUI { self.navigationItem.title = @"定制品售前回执明细"; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button setImage:[UIImage imageNamed:@"icon_back.png"] 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; self.view.frame = CGRectMake(0, 0, self.view.frame.size.width, Screen_Height-rectStatusHeight-rectNavHeight); _scrollView = [[UIScrollView alloc]initWithFrame:self.view.frame]; _scrollView.backgroundColor = [UIColor colorWithRed:234.0/255 green:235.0/255 blue:236.0/255 alpha:1]; [self.view addSubview:_scrollView]; //圆角布局 _content = [[UIView alloc] init]; _content.frame = CGRectMake(10, 10, SCREENWIDTH-20, 500); _content.backgroundColor = [UIColor whiteColor]; _content.layer.masksToBounds = YES; _content.layer.cornerRadius = CornerRadius; _content.layer.borderWidth = 0.0; [_scrollView addSubview:_content]; //回执单号 UILabel *lblReceiptNo = [[UILabel alloc] initWithFrame:CGRectMake(10,10, SCREENWIDTH-30, 14)]; lblReceiptNo.text = [NSString stringWithFormat:@"回执单号:%@",_receiptNo]; lblReceiptNo.font = [UIFont systemFontOfSize:14]; [_content addSubview:lblReceiptNo]; UIImageView *line = [[UIImageView alloc]initWithFrame:CGRectMake(0, 34, SCREENWIDTH-20, 1)]; [line setImage:[UIImage imageNamed:@"titlebotton"]]; [_content addSubview:line]; //回执类型 _lblRecReceiptType = [[UILabel alloc] initWithFrame:CGRectMake(10,CGRectGetMaxY(line.frame)+10, SCREENWIDTH-30, 13)]; _lblRecReceiptType.text = [NSString stringWithFormat:@"回执类型:%@",@""]; _lblRecReceiptType.font = [UIFont systemFontOfSize:13]; [_content addSubview:_lblRecReceiptType]; //安排单号 _lblArrangementNo = [[UILabel alloc] initWithFrame:CGRectMake(10,CGRectGetMaxY(_lblRecReceiptType.frame)+10, SCREENWIDTH-30, 13)]; _lblArrangementNo.text = [NSString stringWithFormat:@"安排单号:%@",@""]; _lblArrangementNo.font = [UIFont systemFontOfSize:13]; [_content addSubview:_lblArrangementNo]; //售前单号 _lblDeliveryNo = [[UILabel alloc] initWithFrame:CGRectMake(10,CGRectGetMaxY(_lblArrangementNo.frame)+10, SCREENWIDTH-30, 13)]; _lblDeliveryNo.text = [NSString stringWithFormat:@"售前单号:%@",@""]; _lblDeliveryNo.font = [UIFont systemFontOfSize:13]; [_content addSubview:_lblDeliveryNo]; _lblCustomerName = [[UILabel alloc] initWithFrame:CGRectMake(10,CGRectGetMaxY(_lblDeliveryNo.frame)+10, SCREENWIDTH-30, 13)]; _lblCustomerName.text = [NSString stringWithFormat:@"客户名称:%@",@""]; _lblCustomerName.font = [UIFont systemFontOfSize:13]; [_content addSubview:_lblCustomerName]; _lblContacts = [[UILabel alloc] initWithFrame:CGRectMake(10,CGRectGetMaxY(_lblCustomerName.frame)+10, SCREENWIDTH-30, 13)]; _lblContacts.text = [NSString stringWithFormat:@"联 系 人:%@",@""]; _lblContacts.font = [UIFont systemFontOfSize:13]; [_content addSubview:_lblContacts]; _lblReceiptStatus = [[UILabel alloc] initWithFrame:CGRectMake(10,CGRectGetMaxY(_lblContacts.frame)+10, SCREENWIDTH-30, 13)]; _lblReceiptStatus.text = [NSString stringWithFormat:@"回执状态:%@",@""]; _lblReceiptStatus.font = [UIFont systemFontOfSize:13]; [_content addSubview:_lblReceiptStatus]; _lblReceivables = [[UILabel alloc] initWithFrame:CGRectMake(10,CGRectGetMaxY(_lblReceiptStatus.frame)+10, SCREENWIDTH-30, 13)]; _lblReceivables.text = [NSString stringWithFormat:@"应收金额:%@",@""]; _lblReceivables.font = [UIFont systemFontOfSize:13]; [_content addSubview:_lblReceivables]; _lblReceivablesType = [[UILabel alloc] initWithFrame:CGRectMake(10,CGRectGetMaxY(_lblReceivables.frame)+10, SCREENWIDTH-30, 13)]; _lblReceivablesType.text = [NSString stringWithFormat:@"应收方式:%@",@""]; _lblReceivablesType.font = [UIFont systemFontOfSize:13]; [_content addSubview:_lblReceivablesType]; _lblCompleteReceivables = [[UILabel alloc] initWithFrame:CGRectMake(10,CGRectGetMaxY(_lblReceivablesType.frame)+10, SCREENWIDTH-30, 13)]; _lblCompleteReceivables.text = [NSString stringWithFormat:@"已回执金额:%@",@""]; _lblCompleteReceivables.font = [UIFont systemFontOfSize:13]; [_content addSubview:_lblCompleteReceivables]; _lblReceiptAmount = [[UILabel alloc] initWithFrame:CGRectMake(10,CGRectGetMaxY(_lblCompleteReceivables.frame)+10, SCREENWIDTH-30, 13)]; _lblReceiptAmount.text = [NSString stringWithFormat:@"回执金额:%@",@""]; _lblReceiptAmount.font = [UIFont systemFontOfSize:13]; [_content addSubview:_lblReceiptAmount]; _content.frame = CGRectMake(10, 10, SCREENWIDTH-20, CGRectGetMaxY(_lblReceiptAmount.frame)+10); _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(_content.frame)+10, SCREENWIDTH, 200) style:UITableViewStylePlain]; _tableView.scrollEnabled=NO; _tableView.delegate = self; [self.tableView registerNib:[UINib nibWithNibName:@"CustomerReceiptDetailCell"bundle:[NSBundle mainBundle]]forCellReuseIdentifier:@"CustomerReceiptDetailCell"]; _tableView.rowHeight = UITableViewAutomaticDimension; _tableView.backgroundColor = _scrollView.backgroundColor; _tableView.separatorStyle = UITableViewCellSeparatorStyleNone; _tableView.dataSource = self; [_scrollView addSubview:_tableView]; UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; flowLayout.itemSize = CGSizeMake(85, 85); flowLayout.minimumInteritemSpacing = 5; flowLayout.minimumLineSpacing = 10; flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical; flowLayout.sectionInset = UIEdgeInsetsMake(7, 20, 0, 20); _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_tableView.frame)+10 , SCREENWIDTH,0) collectionViewLayout:flowLayout]; [self.collectionView registerClass:[AlbumPhotoCollectionViewCell class] forCellWithReuseIdentifier:@"PhotoCollectionViewCellIdentifier"]; _collectionView.dataSource = self; _collectionView.delegate = self; self.collectionView.backgroundColor = [UIColor colorWithRed:234.0/255 green:235.0/255 blue:236.0/255 alpha:1]; [_scrollView addSubview:_collectionView]; //位置view _positionImage = [[UIView alloc] init]; _positionImage.frame=CGRectMake(0, CGRectGetMaxY(_collectionView.frame)+8, Screen_Width, 0); _positionImage.hidden = YES; [_scrollView addSubview:_positionImage]; //星号 UIImageView *ivposition = [UIImageView new]; ivposition.frame=CGRectMake(12,4,9,12); ivposition.image = [UIImage imageNamed:@"icon_position"]; [_positionImage addSubview:ivposition]; _lblPosition = [[UILabel alloc] init]; _lblPosition.font= [UIFont systemFontOfSize:14]; _lblPosition.frame=CGRectMake(28, 0, Screen_Width-32, 20); [_positionImage addSubview:_lblPosition]; } @end