| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492 |
- //
- // InventoryFreezeGoodsSearchViewController.m
- // IBOSS
- //
- // Created by 关宏厚 on 2020/4/28.
- // Copyright © 2020 elongtian. All rights reserved.
- //
- #import "InventoryFreezeGoodsSearchViewController.h"
- @interface InventoryFreezeGoodsSearchViewController ()
- @end
- @implementation InventoryFreezeGoodsSearchViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- _inventoryGoodsList=[[NSMutableArray alloc]init];
- [self initUI];
- [self initSlideSlip];
- [self changeCheckAllUnSelect];
-
- }
- /**
- 安全区视图发生变化
- */
- -(void)viewSafeAreaInsetsDidChange{
- _tableView.frame =CGRectMake(0,CGRectGetMaxY(_searchView.frame)+10, self.view.frame.size.width,self.view.superview.frame.size.height-60-CGRectGetMaxY(_searchView.frame));
- _bottomView.frame=CGRectMake(0, self.view.superview.frame.size.height-50, self.view.frame.size.width, 50);
- [super viewSafeAreaInsetsDidChange];
- }
- /**
- 抽屉初始化
- */
- - (void)initSlideSlip{
- // 抽屉对象
- __weak typeof(self) weakself = self;
- self.filterController = [[SideSlipFilterController alloc]
- initWithSponsor:self
- resetBlock:^(NSArray *dataList) {
- for (SideSlipModel *model in dataList)
- {
-
- model.selectedItemList = nil;
- model.customDict = nil;
- }
- }
- commitBlock:^(NSArray *dataList) {
- // 查询条件
- SideSlipModel *serviceRegionModel = dataList[0];
-
-
- InventoryFreezeGoodsSearchModel *searchModel = [serviceRegionModel.customDict objectForKey:INVENTORY_FREEZE_GOODS_SEARCH_MODEL];
-
- self->_goodsCode=searchModel.goodsCode;
- self->_onlyCode=searchModel.onlyCode;
- self->_goodsName=searchModel.goodsName;
-
- if([ self->_goodsCode isEqualToString:@""]&&[ self->_onlyCode isEqualToString:@""]&&[ self->_goodsName isEqualToString:@""])
- {
- [self showAlertViewText:@"产品编码,唯一编,产品名称至少输入一项"];
- return;
- }
-
- [weakself.filterController dismiss];
-
- if(self->_inventoryGoodsList!=nil&&self->_inventoryGoodsList.count>0)
- {
- [self->_inventoryGoodsList removeAllObjects];
- [self->_tableView reloadData];
- }
- [self loadData];
-
-
- }];
- _filterController.animationDuration = AnimationDuration;
- _filterController.hasHeadView = YES;
- _filterController.sideSlipLeading = UIScreenSideSlipLeading*[UIScreen mainScreen].bounds.size.width;
- _filterController.dataList = [self packageDataList];
- }
- /**
- 抽屉数据源
- @return <#return value description#>
- */
- - (NSArray *)packageDataList {
- NSMutableArray *dataArray = [NSMutableArray array];
- SideSlipModel *model = [[SideSlipModel alloc] init];
- model.containerCellClass = @"InventoryFreezeGoodsSearchCell";
- model.regionTitle = @"查询条件";
-
- [dataArray addObject:model];
- return [dataArray mutableCopy];
- }
- //看是否全选
- - (BOOL)isCheckedAll
- {
- BOOL ischecked=YES;
- for(int i=0;i<_inventoryGoodsList.count;i++) {
- InventoryGoodsModel *goodsModel= [_inventoryGoodsList objectAtIndex:i];
- if(goodsModel.isChecked == NO)
- {
- ischecked=NO;
- break;
- }
- }
- return ischecked;
- }
- -(void)btnCheckPressed:(InventoryGoodsListCell*)cell
- {
- NSInteger pos= cell.position;
- InventoryGoodsModel *goodsModel= [_inventoryGoodsList objectAtIndex:pos];
- goodsModel.isChecked=!goodsModel.isChecked;
- [cell setCheckBackground: goodsModel.isChecked];
-
- int num=0;
- for(int i=0;i<_inventoryGoodsList.count;i++)
- {
- InventoryGoodsModel *goodsModel= [_inventoryGoodsList objectAtIndex:i];
- BOOL isChecked=goodsModel.isChecked;
- if(isChecked)
- {
- ++num;
- }
- }
- NSString *saveTxt=[NSString stringWithFormat:@"确定(%d)",num];
- [_btnSave setTitle:saveTxt forState:UIControlStateNormal];
- if(![self isCheckedAll])
- {
- [self changeCheckAllUnSelect];
- }
- else{
- [self changeCheckALLSelect];
- }
-
- }
- -(void)loadData
- {
- NSMutableDictionary *dict = [NSMutableDictionary dictionary];
- [dict setObject:@"GetInventoryGoods" 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:_goodsCode forKey:@"Code"];
- [dict setObject:_onlyCode forKey:@"OnlyCode"];
- [dict setObject:_goodsName forKey:@"GoodsName"];
- _downManager = [[ASIDownManager alloc] init];
- [self startLoading];
- _downManager.delegate = self;
- _downManager.onRequestSuccess = @selector(onGoodsListLoadFinish:);
- _downManager.onRequestFail = @selector(onGoodsListLoadFail:);
- [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
- }
- -(void)dataSearch
- {
- [_filterController showPagerView:self.cNav];
- }
- -(void)initUI
- {
- self.view.backgroundColor = [UIColor whiteColor];
- _searchView = [[UIView alloc] init];
- _searchView.frame = CGRectMake(15,10,Screen_Width-30,35);
- _searchView.backgroundColor = LineBackgroundColor;
- _searchView.layer.cornerRadius = 10;
- _searchView.layer.masksToBounds = YES;
- UIButton *btnSearch = [UIButton buttonWithType:UIButtonTypeCustom];
- btnSearch.frame = CGRectMake(20,0, Screen_Width-40, 35);
- 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 addTarget:self action:@selector(dataSearch) forControlEvents:UIControlEventTouchUpInside];
- [_searchView addSubview:btnSearch];
- [self.view addSubview:_searchView];
-
- _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_searchView.frame)+10,self.view.frame.size.width, self.view.frame.size.height-140-rectStatusHeight-rectNavHeight)];
- _tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
- _tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
- _tableView.delegate = self;
- _tableView.dataSource=self;
- [self.view addSubview:_tableView];
-
- //保存
- _bottomView = [UIView new];
- [_bottomView setBackgroundColor:[UIColor whiteColor]];
-
- _bottomView.frame=CGRectMake(0, Screen_Height-140-rectStatusHeight-rectNavHeight, self.view.frame.size.width, 50);
- [self.view addSubview:_bottomView];
-
- UIView *bottomSeparator= [UIView new];
- bottomSeparator.frame=CGRectMake(0, 0, Screen_Width, 1);
- bottomSeparator.backgroundColor = LineBackgroundColor;
- [_bottomView addSubview:bottomSeparator];
- _btnCheckAll = [UIButton buttonWithType:UIButtonTypeCustom];
- _btnCheckAll.frame=CGRectMake(15,15, 25, 25);
- [_btnCheckAll addTarget:self action:@selector(checkAll)
- forControlEvents:UIControlEventTouchUpInside];
- [_bottomView addSubview:_btnCheckAll];
- UILabel *lblall = [UILabel new];
- lblall.frame=CGRectMake(CGRectGetMaxX(_btnCheckAll.frame)+3,15, 60, 25);
- lblall.text = @"全选";
- [_bottomView addSubview:lblall];
-
- [ self changeCheckAllUnSelect];
-
- _btnSave = [UIButton buttonWithType:UIButtonTypeCustom];
- [_btnSave setTitle:@"确定" forState:UIControlStateNormal];
- [_btnSave setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- _btnSave.frame=CGRectMake(Screen_Width-114,0, 114,50);
- [_btnSave setBackgroundColor:[UIColor colorWithRed:189.0/255.0 green:0 blue:7.0/255.0 alpha:1]];
- [_btnSave addTarget:self action:@selector(submitFreezeData) forControlEvents:UIControlEventTouchUpInside];
- [_bottomView addSubview:_btnSave];
- }
- -(void)onGoodsListLoadFinish:(ASIDownManager*)sender {
-
- [self cancel];
- RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
- int iStatus = resultModel.status;
- NSString *message=resultModel.message;
- if(iStatus==0)
- {
- NSArray *resultArray=(NSArray*)resultModel.result;
- if(resultArray!=nil&&resultArray.count>0)
- {
- for(int i=0;i<resultArray.count;i++)
- {
- NSDictionary *resultDic=[resultArray objectAtIndex:i];
- InventoryGoodsModel *model = [InventoryGoodsModel dk_modelWithDictionary:resultDic];
- [model setFreezeQuantity:@"0"];
- [model setBox:@"0"];
- [model setPiece:@"0"];
- [model setM2:@"0"];
- [model setUnfreezeQuantity:@"0"];
- [_inventoryGoodsList addObject:model];
- }
- [_tableView reloadData];
- }
-
- }
-
- // 服务器返回数据状态值异常
- else if(iStatus == ActionResultStatusAuthError
- ||iStatus == ActionResultStatusNoLogin
- ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){
-
- [self showReLoginDialog:message];
- }
- else{
-
- [self showAlertViewText:message];
- }
-
- }
- -(void)onGoodsListLoadFail:(ASIDownManager *)sender {
- [self cancel];
- [self showAlertViewText:@"网络异常"];
- }
- -(void)submitFreezeData
- {
- if(_inventoryGoodsList==nil||_inventoryGoodsList.count==0)
- {
- [self showAlertViewText:@"没有可提交的商品!"];
- return;
- }
-
- int num=0;
- for(int i=0;i<_inventoryGoodsList.count;i++)
- {
- InventoryGoodsModel *goodsModel= [_inventoryGoodsList objectAtIndex:i];
- if(goodsModel.isChecked)
- {
- ++num;
- }
- }
-
- if(num==0)
- {
- [self showAlertViewText:@"至少选择一种商品!"];
- return;
- }
-
- _submitInventoryGoodsList=[[NSMutableArray alloc]init];
-
- for(int i=0;i<_inventoryGoodsList.count;i++)
- {
- InventoryGoodsModel *goodsModel= [_inventoryGoodsList objectAtIndex:i];
- if(goodsModel.isChecked)
- {
- [_submitInventoryGoodsList addObject:goodsModel];
- }
- }
-
- self.cNav.visibleViewController.hidesBottomBarWhenPushed=YES;
- NewInventoryFreezeViewController *newVc=[[NewInventoryFreezeViewController alloc] init];
-
-
- newVc.submitInventoryGoodsList=_submitInventoryGoodsList;
- newVc.inventoryDelegate=self;
- newVc.editFlag=NO;
- [self.cNav pushViewController:newVc animated:YES];
-
- }
- -(void)checkAll
- {
- [self updateAllCellCheck];
-
- [_tableView reloadData];
-
- int num=0;
- for(int i=0;i<_inventoryGoodsList.count;i++)
- {
- InventoryGoodsModel *goodsModel= [_inventoryGoodsList objectAtIndex:i];
- BOOL isChecked=goodsModel.isChecked;
- if(isChecked)
- {
- ++num;
- }
- }
- NSString *saveTxt=[NSString stringWithFormat:@"确定(%d)",num];
- [_btnSave setTitle:saveTxt forState:UIControlStateNormal];
- if(![self isCheckedAll])
- {
-
- [self changeCheckAllUnSelect];
-
- }
- else{
-
- [self changeCheckALLSelect];
- }
- }
- //全选或者全不选
- - (BOOL)updateAllCellCheck
- {
- if(!_isCheckAll){
- _isCheckAll=YES;
- for(int i=0;i<_inventoryGoodsList.count;i++) {
- InventoryGoodsModel *goodsModel= [_inventoryGoodsList objectAtIndex:i];
- goodsModel.isChecked =YES;
- }
- }
- else
- {
- _isCheckAll=NO;
- for(int i=0;i<_inventoryGoodsList.count;i++) {
- InventoryGoodsModel *goodsModel= [_inventoryGoodsList objectAtIndex:i];
- goodsModel.isChecked =NO;
- }
- }
- return NO;
- }
- /**
- 隐藏进度条
- */
- - (void)cancel {
- [self stopLoading];
- }
- -(void) refreshData
- {
- if(_inventoryGoodsList!=nil&&_inventoryGoodsList.count>0)
- {
- [_inventoryGoodsList removeAllObjects];
- [_tableView reloadData];
- [self startLoading];
- [self loadData];
- }
- }
- /**
- 单元格cell个数
- @param tableView <#tableView description#>
- @param section <#section description#>
- @return <#return value description#>
- */
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return [_inventoryGoodsList 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 = @"InventoryGoodsListCell";
- InventoryGoodsListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier ];
- cell = [[InventoryGoodsListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
- cell.selectionStyle=UITableViewCellSelectionStyleNone;
-
- InventoryGoodsModel *inventoryGoodsModel= [_inventoryGoodsList objectAtIndex:indexPath.row];
- cell.delegate = self;
- [cell setInventoryGoodsListCell:inventoryGoodsModel];
- cell.position = (int)indexPath.row;
- self.heights[@(indexPath.row)] = @(cell.height);
- BOOL isChecked= inventoryGoodsModel.isChecked;
- [cell setCheckBackground:isChecked];
- return cell;
- }
- /**
- 全部选中
- */
- - (void)changeCheckALLSelect
- {
-
- [_btnCheckAll setBackgroundImage:[UIImage imageNamed:@"order_checked"] forState:UIControlStateNormal];
- }
- /**
- 全部未选中
- */
- - (void)changeCheckAllUnSelect
- {
- [_btnCheckAll setBackgroundImage:[UIImage imageNamed:@"order_unchecked"] forState:UIControlStateNormal];
- }
- @end
|