// // NewInventoryUnfreezeViewController.m // IBOSS // // Created by 关宏厚 on 2020/5/15. // Copyright © 2020 elongtian. All rights reserved. // #import "NewInventoryUnfreezeViewController.h" @interface NewInventoryUnfreezeViewController () @end @implementation NewInventoryUnfreezeViewController - (void)viewDidLoad { [super viewDidLoad]; [self loadNavStyle]; [self initTableView]; [self initUI]; [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; if(_editFlag) { _unfreezeGoodsList=[[NSMutableArray alloc]init]; [self loadEditData]; } else { if(_unfreezeGoodsList!=nil&&_unfreezeGoodsList.count>0) { [_tableView reloadData]; } } } /** 安全区视图发生变化 */ -(void)viewSafeAreaInsetsDidChange{ _tableView.frame =CGRectMake(0, 0, self.view.frame.size.width,self.view.safeAreaLayoutGuide.layoutFrame.size.height-40); _btnSubmit.frame=CGRectMake(0, self.view.safeAreaLayoutGuide.layoutFrame.size.height-40, self.view.frame.size.width, 40); [super viewSafeAreaInsetsDidChange]; } /** 导航按钮样式 */ - (void)loadNavStyle { if(_editFlag) { self.navigationItem.title =@"编辑库存解冻"; } else { self.navigationItem.title =@"新建库存解冻"; } //返回 UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button setImage:[UIImage imageNamed:@"icon_back"] forState:UIControlStateNormal]; [button addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside]; button.frame = CGRectMake(0, 0,45,22); UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button]; self.navigationItem.leftBarButtonItem = menuButton; } -(void)loadEditData { [self startLoading]; _downManager = [[ASIDownManager alloc] init]; _downManager.delegate = self; _downManager.onRequestSuccess = @selector(onEditDataLoadFinish:); _downManager.onRequestFail = @selector(onEditDataLoadFail:); NSString *urlStr = ServerURL; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:@"GetUnFreezeEditDataIPhone" forKey:@"Action"]; [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"]; [dict setObject:kkUserCode forKey:@"UserCode"]; [dict setObject:kkUserPwd forKey:@"UserPassword"]; [dict setObject:kkSessionKey forKey:@"SessionKey"]; [dict setObject:_unfreezeId forKey:@"UnFreezeID"]; [_downManager postHttpRequest:urlStr dic:dict path:nil fileName:nil]; } /** 初始化tableview */ - (void)initTableView { _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-40)]; _tableView.backgroundColor = [UIColor redColor]; _tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight; _tableView.backgroundColor = [UIColor whiteColor]; _tableView.separatorStyle=UITableViewCellSeparatorStyleNone; _tableView.delegate = self; _tableView.dataSource=self; [self.view addSubview:_tableView]; } -(void)initUI { _headerView = [UIView new]; _headerView.frame=CGRectZero; [self.view addSubview:_headerView]; UIView *vInvoiceStyle = [UIView new]; vInvoiceStyle.frame=CGRectMake(0, 0,Screen_Width, 51); [_headerView addSubview:vInvoiceStyle]; UILabel *lblInvoiceStyle = [UILabel new]; lblInvoiceStyle.frame=CGRectMake(15, 16, 100, 25); lblInvoiceStyle.text = @"票据样式"; lblInvoiceStyle.textColor=[UIColor redColor]; lblInvoiceStyle.font=orderTextFont; [vInvoiceStyle addSubview:lblInvoiceStyle]; _btnInvoiceStyle = [UIButton buttonWithType:UIButtonTypeCustom]; _btnInvoiceStyle.frame=CGRectMake(CGRectGetMaxX(lblInvoiceStyle.frame)+10, 16, 150, 25); _btnInvoiceStyle.titleLabel.font=orderTextFont; _btnInvoiceStyle.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; [_btnInvoiceStyle setTitle:@"请选择票据样式" forState:UIControlStateNormal]; [_btnInvoiceStyle setTitleColor:ButtonTitleColor forState:UIControlStateNormal]; [vInvoiceStyle addSubview:_btnInvoiceStyle]; [_btnInvoiceStyle addTarget:self action:@selector(selectInvoiceStyle) forControlEvents:UIControlEventTouchUpInside]; UIImageView *invoiceStyleImg = [[UIImageView alloc] initWithFrame:CGRectMake(Screen_Width-25, 20,7,12)]; [invoiceStyleImg setImage:[UIImage imageNamed:@"rightarrow"] ]; [vInvoiceStyle addSubview:invoiceStyleImg]; UIView *separator1 = [UIView new]; separator1.backgroundColor=LineBackgroundColor; separator1.frame=CGRectMake(CGRectGetMaxX( lblInvoiceStyle.frame)+10,CGRectGetMaxY(_btnInvoiceStyle.frame)+10,Screen_Width-CGRectGetMaxX( lblInvoiceStyle.frame)+10, 1); [vInvoiceStyle addSubview:separator1]; [_headerView addSubview:vInvoiceStyle]; UIView *vRemarks = [UIView new]; vRemarks.frame=CGRectMake(0,CGRectGetMaxY(vInvoiceStyle.frame),Screen_Width, 51); [_headerView addSubview:vRemarks]; UILabel *lblRemarks = [UILabel new]; lblRemarks.frame=CGRectMake(15, 16, 100, 25); lblRemarks.text = @"备注"; lblRemarks.font=orderTextFont; [vRemarks addSubview: lblRemarks]; _txtRemarks = [UITextField new]; _txtRemarks.tag=1302; _txtRemarks.frame=CGRectMake(CGRectGetMaxX(lblRemarks.frame)+10, 16, 150, 25); _txtRemarks.placeholder = @"请输入备注"; _txtRemarks.font=orderTextFont; [vRemarks addSubview:_txtRemarks]; UIView *separator2 = [UIView new]; separator2.backgroundColor=LineBackgroundColor; separator2.frame=CGRectMake(CGRectGetMaxX( lblRemarks.frame)+10,CGRectGetMaxY(_txtRemarks.frame)+10,Screen_Width-CGRectGetMaxX( lblRemarks.frame)+10, 1); [vRemarks addSubview:separator2]; [_headerView addSubview:vRemarks]; UIView *separator3 = [UIView new]; separator3.backgroundColor=LineBackgroundColor; separator3.frame=CGRectMake(0,CGRectGetMaxY(vRemarks.frame)+10,Screen_Width, 10); [_headerView addSubview:separator3]; _headerView.frame=CGRectMake(0, 0, Screen_Width, CGRectGetMaxY(separator3.frame)); _tableView.tableHeaderView=_headerView; //提交订单 _btnSubmit = [UIButton buttonWithType:UIButtonTypeCustom]; _btnSubmit.frame=CGRectMake(0,Screen_Height-40-rectStatusHeight-rectNavHeight, Screen_Width, 40); [_btnSubmit setBackgroundImage:[UIImage imageNamed:@"bt_datasave"] forState:UIControlStateNormal]; [_btnSubmit addTarget:self action:@selector(reallySubmitOrder) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:_btnSubmit]; } -(void)reallySubmitOrder { if(_unfreezeGoodsList!=nil&&_unfreezeGoodsList.count>0) { for(int i=0;i<_unfreezeGoodsList.count;i++) { InventoryFrozenGoodsModel *goodsModel=[_unfreezeGoodsList objectAtIndex:i]; NSString *unfreezeQuantity=[goodsModel unfreezeQuantity]; NSString *freezeQuantity=[goodsModel freezeQuantity]; NSString *okUnfreezeQuantity=[goodsModel allUnfreezeQuantity]; if([unfreezeQuantity doubleValue]<=0) { [self showAlertViewText:@"解冻量不能小于等于0"]; return; } if([unfreezeQuantity doubleValue]>[freezeQuantity doubleValue]-[okUnfreezeQuantity doubleValue]) { [self showAlertViewText:@"最大解冻量不能超过冻结数量-已解冻数量"]; return; } } } [self startLoading]; [self submitData]; } -(void)submitData { _downManager = [[ASIDownManager alloc] init]; _downManager.delegate = self; _downManager.onRequestSuccess = @selector(onSubmitOrderLoadFinish:); _downManager.onRequestFail = @selector(onSubmitOrderLoadFail:); NSString *urlStr = ServerURL; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:@"SaveUnFreezeDataIPhone" forKey:@"Action"]; [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"]; [dict setObject:kkUserCode forKey:@"UserCode"]; [dict setObject:kkUserPwd forKey:@"UserPassword"]; [dict setObject:kkSessionKey forKey:@"SessionKey"]; if(!_editFlag) { [dict setObject:_freezeId forKey:@"FreezeID"]; } [dict setObject:(_unfreezeId==nil?@"":_unfreezeId) forKey:@"UnFreezeID"]; [dict setObject:(_styleId==nil?@"":_styleId) forKey:@"InvoiceLayoutID"]; [dict setObject:(_txtRemarks.text==nil?@"":_txtRemarks.text) forKey:@"Remarks"]; NSMutableArray *unfreezeArray = [[NSMutableArray alloc]init]; if(_unfreezeGoodsList!=nil&&_unfreezeGoodsList.count>0) { for(int i=0;i<_unfreezeGoodsList.count;i++) { NSMutableDictionary *unfreezeDic=[NSMutableDictionary new]; InventoryFrozenGoodsModel *goodsModel=[_unfreezeGoodsList objectAtIndex:i]; NSString *codeId=goodsModel.codeId; NSString *code=goodsModel.code; NSString *freezeQuantity=goodsModel.freezeQuantity; NSString *unfreezeQuantity=goodsModel.unfreezeQuantity; NSString *remarks=goodsModel.remarks; NSString *detailId=goodsModel.detailId; NSString *freezeDetailId=goodsModel.freezeDetailId; [unfreezeDic setObject:freezeQuantity forKey:@"FreezeQuantity"]; [unfreezeDic setObject:(detailId==nil?@"":detailId) forKey:@"DetailID"]; [unfreezeDic setObject:(freezeDetailId==nil?@"":freezeDetailId) forKey:@"FreezeDetailID"]; [unfreezeDic setObject:unfreezeQuantity forKey:@"OKUnFreezeQuantity"]; [unfreezeDic setObject:codeId forKey:@"CodeID"]; [unfreezeDic setObject:code forKey:@"Code"]; [unfreezeDic setObject:remarks forKey:@"Remarks"]; [unfreezeArray addObject:unfreezeDic]; } SBJsonWriter *write = [[SBJsonWriter alloc] init]; NSString *value = [write stringWithObject:unfreezeArray]; [dict setObject:value forKey:@"FreezeDetailDataTable"]; [_downManager postHttpRequest:urlStr dic:dict path:nil fileName:nil]; } } -(void)selectInvoiceStyle { InvoiceStyleViewController *styleVC = [[ InvoiceStyleViewController alloc] init]; styleVC.inventoryDelegate=self; [self.navigationController pushViewController:styleVC animated:YES]; } -(void)onEditDataLoadFinish:(ASIDownManager*)sender { [self cancel]; RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr]; int iStatus = resultModel.status; // 服务器返回数据消息 NSString *message = resultModel.message; if(iStatus==0) { NSDictionary *resultDic=( NSDictionary*) resultModel.result; NSArray *headArray=[resultDic objectForKey:@"Table"]; if(headArray!=nil&&headArray.count>0) { NSDictionary *headDic=[headArray objectAtIndex:0]; _styleId = [headDic objectForKey:@"InvoiceLayoutID"]; _styleName=[headDic objectForKey:@"InvoiceLayoutName"]; NSString *remarks=[headDic objectForKey:@"Remarks"]; if(![_styleName isEqualToString:@""]) { [_btnInvoiceStyle setTitle:_styleName forState:UIControlStateNormal]; } if(![remarks isEqualToString:@""]) { [_txtRemarks setText:remarks]; } NSArray *detailArray=[resultDic objectForKey:@"Table1"]; if(detailArray!=nil&&detailArray.count>0) { for(int i=0;i @param section <#section description#> @return <#return value description#> */ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [_unfreezeGoodsList count]; } /** table view 分区数 @param tableView <#tableView description#> @return <#return value description#> */ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1; } /** cell 高度 @param tableView <#tableView description#> @param indexPath <#indexPath description#> @return <#return value description#> */ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return [self.heights[@(indexPath.row)] doubleValue];; } /** 高度 @return <#return value description#> */ - (NSMutableDictionary *)heights{ if (_heights == nil){ _heights = [NSMutableDictionary dictionary]; } return _heights; } /** 预防高度 @param tableView <#tableView description#> @param indexPath <#indexPath description#> @return <#return value description#> */ -(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 250; } /** 每个单元格cell @param tableView <#tableView description#> @param indexPath <#indexPath description#> @return <#return value description#> */ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellIdentifier = @"NewInventoryUnfreezeGoodsListCell"; NewInventoryUnfreezeGoodsListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier ]; cell = [[NewInventoryUnfreezeGoodsListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; cell.selectionStyle=UITableViewCellSelectionStyleNone; InventoryFrozenGoodsModel *inventoryGoodsModel= [_unfreezeGoodsList objectAtIndex:indexPath.row]; [cell setNewInventoryUnfreezeGoodsListCell:&inventoryGoodsModel]; self.heights[@(indexPath.row)] = @(cell.height); return cell; } /** 键盘弹出 @param note */ - (void)keyboardWillShow:(NSNotification *)note { CGRect keyBoardRect = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; _tableView.contentInset = UIEdgeInsetsMake(0, 0, keyBoardRect.size.height, 0); } /** 键盘隐藏 @param note */ - (void)keyboardWillHide:(NSNotification *)note { _tableView.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)goBack { [self.navigationController popViewControllerAnimated:YES]; } @end