| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499 |
- //
- // NewOtherOutStorageGoodsSearchVC.m
- // IBOSSmini
- //
- // Created by guan hong hou on 2018/4/28.
- // Copyright © 2018年 elongtian. All rights reserved.
- //
- #import "NewOtherOutStorageGoodsSearchVC.h"
- @interface NewOtherOutStorageGoodsSearchVC (){
- int pageNumber;
- Boolean isCheckAll;
- }
- @end
- @implementation NewOtherOutStorageGoodsSearchVC
- #pragma mark 公共函数
- /**
- 视图加载完成函数
- */
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self loadNavStyle];
- [self initUI];
- }
- /**
- 安全区变化函数
- */
- -(void)viewSafeAreaInsetsDidChange{
- _vTableView.frame=CGRectMake(0,0,self.view.frame.size.width,self.view.safeAreaLayoutGuide.layoutFrame.size.height-40);
- _bottomView.frame=CGRectMake(0, self.view.safeAreaLayoutGuide.layoutFrame.size.height-40, self.view.frame.size.width, 40);
- [super viewSafeAreaInsetsDidChange];
- }
- /**
- 内存警告函数
- */
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
-
- }
- #pragma mark 委托函数
- /**
- 其它出库列表加载成功回调
- @param sender <#sender description#>
- */
- - (void)onLoadFinish:(ASIDownManager *)sender {
- [self Cancel];
- NSDictionary *dic = [sender.mWebStr JSONValue];
- _vTableView.backgroundView = nil;
- // 服务器返回数据是否正确
- if (dic && [dic isKindOfClass:[NSDictionary class]])
- {
- // 服务器返回数据状态值
- int iStatus = [[dic objectForKey:@"Status"] intValue];
- // 服务器返回数据消息
- NSString *message=[dic objectForKey:@"Message"];
- // 服务器返回数据状态值正确
- if (iStatus == 0) {
- NSArray * infoArr=[dic objectForKey:@"Result"];
- if(infoArr!=nil&& infoArr.count>0)
- {
- // 转换model对象
- if(infoArr.count > 0 ){
- for (int i = 0; i < infoArr.count; i++) {
-
- NSDictionary *str=infoArr[i];
- InventoryModel *model = [InventoryModel new];
- model.code=[str objectForKey:@"Code"];
- model.inventoryId=[NSString stringWithFormat:@"%ld",[[str objectForKey:@"InventoryID"]integerValue]];
- model.codeId=[[str objectForKey:@"CodeID"]integerValue];
- model.kindId=[NSString stringWithFormat:@"%ld",[[str objectForKey:@"KindID"]integerValue]];
- model.kindName=[str objectForKey:@"KindName"];
- model.varietyId=[NSString stringWithFormat:@"%ld",[[str objectForKey:@"VarietyID"]integerValue]];
- model.varietyName=[str objectForKey:@"VarietyName"];
- model.seriesId=[NSString stringWithFormat:@"%ld",[[str objectForKey:@"SeriesID"]integerValue]];
- model.seriesName=[str objectForKey:@"SeriesName"];
- model.onlyCode=[str objectForKey:@"OnlyCode"];
- model.unitId=[NSString stringWithFormat:@"%ld",[[str objectForKey:@"UnitID"]integerValue]];
- model.unitName=[str objectForKey:@"UnitName"];
- model.weight=[NSString stringWithFormat:@"%lf",[[str objectForKey:@"Weight"]doubleValue]];
- model.goodsName=[str objectForKey:@"GoodsName"];
- model.acreage=[[str objectForKey:@"Acreage"]doubleValue];
- model.specification=[str objectForKey:@"Specification"];
-
- model.colorNumber=[str objectForKey:@"ColorNumber"];
- model.decimalPlaces=[NSString stringWithFormat:@"%d",[[str objectForKey:@"DecimalPlaces"]intValue]];
- model.brandName=[str objectForKey:@"BrandName"];
- model.gradeName=[str objectForKey:@"GradeName"];
- model.warehouseId=[NSString stringWithFormat:@"%ld",[[str objectForKey:@"WarehouseID"]integerValue]];
- model.wareHouseName=[str objectForKey:@"WarehouseName"];
- model.priorColorNumber=[NSString stringWithFormat:@"%ld",[[str objectForKey:@"PriorColorNumber"]integerValue]];
- model.priorInventoryId=[NSString stringWithFormat:@"%ld",[[str objectForKey:@"PriorInventoryID"]integerValue]];
- model.goodsRemarks=[str objectForKey:@"GoodsRemarks"];
- model.remarks=[str objectForKey:@"Remarks"];
- model.expandAtrribute=[str objectForKey:@"ExpandAtrribute"];
- model.expandAtrribute2=[str objectForKey:@"ExpandAtrribute2"];
- model.positionNumber=[str objectForKey:@"PositionNumber"];
- NSInteger circulateType=[[str objectForKey:@"CirculateType"]integerValue];
- model.circulateType=circulateType;
- NSInteger package= [[str objectForKey:@"Package"]integerValue];
- model.package=[NSString stringWithFormat:@"%ld",package];
- model.outQuantity=@"1";
- NSString *InventoryQuantity = [[str objectForKey:@"InventoryQuantity"]stringValue];
- model.inventoryQuantity=InventoryQuantity == nil?@"0":InventoryQuantity;
- double CanSaleQuantity = [[str objectForKey:@"BalanceQuantity"]doubleValue];
- model.canSaleQuantity=[NSString stringWithFormat:@"%lf",CanSaleQuantity];
-
- NSString *jzj = [[str objectForKey:@"jzj"]stringValue];
- model.price=jzj==nil?@"0":jzj;
- [_dataList addObject:model];
-
- }
- }
-
-
- [_vTableView reloadData];
-
- }
- else{
- _vTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- if(self.dataList.count==0){
- UIView *noDataView=[[UIView alloc]init];
- noDataView.frame= _vTableView.bounds;
- UIImageView *nodataImgView=[[UIImageView alloc] initWithFrame:CGRectMake(noDataView.frame.size.width/2-16,noDataView.frame.size.height/2-16,32,32)];
- [nodataImgView setImage:[UIImage imageNamed:@"icon_no_data"]];
- [noDataView addSubview:nodataImgView];
- UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(noDataView.frame.size.width/2-16-12,CGRectGetMaxY(nodataImgView.frame)+3,70, 25)];
- label.font=[UIFont systemFontOfSize:NoDataFontOfSize];
- label.text = @"无数据";
- label.numberOfLines = 2;
- label.textColor = [UIColor lightGrayColor];
- [noDataView addSubview:label];
- _vTableView.backgroundView =noDataView;
- [self showAlertViewBackText:@"未找到匹配结果"];
- }
- }
- }
- // 服务器返回数据状态值异常
- else if(iStatus==ActionResultStatusAuthError
- ||iStatus==ActionResultStatusNoLogin
- ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid){
- [self showReLoginDialog:message];
- }
- else{
-
- [self showAlertViewText:message];
- }
- }
- }
- /**
- 其它出库列表加载失败回调
- @param sender <#sender description#>
- */
- - (void)onLoadFail:(ASIDownManager *)sender {
- [self Cancel];
- [self showAlertViewText:@"加载失败"];
- }
- /**
- checkbox点击回调函数
- @param index <#index description#>
- */
- -(void)btnCheckPressed:(NSInteger)index{
- _inventoryModel= [_dataList objectAtIndex:index];
- _inventoryModel.isCheckedStatus=!_inventoryModel.isCheckedStatus;
- //1.当前所要刷新的cell,传入要刷新的 行数 和 组数
- NSIndexPath *indexPath = [NSIndexPath indexPathForRow:index inSection:0];
- //2.将indexPath添加到数组
- NSArray <NSIndexPath *> *indexPathArray = @[indexPath];
- //3.传入数组,对当前cell进行刷新
- [_vTableView reloadRowsAtIndexPaths:indexPathArray withRowAnimation:UITableViewRowAnimationAutomatic];
-
-
- if([self isCheckedAll]){
- isCheckAll=YES;
- [_btnCheckAll setImage:[UIImage imageNamed:@"check_round"] forState:UIControlStateNormal];
- }
-
- else{
- isCheckAll=NO;
- [_btnCheckAll setImage:[UIImage imageNamed:@"uncheck_round"] forState:UIControlStateNormal];
- }
-
- NSInteger num=[self getCheckedGoodsCount:_dataList];
- NSString *sureCount=[NSString stringWithFormat:@"%@%ld%@",@"确定(",num,@")"];
- [_sureBtn setTitle:sureCount forState:UIControlStateNormal];
- }
- /**
- 单元格cell个数
- @param tableView <#tableView description#>
- @param section <#section description#>
- @return <#return value description#>
- */
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return [self.dataList count];
- }
- /**
- tableview的分区数
- @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 220;
- }
- /**
- 每个单元格cell
- @param tableView <#tableView description#>
- @param indexPath <#indexPath description#>
- @return <#return value description#>
- */
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *cellIdentifier = @"OtherOutStorageSearchCell";
- OtherOutStorageGoodsSearchCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
- if (!cell) {
- cell=[[OtherOutStorageGoodsSearchCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
- cell.selectionStyle=UITableViewCellSelectionStyleNone;
- }
- else
- //当页面拉动的时候 当cell存在并且最后一个存在 把它进行删除就出来一个独特的cell我们在进行数据配置即可避免
- {
- while ([cell.contentView.subviews lastObject] != nil) {
- [(UIView *)[cell.contentView.subviews lastObject] removeFromSuperview];
- }
- }
-
- InventoryModel *infoModel = [_dataList objectAtIndex:indexPath.row];
- [cell setOtherOutStorageGoodsListModel:infoModel];
- cell.checkDelegate=self;
- cell.cellIndex=indexPath.row;
- [cell setCheckBackground:infoModel.isCheckedStatus];
- return cell;
- }
- /**
- 隐藏键盘
-
- @param scrollView <#scrollView description#>
- */
- -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
- {
- [self.view endEditing:YES];
- }
- #pragma mark 私有函数
- /**
- 导航按钮样式
- */
- -(void)loadNavStyle
- {
- self.navigationItem.title=@"库存商品";
-
- //返回
- UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
- [button setBackgroundImage:[UIImage imageNamed:@"icon_back"]
- forState:UIControlStateNormal];
- [button addTarget:self action:@selector(goBack)
- forControlEvents:UIControlEventTouchUpInside];
- button.frame = CGRectMake(0, 0, 15, 18);
-
- UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
- self.navigationItem.leftBarButtonItem = menuButton;
- }
- /**
- 返回函数
- */
- - (void)goBack
- {
- [self.navigationController popViewControllerAnimated:YES];
- }
- /**
- 初始化UI
- */
- -(void)initUI{
- [self.view setBackgroundColor:[UIColor whiteColor]];
- _vTableView = [[UITableView alloc]
- initWithFrame:CGRectMake(0,
- 0,
- self.view.frame.size.width,
- Screen_Height-40)];
-
- [_vTableView setBackgroundColor:[UIColor whiteColor]];
-
- _vTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _vTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
- _vTableView.dataSource=self;
- _vTableView.delegate = self;
- [self.view addSubview:_vTableView];
- //保存
- _bottomView=[UIView new];
- _bottomView.frame=CGRectMake(0, Screen_Height-103, self.view.frame.size.width, 40);
- [self.view addSubview:_bottomView];
- _btnCheckAll=[UIButton buttonWithType:UIButtonTypeCustom];
- _btnCheckAll.frame=CGRectMake(15,8, 25, 25);
- [_btnCheckAll setImage:[UIImage imageNamed:@"uncheck_round"] forState:UIControlStateNormal];
- [_btnCheckAll addTarget:self action:@selector(btnCheckall)
- forControlEvents:UIControlEventTouchUpInside];
- [_bottomView addSubview:_btnCheckAll];
- UILabel *lblall=[UILabel new];
- lblall.frame=CGRectMake(CGRectGetMaxX(_btnCheckAll.frame)+3,8, 60, 25);
- lblall.text=@"全选";
- [_bottomView addSubview:lblall];
- _sureBtn=[UIButton buttonWithType:UIButtonTypeCustom];
- [_sureBtn setTitle:@"确定" forState:UIControlStateNormal];
- [_sureBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- _sureBtn.frame=CGRectMake(Screen_Width-114,0, 114,40);
- [_sureBtn setBackgroundColor:[UIColor colorWithRed:189.0/255.0 green:0 blue:7.0/255.0 alpha:1]];
- [_sureBtn addTarget:self action:@selector(submitData) forControlEvents:UIControlEventTouchUpInside];
- [_bottomView addSubview:_sureBtn];
- _dataList=[[NSMutableArray alloc]init];
- pageNumber=1;
- [self startLoading];
- [self loadData];
- }
- /**
- 加载数据源
- */
- -(void)loadData{
- NSMutableDictionary *dict = [NSMutableDictionary dictionary];
- [dict setObject:@"GetInventoryDataIphone" 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:_goodsName forKeyedSubscript:@"GoodsName"];
- [dict setObject:_goodsCode forKeyedSubscript:@"Code"];
- [dict setObject:_onlyCode forKeyedSubscript:@"OnlyCode"];
- [dict setObject:_warehouseId forKeyedSubscript:@"WarehouseID"];
- [dict setObject:_brandId forKeyedSubscript:@"BrandID"];
- if(_isfilterQuantityEqZero){
- [dict setObject:@"1" forKey:@"isfilterQuantityEqZero"];
- }else{
- [dict setObject:@"" forKey:@"isfilterQuantityEqZero"];
- }
-
- _downManager = [[ASIDownManager alloc] init];
- _downManager.delegate = self;
- _downManager.OnImageDown = @selector(onLoadFinish:);
- _downManager.OnImageFail = @selector(onLoadFail:);
- [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
- }
- -(void)submitData{
- if(_dataList!=nil&&_dataList.count>0){
- NSInteger num= [self getCheckedGoodsCount:_dataList];
- if(num==0){
- [self showAlertViewText:@"请选择商品"];
- return;
- }
-
- NSMutableArray *checkedGoodsList=[[NSMutableArray alloc]init];
- for(InventoryModel *model in _dataList){
- if(model.isCheckedStatus){
- [checkedGoodsList addObject:model];
- }
- }
-
-
- if(_goodsDetailList!=nil&&_goodsDetailList.count>0){
-
- for(InventoryModel *model in checkedGoodsList.reverseObjectEnumerator){
- for(InventoryModel *inventoryModel in _goodsDetailList.reverseObjectEnumerator){
- if([model.inventoryId isEqualToString: inventoryModel.inventoryId] &&model.isCheckedStatus) {
- [checkedGoodsList removeObject:model];
- break;
- }
- }
- }
-
- }
-
-
- if([self.goodsDelegate respondsToSelector:@selector(showSelectedGoods: )]){
- [self.goodsDelegate showSelectedGoods:checkedGoodsList];
- }
- [self.navigationController popViewControllerAnimated:YES];
- }
- }
- /**
- 选中所有数据函数
- */
- -(void)btnCheckall{
- [self updateAllCellCheck];
- NSInteger num= [self getCheckedGoodsCount:_dataList];
- NSString *sureCount=[NSString stringWithFormat:@"%@%ld%@",@"确定(",num,@")"];
- [_sureBtn setTitle:sureCount forState:UIControlStateNormal];
- [_vTableView reloadData];
- }
- -(NSInteger) getCheckedGoodsCount:(NSMutableArray*)goodsList{
- int num=0;
- NSMutableArray *goodsSubmitList=[[NSMutableArray alloc]init];
- NSInteger count=goodsList.count;
-
- for(int i=0;i<count;i++){
- InventoryModel *model= goodsList[i];
- if(model.isCheckedStatus){
- num++;
- [goodsSubmitList addObject:model];
- }
- }
- NSInteger checkedCount=goodsSubmitList.count;
- return checkedCount;
-
- }
- /**
- 全选或者全不选
- @param BOOL <#BOOL description#>
- @return <#return value description#>
- */
- -(BOOL)updateAllCellCheck
- {
- if(!isCheckAll){
- isCheckAll=YES;
- [_btnCheckAll setImage:[UIImage imageNamed:@"check_round"] forState:UIControlStateNormal];
- for(InventoryModel *goodsModel in _dataList) {
- goodsModel.isCheckedStatus=YES;
- }
- }
- else
- {
- [_btnCheckAll setImage:[UIImage imageNamed:@"uncheck_round"] forState:UIControlStateNormal];
- isCheckAll=NO;
- for(InventoryModel *goodsModel in _dataList) {
- goodsModel.isCheckedStatus=NO;
- }
- }
- return NO;
- }
- /**
- 看是否全选
- @return <#return value description#>
- */
- -(BOOL)isCheckedAll
- {
- BOOL ischecked=YES;
- for(InventoryModel *model in _dataList) {
- if( !model.isCheckedStatus)
- {
- ischecked=NO;
- break;
- }
- }
- return ischecked;
-
- }
- /**
- 隐藏进度条
- */
- - (void)Cancel {
- [self stopLoading];
- }
- @end
|