NewOrderGiftDetailVC.m 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  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 "NewOrderGiftDetailVC.h"
  9. @interface NewOrderGiftDetailVC ()
  10. @end
  11. @implementation NewOrderGiftDetailVC
  12. - (void)viewDidLoad {
  13. [super viewDidLoad];
  14. _inventoryGiftDetailList=[[NSMutableArray alloc]init];
  15. _inventoryGiftDetailDeleteList=[[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)updateNewOrderGiftDetail:(NewOrderGiftDetailCell*)cell textField:(UITextField*)field
  121. {
  122. _inventoryGiftDetailList[cell.cellIndex]=cell.inventoryModel;
  123. [_vDetailTableView reloadData];
  124. if(field.tag==1002){
  125. [self.homeVC calculate:@"orderDetail"];
  126. }
  127. }
  128. -(void)goUsePosition:(NSInteger)position{
  129. self.hidesBottomBarWhenPushed = YES;
  130. CustomerReportTextVC *tc=[[CustomerReportTextVC alloc] init];
  131. _cellIndex=position;
  132. tc.delegate=self;
  133. tc.showDialogViewTag=ReportUsePosition;
  134. [self.orderNav pushViewController:tc animated:YES];
  135. }
  136. - (void)customerReportTextDoneDatas:(CustomerReportTextInfoModel *)model CustomerReport:(CustomerReport)cr{
  137. if (model==nil) {
  138. return;
  139. }
  140. if(cr==ReportUsePosition){
  141. _usePositionId=model.idCode;
  142. _usePositionName=model.name;
  143. InventoryListModel *inventoryModel= _inventoryGiftDetailList[_cellIndex];
  144. inventoryModel.usePositionId=_usePositionId;
  145. inventoryModel.usePositionName=_usePositionName;
  146. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:_cellIndex inSection:0];
  147. //2.将indexPath添加到数组
  148. NSArray <NSIndexPath *> *indexPathArray = @[indexPath];
  149. //3.传入数组,对当前cell进行刷新
  150. [_vDetailTableView reloadRowsAtIndexPaths:indexPathArray withRowAnimation:UITableViewRowAnimationAutomatic];
  151. }
  152. }
  153. -(void)showNewOrderDetailError:(NSString*)errorMsg{
  154. [self showAlertViewText:errorMsg];
  155. }
  156. -(void)deleteOrderDetail:(NSInteger)cellIndex{
  157. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"是否要删除?" preferredStyle:UIAlertControllerStyleAlert];
  158. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  159. }];
  160. UIAlertAction *otherAction = [UIAlertAction actionWithTitle:@"确定"
  161. style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  162. InventoryListModel *inventoryModel=self->_inventoryGiftDetailList[cellIndex];
  163. NSString *flag= inventoryModel.flag;
  164. NSString *opCombPromotionFlag=inventoryModel.opCombPromotionFlag;
  165. NSString *promotionType=inventoryModel.promotionTypeDetailId;
  166. NSString *promotionDetailId=inventoryModel.promotionDetailId;
  167. if(self->_editFlag){
  168. InventoryListModel *inventoryModel=self->_inventoryGiftDetailList[cellIndex];
  169. NSString *flag= inventoryModel.flag;
  170. if([flag isEqualToString:@"1"]){
  171. [self->_inventoryGiftDetailList removeObjectAtIndex:cellIndex];
  172. }
  173. else if([flag isEqualToString:@"2"]){
  174. inventoryModel.flag=@"3";
  175. [self->_inventoryGiftDetailDeleteList addObject:inventoryModel];
  176. [self->_inventoryGiftDetailList removeObjectAtIndex:cellIndex];
  177. }
  178. }
  179. else
  180. {
  181. if((promotionType!=nil&&promotionType.length>0)&&(promotionDetailId!=nil&&promotionDetailId.length>0))
  182. {
  183. if([promotionType intValue]==2){
  184. for(long i=self->_inventoryGiftDetailList.count-1;i>=0;i--)
  185. {
  186. InventoryListModel *goodsModel=[self->_inventoryGiftDetailList objectAtIndex:i];
  187. if(goodsModel.promotionDetailId!=nil&&goodsModel.promotionDetailId.length>0)
  188. {
  189. if( [promotionDetailId intValue]
  190. == [goodsModel.promotionDetailId intValue] )
  191. {
  192. [ self->_inventoryGiftDetailList removeObjectAtIndex:i];
  193. }
  194. }
  195. }
  196. }
  197. if([promotionType intValue]==5)
  198. {
  199. for(long i=self->_inventoryGiftDetailList.count-1;i>=0;i--)
  200. {
  201. InventoryListModel *goodsModel=[self->_inventoryGiftDetailList objectAtIndex:i];
  202. if((goodsModel.promotionDetailId!=nil&&goodsModel.promotionDetailId.length>0)&&(goodsModel.opCombPromotionFlag!=nil&&goodsModel.opCombPromotionFlag.length>0))
  203. {
  204. if(([promotionDetailId intValue]==[goodsModel.promotionDetailId intValue])&&[opCombPromotionFlag isEqualToString:goodsModel.opCombPromotionFlag])
  205. {
  206. [self->_inventoryGiftDetailList removeObjectAtIndex:i];
  207. }
  208. } } }
  209. }
  210. else{
  211. [self->_inventoryGiftDetailList removeObjectAtIndex:cellIndex];
  212. }
  213. }
  214. [self->_vDetailTableView reloadData];
  215. [self.homeVC calculate:@"orderDetail"];
  216. }];
  217. UIColor *cancelColor=[UIColor blackColor];
  218. UIColor *sureColor=[UIColor redColor];
  219. [cancelAction setValue:cancelColor forKey:@"titleTextColor"];
  220. [otherAction setValue:sureColor forKey:@"titleTextColor"];
  221. [alertController addAction:cancelAction];
  222. [alertController addAction:otherAction];
  223. [self presentViewController:alertController animated:YES completion:nil];
  224. }
  225. -(void)keyboardWillShow:(NSNotification *)sender{
  226. //获得键盘的尺寸
  227. CGRect keyBoardRect=[sender.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
  228. //当键盘将要显示时,将tableView的下边距增跟改为键盘的高度
  229. self.vDetailTableView.contentInset = UIEdgeInsetsMake(0, 0, keyBoardRect.size.height, 0);
  230. }
  231. -(void)keyboardDidHide:(NSNotification *)sender{
  232. //当键盘将要消失时,边距还原初始状态
  233. self.vDetailTableView.contentInset = UIEdgeInsetsZero;
  234. }
  235. -(void)goodsSearch{
  236. [_filterController showPagerView:self.orderNav];
  237. }
  238. -(void)showCheckedInventoryList:(NSMutableArray*)inventoryList{
  239. if(_editFlag){
  240. for(int i=0;i<inventoryList.count;i++){
  241. InventoryListModel *inventoryModel=inventoryList[i];
  242. Boolean ii=NO;
  243. Boolean jj=NO;
  244. if(_inventoryGiftDetailList!=nil&&_inventoryGiftDetailList.count>0){
  245. for(int j=0;j<_inventoryGiftDetailList.count;j++){
  246. InventoryListModel *detailModel=_inventoryGiftDetailList[j];
  247. if([inventoryModel.inventoryId isEqualToString:detailModel.inventoryId]){
  248. double salesQuantityValue= [detailModel.salesQuantity doubleValue];
  249. ++salesQuantityValue;
  250. detailModel.salesQuantity=[NSString stringWithFormat:@"%lf",salesQuantityValue
  251. ];
  252. ii=YES;
  253. }
  254. }
  255. }
  256. if(!ii){
  257. for(NSInteger j=_inventoryGiftDetailDeleteList.count-1;j>=0;j--){
  258. InventoryListModel *deleteInventoryModel=_inventoryGiftDetailDeleteList[j];
  259. if([inventoryModel.inventoryId isEqualToString:deleteInventoryModel.inventoryId]){
  260. deleteInventoryModel.flag=@"2";
  261. deleteInventoryModel.salesPrice=inventoryModel.salesPrice;
  262. deleteInventoryModel.salesQuantity=@"1";
  263. [_inventoryGiftDetailList addObject:deleteInventoryModel];
  264. [_inventoryGiftDetailDeleteList removeObjectAtIndex:j];
  265. jj=YES;
  266. }
  267. }
  268. if(!jj){
  269. inventoryModel.flag=@"1";
  270. [_inventoryGiftDetailList addObject:inventoryModel];
  271. }
  272. }
  273. }
  274. }
  275. else{
  276. for(int i=0;i<inventoryList.count;i++){
  277. InventoryListModel *inventoryCheckedModel=inventoryList[i];
  278. Boolean ii=NO;
  279. if(_inventoryGiftDetailList!=nil&&_inventoryGiftDetailList.count>0){
  280. for(int j=0;j<_inventoryGiftDetailList.count;j++){
  281. InventoryListModel *detailModel= _inventoryGiftDetailList[j];
  282. if([inventoryCheckedModel.inventoryId isEqualToString:detailModel.inventoryId]){
  283. double salesQuantityValue= [detailModel.salesQuantity doubleValue];
  284. ++salesQuantityValue;
  285. detailModel.salesQuantity=[NSString stringWithFormat:@"%lf",salesQuantityValue
  286. ];
  287. ii=YES;
  288. }
  289. }
  290. }
  291. if(!ii){
  292. [_inventoryGiftDetailList addObject:inventoryCheckedModel];
  293. }
  294. }
  295. }
  296. [_vDetailTableView reloadData];
  297. [self.homeVC calculate:@"orderDetail"];
  298. }
  299. #pragma mark - 委托回调函数
  300. /**
  301. 单元格cell个数
  302. @param tableView <#tableView description#>
  303. @param section <#section description#>
  304. @return <#return value description#>
  305. */
  306. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  307. {
  308. return [_inventoryGiftDetailList count];
  309. }
  310. /**
  311. <#Description#>
  312. @param tableView <#tableView description#>
  313. @return <#return value description#>
  314. */
  315. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  316. return 1;
  317. }
  318. /**
  319. 高度
  320. @param tableView <#tableView description#>
  321. @param indexPath <#indexPath description#>
  322. @return <#return value description#>
  323. */
  324. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  325. return 348;
  326. }
  327. /**
  328. 每个单元格cell
  329. @param tableView <#tableView description#>
  330. @param indexPath <#indexPath description#>
  331. @return <#return value description#>
  332. */
  333. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  334. {
  335. static NSString *CellIdentifier = @"InventoryListCell";
  336. NewOrderGiftDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier ];
  337. cell=[[NewOrderGiftDetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  338. cell.selectionStyle=UITableViewCellSelectionStyleNone;
  339. cell.orderDelegate=self;
  340. cell.cellIndex=indexPath.row;
  341. InventoryModel *inventoryModel= [_inventoryGiftDetailList objectAtIndex:indexPath.row];
  342. [cell setInventoryCell:inventoryModel editStatus:_editStatus];
  343. return cell;
  344. }
  345. /**
  346. 扫描回调函数
  347. @param code <#code description#>
  348. */
  349. -(void)reloadDataWithOnlyCode:(NSString *)code
  350. {
  351. self.hidesBottomBarWhenPushed = YES;
  352. InventoryGoodsSearchListVC* inventoryGoodsSearchVc=[[InventoryGoodsSearchListVC alloc]init];
  353. inventoryGoodsSearchVc.barCode=code;
  354. inventoryGoodsSearchVc.loadFlag=@"scan";
  355. inventoryGoodsSearchVc.isFilterQuantityEqZero=YES;
  356. inventoryGoodsSearchVc.orderListDelegate=self;
  357. [self.orderNav pushViewController:inventoryGoodsSearchVc animated:YES];
  358. }
  359. - (void)didReceiveMemoryWarning {
  360. [super didReceiveMemoryWarning];
  361. }
  362. @end