| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298 |
- //
- // 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
|