| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343 |
- //
- // NewSalesExternalCoordinateVC.m
- // IBOSSmini
- //
- // Created by ssl on 2018/2/24.
- // Copyright © 2018年 elongtian. All rights reserved.
- //
- #import "SaleSlipExternalCoordinateGoodsVC.h"
- @interface SaleSlipExternalCoordinateGoodsVC (){
- UIView *_middleSeparatorView;
- }
- @end
- @implementation SaleSlipExternalCoordinateGoodsVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- _externalCoordinateGoodsList=[[NSMutableArray alloc]init];
- _externalCoordinateGoodsDeleteList=[[NSMutableArray alloc]init];
- [self initUI];
- [self registerKeybordNotification];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- -(void)initUI{
- [self.view setBackgroundColor:[UIColor whiteColor]];
- UIView *topSeparatorView = [UIView new];
- topSeparatorView.frame=CGRectMake(0,3, Screen_Width, 10);
- topSeparatorView.backgroundColor = LineBackgroundColor;
- [self.view addSubview:topSeparatorView];
- CGFloat height = 40;
- UIView *searchView = [[UIView alloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(topSeparatorView.frame)+5, Screen_Width, 50)];
- searchView.backgroundColor = [UIColor whiteColor];
- UIButton *btnSearch = [UIButton buttonWithType:UIButtonTypeCustom];
- btnSearch.frame = CGRectMake(20, 5, Screen_Width-height, height);
- btnSearch.layer.cornerRadius = 6.0f;
- [btnSearch setTitle:@"新增商品" forState:UIControlStateNormal];
- [btnSearch setTitleColor:NavBarUnEnbleItemColor forState:UIControlStateNormal];
- btnSearch.titleLabel.textAlignment = NSTextAlignmentCenter;
- btnSearch.titleLabel.font = [UIFont systemFontOfSize:LabelAndTextFontOfSize];
- btnSearch.backgroundColor = LineBackgroundColor;
- [btnSearch addTarget:self action:@selector(addExternalCoordinateGoods) forControlEvents:UIControlEventTouchUpInside];
- [searchView addSubview:btnSearch];
- [self.view addSubview:searchView];
-
- _middleSeparatorView = [UIView new];
- _middleSeparatorView.frame=CGRectMake(0, CGRectGetMaxY(searchView.frame)+5, Screen_Width, 10);
- _middleSeparatorView.backgroundColor = LineBackgroundColor;
- [self.view addSubview:_middleSeparatorView];
-
- _vTableView = [[UITableView alloc]
- initWithFrame:CGRectMake(0,
- CGRectGetMaxY(_middleSeparatorView.frame),
- self.view.frame.size.width,
- Screen_Height - CGRectGetMaxY(_middleSeparatorView.frame))];
-
- _vTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _vTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
- _vTableView.backgroundColor = [UIColor whiteColor];
- _vTableView.delegate = self;
- _vTableView.dataSource=self;
- [self.view addSubview:_vTableView];
- }
- #pragma mark - 委托回调函数
- #pragma mark - tableView回调
- /**
- 单元格cell个数
-
- @param tableView <#tableView description#>
- @param section <#section description#>
- @return <#return value description#>
- */
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return [_externalCoordinateGoodsList count];
- }
- /**
- <#Description#>
-
- @param tableView <#tableView description#>
- @return <#return value description#>
- */
- -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
- return 1;
- }
- /**
- 高度
-
- @param tableView <#tableView description#>
- @param indexPath <#indexPath description#>
- @return <#return value description#>
- */
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- return 210;
- }
- /**
- 每个单元格cell
-
- @param tableView <#tableView description#>
- @param indexPath <#indexPath description#>
- @return <#return value description#>
- */
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *CellIdentifier = @"InventoryListCell1";
- NewSalesExternalCoordinateCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier ];
- cell=[[NewSalesExternalCoordinateCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
- cell.selectionStyle=UITableViewCellSelectionStyleNone;
- cell.orderDelegate=self;
- cell.cellIndex=indexPath.row;
- ExternalCoordinateGoodsModel *externalModel= [_externalCoordinateGoodsList objectAtIndex:indexPath.row];
- [cell setNewExternalCoordinateGoodsCell:externalModel editStatus:_editStatus editFlag:_editFlag];
-
- return cell;
- }
- -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
-
- _currentPosition=indexPath.row;
- self.hidesBottomBarWhenPushed=YES;
- NewSaleSlipExternalCoordinateGoodsVC *vc=[[NewSaleSlipExternalCoordinateGoodsVC alloc] init];
- _externalCoordinateEditFlag=@"edit";
- vc.externalCoordinateGoodsModel= _externalCoordinateGoodsList[_currentPosition];
- vc.externalCoordinateEditFlag=_externalCoordinateEditFlag;
- vc.editStatus=_editStatus;
- vc.orderNo=_orderNo;
- vc.editFlag=_editFlag;
- vc.orderListDelegate=self;
- [self.orderNav pushViewController:vc animated:YES];
-
- }
- -(void)updateNewSalesExternalCoordinateGoodsCell:(NewSalesExternalCoordinateCell*)cell textField:(UITextField*)field{
- _externalCoordinateGoodsList[cell.cellIndex]=cell.externalCoordinateModel;
-
- if(field.tag==1001||field.tag==1002){
- [self.homeVC calculate:@""];
- }
- }
- -(void)deleteOrderDetail:(NSInteger)cellIndex{
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"是否要删除?" preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
-
- }];
- UIAlertAction *otherAction = [UIAlertAction actionWithTitle:@"确定"
- style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
- if(_editFlag==2){
- ExternalCoordinateGoodsModel *externalGoodsModel= _externalCoordinateGoodsList[cellIndex];
- if([externalGoodsModel.editFlag isEqualToString:@"add"]){
- [_externalCoordinateGoodsList removeObjectAtIndex:cellIndex];
- }
- else if([externalGoodsModel.editFlag isEqualToString:@"modify"])
- {
- externalGoodsModel.editFlag=@"Deleted";
- [_externalCoordinateGoodsDeleteList addObject:externalGoodsModel];
- [_externalCoordinateGoodsList removeObjectAtIndex:cellIndex];
- }
- }
- else{
- [_externalCoordinateGoodsList removeObjectAtIndex:cellIndex];
- }
-
-
- [_vTableView reloadData];
- [self.homeVC calculate:@""];
-
- }];
- UIColor *cancelColor=[UIColor blackColor];
- UIColor *sureColor=[UIColor redColor];
- [cancelAction setValue:cancelColor forKey:@"titleTextColor"];
- [otherAction setValue:sureColor forKey:@"titleTextColor"];
- [alertController addAction:cancelAction];
- [alertController addAction:otherAction];
-
- [self presentViewController:alertController animated:YES completion:nil];
- }
- -(void)addExternalCoordinateGoods{
- if (_editStatus == 4||_editStatus == 5||_editStatus == 7
- || _editStatus == 10||_editFlag == 3) {
- return;
- }
- self.hidesBottomBarWhenPushed=YES;
- NewSaleSlipExternalCoordinateGoodsVC *vc=[[NewSaleSlipExternalCoordinateGoodsVC alloc] init];
- _externalCoordinateEditFlag=@"add";
- vc.orderListDelegate=self;
- vc.externalCoordinateEditFlag=_externalCoordinateEditFlag;
- [self.orderNav pushViewController:vc animated:YES];
- }
- -(void)addExternalCoordinateGoods:(ExternalCoordinateGoodsModel*)externalCoordinateGoodsModel resultCode:(NSString *)resultCode{
-
- //大编辑
- if(_editFlag==2)
- {
- //去的时候是新增页面,回来的时候是新增保存回来
- if([_externalCoordinateEditFlag isEqualToString:@"add"] && [resultCode isEqualToString:@"resultAdd"])
- {
-
- [_externalCoordinateGoodsList addObject:externalCoordinateGoodsModel];
-
- }
-
- if([_externalCoordinateEditFlag isEqualToString:@"edit"]&&[resultCode isEqualToString:@"resultEdit"]){
- [_externalCoordinateGoodsList setObject:externalCoordinateGoodsModel atIndexedSubscript:_currentPosition];
- }
-
-
- }
- //新增
- else {
- if([_externalCoordinateEditFlag isEqualToString:@"add"]&&[resultCode isEqualToString:@"resultAdd"]){
-
- [_externalCoordinateGoodsList addObject:externalCoordinateGoodsModel];
-
- }
-
- if([_externalCoordinateEditFlag isEqualToString:@"edit"]&&[resultCode isEqualToString:@"resultEdit"]){
- [_externalCoordinateGoodsList setObject:externalCoordinateGoodsModel atIndexedSubscript:_currentPosition];
- }
-
- }
-
- [self.homeVC calculate:@""];
- [_vTableView reloadData];
- }
- -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
- [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
- }
- // 键盘弹出改变tableview高度
- - (void)registerKeybordNotification {
-
- NSNotificationCenter *notification = [NSNotificationCenter defaultCenter];
-
- [notification removeObserver:self];
-
- [notification addObserver:self
-
- selector:@selector(showKeyboard:)
-
- name:UIKeyboardWillShowNotification
-
- object:nil];
-
- [notification addObserver:self
-
- selector:@selector(hideKeyboard:)
-
- name:UIKeyboardWillHideNotification
-
- object:nil];
-
- #ifdef __IPHONE_5_0
-
- // 5.0以上系统中文键盘高度与4.0系统不一样
-
- float version = [[[UIDevice currentDevice] systemVersion] floatValue];
-
- if (version >= 5.0) {
-
- [notification addObserver:self
-
- selector:@selector(showKeyboard:)
-
- name:UIKeyboardWillChangeFrameNotification
-
- object:nil];
-
- }
-
- #endif
-
- }
- - (void)showKeyboard:(NSNotification *)notification {
-
- NSDictionary *userInfo = [notification userInfo];
-
- NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
-
- CGFloat keyboardHeight = CGRectGetHeight([aValue CGRectValue]);
- //50底部保存按钮 40为切换按钮
- CGFloat height = SCREENHEIGHT-rectStatusHeight-rectNavHeight-_vTableView.frame.origin.y - keyboardHeight-40-50;
-
-
- /* 使用动画效果,过度更加平滑 */
-
- [UIView beginAnimations:nil context:nil];
-
- [UIView setAnimationDuration:0.1];
-
- {
- if(!self.homeVC.roundAmountTxtFlag){
- CGRect rect = _vTableView.frame;
-
- rect.size.height = height;
-
- _vTableView.frame = rect;
- }
- }
-
- [UIView commitAnimations];
-
- }
- - (void)hideKeyboard:(NSNotification *)notification {
-
- [UIView beginAnimations:nil context:nil];
-
- [UIView setAnimationDuration:0.1];
-
- {
- if(!self.homeVC.roundAmountTxtFlag){
-
- CGRect rect = _vTableView.frame;
-
- rect.size.height = CGRectGetHeight(self.view.frame)-CGRectGetMaxY(_middleSeparatorView.frame);
-
- _vTableView.frame = rect;
- }
- }
-
- [UIView commitAnimations];
-
- }
- @end
|