// // SalesOrderOptionCombinationPromotionDetailVC.m // IBOSS // // Created by 关宏厚 on 2020/9/14. // Copyright © 2020 elongtian. All rights reserved. // #import "SalesOrderOptionCombinationPromotionDetailVC.h" @interface SalesOrderOptionCombinationPromotionDetailVC () @end @implementation SalesOrderOptionCombinationPromotionDetailVC - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; [self initUI]; } /** 安全区视图发生变化 */ -(void)viewSafeAreaInsetsDidChange{ _vTableView.frame = CGRectMake(0,0,Screen_Width, self.view.superview.frame.size.height-50); [super viewSafeAreaInsetsDidChange]; } /** 键盘弹出 @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)initUI { _vTableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height-rectNavHeight-rectStatusHeight - 100)]; _vTableView.separatorStyle = UITableViewCellSeparatorStyleNone; _vTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight; _vTableView.backgroundColor = [UIColor whiteColor]; _vTableView.delegate = self; _vTableView.dataSource=self; [self.view addSubview:_vTableView]; } -(void)loadData:(NSMutableArray*)promotionGoodsList combinationGoodsList:(NSMutableArray*)combinationGoodsList { _combinationGoodsList=combinationGoodsList; if(promotionGoodsList!=nil&&promotionGoodsList.count>0) { _promotionGoodsDetailList=promotionGoodsList; [_vTableView reloadData]; } } -(void)combinationQuantityChanged:(NSString*)combinationQuantity position:(NSInteger)pos { InventoryListModel *inventoryModel= [_promotionGoodsDetailList objectAtIndex:pos]; if(combinationQuantity==nil||[combinationQuantity isEqualToString:@""]) { combinationQuantity=@"0"; } if(!inventoryModel.giftFlag) { for(int i=0;i<_promotionGoodsDetailList.count;i++) { InventoryListModel *goodsModel=[_promotionGoodsDetailList 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)btnOrderGoodsOptionCombinationCheckPressed:(OrderGoodsSinglePromotionDetailCell*)cell { NSInteger pos= cell.position; InventoryListModel *goodsModel= [_promotionGoodsDetailList objectAtIndex:pos]; goodsModel.isChecked=!goodsModel.isChecked; if( goodsModel.isChecked) { for(int i=0;i<_promotionGoodsDetailList.count;i++) { InventoryListModel *goodsDetailModel=[_promotionGoodsDetailList objectAtIndex:i]; if(pos==i) { [goodsDetailModel setIsChecked:YES]; } else{ [goodsDetailModel setIsChecked:NO]; } } [_vTableView reloadData]; NSMutableArray *combinationGoodsFilterList=[[NSMutableArray alloc]init]; for(int i=0;i<_combinationGoodsList.count;i++) { InventoryListModel *inventoryModel=[_combinationGoodsList objectAtIndex:i]; if([goodsModel.combinationId intValue]==[inventoryModel.combinationId intValue]) { [combinationGoodsFilterList addObject:inventoryModel]; } } if(combinationGoodsFilterList!=nil&&combinationGoodsFilterList.count>0) { InventoryListModel *combinationGoodsModel= [combinationGoodsFilterList objectAtIndex:0]; [combinationGoodsModel setIsCheckedStatus:YES]; __weak typeof(self) weakself=self; if ([weakself.goodsDelegate respondsToSelector:@selector(refreshData:)]){ [weakself.goodsDelegate refreshData:combinationGoodsFilterList]; } } } } /** 高度 @return <#return value description#> */ - (NSMutableDictionary *)heights{ if (_heights == nil){ _heights = [NSMutableDictionary dictionary]; } return _heights; } /** 单元格cell个数 @param tableView <#tableView description#> @param section <#section description#> @return <#return value description#> */ -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [_promotionGoodsDetailList 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]; } /** 预防高度 @param tableView <#tableView description#> @param indexPath <#indexPath description#> @return <#return value description#> */ -(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 355; } /** 每个单元格cell @param tableView <#tableView description#> @param indexPath <#indexPath description#> @return <#return value description#> */ -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"PromotionGoodsDetailListCell"; 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 *promotionGoodsModel= [_promotionGoodsDetailList objectAtIndex:indexPath.row]; cell.delegate=self; cell.position=indexPath.row; [cell setPromotionGoodsDetailCell:promotionGoodsModel isCanChoose:NO]; BOOL checked = promotionGoodsModel.isCheckedStatus; BOOL combinationChecked=promotionGoodsModel.isChecked; [cell setCheckBackground:checked]; [cell setCombinationBackground:combinationChecked]; self.heights[@(indexPath.row)] = @(cell.height); return cell; } @end