// GoodsDetailViewController // IOBSS 2.0 // // Created by on 2017.7.24 // Copyright 2017 沈阳东科云信软件有限公司. All rights reserved. // // 系统名称: // 功能描述:商品详细界面 #import "GoodsDetailViewController.h" #import "XHImageViewer.h" @interface GoodsDetailViewController() { /** 图片点击手势 */ UITapGestureRecognizer *_singleTap; } @end @implementation GoodsDetailViewController #pragma mark - 公共函数 /** viewDidLoad函数 */ - (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.title=@"商品详细"; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button setBackgroundImage:[UIImage imageNamed:@"icon_back.png"] 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; _detailArr = [[NSMutableArray alloc] init]; [self initUI]; [self loadData]; } /** 修改:2017-9-25 适配机型 安全区视图发生变化 */ -(void)viewSafeAreaInsetsDidChange{ _scroll.frame = self.view.safeAreaLayoutGuide.layoutFrame; [super viewSafeAreaInsetsDidChange]; } /** didReceiveMemoryWarning函数 */ - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } #pragma mark - 委托函数 //数据加载成功函数 - (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) { NSArray * approvArr=[dic objectForKey:@"Result"]; if(approvArr!=nil&&approvArr.count>0) { _detailArr= [NSMutableArray arrayWithArray: approvArr]; if( _detailArr.count == 0){ [self showAlertViewText:@"未找到匹配结果"]; } NSDictionary *dic=_detailArr[0]; NSString *Photo = [dic objectForKey:@"Photo"]; if(Photo){ NSData *_decodedImageData = [[NSData alloc] initWithBase64EncodedString:Photo options:(NSDataBase64DecodingIgnoreUnknownCharacters)]; UIImage *_decodedImage = [UIImage imageWithData:_decodedImageData]; _imageView.image = _decodedImage; _imageView.frame =CGRectMake(10, CGRectGetMaxY(_contentView.frame)+10, 85, 85); _scroll.contentSize=CGSizeMake(self.view.frame.size.width, CGRectGetMaxY(_imageView.frame)+10); } _lblCode.text=[NSString stringWithFormat:@"%@",[dic objectForKey:@"Code"] ]; _lblOnlyCode.text=[NSString stringWithFormat:@"%@",[dic objectForKey:@"OnlyCode"]]; _lblBrandName.text=[NSString stringWithFormat:@"%@",[dic objectForKey:@"BrandName"]]; _lblKindName.text=[NSString stringWithFormat:@"%@",[dic objectForKey:@"KindName"]]; _lblVarietyName.text=[NSString stringWithFormat:@"%@",[dic objectForKey:@"VarietyName"]]; _lblSeriesName.text=[NSString stringWithFormat:@"%@",[dic objectForKey:@"SeriesName"]]; _lblColorNumber.text=[NSString stringWithFormat:@"%@",[dic objectForKey:@"ColorNumber"]]; _lblGradeName.text=[NSString stringWithFormat:@"%@",[dic objectForKey:@"GradeName"]]; _lblWarehouseName.text=[NSString stringWithFormat:@"%@",[dic objectForKey:@"WarehouseName"]]; _lblPositionNumber.text=[NSString stringWithFormat:@"%@",[dic objectForKey:@"PositionNumber"]]; _lblSpecification.text=[NSString stringWithFormat:@"%@",[dic objectForKey:@"Specification"]]; _lblWeight.text=[NSString stringWithFormat:@"%@",[dic objectForKey:@"Weight"]]; _lblAcreage.text=[NSString stringWithFormat:@"%@",[dic objectForKey:@"Acreage"]]; _lblPackage.text=[NSString stringWithFormat:@"%@",[dic objectForKey:@"Package"]]; _lblInventoryQuantity.text=[NSString stringWithFormat:@"%@",[dic objectForKey:@"InventoryQuantity"]]; _lblOccupyQuantity.text=[NSString stringWithFormat:@"%@",[dic objectForKey:@"OccupyQuantity"]]; _lblFreezeQuantity.text=[NSString stringWithFormat:@"%@",[dic objectForKey:@"FreezeQuantity"]]; _lblNoDeliveryQuantity.text=[NSString stringWithFormat:@"%@",[dic objectForKey:@"NoDeliveryQuantity"]]; _lblNoEnterQuantity.text=[NSString stringWithFormat:@"%@",[dic objectForKey:@"NoEnterQuantity"]]; _lblBalanceQuantity.text=[NSString stringWithFormat:@"%@",[dic objectForKey:@"BalanceQuantity"]]; } } else if(iStatus==ActionResultStatusAuthError ||iStatus==ActionResultStatusNoLogin ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid){ [self showReLoginDialog:message]; return; } else { [self showAlertViewText:message]; } } } /** 数据加载失败函数 @param sender */ - (void)onLoadFail:(ASIDownManager *)sender { [self cancel]; [self showAlertViewText:@"加载失败"]; } #pragma mark - 私有函数 /** 返回函数 */ - (void)goBack{ [self.navigationController popViewControllerAnimated:YES]; } /** 初始化UI */ - (void)initUI{ _scroll = [UIScrollView new]; _scroll.frame = CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGHT - rectNavHeight - rectStatusHeight); [self.view addSubview:_scroll]; _contentView = [[UIView alloc]init]; _contentView.layer.cornerRadius = CornerRadius; _contentView.backgroundColor = [UIColor whiteColor]; CGFloat xpadding = 5; CGFloat ypadding = 10; _contentView.frame = CGRectZero; [_scroll addSubview:_contentView]; UILabel *lblTitleCode = [[UILabel alloc]init]; lblTitleCode.frame = CGRectMake(xpadding,10,80,25); lblTitleCode.text=@"商品编码:"; lblTitleCode.font=orderTextFont; [_contentView addSubview:lblTitleCode]; _lblCode = [[UILabel alloc]init]; _lblCode.frame=CGRectMake(CGRectGetMaxX(lblTitleCode.frame),10,250, 25); _lblCode.font=orderTextFont; [_contentView addSubview:_lblCode]; UILabel *lblTitleOnlyCode = [[UILabel alloc]init]; lblTitleOnlyCode.frame=CGRectMake(xpadding,CGRectGetMaxY(lblTitleCode.frame)+ypadding,80,25); lblTitleOnlyCode.text=@"唯一编码:"; lblTitleOnlyCode.font=orderTextFont; [_contentView addSubview:lblTitleOnlyCode]; _lblOnlyCode = [[UILabel alloc]init]; _lblOnlyCode.frame=CGRectMake(CGRectGetMaxX(lblTitleOnlyCode.frame),CGRectGetMaxY(lblTitleCode.frame)+ypadding,250, 25); _lblOnlyCode.font=orderTextFont; [_contentView addSubview:_lblOnlyCode]; UILabel *lblTitleBrand = [[UILabel alloc]init]; lblTitleBrand.frame=CGRectMake(xpadding,CGRectGetMaxY(lblTitleOnlyCode.frame)+ypadding,80,25); lblTitleBrand.text=@"品 牌:"; lblTitleBrand.font=orderTextFont; [_contentView addSubview:lblTitleBrand]; _lblBrandName = [[UILabel alloc]init]; _lblBrandName.frame=CGRectMake(CGRectGetMaxX(lblTitleBrand.frame),CGRectGetMaxY(lblTitleOnlyCode.frame)+ypadding,250, 25); _lblBrandName.font=orderTextFont; [_contentView addSubview:_lblBrandName]; UILabel *lblTitleKind = [[UILabel alloc]init]; lblTitleKind.frame=CGRectMake(xpadding,CGRectGetMaxY(lblTitleBrand.frame)+ypadding,80,25); lblTitleKind.text=@"种 类:"; lblTitleKind.font=orderTextFont; [_contentView addSubview:lblTitleKind]; _lblKindName = [[UILabel alloc]init]; _lblKindName.frame=CGRectMake(CGRectGetMaxX(lblTitleKind.frame),CGRectGetMaxY(lblTitleBrand.frame)+ypadding,250, 25); _lblKindName.font=orderTextFont; [_contentView addSubview:_lblKindName]; UILabel *lblTitleVariety = [[UILabel alloc]init]; lblTitleVariety.frame=CGRectMake(xpadding,CGRectGetMaxY(lblTitleKind.frame)+ypadding,80,25); lblTitleVariety.text=@"品 种:"; lblTitleVariety.font=orderTextFont; [_contentView addSubview:lblTitleVariety]; _lblVarietyName = [[UILabel alloc]init]; _lblVarietyName.frame=CGRectMake(CGRectGetMaxX(lblTitleVariety.frame),CGRectGetMaxY(lblTitleKind.frame)+ypadding,250, 25); _lblVarietyName.font=orderTextFont; [_contentView addSubview:_lblVarietyName]; UILabel *lblTitleSeries = [[UILabel alloc]init]; lblTitleSeries.frame=CGRectMake(xpadding,CGRectGetMaxY(lblTitleVariety.frame)+ypadding,80,25); lblTitleSeries.text=@"系 列:"; lblTitleSeries.font=orderTextFont; [_contentView addSubview:lblTitleSeries]; _lblSeriesName = [[UILabel alloc]init]; _lblSeriesName.frame=CGRectMake(CGRectGetMaxX(lblTitleSeries.frame),CGRectGetMaxY(lblTitleVariety.frame)+ypadding,250, 25); _lblSeriesName.font=orderTextFont; [_contentView addSubview:_lblSeriesName]; UILabel *lblTitleColorNumber = [[UILabel alloc]init]; lblTitleColorNumber.frame=CGRectMake(xpadding,CGRectGetMaxY(lblTitleSeries.frame)+ypadding,80,25); lblTitleColorNumber.text=@"色 号:"; lblTitleColorNumber.font=orderTextFont; [_contentView addSubview:lblTitleColorNumber]; _lblColorNumber = [[UILabel alloc]init]; _lblColorNumber.frame=CGRectMake(CGRectGetMaxX(lblTitleColorNumber.frame),CGRectGetMaxY(lblTitleSeries.frame)+ypadding,250, 25); _lblColorNumber.font=orderTextFont; [_contentView addSubview:_lblColorNumber]; UILabel *lblTitleGrade = [[UILabel alloc]init]; lblTitleGrade.frame=CGRectMake(xpadding,CGRectGetMaxY(lblTitleColorNumber.frame)+ypadding,80,25); lblTitleGrade.text=@"等 级:"; lblTitleGrade.font=orderTextFont; [_contentView addSubview:lblTitleGrade]; _lblGradeName = [[UILabel alloc]init]; _lblGradeName.frame=CGRectMake(CGRectGetMaxX(lblTitleGrade.frame),CGRectGetMaxY(lblTitleColorNumber.frame)+ypadding,250, 25); _lblGradeName.font=orderTextFont; [_contentView addSubview:_lblGradeName]; UILabel *lblTitleWarehouse = [[UILabel alloc]init]; lblTitleWarehouse.frame=CGRectMake(xpadding,CGRectGetMaxY(lblTitleGrade.frame)+ypadding,80,25); lblTitleWarehouse.text=@"库 区:"; lblTitleWarehouse.font=orderTextFont; [_contentView addSubview:lblTitleWarehouse]; _lblWarehouseName = [[UILabel alloc]init]; _lblWarehouseName.frame=CGRectMake(CGRectGetMaxX(lblTitleWarehouse.frame),CGRectGetMaxY(lblTitleGrade.frame)+ypadding,250, 25); _lblWarehouseName.font=orderTextFont; [_contentView addSubview:_lblWarehouseName]; UILabel *lblTitlePositionNumber = [[UILabel alloc]init]; lblTitlePositionNumber.frame=CGRectMake(xpadding,CGRectGetMaxY(lblTitleWarehouse.frame)+ypadding,80,25); lblTitlePositionNumber.text=@"仓 位 号:"; lblTitlePositionNumber.font=orderTextFont; [_contentView addSubview:lblTitlePositionNumber]; _lblPositionNumber = [[UILabel alloc]init]; _lblPositionNumber.frame=CGRectMake(CGRectGetMaxX(lblTitlePositionNumber.frame),CGRectGetMaxY(lblTitleWarehouse.frame)+ypadding,250, 25); _lblPositionNumber.font=orderTextFont; [_contentView addSubview:_lblPositionNumber]; UILabel *lblTitleSpecification = [[UILabel alloc]init]; lblTitleSpecification.frame=CGRectMake(xpadding,CGRectGetMaxY(lblTitlePositionNumber.frame)+ypadding,80,25); lblTitleSpecification.text=@"规 格:"; lblTitleSpecification.font=orderTextFont; [_contentView addSubview:lblTitleSpecification]; _lblSpecification = [[UILabel alloc]init]; _lblSpecification.frame=CGRectMake(CGRectGetMaxX(lblTitleSpecification.frame),CGRectGetMaxY(lblTitlePositionNumber.frame)+ypadding,250, 25); _lblSpecification.font=orderTextFont; [_contentView addSubview:_lblSpecification]; UILabel *lblTitleWeight = [[UILabel alloc]init]; lblTitleWeight.frame=CGRectMake(xpadding,CGRectGetMaxY(lblTitleSpecification.frame)+ypadding,80,25); lblTitleWeight.text=@"重 量:"; lblTitleWeight.font=orderTextFont; [_contentView addSubview:lblTitleWeight]; _lblWeight = [[UILabel alloc]init]; _lblWeight.frame=CGRectMake(CGRectGetMaxX(lblTitleWeight.frame),CGRectGetMaxY(lblTitleSpecification.frame)+ypadding,250, 25); _lblWeight.font=orderTextFont; [_contentView addSubview:_lblWeight]; UILabel *lblTitleAreage = [[UILabel alloc]init]; lblTitleAreage.frame=CGRectMake(xpadding,CGRectGetMaxY(lblTitleWeight.frame)+ypadding,80,25); lblTitleAreage.text=@"面 积:"; lblTitleAreage.font=orderTextFont; [_contentView addSubview:lblTitleAreage]; _lblAcreage = [[UILabel alloc]init]; _lblAcreage.frame=CGRectMake(CGRectGetMaxX(lblTitleAreage.frame),CGRectGetMaxY(lblTitleWeight.frame)+ypadding,250, 25); _lblAcreage.font=orderTextFont; [_contentView addSubview:_lblAcreage]; UILabel *lblTitlePackage = [[UILabel alloc]init]; lblTitlePackage.frame=CGRectMake(xpadding,CGRectGetMaxY(lblTitleAreage.frame)+ypadding,80,25); lblTitlePackage.text=@"包 装:"; lblTitlePackage.font=orderTextFont; [_contentView addSubview:lblTitlePackage]; _lblPackage = [[UILabel alloc]init]; _lblPackage.frame=CGRectMake(CGRectGetMaxX(lblTitlePackage.frame),CGRectGetMaxY(lblTitleAreage.frame)+ypadding,250, 25); _lblPackage.font=orderTextFont; [_contentView addSubview:_lblPackage]; UILabel *lblTitleInventoryQuantity = [[UILabel alloc]init]; lblTitleInventoryQuantity.frame=CGRectMake(xpadding,CGRectGetMaxY(lblTitlePackage.frame)+ypadding,80,25); lblTitleInventoryQuantity.text=@"库 存 量:"; lblTitleInventoryQuantity.font=orderTextFont; [_contentView addSubview:lblTitleInventoryQuantity]; _lblInventoryQuantity = [[UILabel alloc]init]; _lblInventoryQuantity.frame=CGRectMake(CGRectGetMaxX(lblTitleInventoryQuantity.frame),CGRectGetMaxY(lblTitlePackage.frame)+ypadding,250, 25); _lblInventoryQuantity.font=orderTextFont; [_contentView addSubview:_lblInventoryQuantity]; UILabel *lblTitleOccupyQuantity = [[UILabel alloc]init]; lblTitleOccupyQuantity.frame=CGRectMake(xpadding,CGRectGetMaxY( lblTitleInventoryQuantity.frame)+ypadding,80,25); lblTitleOccupyQuantity.text=@"占 库 量:"; lblTitleOccupyQuantity.font=orderTextFont; [_contentView addSubview:lblTitleOccupyQuantity]; _lblOccupyQuantity = [[UILabel alloc]init]; _lblOccupyQuantity.frame=CGRectMake(CGRectGetMaxX(lblTitleOccupyQuantity.frame),CGRectGetMaxY( lblTitleInventoryQuantity.frame)+ypadding,250, 25); _lblOccupyQuantity.font=orderTextFont; [_contentView addSubview:_lblOccupyQuantity]; UILabel *lblTitleFreezeQuantity = [[UILabel alloc]init]; lblTitleFreezeQuantity.frame=CGRectMake(xpadding,CGRectGetMaxY(lblTitleOccupyQuantity.frame)+ypadding,80,25); lblTitleFreezeQuantity.text=@"冻 结 量:"; lblTitleFreezeQuantity.font=orderTextFont; [_contentView addSubview:lblTitleFreezeQuantity]; _lblFreezeQuantity = [[UILabel alloc]init]; _lblFreezeQuantity.frame=CGRectMake(CGRectGetMaxX(lblTitleFreezeQuantity.frame),CGRectGetMaxY(lblTitleOccupyQuantity.frame)+ypadding,250, 25); _lblFreezeQuantity.font=orderTextFont; [_contentView addSubview:_lblFreezeQuantity]; UILabel *lblTitleNoDeliveryQuantity = [[UILabel alloc]init]; lblTitleNoDeliveryQuantity.frame=CGRectMake(xpadding,CGRectGetMaxY(lblTitleFreezeQuantity.frame)+ypadding,80,25); lblTitleNoDeliveryQuantity.text=@"未 提 量:"; lblTitleNoDeliveryQuantity.font=orderTextFont; [_contentView addSubview:lblTitleNoDeliveryQuantity]; _lblNoDeliveryQuantity = [[UILabel alloc]init]; _lblNoDeliveryQuantity.frame=CGRectMake(CGRectGetMaxX(lblTitleNoDeliveryQuantity.frame),CGRectGetMaxY(lblTitleFreezeQuantity.frame)+ypadding,250, 25); _lblNoDeliveryQuantity.font=orderTextFont; [_contentView addSubview:_lblNoDeliveryQuantity]; UILabel *lblTitleNoEnterQuantity = [[UILabel alloc]init]; lblTitleNoEnterQuantity.frame=CGRectMake(xpadding,CGRectGetMaxY(lblTitleNoDeliveryQuantity.frame)+ypadding,80,25); lblTitleNoEnterQuantity.text=@"未 入 量:"; lblTitleNoEnterQuantity.font=orderTextFont; [_contentView addSubview:lblTitleNoEnterQuantity]; _lblNoEnterQuantity = [[UILabel alloc]init]; _lblNoEnterQuantity.frame=CGRectMake(CGRectGetMaxX(lblTitleNoEnterQuantity.frame),CGRectGetMaxY(lblTitleNoDeliveryQuantity.frame)+ypadding,250, 25); _lblNoEnterQuantity.font=orderTextFont; [_contentView addSubview:_lblNoEnterQuantity]; UILabel *lblTitleBalanceQuantity = [[UILabel alloc]init]; lblTitleBalanceQuantity.frame=CGRectMake(xpadding,CGRectGetMaxY(lblTitleNoEnterQuantity.frame)+ypadding,80,25); lblTitleBalanceQuantity.text=@"可 售 量:"; lblTitleBalanceQuantity.font=orderTextFont; [_contentView addSubview:lblTitleBalanceQuantity]; _lblBalanceQuantity = [[UILabel alloc]init]; _lblBalanceQuantity.frame=CGRectMake(CGRectGetMaxX(lblTitleBalanceQuantity.frame),CGRectGetMaxY(lblTitleNoEnterQuantity.frame)+ypadding,250, 25); _lblBalanceQuantity.font=orderTextFont; [_contentView addSubview:_lblBalanceQuantity]; _contentView.frame=CGRectMake(10,10, Screen_Width-20, CGRectGetMaxY( lblTitleBalanceQuantity.frame)); _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(5, CGRectGetMaxY(_contentView.frame)+10, 85, 0)]; [_imageView setUserInteractionEnabled:YES]; _singleTap =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onClickImage)]; [_imageView addGestureRecognizer:_singleTap]; [_scroll addSubview:_imageView]; _scroll.contentSize=CGSizeMake(self.view.frame.size.width, CGRectGetMaxY(_imageView.frame)); } /** 图片点击事件 */ - (void) onClickImage { NSMutableArray *arr = [[NSMutableArray alloc] init]; [arr addObject:_imageView]; XHImageViewer *imageViewer = [[XHImageViewer alloc] init]; imageViewer.delegate = self; [imageViewer showWithImageViews:arr selectedView:_imageView]; [_imageView removeGestureRecognizer:_singleTap]; } /** 图片缩小添加手势 @param imageViewer @param selectedView */ - (void)imageViewer:(XHImageViewer *)imageViewer willDismissWithSelectedView:(UIImageView*)selectedView { [_imageView addGestureRecognizer:_singleTap]; } /** 加载数据函数 */ - (void)loadData { self.mDownManager = [[ASIDownManager alloc] init]; _mDownManager.delegate = self; _mDownManager.OnImageDown = @selector(onLoadFinish:); _mDownManager.OnImageFail = @selector(onLoadFail:); [self startLoading]; NSString *urlStr = ServerURL; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:@"GetInventoryDetailIphone" 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:_inventoryId forKey:@"InventoryID"]; [_mDownManager postHttpRequest:urlStr dic:dict path:nil fileName:nil]; } /** 进度条取消 */ - (void)cancel { [self stopLoading]; } @end