| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556 |
- //
- // InventoryGoodsSearchListVC.m
- // IBOSSmini
- //
- // Created by guan hong hou on 2018/2/2.
- // Copyright © 2018年 elongtian. All rights reserved.
- //
- #import "InventoryGoodsSearchListVC.h"
- @interface InventoryGoodsSearchListVC (){
- BOOL isCheckAll;
- }
- @property(nonatomic,assign) int pageNumber;
- @end
- @implementation InventoryGoodsSearchListVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- _inventoryGoodsList=[[NSMutableArray alloc]init];
- _inventoryGoodsResultList=[[NSMutableArray alloc]init];
- _inventorySubmitList=[[NSMutableArray alloc]init];
- [self loadNavStyle];
- [self initUI];
- }
- -(void)viewSafeAreaInsetsDidChange{
- _vCustomTableView.frame = CGRectMake(0, 0, SCREENWIDTH, CGRectGetHeight(self.view.safeAreaLayoutGuide.layoutFrame)-40);
- _bottomView.frame = CGRectMake(0, CGRectGetMaxY(_vCustomTableView.frame), SCREENWIDTH, 40);
- [super viewSafeAreaInsetsDidChange];
- }
- -(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)initUI{
- [self.view setBackgroundColor:[UIColor whiteColor]];
- _vCustomTableView = [[RefreshTableView alloc]
- initWithFrame:CGRectMake(0,0,self.view.frame.size.width,Screen_Height-40)];
-
- _vCustomTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _vCustomTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
- _vCustomTableView.backgroundColor = [UIColor whiteColor];
- _vCustomTableView.delegate = self;
- [_vCustomTableView.mRefreshHeader removeFromSuperview];
- [self.view addSubview:_vCustomTableView];
-
- //保存
- _bottomView=[UIView new];
- _bottomView.frame=CGRectMake(0, Screen_Height-110, self.view.frame.size.width, 50);
- [self.view addSubview:_bottomView];
- _btnCheckAll=[UIButton buttonWithType:UIButtonTypeCustom];
- _btnCheckAll.frame=CGRectMake(15,15, 25, 25);
- [_btnCheckAll setImage:[UIImage imageNamed:@"order_unchecked"] forState:UIControlStateNormal];
- [_btnCheckAll addTarget:self action:@selector(btnCheckall)
- forControlEvents:UIControlEventTouchUpInside];
- [_bottomView addSubview:_btnCheckAll];
- UILabel *lblall=[UILabel new];
- lblall.frame=CGRectMake(CGRectGetMaxX(_btnCheckAll.frame)+3,15, 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,50);
- [_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];
-
- _pageNumber=1;
- if([_loadFlag isEqualToString:@"scan"]){
- [self scanData];
- }
- else{
- [self loadData];
- }
-
- }
- -(void)btnCheckall{
- [self updateAllCellCheck];
- NSInteger num= [self getCheckedInventoryCount:_inventoryGoodsResultList];
- NSString *sureCount=[NSString stringWithFormat:@"%@%d%@",@"确定(",num,@")"];
- [_sureBtn setTitle:sureCount forState:UIControlStateNormal];
- [_vCustomTableView reloadData];
- }
- -(NSInteger) getCheckedInventoryCount:(NSMutableArray*)inventoryList{
- int num=0;
- NSMutableArray *inventorySubmitList=[[NSMutableArray alloc]init];
- NSInteger count=inventoryList.count;
-
- for(int i=0;i<count;i++){
- InventoryListModel *model= inventoryList[i];
- if(model.isCheckedStatus){
- num++;
- [inventorySubmitList addObject:model];
- }
- }
- NSInteger checkedCount=inventorySubmitList.count;
- return checkedCount;
-
- }
- -(void)submitData{
- if(_inventoryGoodsResultList==nil||_inventoryGoodsResultList.count==0){
- [self showAlertViewText:@"没有选择商品!"];
- return;
- }
- int num=0;
- NSInteger count=_inventoryGoodsResultList.count;
-
- for(int i=0;i<count;i++){
- InventoryListModel *model= _inventoryGoodsResultList[i];
- if(model.isCheckedStatus){
- num++;
- [_inventorySubmitList addObject:model];
- }
- }
- if(num==0){
- [self showAlertViewText:@"至少选择一种商品"];
- return;
- }
-
- __weak typeof(self) weakself=self;
- if ([weakself.orderListDelegate respondsToSelector:@selector(showCheckedInventoryList:)]){
-
- [weakself.orderListDelegate performSelector:@selector(showCheckedInventoryList:) withObject:_inventorySubmitList];
- }
- [self.navigationController popViewControllerAnimated:YES];
-
-
- }
- //全选或者全不选
- -(BOOL)updateAllCellCheck
- {
- if(!isCheckAll){
- isCheckAll=YES;
- [_btnCheckAll setImage:[UIImage imageNamed:@"order_checked"] forState:UIControlStateNormal];
- for(InventoryListModel *inventoryModel in _inventoryGoodsResultList) {
- inventoryModel.isCheckedStatus=YES;
- }
- }
- else
- {
- [_btnCheckAll setImage:[UIImage imageNamed:@"order_unchecked"] forState:UIControlStateNormal];
- isCheckAll=NO;
- for(InventoryListModel *inventoryModel in _inventoryGoodsResultList) {
- inventoryModel.isCheckedStatus=NO;
- }
- }
- return NO;
- }
- //看是否全选
- -(BOOL)isCheckedAll
- {
- BOOL ischecked=YES;
- for(InventoryListModel *model in _inventoryGoodsResultList) {
- if( !model.isCheckedStatus)
- {
- ischecked=NO;
- break;
- }
- }
- return ischecked;
-
- }
- -(void)scanData{
- NSMutableDictionary *dict = [NSMutableDictionary dictionary];
- [dict setObject:@"GettOrderSalesInventoryGoodsByScan" 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:_barCode forKeyedSubscript:@"Barcode"];
- if(_isFilterQuantityEqZero){
- [dict setObject:@"true" forKey:@"isfilterQuantityEqZero"];
- }else{
- [dict setObject:@"false" forKey:@"isfilterQuantityEqZero"];
- }
-
- _downManager = [[ASIDownManager alloc] init];
- _downManager.delegate = self;
- _downManager.onRequestSuccess = @selector(onLoadScanFinish:);
- _downManager.onRequestFail = @selector(onLoadScanFail:);
- [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
- }
- -(void)loadData{
- NSMutableDictionary *dict = [NSMutableDictionary dictionary];
- [dict setObject:@"GetNewInventoryList" 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:[NSString stringWithFormat:@"%d",_pageNumber] forKey:@"PageNum"];
- [dict setObject:[NSString stringWithFormat:@"%d",pageSize] forKey:@"PageSize"];
- [dict setObject:_goodsName forKeyedSubscript:@"GoodsName"];
- [dict setObject:_goodsCode forKeyedSubscript:@"GoodsCode"];
- [dict setObject:_onlyCode forKeyedSubscript:@"OnlyCode"];
- [dict setObject:_warehouseAreaId forKeyedSubscript:@"WarehouseCode"];
- [dict setObject:_brandId forKeyedSubscript:@"BrandID"];
- if(_isFilterQuantityEqZero){
- [dict setObject:@"true" forKey:@"isfilterQuantityEqZero"];
- }else{
- [dict setObject:@"false" forKey:@"isfilterQuantityEqZero"];
- }
-
- _downManager = [[ASIDownManager alloc] init];
- _downManager.delegate = self;
- _downManager.onRequestSuccess = @selector(onLoadFinish:);
- _downManager.onRequestFail = @selector(onLoadFail:);
- [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
- }
- - (void)goBack
- {
- [self.navigationController popViewControllerAnimated:YES];
- }
- /**
- 隐藏进度条
- */
- - (void)cancel {
- [self stopLoading];
- }
- /**
- 加载列表数据成功回调
-
- @param sender <#sender description#>
- */
- - (void)onLoadFinish:(ASIDownManager *)sender {
- [self cancel];
- NSDictionary *dic = [sender.mWebStr JSONValue];
- int iNewCount = 0;
- _vCustomTableView.mTableView.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)
- {
-
- [self.inventoryGoodsList addObjectsFromArray:infoArr];
-
- if(self.inventoryGoodsList.count > 0 ){
- for (int i = 0; i < self.inventoryGoodsList.count; i++) {
-
- NSDictionary *dic=self.inventoryGoodsList[i];
- InventoryListModel *model = [InventoryListModel new];
- model.code=[dic objectForKey:@"Code"];
- model.codeId=[[dic objectForKey:@"CodeID"]integerValue];
-
- model.onlyCode=[dic objectForKey:@"OnlyCode"];
- model.inventoryId=[NSString stringWithFormat:@"%ld",[[dic objectForKey:@"InventoryID"]integerValue]];
- model.isContractPrice=NO;
- // model.costPrice=[NSString stringWithFormat:@"%lf",[[dic objectForKey:@"CostPrice"]doubleValue]];
- model.goodsName=[dic objectForKey:@"GoodsName"];
- model.detailId=@"";
- model.orderId=@"";
- model.specification=[dic objectForKey:@"Specification"];
- model.acreageFlag=[[dic objectForKey:@"AcreageFlag"]boolValue];
- model.originalOrderQuantity=@"0";
- model.package=[NSString stringWithFormat:@"%ld",[[dic objectForKey:@"Package"]integerValue]];
- model.acreage=[[dic objectForKey:@"Acreage"]doubleValue];
- model.usePositionId=@"0";
- model.usePositionName=@"";
- model.salesQuantity=@"1";
- model.circulateType=[[dic objectForKey:@"CirculateType"]integerValue];
- NSInteger unitIdValue= [[dic objectForKey:@"UnitID"]integerValue];
- model.unitId=[NSString stringWithFormat:@"%ld",unitIdValue];
- model.unitName=[dic objectForKey:@"UnitName"];
- model.remarks=@"";
- NSInteger varietyIdValue=[[dic objectForKey:@"VarietyID"]integerValue];
- model.varietyId=[NSString stringWithFormat:@"%ld",varietyIdValue];
- model.varietyName=[dic objectForKey:@"VarietyName"];
- model.isCheckedStatus=NO;
- model.positionNumber=[dic objectForKey:@"PositionNumber"];
-
- model.factOccupyQuantity=@"0";
- NSInteger seriesIdValue=[[dic objectForKey:@"SeriesID"]integerValue];
- model.seriesId=[NSString stringWithFormat:@"%ld",seriesIdValue ];
- model.seriesName=[dic objectForKey:@"SeriesName"];
-
- model.decimalPlaces=[NSString stringWithFormat:@"%@",[dic objectForKey:@"DecimalPlaces"]];
- // model.usePositionName=@"请选择使用位置";
- model.colorNumber=[dic objectForKey:@"ColorNumber"];
- NSInteger brandIdValue= [[dic objectForKey:@"BrandID"]integerValue];
- model.brandId=[NSString stringWithFormat:@"%ld",brandIdValue];
- model.brandName=[dic objectForKey:@"BrandName"];
- model.gradeId=[[dic objectForKey:@"GradeID"]integerValue];
- model.gradeName=[dic objectForKey:@"GradeName"];
- model.warehouseId=[NSString stringWithFormat:@"%ld",[[dic objectForKey:@"WarehouseID"]integerValue]];
- model.warehouseCode=[dic objectForKey:@"WarehouseCode"];
- model.wareHouseName=[dic objectForKey:@"WarehouseName"];
- double weightValue= [[dic objectForKey:@"Weight"]doubleValue];
- double volumeValue=[[dic objectForKey:@"Volume"]doubleValue];
-
- model.weight=[NSString stringWithFormat:@"%.6f",weightValue];
- model.volume=[NSString stringWithFormat:@"%.6f",volumeValue];
- model.discount=[NSString stringWithFormat:@"%d",100];
- NSString *InventoryQuantity = [[dic objectForKey:@"InventoryQuantity"]stringValue];
- model.inventoryQuantity=InventoryQuantity == nil?@"0":InventoryQuantity;
-
- NSString *CanSaleQuantity = [[dic objectForKey:@"CanSaleQuantity"]stringValue];
- model.canSaleQuantity=CanSaleQuantity==nil?@"0":CanSaleQuantity;
-
-
-
- NSInteger kindId=[[dic objectForKey:@"KindID"]integerValue];
- model.kindId=[NSString stringWithFormat:@"%ld",kindId];
- model.kindName=[dic objectForKey:@"KindName"];
- NSString *jzj = [[dic objectForKey:@"jzj"]stringValue];
- model.markedPrice=jzj==nil?@"0":jzj;
- model.salesPrice=jzj==nil?@"0":jzj;
- [self.inventoryGoodsResultList addObject:model];
- }
- }
-
- iNewCount =(int)infoArr.count;
- _vCustomTableView.mbMoreHidden = (iNewCount == 0);
- [ _vCustomTableView FinishLoading];
- [ _vCustomTableView reloadData];
-
- }
- else{
- [ _vCustomTableView FinishLoading];
- _vCustomTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- if(self.inventoryGoodsList.count==0){
- UIView *noDataView=[[UIView alloc]init];
- noDataView.frame= _vCustomTableView.mTableView.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];
- _vCustomTableView.mTableView.backgroundView =noDataView;
- [self showAlertViewBackText:@"未找到匹配结果"];
- }
- }
- }
- // 服务器返回数据状态值异常
- else if(iStatus == ActionResultStatusAuthError
- ||iStatus == ActionResultStatusNoLogin
- ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){
- [self showReLoginDialog:message];
- }
- else{
- [_vCustomTableView FinishLoading];
- [self showAlertViewText:message];
- }
- }
- }
- /**
- 加载列表数据失败回调
-
- @param sender <#sender description#>
- */
- - (void)onLoadFail:(ASIDownManager *)sender {
- [self cancel];
- [self showAlertViewText:@"加载失败"];
- }
- /**
- 加载列表数据成功回调
-
- @param sender <#sender description#>
- */
- - (void)onLoadScanFinish:(ASIDownManager *)sender {
- NSDictionary *dic = [sender.mWebStr JSONValue];
-
- if (dic && [dic isKindOfClass:[NSDictionary class]])
- {
- // 服务器返回数据状态值
- int iStatus = [[dic objectForKey:@"Status"] intValue];
- // 服务器返回数据消息
- NSString *message=[dic objectForKey:@"Message"];
- // 服务器返回数据状态值正确
- if (iStatus == 0) {
- _onlyCode=[dic objectForKey:@"Result"];
- [self loadData];
- }
- else if(iStatus == ActionResultStatusAuthError
- ||iStatus == ActionResultStatusNoLogin
- ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){
- [self showReLoginDialog:message];
- }
- else{
- [self showAlertViewText:message];
- }
- }
- }
- /**
- 加载列表数据失败回调
-
- @param sender <#sender description#>
- */
- - (void)onLoadScanFail:(ASIDownManager *)sender {
- [self cancel];
- [self showAlertViewText:@"加载失败"];
- }
- #pragma mark - 刷新回调
- /**
- 取消刷新
-
- @param sender sender description
- @return return value description
- */
- - (BOOL)CanRefreshTableView:(RefreshTableView *)sender {
- return YES;
- }
- #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 [_inventoryGoodsResultList 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 208.7;
- }
- /**
- 每个单元格cell
-
- @param tableView <#tableView description#>
- @param indexPath <#indexPath description#>
- @return <#return value description#>
- */
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *cellIdentifier = @"InventoryCell";
- InventoryGoodsSearchCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
-
- cell=[[InventoryGoodsSearchCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
- cell.selectionStyle=UITableViewCellSelectionStyleNone;
-
-
-
- InventoryListModel *inventoryModel= [_inventoryGoodsResultList objectAtIndex:indexPath.row];
- cell.delegate = self;
- cell.position=indexPath.row;
- [cell setInventoryGoods:inventoryModel];
- BOOL checked = inventoryModel.isCheckedStatus;
- [cell setCheckBackground:checked];
- return cell;
- }
- -(void)btnInventoryListCheckPressed:(InventoryGoodsSearchCell*)cell{
- InventoryListModel *inventoryModel= _inventoryGoodsResultList[cell.position];
- inventoryModel.isCheckedStatus=!inventoryModel.isCheckedStatus;
- [_vCustomTableView reloadData];
- if([self isCheckedAll]){
- [_btnCheckAll setImage:[UIImage imageNamed:@"order_checked"] forState:UIControlStateNormal];
- }
-
- else{
- [_btnCheckAll setImage:[UIImage imageNamed:@"order_unchecked"] forState:UIControlStateNormal];
- }
-
- NSInteger num=[self getCheckedInventoryCount:_inventoryGoodsResultList];
- NSString *sureCount=[NSString stringWithFormat:@"%@%d%@",@"确定(",num,@")"];
- [_sureBtn setTitle:sureCount forState:UIControlStateNormal];
- }
- /**
- 加载更多
-
- @param sender <#sender description#>
- */
- - (void)LoadMoreList:(RefreshTableView *)sender {
- _pageNumber++;
- [self startLoading];
- [self loadData];
- }
- /**
- 隐藏进度条
- */
- - (void)Cancel {
- [self stopLoading];
- }
- /**
- 隐藏键盘
-
- @param scrollView <#scrollView description#>
- */
- -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
- {
- [self.view endEditing:YES];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- @end
|