// // PromotionGoodsDetailVC.m // IBOSS // // Created by 关宏厚 on 2020/9/9. // Copyright © 2020 elongtian. All rights reserved. // #import "OrderGoodsSinglePromotionDetailVC.h" @interface OrderGoodsSinglePromotionDetailVC () @end @implementation OrderGoodsSinglePromotionDetailVC - (void)viewDidLoad { [super viewDidLoad]; [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; [self loadNavStyle]; [self initUI]; _isCanChoose=[self isCanChooseFullGift]; [self loadGoodsDetail]; } /** 导航按钮样式 */ -(void)loadNavStyle { self.navigationItem.title=@"促销品详细"; //返回 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)initUI { [self.view setBackgroundColor:[UIColor whiteColor]]; UIImage *pic = [UIImage imageNamed:@"bt_datasave"]; CGFloat h = 50; _vTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-h)]; _vTableView.separatorStyle = UITableViewCellSeparatorStyleNone; _vTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight; _vTableView.backgroundColor = [UIColor whiteColor]; _vTableView.delegate = self; _vTableView.dataSource=self; [self.view addSubview: _vTableView]; //保存按钮 _btnSave = [UIButton buttonWithType:UIButtonTypeCustom]; _btnSave.frame=CGRectMake(0, self.view.frame.size.height-h, Screen_Width,h) ; [_btnSave setBackgroundImage:pic forState:UIControlStateNormal]; [_btnSave addTarget:self action:@selector(saveData) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:_btnSave]; } /** 键盘弹出 @param note */ - (void)keyboardWillShow:(NSNotification *)note { CGRect keyBoardRect = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; _vTableView.contentInset = UIEdgeInsetsMake(0, 0, keyBoardRect.size.height, 0); } /** 键盘隐藏 @param note */ - (void)keyboardWillHide:(NSNotification *)note { _vTableView.contentInset = UIEdgeInsetsZero; } /** 屏幕触摸回调函数 @param touches <#touches description#> @param event <#event description#> */ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [self.view endEditing:YES]; } /** scrollview回调函数 @param scrollView <#scrollView description#> */ - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{ [self.view endEditing:YES]; } /** 安全区视图发生变化 */ -(void)viewSafeAreaInsetsDidChange{ _vTableView.frame =CGRectMake(0, 0, self.view.frame.size.width,self.view.safeAreaLayoutGuide.layoutFrame.size.height-50); _btnSave.frame=CGRectMake(0, self.view.safeAreaLayoutGuide.layoutFrame.size.height-50, self.view.frame.size.width, 50); [super viewSafeAreaInsetsDidChange]; } -(void)saveData{ if([_promotionOrderModel.promotionTypeId intValue]==4||[_promotionOrderModel.promotionTypeId intValue]==3){ BOOL isCanChooseDiscount=[self isCanChooseDiscount]; if(!isCanChooseDiscount) { [self showAlertViewText:@"不满足该促销条件"]; return; } } NSMutableArray *submitOrderGoodsList=[[NSMutableArray alloc]init]; double giftAmount=0; if(_orderGoodsDetailList!=nil&&_orderGoodsDetailList.count>0) { for(int i=0;i<_orderGoodsDetailList.count;i++) { InventoryListModel *goodsModel=[_orderGoodsDetailList objectAtIndex:i]; if(goodsModel.isCheckedStatus) { [submitOrderGoodsList addObject:goodsModel]; } } } if(submitOrderGoodsList!=nil&&submitOrderGoodsList.count>0) { if([_promotionOrderModel.promotionTypeId intValue]==2) { int giftNum=0; int noGiftNum=0; for(int i=0;i_promotionOrderModel.giftGoodsNumber) { [self showAlertViewText:@"赠品选择个数大于促销赠品可选个数"]; return; } } else if([_promotionOrderModel.promotionTypeId intValue]==3) { int giftNum=0; for(int i=0;i_promotionOrderModel.giftGoodsNumber) { [self showAlertViewText:@"满再送促销赠品数量选择不符"]; return; } } } else { if([_promotionOrderModel.promotionTypeId intValue]==3||[_promotionOrderModel.promotionTypeId intValue]==4) { if([_promotionOrderModel.promotionTypeId intValue]==3) { double promotionAmount=0; double factGoodsAmount=0; if(_promotionOrderModel.reachAmountFlag) { NSMutableArray *promotionOrderList=[[NSMutableArray alloc]init]; for(int i=0;i<_orderGoodsDetailList.count;i++) { InventoryListModel *goodsModel=[_orderGoodsDetailList objectAtIndex:i]; if(goodsModel.promotionDetailId!=nil&&goodsModel.promotionDetailId.length>0) { [promotionOrderList addObject:goodsModel]; } } if(promotionOrderList!=nil&&promotionOrderList.count>0) { for(int i=0;i0) { [promotionOrderGoodsList addObject:inventoryModel]; } } if(promotionOrderGoodsList!=nil&&promotionOrderGoodsList.count>0) { for(int i=0;i0) { [promotionGoodsList addObject:goodsModel]; } } double factMarkAmount=0; for(int i=0;idiscount) { isCanChoose=NO; } } else { if(_promotionOrderModel.reachDiscount>[_fullDiscount doubleValue]) { isCanChoose=NO; } } } } return isCanChoose; } -(BOOL) isCanChooseFullGift { double factGoodsAmount=0; double promotionAmount=0; BOOL isCanChoose=YES; NSMutableArray *promotionOrderList=[[NSMutableArray alloc]init]; if([_promotionOrderModel reachAmountFlag]) { if(_orderGoodsDetailList!=nil&&_orderGoodsDetailList.count>0) { for(int i=0;i<_orderGoodsDetailList.count;i++) { InventoryListModel *inventoryModel=[_orderGoodsDetailList objectAtIndex:i]; if(inventoryModel.promotionDetailId!=nil&&inventoryModel.promotionDetailId.length>0) { [promotionOrderList addObject:inventoryModel]; } } if(promotionOrderList!=nil&&promotionOrderList.count>0) { for(int i=0;i0)) { continue; } if(inventoryModel.discount!=nil&&inventoryModel.discount.length>0) { detailDiscount=[inventoryModel.discount doubleValue]; if(detailDiscount<_promotionOrderModel.reachDiscount) { isCanChoose=NO; break; } } else { isCanChoose=NO; break; } } } } } return isCanChoose; } -(void)loadGoodsDetail { [self startLoading]; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:@"GetPromotionDetailData" 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:_code forKeyedSubscript:@"Code"]; [dict setObject:_brandId forKeyedSubscript:@"BrandID"]; [dict setObject:_kindCode forKeyedSubscript:@"KindCode"]; [dict setObject:_warehouseId forKeyedSubscript:@"WarehouseID"]; [dict setObject:_varietyId forKeyedSubscript:@"VarietyID"]; [dict setObject:_seriesId forKeyedSubscript:@"SeriesID"]; [dict setObject:_specification forKeyedSubscript:@"Specification"]; [dict setObject:_onlyCode forKeyedSubscript:@"OnlyCode"]; [dict setObject:_colorNumber forKeyedSubscript:@"ColorNumber"]; [dict setObject:_gradeIds forKeyedSubscript:@"GradeIDs"]; [dict setObject:_promotionTypeId forKeyedSubscript:@"PromotionsType"]; [dict setObject:_promotionDetailName forKeyedSubscript:@"PromotionDetailName"]; [dict setObject:_promotionName forKeyedSubscript:@"PromotionName"]; [dict setObject:_organizationCode forKeyedSubscript:@"OrganizationCode"]; [dict setObject:_promotionOrderModel.detailId forKeyedSubscript:@"DetailID"]; _downManager = [[ASIDownManager alloc] init]; [self startLoading]; _downManager.delegate = self; _downManager.onRequestSuccess = @selector(onPromotionGoodsListLoadFinish:); _downManager.onRequestFail = @selector(onPromotionGoodsListLoadFail:); [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil]; } -(void)onPromotionGoodsListLoadFinish:(ASIDownManager *)sender { NSDictionary *dic = [sender.mWebStr JSONValue]; [self stopLoading]; // 服务器返回数据是否正确 if (dic && [dic isKindOfClass:[NSDictionary class]]) { // 服务器返回数据状态值 int iStatus = [[dic objectForKey:@"Status"] intValue]; int iNewCount = 0; // 服务器返回数据消息 NSString *message=[dic objectForKey:@"Message"]; // 服务器返回数据状态值正确 if (iStatus == 0) { NSDictionary *resultDic=[dic objectForKey:@"Result"]; NSArray *resultArray= [resultDic objectForKey:@"Table"]; if(resultArray!=nil&&resultArray.count>0) { _orderGoodsDetailList=[[NSMutableArray alloc]init]; for(int i=0;i0) { OrderQuantity *orderQuantity=[OrderQuantity new]; [orderQuantity setSalesOrderDetailBoxAndPiece:[goodsQuantity intValue] inventoryModel:inventoryModel]; if([goodsQuantity doubleValue]>0) { [inventoryModel setIsCheckedStatus:YES]; } else { [inventoryModel setIsCheckedStatus:NO]; } } else { [inventoryModel setIsCheckedStatus:NO]; } [_vTableView reloadData]; } -(void)combinationQuantityChanged:(NSString*)combinationQuantity position:(NSInteger)pos { InventoryListModel *inventoryModel= [_orderGoodsDetailList objectAtIndex:pos]; if(combinationQuantity==nil||[combinationQuantity isEqualToString:@""]) { combinationQuantity=@"0"; } if(!inventoryModel.giftFlag) { for(int i=0;i<_orderGoodsDetailList.count;i++) { InventoryListModel *goodsModel=[_orderGoodsDetailList objectAtIndex:i]; if(!goodsModel.giftFlag) { NSString *goodsQuantityHide=goodsModel.goodsQuantityHide; int decimalPlaces=[goodsModel.decimalPlaces intValue]; double goodsQuantity=[goodsQuantityHide doubleValue]*[combinationQuantity doubleValue]; NSString *decimalPlacesStr=[NSString stringWithFormat:@"%@%d%@",@"%.",decimalPlaces,@"f"]; NSString *goodsQuantityStr=[NSString stringWithFormat:decimalPlacesStr,goodsQuantity]; [goodsModel setSalesQuantity:goodsQuantityStr]; [goodsModel setCombinationQuantity:combinationQuantity]; if([combinationQuantity intValue]>0) { [goodsModel setIsCheckedStatus:YES]; } else{ [goodsModel setIsCheckedStatus:NO]; } } } } else{ double goodsQuantityHideValue= [inventoryModel.goodsQuantityHide doubleValue]; double goodsQuantityValue=goodsQuantityHideValue*[combinationQuantity doubleValue]; int decimalPlaces=[[inventoryModel decimalPlaces]intValue]; NSString *decimalPlacesStr=[NSString stringWithFormat:@"%@%d%@",@"%.",decimalPlaces,@"f"]; NSString *goodsQuantity=[NSString stringWithFormat:decimalPlacesStr,goodsQuantityValue]; [inventoryModel setSalesQuantity:goodsQuantity]; [inventoryModel setCombinationQuantity:combinationQuantity]; if([combinationQuantity intValue]>0) { [inventoryModel setIsCheckedStatus:YES]; } else{ [inventoryModel setIsCheckedStatus:NO]; } } [_vTableView reloadData]; } -(void)btnOrderGoodsSinglePromotionCheckPressed:(OrderGoodsSinglePromotionDetailCell*)cell { NSInteger pos= cell.position; InventoryListModel *goodsModel= [_orderGoodsDetailList objectAtIndex:pos]; goodsModel.isCheckedStatus=!goodsModel.isCheckedStatus; [cell setCheckBackground: goodsModel.isCheckedStatus]; } /** 单元格cell个数 @param tableView <#tableView description#> @param section <#section description#> @return <#return value description#> */ -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [_orderGoodsDetailList count]; } /** <#Description#> @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]; } /** 每个单元格cell @param tableView <#tableView description#> @param indexPath <#indexPath description#> @return <#return value description#> */ -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"OrderGoodsListCell"; OrderGoodsSinglePromotionDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier ]; if (!cell) { cell=[[OrderGoodsSinglePromotionDetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; cell.selectionStyle=UITableViewCellSelectionStyleNone; } else //当页面拉动的时候 当cell存在并且最后一个存在 把它进行删除就出来一个独特的cell我们在进行数据配置即可避免 { while ([cell.contentView.subviews lastObject] != nil) { [(UIView *)[cell.contentView.subviews lastObject] removeFromSuperview]; } } InventoryListModel *goodsModel= [_orderGoodsDetailList objectAtIndex:indexPath.row]; cell.delegate = self; cell.position=indexPath.row; [cell setPromotionGoodsDetailCell:goodsModel isCanChoose:_isCanChoose]; self.heights[@(indexPath.row)] = @(cell.height); BOOL checked = goodsModel.isCheckedStatus; [cell setCheckBackground:checked]; return cell; } /** 预防高度 @param tableView <#tableView description#> @param indexPath <#indexPath description#> @return <#return value description#> */ -(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 355; } /** 高度 @return <#return value description#> */ - (NSMutableDictionary *)heights{ if (_heights == nil){ _heights = [NSMutableDictionary dictionary]; } return _heights; } /** 返回函数 */ - (void)goBack { [self.navigationController popViewControllerAnimated:YES]; } @end