OrderGoodsSinglePromotionDetailVC.m 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  1. //
  2. // PromotionGoodsDetailVC.m
  3. // IBOSS
  4. //
  5. // Created by 关宏厚 on 2020/9/9.
  6. // Copyright © 2020 elongtian. All rights reserved.
  7. //
  8. #import "OrderGoodsSinglePromotionDetailVC.h"
  9. @interface OrderGoodsSinglePromotionDetailVC ()
  10. @end
  11. @implementation OrderGoodsSinglePromotionDetailVC
  12. - (void)viewDidLoad {
  13. [super viewDidLoad];
  14. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
  15. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
  16. [self loadNavStyle];
  17. [self initUI];
  18. _isCanChoose=[self isCanChooseFullGift];
  19. [self loadGoodsDetail];
  20. }
  21. /**
  22. 导航按钮样式
  23. */
  24. -(void)loadNavStyle
  25. {
  26. self.navigationItem.title=@"促销品详细";
  27. //返回
  28. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  29. [button setBackgroundImage:[UIImage imageNamed:@"icon_back"]
  30. forState:UIControlStateNormal];
  31. [button addTarget:self action:@selector(goBack)
  32. forControlEvents:UIControlEventTouchUpInside];
  33. button.frame = CGRectMake(0, 0, 15, 18);
  34. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  35. self.navigationItem.leftBarButtonItem = menuButton;
  36. }
  37. -(void)initUI
  38. {
  39. [self.view setBackgroundColor:[UIColor whiteColor]];
  40. UIImage *pic = [UIImage imageNamed:@"bt_datasave"];
  41. CGFloat h = 50;
  42. _vTableView = [[UITableView alloc]
  43. initWithFrame:CGRectMake(0,
  44. 0,
  45. self.view.frame.size.width,
  46. self.view.frame.size.height-h)];
  47. _vTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  48. _vTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
  49. _vTableView.backgroundColor = [UIColor whiteColor];
  50. _vTableView.delegate = self;
  51. _vTableView.dataSource=self;
  52. [self.view addSubview: _vTableView];
  53. //保存按钮
  54. _btnSave = [UIButton buttonWithType:UIButtonTypeCustom];
  55. _btnSave.frame=CGRectMake(0, self.view.frame.size.height-h, Screen_Width,h) ;
  56. [_btnSave setBackgroundImage:pic forState:UIControlStateNormal];
  57. [_btnSave addTarget:self action:@selector(saveData) forControlEvents:UIControlEventTouchUpInside];
  58. [self.view addSubview:_btnSave];
  59. }
  60. /**
  61. 键盘弹出
  62. @param note
  63. */
  64. - (void)keyboardWillShow:(NSNotification *)note
  65. {
  66. CGRect keyBoardRect = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
  67. _vTableView.contentInset = UIEdgeInsetsMake(0, 0, keyBoardRect.size.height, 0);
  68. }
  69. /**
  70. 键盘隐藏
  71. @param note
  72. */
  73. - (void)keyboardWillHide:(NSNotification *)note
  74. {
  75. _vTableView.contentInset = UIEdgeInsetsZero;
  76. }
  77. /**
  78. 屏幕触摸回调函数
  79. @param touches <#touches description#>
  80. @param event <#event description#>
  81. */
  82. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
  83. {
  84. [self.view endEditing:YES];
  85. }
  86. /**
  87. scrollview回调函数
  88. @param scrollView <#scrollView description#>
  89. */
  90. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
  91. [self.view endEditing:YES];
  92. }
  93. /**
  94. 安全区视图发生变化
  95. */
  96. -(void)viewSafeAreaInsetsDidChange{
  97. _vTableView.frame =CGRectMake(0, 0, self.view.frame.size.width,self.view.safeAreaLayoutGuide.layoutFrame.size.height-50);
  98. _btnSave.frame=CGRectMake(0, self.view.safeAreaLayoutGuide.layoutFrame.size.height-50, self.view.frame.size.width, 50);
  99. [super viewSafeAreaInsetsDidChange];
  100. }
  101. -(void)saveData{
  102. if([_promotionOrderModel.promotionTypeId intValue]==4||[_promotionOrderModel.promotionTypeId intValue]==3){
  103. BOOL isCanChooseDiscount=[self isCanChooseDiscount];
  104. if(!isCanChooseDiscount)
  105. {
  106. [self showAlertViewText:@"不满足该促销条件"];
  107. return;
  108. }
  109. }
  110. NSMutableArray *submitOrderGoodsList=[[NSMutableArray alloc]init];
  111. double giftAmount=0;
  112. if(_orderGoodsDetailList!=nil&&_orderGoodsDetailList.count>0)
  113. {
  114. for(int i=0;i<_orderGoodsDetailList.count;i++)
  115. {
  116. InventoryListModel *goodsModel=[_orderGoodsDetailList objectAtIndex:i];
  117. if(goodsModel.isCheckedStatus)
  118. {
  119. [submitOrderGoodsList addObject:goodsModel];
  120. }
  121. }
  122. }
  123. if(submitOrderGoodsList!=nil&&submitOrderGoodsList.count>0)
  124. {
  125. if([_promotionOrderModel.promotionTypeId intValue]==2)
  126. {
  127. int giftNum=0;
  128. int noGiftNum=0;
  129. for(int i=0;i<submitOrderGoodsList.count;i++)
  130. {
  131. InventoryListModel *inventoryModel=[submitOrderGoodsList objectAtIndex:i];
  132. if(!inventoryModel.giftFlag)
  133. {
  134. if(noGiftNum==0)
  135. {
  136. noGiftNum= [inventoryModel.combinationQuantity intValue];
  137. }
  138. }
  139. else{
  140. giftNum++;
  141. }
  142. }
  143. if(giftNum>_promotionOrderModel.giftGoodsNumber)
  144. {
  145. [self showAlertViewText:@"赠品选择个数大于促销赠品可选个数"];
  146. return;
  147. }
  148. }
  149. else if([_promotionOrderModel.promotionTypeId intValue]==3)
  150. {
  151. int giftNum=0;
  152. for(int i=0;i<submitOrderGoodsList.count;i++)
  153. {
  154. InventoryListModel *goodsDetailModel=[submitOrderGoodsList objectAtIndex:i];
  155. giftNum+=[goodsDetailModel.salesQuantity doubleValue];
  156. }
  157. if(giftNum>_promotionOrderModel.giftGoodsNumber)
  158. {
  159. [self showAlertViewText:@"满再送促销赠品数量选择不符"];
  160. return;
  161. }
  162. }
  163. }
  164. else
  165. {
  166. if([_promotionOrderModel.promotionTypeId intValue]==3||[_promotionOrderModel.promotionTypeId intValue]==4)
  167. {
  168. if([_promotionOrderModel.promotionTypeId intValue]==3)
  169. {
  170. double promotionAmount=0;
  171. double factGoodsAmount=0;
  172. if(_promotionOrderModel.reachAmountFlag)
  173. {
  174. NSMutableArray *promotionOrderList=[[NSMutableArray alloc]init];
  175. for(int i=0;i<_orderGoodsDetailList.count;i++)
  176. {
  177. InventoryListModel *goodsModel=[_orderGoodsDetailList objectAtIndex:i];
  178. if(goodsModel.promotionDetailId!=nil&&goodsModel.promotionDetailId.length>0)
  179. {
  180. [promotionOrderList addObject:goodsModel];
  181. }
  182. }
  183. if(promotionOrderList!=nil&&promotionOrderList.count>0)
  184. {
  185. for(int i=0;i<promotionOrderList.count;i++)
  186. {
  187. InventoryListModel *goodsModel=[promotionOrderList objectAtIndex:i];
  188. promotionAmount+=[goodsModel.salesPrice doubleValue]*[goodsModel.salesQuantity doubleValue];
  189. }
  190. }
  191. factGoodsAmount=[_goodsAmount doubleValue]-promotionAmount;
  192. double num=floor(factGoodsAmount/_promotionOrderModel.reachAmount);
  193. giftAmount=_promotionOrderModel.giftAmount*num;
  194. }
  195. }
  196. }
  197. else
  198. {
  199. [self showAlertViewText:@"没有选择任何数据"];
  200. return;
  201. }
  202. }
  203. if([self.orderDelegate respondsToSelector:@selector(updatePromotionGoodsData: goodsDetailList:giftAmount: goodsDetailDic:)])
  204. {
  205. [self.orderDelegate updatePromotionGoodsData:_promotionOrderModel goodsDetailList:submitOrderGoodsList giftAmount:giftAmount goodsDetailDic:nil];
  206. [self.navigationController popViewControllerAnimated:YES];
  207. }
  208. }
  209. -(BOOL) isCanChooseDiscount
  210. {
  211. double factGoodsAmount=0;
  212. double promotionAmount=0;
  213. BOOL isCanChoose=YES;
  214. NSMutableArray *promotionOrderGoodsList=[[NSMutableArray alloc]init];
  215. if(_promotionOrderModel.reachAmountFlag)
  216. {
  217. for(int i=0;i<_orderGoodsDetailList.count;i++)
  218. {
  219. InventoryListModel *inventoryModel=[_orderGoodsDetailList objectAtIndex:i];
  220. if(inventoryModel.projectDetailID!=nil&&inventoryModel.projectDetailID.length>0)
  221. {
  222. [promotionOrderGoodsList addObject:inventoryModel];
  223. }
  224. }
  225. if(promotionOrderGoodsList!=nil&&promotionOrderGoodsList.count>0)
  226. {
  227. for(int i=0;i<promotionOrderGoodsList.count;i++)
  228. {
  229. InventoryListModel *inventoryModel=[promotionOrderGoodsList objectAtIndex:i];
  230. promotionAmount+=[inventoryModel.salesPrice doubleValue]*[inventoryModel.salesQuantity doubleValue];
  231. }
  232. }
  233. if(_goodsAmount==nil||[_goodsAmount isEqualToString:@""])
  234. {
  235. _goodsAmount=@"0";
  236. }
  237. factGoodsAmount=[_goodsAmount doubleValue]-promotionAmount;
  238. if(_promotionOrderModel.reachAmount!=0&&factGoodsAmount<_promotionOrderModel.reachAmount)
  239. {
  240. isCanChoose=NO;
  241. }
  242. if(isCanChoose)
  243. {
  244. if(_promotionOrderModel.reachDiscountFlag)
  245. {
  246. NSMutableArray *promotionGoodsList=[[NSMutableArray alloc]init];
  247. for(int i=0;i<_orderGoodsDetailList.count;i++)
  248. {
  249. InventoryListModel *goodsModel=[_orderGoodsDetailList objectAtIndex:i];
  250. if(goodsModel.promotionDetailId!=nil&&goodsModel.promotionDetailId.length>0)
  251. {
  252. [promotionGoodsList addObject:goodsModel];
  253. }
  254. }
  255. double factMarkAmount=0;
  256. for(int i=0;i<promotionGoodsList.count;i++)
  257. {
  258. InventoryListModel *goodsModel=[promotionGoodsList objectAtIndex:i];
  259. factMarkAmount+=[goodsModel.salesQuantity doubleValue]*[goodsModel.markedPrice doubleValue];
  260. promotionAmount+=[goodsModel.salesQuantity doubleValue]*[goodsModel.salesPrice doubleValue];
  261. }
  262. if(_markPriceAmount==nil||[_markPriceAmount isEqualToString:@""])
  263. {
  264. _markPriceAmount=@"0";
  265. }
  266. double discount=[_markPriceAmount doubleValue]-factMarkAmount==0?0:([_goodsAmount doubleValue]-promotionAmount)*100/([_markPriceAmount doubleValue]-factMarkAmount);
  267. if(_promotionOrderModel.reachDiscount>discount)
  268. {
  269. isCanChoose=NO;
  270. }
  271. }
  272. else
  273. {
  274. if(_promotionOrderModel.reachDiscount>[_fullDiscount doubleValue])
  275. {
  276. isCanChoose=NO;
  277. }
  278. }
  279. }
  280. }
  281. return isCanChoose;
  282. }
  283. -(BOOL) isCanChooseFullGift
  284. {
  285. double factGoodsAmount=0;
  286. double promotionAmount=0;
  287. BOOL isCanChoose=YES;
  288. NSMutableArray *promotionOrderList=[[NSMutableArray alloc]init];
  289. if([_promotionOrderModel reachAmountFlag])
  290. {
  291. if(_orderGoodsDetailList!=nil&&_orderGoodsDetailList.count>0)
  292. {
  293. for(int i=0;i<_orderGoodsDetailList.count;i++)
  294. {
  295. InventoryListModel *inventoryModel=[_orderGoodsDetailList objectAtIndex:i];
  296. if(inventoryModel.promotionDetailId!=nil&&inventoryModel.promotionDetailId.length>0)
  297. {
  298. [promotionOrderList addObject:inventoryModel];
  299. }
  300. }
  301. if(promotionOrderList!=nil&&promotionOrderList.count>0)
  302. {
  303. for(int i=0;i<promotionOrderList.count;i++)
  304. {
  305. InventoryListModel *inventoryModel=[promotionOrderList objectAtIndex:i];
  306. promotionAmount+=[inventoryModel.salesPrice doubleValue]*[inventoryModel.salesQuantity doubleValue ];
  307. }
  308. }
  309. if(_goodsAmount==nil||[_goodsAmount isEqualToString:@""])
  310. {
  311. _goodsAmount=@"0";
  312. }
  313. factGoodsAmount=[_goodsAmount doubleValue]-promotionAmount;
  314. if(_promotionOrderModel.reachAmount!=0&&factGoodsAmount<_promotionOrderModel.reachAmount)
  315. {
  316. isCanChoose=NO;
  317. }
  318. if(isCanChoose&&_promotionOrderModel.reachDiscount!=0)
  319. {
  320. double detailDiscount=0;
  321. for(int i=0;i<_orderGoodsDetailList.count;i++)
  322. {
  323. InventoryListModel *inventoryModel=[_orderGoodsDetailList objectAtIndex:i];
  324. if(!_promotionOrderModel.reachDiscountFlag&&(inventoryModel.promotionDetailId!=nil&&inventoryModel.promotionDetailId.length>0))
  325. {
  326. continue;
  327. }
  328. if(inventoryModel.discount!=nil&&inventoryModel.discount.length>0)
  329. {
  330. detailDiscount=[inventoryModel.discount doubleValue];
  331. if(detailDiscount<_promotionOrderModel.reachDiscount)
  332. {
  333. isCanChoose=NO;
  334. break;
  335. }
  336. }
  337. else
  338. {
  339. isCanChoose=NO;
  340. break;
  341. }
  342. }
  343. }
  344. }
  345. }
  346. return isCanChoose;
  347. }
  348. -(void)loadGoodsDetail
  349. {
  350. [self startLoading];
  351. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  352. [dict setObject:@"GetPromotionDetailData" forKey:@"Action"];
  353. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  354. [dict setObject:kkUserCode forKey:@"UserCode"];
  355. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  356. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  357. [dict setObject:_code forKeyedSubscript:@"Code"];
  358. [dict setObject:_brandId forKeyedSubscript:@"BrandID"];
  359. [dict setObject:_kindCode forKeyedSubscript:@"KindCode"];
  360. [dict setObject:_warehouseId forKeyedSubscript:@"WarehouseID"];
  361. [dict setObject:_varietyId forKeyedSubscript:@"VarietyID"];
  362. [dict setObject:_seriesId forKeyedSubscript:@"SeriesID"];
  363. [dict setObject:_specification forKeyedSubscript:@"Specification"];
  364. [dict setObject:_onlyCode forKeyedSubscript:@"OnlyCode"];
  365. [dict setObject:_colorNumber forKeyedSubscript:@"ColorNumber"];
  366. [dict setObject:_gradeIds forKeyedSubscript:@"GradeIDs"];
  367. [dict setObject:_promotionTypeId forKeyedSubscript:@"PromotionsType"];
  368. [dict setObject:_promotionDetailName forKeyedSubscript:@"PromotionDetailName"];
  369. [dict setObject:_promotionName forKeyedSubscript:@"PromotionName"];
  370. [dict setObject:_organizationCode forKeyedSubscript:@"OrganizationCode"];
  371. [dict setObject:_promotionOrderModel.detailId forKeyedSubscript:@"DetailID"];
  372. _downManager = [[ASIDownManager alloc] init];
  373. [self startLoading];
  374. _downManager.delegate = self;
  375. _downManager.onRequestSuccess = @selector(onPromotionGoodsListLoadFinish:);
  376. _downManager.onRequestFail = @selector(onPromotionGoodsListLoadFail:);
  377. [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
  378. }
  379. -(void)onPromotionGoodsListLoadFinish:(ASIDownManager *)sender {
  380. NSDictionary *dic = [sender.mWebStr JSONValue];
  381. [self stopLoading];
  382. // 服务器返回数据是否正确
  383. if (dic && [dic isKindOfClass:[NSDictionary class]]) {
  384. // 服务器返回数据状态值
  385. int iStatus = [[dic objectForKey:@"Status"] intValue];
  386. int iNewCount = 0;
  387. // 服务器返回数据消息
  388. NSString *message=[dic objectForKey:@"Message"];
  389. // 服务器返回数据状态值正确
  390. if (iStatus == 0)
  391. {
  392. NSDictionary *resultDic=[dic objectForKey:@"Result"];
  393. NSArray *resultArray= [resultDic objectForKey:@"Table"];
  394. if(resultArray!=nil&&resultArray.count>0)
  395. {
  396. _orderGoodsDetailList=[[NSMutableArray alloc]init];
  397. for(int i=0;i<resultArray.count;i++)
  398. {
  399. NSDictionary *dic=[resultArray objectAtIndex:i];
  400. InventoryListModel *model = [InventoryListModel new];
  401. model.promotionGoodsId=[dic objectForKey:@"PromotionGoodsID"];
  402. int promotionDetailId= [[dic objectForKey:@"PromotionDetailID"]intValue];
  403. model.promotionDetailId=[NSString stringWithFormat:@"%d",promotionDetailId];
  404. model.codeId=[[dic objectForKey:@"CodeID"]intValue];
  405. model.code=[dic objectForKey:@"Code"];
  406. model.onlyCode=[dic objectForKey:@"OnlyCode"];
  407. model.specification=[dic objectForKey:@"Specification"];
  408. model.brandId=[dic objectForKey:@"BrandID"];
  409. model.brandName=[dic objectForKey:@"BrandName"];
  410. model.gradeId=[[dic objectForKey:@"GradeID"]intValue];
  411. model.gradeName=[dic objectForKey:@"GradeName"];
  412. model.kindId=[dic objectForKey:@"KindID"];
  413. model.kindName=[dic objectForKey:@"KindName"];
  414. model.seriesId=[dic objectForKey:@"SeriesID"];
  415. model.seriesName=[dic objectForKey:@"SeriesName"];
  416. model.varietyId=[dic objectForKey:@"VarietyID"];
  417. model.varietyName=[dic objectForKey:@"VarietyName"];
  418. model.unitId=[dic objectForKey:@"UnitID"];
  419. model.unitName=[dic objectForKey:@"UnitName"];
  420. model.warehouseId=[dic objectForKey:@"WarehouseID"];
  421. model.wareHouseName=[dic objectForKey:@"WarehouseName"];
  422. model.positionNumber=[dic objectForKey:@"PositionNumber"];
  423. double salesPriceValue= [[dic objectForKey:@"SalsePrice"]doubleValue];
  424. model.salesPrice=[NSString stringWithFormat:@"%lf",salesPriceValue];
  425. model.usePositionId=@"0";
  426. model.giftFlag=[[dic objectForKey:@"GiftGoodsFlag"]boolValue];
  427. int goodsNumberValue= [[dic objectForKey:@"GoodsNumber"]intValue];
  428. model.goodsQuantity=[NSString stringWithFormat:@"%d",goodsNumberValue];
  429. model.colorNumber=[dic objectForKey:@"ColorNumber"];
  430. model.acreage=[[dic objectForKey:@"Acreage"]doubleValue];
  431. double weightValue= [[dic objectForKey:@"Weight"]doubleValue];
  432. model.weight=[NSString stringWithFormat:@"%lf",weightValue];
  433. double volumeValue= [[dic objectForKey:@"Volume"]doubleValue];
  434. model.volume=[NSString stringWithFormat:@"%lf",volumeValue];
  435. model.decimalPlaces=[dic objectForKey:@"DecimalPlaces"];
  436. int promotionTypeId= [[dic objectForKey:@"PromotionTypeDetailID"]intValue];
  437. model.promotionTypeDetailId=[NSString stringWithFormat:@"%d",promotionTypeId];
  438. model.circulateType=[[dic objectForKey:@"CirculateType"]integerValue];
  439. int packageValue= [[dic objectForKey:@"Package"]intValue];
  440. model.package=[NSString stringWithFormat:@"%d",packageValue];
  441. model.goodsName=[dic objectForKey:@"GoodsName"];
  442. double markedPriceValue= [[dic objectForKey:@"MarkedPrice"]doubleValue];
  443. model.markedPrice=[NSString stringWithFormat:@"%lf",markedPriceValue];
  444. int inventoryQuantityValue= [[dic objectForKey:@"InventoryQuantity"]intValue];
  445. model.inventoryQuantity=[NSString stringWithFormat:@"%d",inventoryQuantityValue];
  446. int salesQuantityValue= [[dic objectForKey:@"salesQuantity"]intValue];
  447. model.salesQuantity=[NSString stringWithFormat:@"%d",salesQuantityValue];
  448. model.canSaleQuantity=[NSString stringWithFormat:@"%d",salesQuantityValue];
  449. model.promotionTypeId=[dic objectForKey:@"PromotionsTypeID"];
  450. model.acreageFlag=[[dic objectForKey:@"AcreageFlag"]boolValue];
  451. model.inventoryId=[dic objectForKey:@"InventoryID"];
  452. int goodsNumberHideValue= [[dic objectForKey:@"GoodsNumberHide"]intValue];
  453. model.goodsQuantityHide=[NSString stringWithFormat:@"%d",goodsNumberHideValue];
  454. int minimumPurchaseQuantityValue= [[dic objectForKey:@"MinimPurchaseQuantity"]intValue];
  455. model.minimumPurchaseQuantity=[NSString stringWithFormat:@"%d",minimumPurchaseQuantityValue];
  456. model.priceSource=[dic objectForKey:@"PriceSource"];
  457. model.installationFlag=[dic objectForKey:@"InstallationFlag"];
  458. model.combinationQuantity=@"0";
  459. OrderQuantity *orderQuantity=[OrderQuantity new];
  460. [orderQuantity setSalesOrderDetailBoxAndPiece:[model.salesQuantity intValue] inventoryModel:model];
  461. [_orderGoodsDetailList addObject:model];
  462. }
  463. [_vTableView reloadData];
  464. }
  465. }
  466. }
  467. }
  468. -(void)onPromotionGoodsListLoadFail:(ASIDownManager *)sender {
  469. [self stopLoading];
  470. [self showAlertViewText:@"加载失败"];
  471. }
  472. #pragma mark - 委托回调函数
  473. -(void)goodsQuantityChanged:(NSString*)goodsQuantity position:(NSInteger)pos
  474. {
  475. InventoryListModel *inventoryModel= [_orderGoodsDetailList objectAtIndex:pos];
  476. [inventoryModel setSalesQuantity:goodsQuantity];
  477. if(goodsQuantity!=nil&&goodsQuantity.length>0)
  478. {
  479. OrderQuantity *orderQuantity=[OrderQuantity new];
  480. [orderQuantity setSalesOrderDetailBoxAndPiece:[goodsQuantity intValue] inventoryModel:inventoryModel];
  481. if([goodsQuantity doubleValue]>0)
  482. {
  483. [inventoryModel setIsCheckedStatus:YES];
  484. }
  485. else
  486. {
  487. [inventoryModel setIsCheckedStatus:NO];
  488. }
  489. }
  490. else
  491. {
  492. [inventoryModel setIsCheckedStatus:NO];
  493. }
  494. [_vTableView reloadData];
  495. }
  496. -(void)combinationQuantityChanged:(NSString*)combinationQuantity position:(NSInteger)pos
  497. {
  498. InventoryListModel *inventoryModel= [_orderGoodsDetailList objectAtIndex:pos];
  499. if(combinationQuantity==nil||[combinationQuantity isEqualToString:@""])
  500. {
  501. combinationQuantity=@"0";
  502. }
  503. if(!inventoryModel.giftFlag)
  504. {
  505. for(int i=0;i<_orderGoodsDetailList.count;i++)
  506. {
  507. InventoryListModel *goodsModel=[_orderGoodsDetailList objectAtIndex:i];
  508. if(!goodsModel.giftFlag)
  509. {
  510. NSString *goodsQuantityHide=goodsModel.goodsQuantityHide;
  511. int decimalPlaces=[goodsModel.decimalPlaces intValue];
  512. double goodsQuantity=[goodsQuantityHide doubleValue]*[combinationQuantity doubleValue];
  513. NSString *decimalPlacesStr=[NSString stringWithFormat:@"%@%d%@",@"%.",decimalPlaces,@"f"];
  514. NSString *goodsQuantityStr=[NSString stringWithFormat:decimalPlacesStr,goodsQuantity];
  515. [goodsModel setSalesQuantity:goodsQuantityStr];
  516. [goodsModel setCombinationQuantity:combinationQuantity];
  517. if([combinationQuantity intValue]>0)
  518. {
  519. [goodsModel setIsCheckedStatus:YES];
  520. }
  521. else{
  522. [goodsModel setIsCheckedStatus:NO];
  523. }
  524. }
  525. }
  526. }
  527. else{
  528. double goodsQuantityHideValue= [inventoryModel.goodsQuantityHide doubleValue];
  529. double goodsQuantityValue=goodsQuantityHideValue*[combinationQuantity doubleValue];
  530. int decimalPlaces=[[inventoryModel decimalPlaces]intValue];
  531. NSString *decimalPlacesStr=[NSString stringWithFormat:@"%@%d%@",@"%.",decimalPlaces,@"f"];
  532. NSString *goodsQuantity=[NSString stringWithFormat:decimalPlacesStr,goodsQuantityValue];
  533. [inventoryModel setSalesQuantity:goodsQuantity];
  534. [inventoryModel setCombinationQuantity:combinationQuantity];
  535. if([combinationQuantity intValue]>0)
  536. {
  537. [inventoryModel setIsCheckedStatus:YES];
  538. }
  539. else{
  540. [inventoryModel setIsCheckedStatus:NO];
  541. }
  542. }
  543. [_vTableView reloadData];
  544. }
  545. -(void)btnOrderGoodsSinglePromotionCheckPressed:(OrderGoodsSinglePromotionDetailCell*)cell
  546. {
  547. NSInteger pos= cell.position;
  548. InventoryListModel *goodsModel= [_orderGoodsDetailList objectAtIndex:pos];
  549. goodsModel.isCheckedStatus=!goodsModel.isCheckedStatus;
  550. [cell setCheckBackground: goodsModel.isCheckedStatus];
  551. }
  552. /**
  553. 单元格cell个数
  554. @param tableView <#tableView description#>
  555. @param section <#section description#>
  556. @return <#return value description#>
  557. */
  558. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  559. {
  560. return [_orderGoodsDetailList count];
  561. }
  562. /**
  563. <#Description#>
  564. @param tableView <#tableView description#>
  565. @return <#return value description#>
  566. */
  567. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  568. return 1;
  569. }
  570. /**
  571. 高度
  572. @param tableView <#tableView description#>
  573. @param indexPath <#indexPath description#>
  574. @return <#return value description#>
  575. */
  576. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  577. return [self.heights[@(indexPath.row)] floatValue];
  578. }
  579. /**
  580. 每个单元格cell
  581. @param tableView <#tableView description#>
  582. @param indexPath <#indexPath description#>
  583. @return <#return value description#>
  584. */
  585. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  586. {
  587. static NSString *CellIdentifier = @"OrderGoodsListCell";
  588. OrderGoodsSinglePromotionDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier ];
  589. if (!cell) {
  590. cell=[[OrderGoodsSinglePromotionDetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  591. cell.selectionStyle=UITableViewCellSelectionStyleNone;
  592. }
  593. else
  594. //当页面拉动的时候 当cell存在并且最后一个存在 把它进行删除就出来一个独特的cell我们在进行数据配置即可避免
  595. {
  596. while ([cell.contentView.subviews lastObject] != nil) {
  597. [(UIView *)[cell.contentView.subviews lastObject] removeFromSuperview];
  598. }
  599. }
  600. InventoryListModel *goodsModel= [_orderGoodsDetailList objectAtIndex:indexPath.row];
  601. cell.delegate = self;
  602. cell.position=indexPath.row;
  603. [cell setPromotionGoodsDetailCell:goodsModel isCanChoose:_isCanChoose];
  604. self.heights[@(indexPath.row)] = @(cell.height);
  605. BOOL checked = goodsModel.isCheckedStatus;
  606. [cell setCheckBackground:checked];
  607. return cell;
  608. }
  609. /**
  610. 预防高度
  611. @param tableView <#tableView description#>
  612. @param indexPath <#indexPath description#>
  613. @return <#return value description#>
  614. */
  615. -(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
  616. return 355;
  617. }
  618. /**
  619. 高度
  620. @return <#return value description#>
  621. */
  622. - (NSMutableDictionary *)heights{
  623. if (_heights == nil){
  624. _heights = [NSMutableDictionary dictionary];
  625. }
  626. return _heights;
  627. }
  628. /**
  629. 返回函数
  630. */
  631. - (void)goBack
  632. {
  633. [self.navigationController popViewControllerAnimated:YES];
  634. }
  635. @end