| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 |
- //
- // StockingGoodsListViewController.m
- // IBOSSmini
- //
- // Created by apple on 2017/5/17.
- // Copyright © 2017年 elongtian. All rights reserved.
- //
- #import "StockingGoodsListViewController.h"
- #import "StockingGoodsCell.h"
- @interface StockingGoodsListViewController ()<UITableViewDataSource, UITableViewDelegate>
- @end
- @implementation StockingGoodsListViewController
- @synthesize customTableView;
- #pragma mark - 公共函数
- /**
- viewDidLoad函数
- */
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self showTitle:@"库存商品一览"];
- [self initUI];
- [self reloadDataByOnlyCode];
- }
- /**
- 安全区视图发生变化
- */
- -(void)viewSafeAreaInsetsDidChange{
- self.view.backgroundColor = [UIColor whiteColor];
- customTableView.frame = self.view.safeAreaLayoutGuide.layoutFrame;
- [super viewSafeAreaInsetsDidChange];
- }
- #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 [_newdataList 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 181;
- }
- /**
- 每个单元格cell
-
- @param tableView <#tableView description#>
- @param indexPath <#indexPath description#>
- @return <#return value description#>
- */
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *CellIdentifier = @"StockingGoodsCell";
- StockingGoodsCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- if (!cell) {
- cell=[[StockingGoodsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
- cell.selectionStyle=UITableViewCellSelectionStyleNone;
- }
- else
- //当页面拉动的时候 当cell存在并且最后一个存在 把它进行删除就出来一个独特的cell我们在进行数据配置即可避免
- {
- while ([cell.contentView.subviews lastObject] != nil) {
- [(UIView *)[cell.contentView.subviews lastObject] removeFromSuperview];
- }
- }
- // StockingGoodsCell *cell=[[StockingGoodsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
- // cell.selectionStyle=UITableViewCellSelectionStyleNone;
- _infoModel = [_newdataList objectAtIndex:indexPath.row];
- cell.model = _infoModel;
- // 强制布局 xib时调用
- //[cell layoutIfNeeded];
- return cell;
- }
- /**
- 点击单元格事件
-
- @param tableView <#tableView description#>
- @param indexPath <#indexPath description#>
- */
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if ([self.stockDelegate respondsToSelector:@selector(stockTextDoneDatas:)]) {
- [self.stockDelegate stockTextDoneDatas:self.newdataList[indexPath.row]];
- }
-
- [self.navigationController popViewControllerAnimated:YES];
- }
- #pragma mark - scrollView回调
- /**
- 刷新数据源
- */
- -(void)refreshTableView
- {
- [self.customTableView reloadData];
- }
- /**
- 加载列表数据失败回调
-
- @param sender <#sender description#>
- */
- - (void)onLoadFail:(ASIDownManager *)sender {
- [self cancel];
- [self showAlertViewText:@"加载失败"];
- }
- /**
- 加载列表数据成功回调
-
- @param sender <#sender description#>
- */
- - (void)onLoadFinish:(ASIDownManager *)sender
- {
- [self cancel];
- 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)
- {
- NSArray * infoArr=[dic objectForKey:@"Result"];
- if(infoArr!=nil&& infoArr.count>0)
- {
- [self.dataList removeAllObjects];
- [_newdataList removeAllObjects];
-
- [self.dataList addObjectsFromArray:infoArr];
- // 转换model对象
- if(self.dataList.count >0 )
- {
- // 格式化日期
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- [dateFormatter setDateFormat:@"yyyy-MM-dd"];
-
- for (int i = 0; i < self.dataList.count; i++)
- {
- NSDictionary *dicValue = self.dataList[i];
- StockingModel *model = [StockingModel new];
- model.inventoryID = [[dicValue objectForKey:@"InventoryID"]stringValue];
- model.codeID = [[dicValue objectForKey:@"CodeID"]stringValue];
- model.code = [dicValue objectForKey:@"Code"];
- model.onlyCode = [dicValue objectForKey:@"OnlyCode"];
- model.specification = [dicValue objectForKey:@"Specification"];
- model.colorNumber = [dicValue objectForKey:@"ColorNumber"];
- model.gradeName = [dicValue objectForKey:@"GradeName"];
- model.warehouseName = [dicValue objectForKey:@"WarehouseName"];
- model.positionNumber = [dicValue objectForKey:@"PositionNumber"];
- model.quantity = [[dicValue objectForKey:@"InventoryQuantity"] stringValue];
- model.balanceQuantity = [[dicValue objectForKey:@"BalanceQuantity"] stringValue];
- [_newdataList addObject:model];
- }
- }
-
- if(self.dataList.count==0){
- [self showAlertViewText:@"未找到匹配结果"];
- }
-
- [customTableView reloadData];
-
- }
- else{
- // 有刷新数据的时候
- if(_dataList == nil || _dataList.count==0){
- [self showAlertViewBackText:@"未找到匹配结果"];
- }
- }
- }
- // 服务器返回数据状态值异常
- else if(iStatus==ActionResultStatusAuthError
- ||iStatus==ActionResultStatusNoLogin
- ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid)
- {
- [self showReLoginDialog:message];
- }
- else
- {
- [self showAlertViewText:message];
- return;
- }
- }
- }
- #pragma mark - 刷新回调
- /**
- 隐藏进度条
- */
- - (void)cancel {
- [self stopLoading];
- }
- /**
- 隐藏键盘
-
- @param scrollView <#scrollView description#>
- */
- -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
- {
- [self.view endEditing:YES];
- }
- #pragma mark - 私有函数
- /**
- 初始化ui
- */
- - (void)initUI{
- _dataList=[[NSMutableArray alloc]init];
- _newdataList=[[NSMutableArray alloc]init];
- _infoModel=[[StockingModel alloc]init];
- customTableView = [[UITableView alloc]
- initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,
- Screen_Height-rectNavHeight-rectStatusHeight)];
-
- customTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- customTableView.delegate = self;
- customTableView.dataSource = self;
- [self.view addSubview:customTableView];
- }
- /**
- 加载数据
- */
- -(void)reloadDataByOnlyCode
- {
- //NSString *urlStr = ServerURL;
- NSMutableDictionary *dict = [NSMutableDictionary dictionary];
- [dict setObject:@"GetInventoryByOnlyCodeIphone" 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:_onlyCode forKeyedSubscript:@"OnlyCode"];
-
- self.downManager = [[ASIDownManager alloc] init];
- self.downManager.delegate = self;
- self.downManager.OnImageDown = @selector(onLoadFinish:);
- self.downManager.OnImageFail = @selector(onLoadFail:);
- [self.downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
- }
- @end
|