NewOrderGoodsDetailVC.m 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. //
  2. // NewOrderGoodsDetailVC.m
  3. // IBOSSmini
  4. //
  5. // Created by guan hong hou on 2018/1/24.
  6. // Copyright © 2018年 elongtian. All rights reserved.
  7. //
  8. #import "NewOrderGoodsDetailVC.h"
  9. @interface NewOrderGoodsDetailVC ()
  10. @end
  11. @implementation NewOrderGoodsDetailVC
  12. - (void)viewDidLoad {
  13. [super viewDidLoad];
  14. _inventoryGoodsDetailList=[[NSMutableArray alloc]init];
  15. _inventoryGoodsDetailDeleteList=[[NSMutableArray alloc]init];
  16. [self initSlideSlip];
  17. [self initUI];
  18. }
  19. -(void)initUI{
  20. [self.view setBackgroundColor:[UIColor whiteColor]];
  21. UIView *topSeparatorView = [UIView new];
  22. topSeparatorView.frame=CGRectMake(0,3, Screen_Width, 10);
  23. topSeparatorView.backgroundColor = LineBackgroundColor;
  24. [self.view addSubview:topSeparatorView];
  25. CGFloat height = 40;
  26. UIView *searchView = [[UIView alloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(topSeparatorView.frame)+5, Screen_Width, 50)];
  27. searchView.backgroundColor = [UIColor whiteColor];
  28. _btnSearch = [UIButton buttonWithType:UIButtonTypeCustom];
  29. _btnSearch.frame = CGRectMake(20, 5, Screen_Width-40, height);
  30. _btnSearch.layer.cornerRadius = 6.0f;
  31. [_btnSearch setTitle:@"搜索商品" forState:UIControlStateNormal];
  32. [_btnSearch setTitleColor:NavBarUnEnbleItemColor forState:UIControlStateNormal];
  33. _btnSearch.titleLabel.textAlignment = NSTextAlignmentCenter;
  34. _btnSearch.titleLabel.font = [UIFont systemFontOfSize:LabelAndTextFontOfSize];
  35. _btnSearch.backgroundColor = LineBackgroundColor;
  36. [_btnSearch addTarget:self action:@selector(goodsSearch) forControlEvents:UIControlEventTouchUpInside];
  37. [searchView addSubview:_btnSearch];
  38. [self.view addSubview:searchView];
  39. // UIButton *scan=[UIButton buttonWithType:UIButtonTypeCustom];
  40. // scan.frame=CGRectMake(searchView.frame.size.width-35,8,35,35);
  41. // scan.contentHorizontalAlignment=UIControlContentHorizontalAlignmentRight;
  42. // [scan setImage:[UIImage imageNamed:@"scan"] forState:UIControlStateNormal];
  43. // [searchView addSubview:scan];
  44. [self.view addSubview:searchView];
  45. // [scan addTarget:self action:@selector(btnScanCilck) forControlEvents:UIControlEventTouchUpInside];
  46. UIView *middleSeparatorView = [UIView new];
  47. middleSeparatorView.frame=CGRectMake(0, CGRectGetMaxY(searchView.frame)+5, Screen_Width, 10);
  48. middleSeparatorView.backgroundColor = LineBackgroundColor;
  49. [self.view addSubview:middleSeparatorView];
  50. _vDetailTableView = [[UITableView alloc]
  51. initWithFrame:CGRectMake(0,
  52. CGRectGetMaxY(middleSeparatorView.frame),
  53. self.view.frame.size.width,
  54. Screen_Height - CGRectGetMaxY(middleSeparatorView.frame))];
  55. _vDetailTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  56. _vDetailTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
  57. _vDetailTableView.backgroundColor = [UIColor whiteColor];
  58. _vDetailTableView.delegate = self;
  59. _vDetailTableView.dataSource=self;
  60. [self.view addSubview:_vDetailTableView];
  61. _vDetailTableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
  62. //键盘将要显示时候的通知
  63. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
  64. //键盘将要结束时候的通知
  65. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];
  66. }
  67. /**
  68. 扫描点击事件
  69. */
  70. -(void)btnScanCilck{
  71. ScanViewController *scanVc=[[ScanViewController alloc]init];
  72. scanVc.rootVC=self;
  73. [self.orderNav pushViewController:scanVc animated:YES];
  74. }
  75. /**
  76. 抽屉初始化
  77. */
  78. - (void)initSlideSlip{
  79. // 抽屉对象
  80. __weak typeof(self) weakself=self;
  81. self.filterController = [[SideSlipFilterController alloc]
  82. initWithSponsor:self
  83. resetBlock:^(NSArray *dataList) {
  84. for (SideSlipModel *model in dataList) {
  85. model.selectedItemList = nil;
  86. model.customDict = nil;
  87. }
  88. } commitBlock:^(NSArray *dataList) {
  89. SideSlipModel *serviceRegionModel = dataList[0];
  90. InventorySearchModel *m = [serviceRegionModel.customDict objectForKey:INVENTORY_SEARCH_RANGE_MODEL];
  91. [weakself.filterController dismiss];
  92. self.hidesBottomBarWhenPushed = YES;
  93. InventoryGoodsSearchListVC* inventoryGoodsSearchVc=[[InventoryGoodsSearchListVC alloc]init];
  94. inventoryGoodsSearchVc.brandId = m.brandId;
  95. inventoryGoodsSearchVc.goodsCode = m.goodsCode;
  96. inventoryGoodsSearchVc.goodsName= m.goodsName;
  97. inventoryGoodsSearchVc.onlyCode = m.onlyCode;
  98. inventoryGoodsSearchVc.warehouseAreaId = m.warehouseId;
  99. inventoryGoodsSearchVc.isFilterQuantityEqZero = m.isfilterQuantityEqZero;
  100. inventoryGoodsSearchVc.orderListDelegate=self;
  101. [self.orderNav pushViewController:inventoryGoodsSearchVc animated:YES];
  102. }];
  103. _filterController.animationDuration = AnimationDuration;
  104. _filterController.hasHeadView = YES;
  105. _filterController.sideSlipLeading = UIScreenSideSlipLeading*[UIScreen mainScreen].bounds.size.width;
  106. _filterController.dataList = [self packageDataList];
  107. }
  108. /**
  109. 数据源
  110. @return <#return value description#>
  111. */
  112. - (NSArray *)packageDataList {
  113. NSMutableArray *dataArray = [NSMutableArray array];
  114. SideSlipModel *model = [[SideSlipModel alloc] init];
  115. model.containerCellClass = @"OrderGoodsDetailSearchCell";
  116. model.regionTitle = @"查询条件";
  117. [dataArray addObject:model];
  118. return [dataArray mutableCopy];
  119. }
  120. -(void)goUsePosition:(NSInteger)position{
  121. self.hidesBottomBarWhenPushed = YES;
  122. CustomerReportTextVC *tc=[[CustomerReportTextVC alloc] init];
  123. _cellIndex=position;
  124. tc.delegate=self;
  125. tc.showDialogViewTag=ReportUsePosition;
  126. [self.orderNav pushViewController:tc animated:YES];
  127. }
  128. - (void)customerReportTextDoneDatas:(CustomerReportTextInfoModel *)model CustomerReport:(CustomerReport)cr{
  129. if (model==nil) {
  130. return;
  131. }
  132. if(cr==ReportUsePosition){
  133. _usePositionId=model.idCode;
  134. _usePositionName=model.name;
  135. InventoryListModel *inventoryModel= _inventoryGoodsDetailList[_cellIndex];
  136. inventoryModel.usePositionId=_usePositionId;
  137. inventoryModel.usePositionName=_usePositionName;
  138. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:_cellIndex inSection:0];
  139. //2.将indexPath添加到数组
  140. NSArray <NSIndexPath *> *indexPathArray = @[indexPath];
  141. //3.传入数组,对当前cell进行刷新
  142. [_vDetailTableView reloadRowsAtIndexPaths:indexPathArray withRowAnimation:UITableViewRowAnimationAutomatic];
  143. }
  144. }
  145. -(void)showNewOrderDetailError:(NSString*)errorMsg{
  146. [self showAlertViewText:errorMsg];
  147. }
  148. -(void)updateNewOrderGoodsDetail:(NewOrderGoodsDetailCell*)cell textField:(UITextField *)field{
  149. _inventoryGoodsDetailList[cell.cellIndex]=cell.inventoryModel;
  150. if(field.tag==1004)
  151. {
  152. InventoryListModel *goodsModel= _inventoryGoodsDetailList[cell.cellIndex];
  153. NSString *combinationQuantity=field.text;
  154. NSString *currentPromotionDetailId=goodsModel.promotionDetailId;
  155. NSString *currentOpCombPromotionFlag=goodsModel.opCombPromotionFlag;
  156. if(currentOpCombPromotionFlag==nil)
  157. {
  158. currentOpCombPromotionFlag=@"";
  159. }
  160. for(int i=0;i<_inventoryGoodsDetailList.count;i++)
  161. {
  162. InventoryListModel *inventModel=[_inventoryGoodsDetailList objectAtIndex:i];
  163. NSString *promotionDetailId=inventModel.promotionDetailId;
  164. NSString *opCombPromotionFlag=inventModel.opCombPromotionFlag;
  165. if(opCombPromotionFlag==nil||[opCombPromotionFlag isEqualToString:@""])
  166. {
  167. opCombPromotionFlag=@"";
  168. }
  169. if((currentPromotionDetailId!=nil&&currentPromotionDetailId.length>0)&&(promotionDetailId!=nil&&promotionDetailId.length>0))
  170. {
  171. if(([currentPromotionDetailId intValue]==[promotionDetailId intValue])&&([currentOpCombPromotionFlag isEqualToString:opCombPromotionFlag]))
  172. {
  173. NSString *goodsQuantityHide=inventModel.goodsQuantityHide;
  174. int decimalPlaces=[inventModel.decimalPlaces intValue];
  175. double combinationQuantityValue= [combinationQuantity doubleValue];
  176. double goodsQuantity=[goodsQuantityHide doubleValue]*combinationQuantityValue;
  177. NSString *format=[NSString stringWithFormat:@"%@%d%@",@"%.",decimalPlaces,@"f"];
  178. NSString *goodsQuantityStr=[NSString stringWithFormat:format,goodsQuantity];
  179. [inventModel setSalesQuantity:goodsQuantityStr];
  180. [inventModel setCombinationQuantity:combinationQuantity];
  181. OrderQuantity *orderQuantity=[OrderQuantity new];
  182. [orderQuantity setSalesOrderDetailBoxAndPiece:[inventModel.salesQuantity intValue] inventoryModel:inventModel];
  183. }
  184. }
  185. }
  186. }
  187. if(field.tag==1005)
  188. {
  189. InventoryListModel *goodsModel= _inventoryGoodsDetailList[cell.cellIndex];
  190. if(goodsModel.circulateType==1&&goodsModel.acreageFlag)
  191. {
  192. NSString *markedPrice=goodsModel.markedPrice;
  193. if(goodsModel.acreagePrice!=nil&&goodsModel.acreagePrice.length>0)
  194. {
  195. if([goodsModel.acreagePrice doubleValue]!=0)
  196. {
  197. double salesPrice=[goodsModel.acreagePrice doubleValue]*goodsModel.acreage;
  198. [goodsModel setSalesPrice:[NSString stringWithFormat:@"%lf",salesPrice]];
  199. double discount=[goodsModel.acreagePrice doubleValue]/[goodsModel.markedPrice doubleValue]*100;
  200. NSString *discountStr=[NSString stringWithFormat:@"%.2f",discount];
  201. [goodsModel setDiscount:discountStr];
  202. }
  203. else
  204. {
  205. [goodsModel setDiscount:@"100"];
  206. }
  207. }
  208. else
  209. {
  210. if([markedPrice doubleValue]!=0)
  211. {
  212. [goodsModel setDiscount:@"0"];
  213. }
  214. else
  215. {
  216. [goodsModel setDiscount:@"100"];
  217. }
  218. }
  219. }
  220. }
  221. [_vDetailTableView reloadData];
  222. if(field.tag==1001||field.tag==1002||field.tag==1004||field.tag==1005){
  223. [self.homeVC calculate:@"orderDetail"];
  224. }
  225. }
  226. -(void)deleteOrderDetail:(NSInteger)cellIndex{
  227. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"是否要删除?" preferredStyle:UIAlertControllerStyleAlert];
  228. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  229. }];
  230. UIAlertAction *otherAction = [UIAlertAction actionWithTitle:@"确定"
  231. style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  232. InventoryListModel *inventoryModel=self->_inventoryGoodsDetailList[cellIndex];
  233. NSString *flag= inventoryModel.flag;
  234. NSString *opCombPromotionFlag=inventoryModel.opCombPromotionFlag;
  235. NSString *promotionType=inventoryModel.promotionTypeDetailId;
  236. NSString *promotionDetailId=inventoryModel.promotionDetailId;
  237. if(self->_editFlag){
  238. if([flag isEqualToString:@"1"]){
  239. [self->_inventoryGoodsDetailList removeObjectAtIndex:cellIndex];
  240. }
  241. else if([flag isEqualToString:@"2"]){
  242. inventoryModel.flag=@"3";
  243. [self->_inventoryGoodsDetailDeleteList addObject:inventoryModel];
  244. [self->_inventoryGoodsDetailList removeObjectAtIndex:cellIndex];
  245. }
  246. }
  247. else
  248. {
  249. if((promotionType!=nil&&promotionType.length>0)&&(promotionDetailId!=nil&&promotionDetailId.length>0))
  250. {
  251. if([promotionType intValue]==1){
  252. [self->_inventoryGoodsDetailList removeObjectAtIndex:cellIndex];
  253. }
  254. if([promotionType intValue]==2){
  255. for(long i=self->_inventoryGoodsDetailList.count-1;i>=0;i--)
  256. {
  257. InventoryListModel *goodsModel=[self->_inventoryGoodsDetailList objectAtIndex:i];
  258. if(goodsModel.promotionDetailId!=nil&&goodsModel.promotionDetailId.length>0)
  259. {
  260. if( [promotionDetailId intValue]
  261. == [goodsModel.promotionDetailId intValue] )
  262. {
  263. [ self->_inventoryGoodsDetailList removeObjectAtIndex:i];
  264. }
  265. }
  266. }
  267. }
  268. if([promotionType intValue]==5)
  269. {
  270. for(long i=self->_inventoryGoodsDetailList.count-1;i>=0;i--)
  271. {
  272. InventoryListModel *goodsModel=[self->_inventoryGoodsDetailList objectAtIndex:i];
  273. if((goodsModel.promotionDetailId!=nil&&goodsModel.promotionDetailId.length>0)&&(goodsModel.opCombPromotionFlag!=nil&&goodsModel.opCombPromotionFlag.length>0))
  274. {
  275. if(([promotionDetailId intValue]==[goodsModel.promotionDetailId intValue])&&[opCombPromotionFlag isEqualToString:goodsModel.opCombPromotionFlag])
  276. {
  277. [self->_inventoryGoodsDetailList removeObjectAtIndex:i];
  278. }
  279. } } }
  280. }
  281. else{
  282. [self->_inventoryGoodsDetailList removeObjectAtIndex:cellIndex];
  283. }
  284. }
  285. [self->_vDetailTableView reloadData];
  286. [self.homeVC calculate:@"orderDetail"];
  287. }];
  288. UIColor *cancelColor=[UIColor blackColor];
  289. UIColor *sureColor=[UIColor redColor];
  290. [cancelAction setValue:cancelColor forKey:@"titleTextColor"];
  291. [otherAction setValue:sureColor forKey:@"titleTextColor"];
  292. [alertController addAction:cancelAction];
  293. [alertController addAction:otherAction];
  294. [self presentViewController:alertController animated:YES completion:nil];
  295. }
  296. -(void)keyboardWillShow:(NSNotification *)sender{
  297. //获得键盘的尺寸
  298. CGRect keyBoardRect=[sender.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
  299. //当键盘将要显示时,将tableView的下边距增跟改为键盘的高度
  300. self.vDetailTableView.contentInset = UIEdgeInsetsMake(0, 0, keyBoardRect.size.height, 0);
  301. }
  302. -(void)keyboardDidHide:(NSNotification *)sender{
  303. //当键盘将要消失时,边距还原初始状态
  304. self.vDetailTableView.contentInset = UIEdgeInsetsZero;
  305. }
  306. -(void)goodsSearch{
  307. [_filterController showPagerView:self.orderNav];
  308. }
  309. -(void)showCheckedInventoryList:(NSMutableArray*)inventoryList{
  310. if(_editFlag){
  311. for(int i=0;i<inventoryList.count;i++){
  312. InventoryListModel *inventoryModel=inventoryList[i];
  313. Boolean ii=NO;
  314. Boolean jj=NO;
  315. if(_inventoryGoodsDetailList!=nil&&_inventoryGoodsDetailList.count>0){
  316. for(int j=0;j<_inventoryGoodsDetailList.count;j++){
  317. InventoryListModel *detailModel=_inventoryGoodsDetailList[j];
  318. if([inventoryModel.inventoryId isEqualToString:detailModel.inventoryId]){
  319. double salesQuantityValue= [detailModel.salesQuantity doubleValue];
  320. ++salesQuantityValue;
  321. detailModel.salesQuantity=[NSString stringWithFormat:@"%lf",salesQuantityValue
  322. ];
  323. ii=YES;
  324. }
  325. }
  326. }
  327. if(!ii){
  328. for(NSInteger j=_inventoryGoodsDetailDeleteList.count-1;j>=0;j--){
  329. InventoryListModel *deleteInventoryModel=_inventoryGoodsDetailDeleteList[j];
  330. if([inventoryModel.inventoryId isEqualToString:deleteInventoryModel.inventoryId]){
  331. deleteInventoryModel.flag=@"2";
  332. deleteInventoryModel.salesPrice=inventoryModel.salesPrice;
  333. deleteInventoryModel.salesQuantity=@"1";
  334. [_inventoryGoodsDetailList addObject:deleteInventoryModel];
  335. [_inventoryGoodsDetailDeleteList removeObjectAtIndex:j];
  336. jj=YES;
  337. }
  338. }
  339. if(!jj){
  340. inventoryModel.flag=@"1";
  341. [_inventoryGoodsDetailList addObject:inventoryModel];
  342. }
  343. }
  344. }
  345. }
  346. else{
  347. for(int i=0;i<inventoryList.count;i++){
  348. InventoryListModel *inventoryCheckedModel=inventoryList[i];
  349. Boolean ii=NO;
  350. if(_inventoryGoodsDetailList!=nil&&_inventoryGoodsDetailList.count>0){
  351. for(int j=0;j<_inventoryGoodsDetailList.count;j++){
  352. InventoryListModel *detailModel= _inventoryGoodsDetailList[j];
  353. if([inventoryCheckedModel.inventoryId isEqualToString:detailModel.inventoryId]){
  354. double salesQuantityValue= [detailModel.salesQuantity doubleValue];
  355. ++salesQuantityValue;
  356. detailModel.salesQuantity=[NSString stringWithFormat:@"%lf",salesQuantityValue
  357. ];
  358. ii=YES;
  359. }
  360. }
  361. }
  362. if(!ii){
  363. [_inventoryGoodsDetailList addObject:inventoryCheckedModel];
  364. }
  365. }
  366. }
  367. [_vDetailTableView reloadData];
  368. [self.homeVC calculate:@"orderDetail"];
  369. }
  370. #pragma mark - 委托回调函数
  371. #pragma mark - tableView回调
  372. /**
  373. 单元格cell个数
  374. @param tableView <#tableView description#>
  375. @param section <#section description#>
  376. @return <#return value description#>
  377. */
  378. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  379. {
  380. return [_inventoryGoodsDetailList count];
  381. }
  382. /**
  383. <#Description#>
  384. @param tableView <#tableView description#>
  385. @return <#return value description#>
  386. */
  387. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  388. return 1;
  389. }
  390. /**
  391. 高度
  392. @param tableView <#tableView description#>
  393. @param indexPath <#indexPath description#>
  394. @return <#return value description#>
  395. */
  396. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  397. return 417;
  398. }
  399. /**
  400. 每个单元格cell
  401. @param tableView <#tableView description#>
  402. @param indexPath <#indexPath description#>
  403. @return <#return value description#>
  404. */
  405. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  406. {
  407. static NSString *CellIdentifier = @"InventoryListCell";
  408. NewOrderGoodsDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier ];
  409. cell=[[NewOrderGoodsDetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  410. cell.selectionStyle=UITableViewCellSelectionStyleNone;
  411. cell.orderDelegate=self;
  412. cell.cellIndex=indexPath.row;
  413. InventoryModel *inventoryModel= [_inventoryGoodsDetailList objectAtIndex:indexPath.row];
  414. [cell setInventoryCell:inventoryModel editStatus:_editStatus ContractPriceFlag:_contractPriceValues];
  415. return cell;
  416. }
  417. /**
  418. 扫描回调函数
  419. @param code <#code description#>
  420. */
  421. -(void)reloadDataWithOnlyCode:(NSString *)code
  422. {
  423. self.hidesBottomBarWhenPushed = YES;
  424. InventoryGoodsSearchListVC* inventoryGoodsSearchVc=[[InventoryGoodsSearchListVC alloc]init];
  425. inventoryGoodsSearchVc.barCode=code;
  426. inventoryGoodsSearchVc.loadFlag=@"scan";
  427. inventoryGoodsSearchVc.isFilterQuantityEqZero=YES;
  428. inventoryGoodsSearchVc.orderListDelegate=self;
  429. [self.orderNav pushViewController:inventoryGoodsSearchVc animated:YES];
  430. }
  431. - (void)didReceiveMemoryWarning {
  432. [super didReceiveMemoryWarning];
  433. }
  434. @end