| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513 |
- //
- // 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<detailArray.count;i++)
- {
- NSDictionary *detailDic=[detailArray objectAtIndex:i];
- InventoryFrozenGoodsModel *goodsModel=[InventoryFrozenGoodsModel dk_modelWithDictionary:detailDic];
- OrderQuantity *quantity=[OrderQuantity new];
- [quantity setBoxAndPiece:[goodsModel.unfreezeQuantity doubleValue] model:goodsModel];
- [_unfreezeGoodsList addObject:goodsModel];
-
- }
- [_tableView reloadData];
- }
-
- }
- }
-
- // 服务器返回数据状态值异常
- else if(iStatus == ActionResultStatusAuthError
- ||iStatus == ActionResultStatusNoLogin
- ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){
-
- [self showReLoginDialog:message];
- }
- else{
-
- [self showAlertViewText:message];
- }
- }
- -(void)onEditDataLoadFail:(ASIDownManager*)sender {
-
- [self cancel];
- [self showAlertViewText:@"网络异常"];
-
- }
- -(void)getInvoiceStyle:(NSString*)invoiceStyleId name:(NSString*)invoiceStyleName
- {
- _styleId=invoiceStyleId;
- _styleName=invoiceStyleName;
- [_btnInvoiceStyle setTitle:_styleName forState:UIControlStateNormal];
- [_btnInvoiceStyle setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
- }
- -(void)onSubmitOrderLoadFinish:(ASIDownManager*)sender {
- [self cancel];
- RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
- int iStatus = resultModel.status;
- // 服务器返回数据消息
- NSString *message = resultModel.message;
- if(iStatus==0)
- {
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"保存成功" preferredStyle:UIAlertControllerStyleAlert];
-
- UIAlertAction *otherAction = [UIAlertAction actionWithTitle:@"确定"
- style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
- if([self.inventoryDelegate respondsToSelector:@selector(refreshData)])
- {
- [self.inventoryDelegate refreshData];
- } [self goBack];
- }];
-
- UIColor *sureColor = [UIColor redColor];
- [otherAction setValue:sureColor forKey:@"titleTextColor"];
- [alertController addAction:otherAction];
-
- [self presentViewController:alertController animated:YES completion:nil];
- }
-
- else if(iStatus == ActionResultStatusAuthError
- ||iStatus == ActionResultStatusNoLogin
- ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){
-
-
- [self showReLoginDialog:message];
- }
- else{
-
- [self showAlertViewText:message];
- return;
- }
- }
- -(void)onSubmitOrderLoadFail:(ASIDownManager *)sender {
- [self cancel];
- [self showAlertViewText:@"网络异常"];
- }
- /**
- 隐藏进度条
- */
- - (void)cancel {
- [self stopLoading];
- }
- /**
- 单元格cell个数
- @param tableView <#tableView description#>
- @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
|