SalesOrderOptionCombinationPromotionDetailVC.m 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. //
  2. // SalesOrderOptionCombinationPromotionDetailVC.m
  3. // IBOSS
  4. //
  5. // Created by 关宏厚 on 2020/9/14.
  6. // Copyright © 2020 elongtian. All rights reserved.
  7. //
  8. #import "SalesOrderOptionCombinationPromotionDetailVC.h"
  9. @interface SalesOrderOptionCombinationPromotionDetailVC ()
  10. @end
  11. @implementation SalesOrderOptionCombinationPromotionDetailVC
  12. - (void)viewDidLoad {
  13. [super viewDidLoad];
  14. self.view.backgroundColor = [UIColor whiteColor];
  15. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
  16. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
  17. [self initUI];
  18. }
  19. /**
  20. 安全区视图发生变化
  21. */
  22. -(void)viewSafeAreaInsetsDidChange{
  23. _vTableView.frame = CGRectMake(0,0,Screen_Width, self.view.superview.frame.size.height-50);
  24. [super viewSafeAreaInsetsDidChange];
  25. }
  26. /**
  27. 键盘弹出
  28. @param note
  29. */
  30. - (void)keyboardWillShow:(NSNotification *)note
  31. {
  32. CGRect keyBoardRect = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
  33. _vTableView.contentInset = UIEdgeInsetsMake(0, 0, keyBoardRect.size.height, 0);
  34. }
  35. /**
  36. 键盘隐藏
  37. @param note
  38. */
  39. - (void)keyboardWillHide:(NSNotification *)note
  40. {
  41. _vTableView.contentInset = UIEdgeInsetsZero;
  42. }
  43. /**
  44. 屏幕触摸回调函数
  45. @param touches <#touches description#>
  46. @param event <#event description#>
  47. */
  48. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
  49. {
  50. [self.view endEditing:YES];
  51. }
  52. /**
  53. scrollview回调函数
  54. @param scrollView <#scrollView description#>
  55. */
  56. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
  57. [self.view endEditing:YES];
  58. }
  59. -(void)initUI
  60. {
  61. _vTableView = [[UITableView alloc]
  62. initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height-rectNavHeight-rectStatusHeight - 100)];
  63. _vTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  64. _vTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
  65. _vTableView.backgroundColor = [UIColor whiteColor];
  66. _vTableView.delegate = self;
  67. _vTableView.dataSource=self;
  68. [self.view addSubview:_vTableView];
  69. }
  70. -(void)loadData:(NSMutableArray*)promotionGoodsList combinationGoodsList:(NSMutableArray*)combinationGoodsList
  71. {
  72. _combinationGoodsList=combinationGoodsList;
  73. if(promotionGoodsList!=nil&&promotionGoodsList.count>0)
  74. {
  75. _promotionGoodsDetailList=promotionGoodsList;
  76. [_vTableView reloadData];
  77. }
  78. }
  79. -(void)combinationQuantityChanged:(NSString*)combinationQuantity position:(NSInteger)pos
  80. {
  81. InventoryListModel *inventoryModel= [_promotionGoodsDetailList objectAtIndex:pos];
  82. if(combinationQuantity==nil||[combinationQuantity isEqualToString:@""])
  83. {
  84. combinationQuantity=@"0";
  85. }
  86. if(!inventoryModel.giftFlag)
  87. {
  88. for(int i=0;i<_promotionGoodsDetailList.count;i++)
  89. {
  90. InventoryListModel *goodsModel=[_promotionGoodsDetailList objectAtIndex:i];
  91. if(!goodsModel.giftFlag)
  92. {
  93. NSString *goodsQuantityHide=goodsModel.goodsQuantityHide;
  94. int decimalPlaces=[goodsModel.decimalPlaces intValue];
  95. double goodsQuantity=[goodsQuantityHide doubleValue]*[combinationQuantity doubleValue];
  96. NSString *decimalPlacesStr=[NSString stringWithFormat:@"%@%d%@",@"%.",decimalPlaces,@"f"];
  97. NSString *goodsQuantityStr=[NSString stringWithFormat:decimalPlacesStr,goodsQuantity];
  98. [goodsModel setSalesQuantity:goodsQuantityStr];
  99. [goodsModel setCombinationQuantity:combinationQuantity];
  100. if([combinationQuantity intValue]>0)
  101. {
  102. [goodsModel setIsCheckedStatus:YES];
  103. }
  104. else{
  105. [goodsModel setIsCheckedStatus:NO];
  106. }
  107. }
  108. }
  109. }
  110. else{
  111. double goodsQuantityHideValue= [inventoryModel.goodsQuantityHide doubleValue];
  112. double goodsQuantityValue=goodsQuantityHideValue*[combinationQuantity doubleValue];
  113. int decimalPlaces=[[inventoryModel decimalPlaces]intValue];
  114. NSString *decimalPlacesStr=[NSString stringWithFormat:@"%@%d%@",@"%.",decimalPlaces,@"f"];
  115. NSString *goodsQuantity=[NSString stringWithFormat:decimalPlacesStr,goodsQuantityValue];
  116. [inventoryModel setSalesQuantity:goodsQuantity];
  117. [inventoryModel setCombinationQuantity:combinationQuantity];
  118. if([combinationQuantity intValue]>0)
  119. {
  120. [inventoryModel setIsCheckedStatus:YES];
  121. }
  122. else{
  123. [inventoryModel setIsCheckedStatus:NO];
  124. }
  125. }
  126. [_vTableView reloadData];
  127. }
  128. -(void)btnOrderGoodsOptionCombinationCheckPressed:(OrderGoodsSinglePromotionDetailCell*)cell
  129. {
  130. NSInteger pos= cell.position;
  131. InventoryListModel *goodsModel= [_promotionGoodsDetailList objectAtIndex:pos];
  132. goodsModel.isChecked=!goodsModel.isChecked;
  133. if( goodsModel.isChecked)
  134. {
  135. for(int i=0;i<_promotionGoodsDetailList.count;i++)
  136. {
  137. InventoryListModel *goodsDetailModel=[_promotionGoodsDetailList objectAtIndex:i];
  138. if(pos==i)
  139. {
  140. [goodsDetailModel setIsChecked:YES];
  141. }
  142. else{
  143. [goodsDetailModel setIsChecked:NO];
  144. }
  145. }
  146. [_vTableView reloadData];
  147. NSMutableArray *combinationGoodsFilterList=[[NSMutableArray alloc]init];
  148. for(int i=0;i<_combinationGoodsList.count;i++)
  149. {
  150. InventoryListModel *inventoryModel=[_combinationGoodsList objectAtIndex:i];
  151. if([goodsModel.combinationId intValue]==[inventoryModel.combinationId intValue])
  152. {
  153. [combinationGoodsFilterList addObject:inventoryModel];
  154. }
  155. }
  156. if(combinationGoodsFilterList!=nil&&combinationGoodsFilterList.count>0)
  157. {
  158. InventoryListModel *combinationGoodsModel= [combinationGoodsFilterList objectAtIndex:0];
  159. [combinationGoodsModel setIsCheckedStatus:YES];
  160. __weak typeof(self) weakself=self;
  161. if ([weakself.goodsDelegate respondsToSelector:@selector(refreshData:)]){
  162. [weakself.goodsDelegate refreshData:combinationGoodsFilterList];
  163. }
  164. }
  165. }
  166. }
  167. /**
  168. 高度
  169. @return <#return value description#>
  170. */
  171. - (NSMutableDictionary *)heights{
  172. if (_heights == nil){
  173. _heights = [NSMutableDictionary dictionary];
  174. }
  175. return _heights;
  176. }
  177. /**
  178. 单元格cell个数
  179. @param tableView <#tableView description#>
  180. @param section <#section description#>
  181. @return <#return value description#>
  182. */
  183. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  184. {
  185. return [_promotionGoodsDetailList count];
  186. }
  187. /**
  188. <#Description#>
  189. @param tableView <#tableView description#>
  190. @return <#return value description#>
  191. */
  192. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  193. return 1;
  194. }
  195. /**
  196. 高度
  197. @param tableView <#tableView description#>
  198. @param indexPath <#indexPath description#>
  199. @return <#return value description#>
  200. */
  201. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  202. return [self.heights[@(indexPath.row)] floatValue];
  203. }
  204. /**
  205. 预防高度
  206. @param tableView <#tableView description#>
  207. @param indexPath <#indexPath description#>
  208. @return <#return value description#>
  209. */
  210. -(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
  211. return 355;
  212. }
  213. /**
  214. 每个单元格cell
  215. @param tableView <#tableView description#>
  216. @param indexPath <#indexPath description#>
  217. @return <#return value description#>
  218. */
  219. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  220. {
  221. static NSString *CellIdentifier = @"PromotionGoodsDetailListCell";
  222. OrderGoodsSinglePromotionDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier ];
  223. if (!cell) {
  224. cell=[[OrderGoodsSinglePromotionDetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  225. cell.selectionStyle=UITableViewCellSelectionStyleNone;
  226. }
  227. else
  228. //当页面拉动的时候 当cell存在并且最后一个存在 把它进行删除就出来一个独特的cell我们在进行数据配置即可避免
  229. {
  230. while ([cell.contentView.subviews lastObject] != nil) {
  231. [(UIView *)[cell.contentView.subviews lastObject] removeFromSuperview];
  232. }
  233. }
  234. InventoryListModel *promotionGoodsModel= [_promotionGoodsDetailList objectAtIndex:indexPath.row];
  235. cell.delegate=self;
  236. cell.position=indexPath.row;
  237. [cell setPromotionGoodsDetailCell:promotionGoodsModel isCanChoose:NO];
  238. BOOL checked = promotionGoodsModel.isCheckedStatus;
  239. BOOL combinationChecked=promotionGoodsModel.isChecked;
  240. [cell setCheckBackground:checked];
  241. [cell setCombinationBackground:combinationChecked];
  242. self.heights[@(indexPath.row)] = @(cell.height);
  243. return cell;
  244. }
  245. @end