| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476 |
- //
- // NewOtherInStorageGoodsSearchVCViewController.m
- // IBOSSmini
- //
- // Created by guan hong hou on 2018/4/25.
- // Copyright © 2018年 elongtian. All rights reserved.
- //
- #import "NewOtherInStorageGoodsSearchVC.h"
- @interface NewOtherInStorageGoodsSearchVC (){
- int pageNumber;
- BOOL isCheckAll;
- }
- @end
- @implementation NewOtherInStorageGoodsSearchVC
- #pragma mark 公共函数
- /**
- 视图加载完成函数
- */
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self loadNavStyle];
- [self initUI];
- isCheckAll=NO;
- }
- /**
- 安全区变化函数
- */
- -(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)onGoodsListLoadFinish:(ASIDownManager *)sender {
- NSDictionary *dic = [sender.mWebStr JSONValue];
- [self stopLoading];
- // 服务器返回数据是否正确
- if (dic && [dic isKindOfClass:[NSDictionary class]]) {
- // 服务器返回数据状态值
- int iStatus = [[dic objectForKey:@"Status"] intValue];
- int iNewCount = 0;
- // 服务器返回数据消息
- NSString *message=[dic objectForKey:@"Message"];
- // 服务器返回数据状态值正确
- if (iStatus == 0) {
- NSArray * infoArr=[dic objectForKey:@"Result"];
- // 返回结果
- if(infoArr!=nil&& infoArr.count>0)
- {
- for (int i = 0; i < infoArr.count; i++) {
- NSDictionary * dic=infoArr[i];
- OtherInStorageGoodsSearchListModel *otherInStorageListModel=[OtherInStorageGoodsSearchListModel new];
- [otherInStorageListModel parseDic:dic];
- [_dataList addObject:otherInStorageListModel];
- }
- iNewCount =(int)infoArr.count;
- _vTableView.mbMoreHidden = (iNewCount == 0);
- [_vTableView FinishLoading];
- [_vTableView reloadData];
- }
- else{
- if(pageNumber==1){
- [self showAlertViewText:@"无数据"];
- }
- else{
- _vTableView.mbMoreHidden=YES;
- }
- return;
- }
- }
-
- else if(iStatus==ActionResultStatusAuthError
- ||iStatus==ActionResultStatusNoLogin
- ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid){
-
- [self showReLoginDialog:message];
- }
- else{
-
- [self showAlertViewText:message];
- }
- }
- }
- /**
- 隐藏键盘
- @param scrollView <#scrollView description#>
- */
- -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
- {
- [self.view endEditing:YES];
- }
- /**
- 产品列表加载失败回调
- @param sender <#sender description#>
- */
- - (void)onGoodsListLoadFail:(ASIDownManager *)sender {
- [self stopLoading];
- [self showAlertViewText:@"加载失败"];
- }
- /**
- 单元格cell个数
-
- @param tableView <#tableView description#>
- @param section <#section description#>
- @return <#return value description#>
- */
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return [_dataList 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 224;
-
- }
- /**
- 每个单元格cell
-
- @param tableView <#tableView description#>
- @param indexPath <#indexPath description#>
- @return <#return value description#>
- */
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *CellIdentifier = @"SalesInStorageGoodsSearchCell";
- OtherInStorageGoodsSearchCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier ];
- if (!cell) {
- cell=[[OtherInStorageGoodsSearchCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
- cell.selectionStyle=UITableViewCellSelectionStyleNone;
- }
- else
- //当页面拉动的时候 当cell存在并且最后一个存在 把它进行删除就出来一个独特的cell我们在进行数据配置即可避免
- {
- while ([cell.contentView.subviews lastObject] != nil) {
- [(UIView *)[cell.contentView.subviews lastObject] removeFromSuperview];
- }
- }
-
- _goodsSearchListModel= [_dataList objectAtIndex:indexPath.row];
- cell.inStorageDelegate = self;
- cell.index=indexPath.row;
- [cell setOtherInStorageGoodsSearchModel:_goodsSearchListModel];
- [cell setCheckBackground:_goodsSearchListModel.checkedFlag];
- return cell;
- }
- /**
- 取消刷新
- @param sender sender description
- @return return value description
- */
- - (BOOL)CanRefreshTableView:(RefreshTableView *)sender {
- return YES;
- }
- /**
- 加载更多
- @param sender sender description
- */
- - (void)LoadMoreList:(RefreshTableView *)sender {
- pageNumber++;
- [self startLoading];
- [self loadData];
- }
- /**
- 下拉刷新
-
- @param sender <#sender description#>
- */
- - (void)ReloadList:(RefreshTableView *)sender{
- pageNumber = 1;
- [_dataList removeAllObjects];
- [_vTableView reloadData];
- _vTableView.mbMoreHidden=YES;
- [self startLoading];
- [self loadData];
- }
- #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;
- }
- /**
- 初始化UI
- */
- -(void)initUI{
- [self.view setBackgroundColor:[UIColor whiteColor]];
- _vTableView = [[RefreshTableView alloc]
- initWithFrame:CGRectMake(0,
- 0,
- self.view.frame.size.width,
- Screen_Height-40)];
-
- [_vTableView setBackgroundColor:[UIColor whiteColor]];
- _vTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _vTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
-
- _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 loadData];
- }
- /**
- 提交数据
- */
- -(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(int i=0;i<_dataList.count;i++){
- OtherInStorageGoodsSearchListModel *model=[_dataList objectAtIndex:i];
- if(model.checkedFlag){
- [checkedGoodsList addObject:model];
- }
- }
-
- if(_goodsDetailList!=nil&&_goodsDetailList.count>0){
- for(OtherInStorageGoodsSearchListModel *checkedGoodsModel in checkedGoodsList.reverseObjectEnumerator ){
- for(OtherInStorageGoodsSearchListModel *goodsModel in _goodsDetailList.reverseObjectEnumerator){
- if([checkedGoodsModel.codeId integerValue] ==[goodsModel.codeId integerValue]){
- [checkedGoodsList removeObject:checkedGoodsModel];
- break;
- }
- }
- }
-
-
- }
-
- if([self.goodsDelegate respondsToSelector:@selector(showSelectedGoods: )]){
- [self.goodsDelegate showSelectedGoods:checkedGoodsList];
- }
- [self.navigationController popViewControllerAnimated:YES];
- }
- }
- /**
- 返回函数
- */
- - (void)goBack
- {
- [self.navigationController popViewControllerAnimated:YES];
- }
- /**
- 加载产品列表数据源
- */
- -(void)loadData{
-
- NSMutableDictionary *dict = [NSMutableDictionary dictionary];
- [dict setObject:@"GetGoodsCodeByConditionIphone" 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== nil? @"" : _goodsCode forKey:@"GoodsCode"];
- [dict setObject:_onlyCode== nil? @"" : _onlyCode forKey:@"OnlyCode"];
- [dict setObject:@"" forKey:@"WarehouseCode"];
- [dict setObject:_brandId== nil? @"" : _brandId forKey:@"BrandID"];
- [dict setObject:@"" forKey:@"isFilterQuantityEqZero"];
- [dict setObject:_kindCode == nil? @"" : _kindCode forKey:@"KindCode"];
- [dict setObject:_goodsName == nil? @"" : _goodsName forKey:@"GoodsName"];
- [dict setObject:_varietyId == nil? @"" : _varietyId forKey:@"VarietyID"];
- [dict setObject:@"20" forKey:@"PageSize"];
- [dict setObject:[NSString stringWithFormat:@"%d",pageNumber] forKey:@"PageNum"];
- _downManager = [[ASIDownManager alloc] init];
- [self startLoading];
- _downManager.delegate = self;
- _downManager.OnImageDown = @selector(onGoodsListLoadFinish:);
- _downManager.OnImageFail = @selector(onGoodsListLoadFail:);
- [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
-
- }
- /**
- 选中所有的产品
- */
- -(void)btnCheckall{
- [self updateAllCellCheck];
- NSInteger num= [self getCheckedGoodsCount:_dataList];
- NSString *sureCount=[NSString stringWithFormat:@"%@%d%@",@"确定(",num,@")"];
- [_sureBtn setTitle:sureCount forState:UIControlStateNormal];
- [_vTableView reloadData];
- }
- /**
- 全选或者不选
- @return <#return value description#>
- */
- -(BOOL)updateAllCellCheck
- {
- if(!isCheckAll){
- isCheckAll=YES;
- [_btnCheckAll setImage:[UIImage imageNamed:@"check_round"] forState:UIControlStateNormal];
- for(OtherInStorageGoodsSearchListModel *goodsModel in _dataList) {
- goodsModel.checkedFlag=YES;
- }
- }
- else
- {
- [_btnCheckAll setImage:[UIImage imageNamed:@"uncheck_round"] forState:UIControlStateNormal];
- isCheckAll=NO;
- for(OtherInStorageGoodsSearchListModel *goodsModel in _dataList) {
- goodsModel.checkedFlag=NO;
- }
- }
- return NO;
- }
- /**
- checkbox点击回调函数
-
- @param index <#index description#>
- */
- -(void)btnCheckPressed:(NSInteger)index{
- _goodsSearchListModel= [_dataList objectAtIndex:index];
- _goodsSearchListModel.checkedFlag=!_goodsSearchListModel.checkedFlag;
- [_vTableView reloadData];
- 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];
- }
- /**
- 获取选中的产品数
- @param goodsList <#goodsList description#>
- @return <#return value description#>
- */
- -(NSInteger) getCheckedGoodsCount:(NSMutableArray*)goodsList{
- int num=0;
- NSMutableArray *goodsSubmitList=[[NSMutableArray alloc]init];
- NSInteger count=goodsList.count;
-
- for(int i=0;i<count;i++){
- OtherInStorageGoodsSearchListModel *model= goodsList[i];
- if(model.checkedFlag){
- num++;
- [goodsSubmitList addObject:model];
- }
- }
- NSInteger checkedCount=goodsSubmitList.count;
- return checkedCount;
-
- }
- /**
- 判断是否全选
- @return <#return value description#>
- */
- -(BOOL)isCheckedAll
- {
- BOOL ischecked=YES;
- for(OtherInStorageGoodsSearchListModel *model in _dataList) {
- if( !model.checkedFlag)
- {
- ischecked=NO;
- break;
- }
- }
- return ischecked;
-
- }
- @end
|