StockingViewController.m 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. //
  2. // StockingViewController.m
  3. // IBOSSmini
  4. //
  5. // Created by apple on 2017/5/15.
  6. // Copyright © 2017年 elongtian. All rights reserved.
  7. //
  8. #import "StockingViewController.h"
  9. #import "StockingDetailViewController.h"
  10. #import "StockingCell.h"
  11. #import "NewStockingViewController.h"
  12. #import "SideSlipModel.h"
  13. #import "StockingSearchModel.h"
  14. #import "DateFormat.h"
  15. @interface StockingViewController ()<UITableViewDataSource, UITableViewDelegate,RefreshTableViewDelegate,StockRefreshDataProtocol>{
  16. int pageNumber;
  17. }
  18. @end
  19. @implementation StockingViewController
  20. @synthesize customTableView;
  21. #pragma mark - 公共函数
  22. /**
  23. viewDidLoad函数
  24. */
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. [self loadNavStyle];
  28. [self initUI];
  29. [self initSlideSlip];
  30. [self startLoading];
  31. [self reloadData];
  32. }
  33. #pragma mark - 委托回调函数
  34. #pragma mark - tableView回调
  35. /**
  36. 单元格cell个数
  37. @param tableView <#tableView description#>
  38. @param section <#section description#>
  39. @return <#return value description#>
  40. */
  41. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  42. {
  43. return [self.dataList count];
  44. }
  45. /**
  46. <#Description#>
  47. @param tableView <#tableView description#>
  48. @return <#return value description#>
  49. */
  50. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  51. return 1;
  52. }
  53. /**
  54. 高度
  55. @param tableView <#tableView description#>
  56. @param indexPath <#indexPath description#>
  57. @return <#return value description#>
  58. */
  59. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  60. return 220;
  61. }
  62. /**
  63. 预计高度
  64. @param tableView <#tableView description#>
  65. @param indexPath <#indexPath description#>
  66. @return <#return value description#>
  67. */
  68. - (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
  69. return 220;
  70. }
  71. /**
  72. 每个单元格cell
  73. @param tableView <#tableView description#>
  74. @param indexPath <#indexPath description#>
  75. @return <#return value description#>
  76. */
  77. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  78. {
  79. static NSString *CellIdentifier = @"StockingCell";
  80. StockingCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  81. if (!cell) {
  82. cell=[[StockingCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  83. cell.selectionStyle=UITableViewCellSelectionStyleNone;
  84. }
  85. else
  86. //当页面拉动的时候 当cell存在并且最后一个存在 把它进行删除就出来一个独特的cell我们在进行数据配置即可避免
  87. {
  88. while ([cell.contentView.subviews lastObject] != nil) {
  89. [(UIView *)[cell.contentView.subviews lastObject] removeFromSuperview];
  90. }
  91. }
  92. // StockingCell *cell=[[StockingCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
  93. // cell.selectionStyle=UITableViewCellSelectionStyleNone;
  94. _infoModel = [_newdataList objectAtIndex:indexPath.row];
  95. cell.model = _infoModel;
  96. // 强制布局 xib时调用
  97. //[cell layoutIfNeeded];
  98. return cell;
  99. }
  100. /**
  101. 点击单元格事件
  102. @param tableView <#tableView description#>
  103. @param indexPath <#indexPath description#>
  104. */
  105. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  106. {
  107. self.hidesBottomBarWhenPushed=YES;
  108. StockingDetailViewController *detailVc=[[StockingDetailViewController alloc] init];
  109. _infoModel= [_newdataList objectAtIndex:indexPath.row];
  110. detailVc.stockingID = _infoModel.stockingID;
  111. [self.navigationController pushViewController:detailVc animated:YES];
  112. }
  113. #pragma mark - scrollView回调
  114. /**
  115. 显示下拉更新
  116. @param scrollView <#scrollView description#>
  117. */
  118. - (void)scrollViewDidScroll:(UIScrollView *)scrollView{
  119. if (scrollView.isDragging) {//显示下拉更新
  120. if (customTableView.mRefreshHeader.state == PullRefreshPulling && scrollView.contentOffset.y > -65.0f && scrollView.contentOffset.y < 0.0f && [customTableView CanRefresh]) {
  121. [customTableView.mRefreshHeader setState:PullRefreshNormal];
  122. }
  123. else if (customTableView.mRefreshHeader.state == PullRefreshNormal && scrollView.contentOffset.y < -65.0f && [customTableView CanRefresh]) {//显示松开更新
  124. [customTableView.mRefreshHeader setState:PullRefreshPulling];
  125. }
  126. }
  127. }
  128. /**
  129. 刷新数据源
  130. */
  131. -(void)refreshTableView
  132. {
  133. [self.customTableView reloadData];
  134. }
  135. /**
  136. 加载列表数据失败回调
  137. @param sender <#sender description#>
  138. */
  139. - (void)onLoadFail:(ASIDownManager *)sender {
  140. [self cancel];
  141. [self showAlertViewText:@"加载失败"];
  142. }
  143. /**
  144. 加载列表数据成功回调
  145. @param sender <#sender description#>
  146. */
  147. - (void)onLoadFinish:(ASIDownManager *)sender {
  148. [self cancel];
  149. // 服务器返回数据
  150. NSDictionary *dic = [sender.mWebStr JSONValue];
  151. int iNewCount = 0;
  152. customTableView.mTableView.backgroundView = nil;
  153. // 服务器返回数据是否正确
  154. if (dic && [dic isKindOfClass:[NSDictionary class]])
  155. {
  156. // 服务器返回数据状态值
  157. int iStatus = [[dic objectForKey:@"Status"] intValue];
  158. // 服务器返回数据消息
  159. NSString *message=[dic objectForKey:@"Message"];
  160. // 服务器返回数据状态值正确
  161. if (iStatus == 0)
  162. {
  163. // 数据结果
  164. NSArray * infoArr=[dic objectForKey:@"Result"];
  165. if(infoArr!=nil&& infoArr.count>0)
  166. {
  167. if (pageNumber == 1) {
  168. [self.dataList removeAllObjects];
  169. [self.newdataList removeAllObjects];
  170. }
  171. [self.dataList addObjectsFromArray:infoArr];
  172. // 转换model对象
  173. if(self.dataList.count >0 )
  174. {
  175. DateFormat *d =[DateFormat new];
  176. for (int i = 0; i < self.dataList.count; i++) {
  177. NSDictionary *dicValue = self.dataList[i];
  178. StockingModel *model = [StockingModel new];
  179. model.code = [dicValue objectForKey:@"Code"];
  180. model.onlyCode = [dicValue objectForKey:@"OnlyCode"];
  181. model.specification = [dicValue objectForKey:@"Specification"];
  182. model.colorNumber = [dicValue objectForKey:@"ColorNumber"];
  183. model.gradeName = [dicValue objectForKey:@"GradeName"];
  184. model.warehouseName = [dicValue objectForKey:@"WarehouseName"];
  185. model.positionNumber = [dicValue objectForKey:@"PositionNumber"];
  186. model.stockingNo = [dicValue objectForKey:@"CheckNo"];
  187. model.stockingID = [[dicValue objectForKey:@"DetailID"]stringValue];
  188. model.createUser = [dicValue objectForKey:@"UserName"];
  189. model.createTime = [d dateFormat:[dicValue objectForKey:@"CreateTime"]];
  190. [self.newdataList addObject:model];
  191. }
  192. }
  193. if(self.dataList.count==0){
  194. [self showAlertViewText:@"未找到匹配结果"];
  195. }
  196. iNewCount =(int)infoArr.count;
  197. //pageNumber ++;
  198. customTableView.mbMoreHidden = (iNewCount == 0);
  199. [customTableView FinishLoading];
  200. [customTableView reloadData];
  201. }
  202. else{
  203. // 无数据 关宏厚 2017-7-6
  204. [customTableView FinishLoading];
  205. customTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  206. UIView *noDataView=[[UIView alloc]init];
  207. noDataView.frame= customTableView.mTableView.bounds;
  208. UIImageView *nodataImgView=[[UIImageView alloc] initWithFrame:CGRectMake(noDataView.frame.size.width/2-16,noDataView.frame.size.height/2-16,32,32)];
  209. [nodataImgView setImage:[UIImage imageNamed:@"icon_no_data"]];
  210. [noDataView addSubview:nodataImgView];
  211. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(noDataView.frame.size.width/2-16-12,CGRectGetMaxY(nodataImgView.frame)+3,70, 25)];
  212. label.font=[UIFont systemFontOfSize:NoDataFontOfSize];
  213. label.text = @"无数据";
  214. label.numberOfLines = 2;
  215. label.textColor = [UIColor lightGrayColor];
  216. [noDataView addSubview:label];
  217. ;
  218. // 有刷新数据的时候
  219. if(_dataList == nil || _dataList.count==0){
  220. customTableView.mTableView.backgroundView = noDataView;
  221. [self showAlertViewBackText:@"未找到匹配结果"];
  222. }
  223. }
  224. }
  225. // 服务器返回数据状态值异常
  226. else if(iStatus==ActionResultStatusAuthError
  227. ||iStatus==ActionResultStatusNoLogin
  228. ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid){
  229. [self showReLoginDialog:message];
  230. }
  231. else{
  232. [customTableView FinishLoading];
  233. [self showAlertViewText:message];
  234. }
  235. }
  236. }
  237. #pragma mark - 刷新回调
  238. /**
  239. 新增盘点后刷新回调
  240. */
  241. - (void)refreshData{
  242. pageNumber = 1;
  243. [_dataList removeAllObjects];
  244. [_newdataList removeAllObjects];
  245. [customTableView reloadData];
  246. customTableView.mbMoreHidden=YES;
  247. [self startLoading];
  248. [self reloadData];
  249. }
  250. /**
  251. 取消刷新
  252. @param sender <#sender description#>
  253. @return <#return value description#>
  254. */
  255. - (BOOL)CanRefreshTableView:(RefreshTableView *)sender {
  256. return YES;
  257. }
  258. /**
  259. 加载更多
  260. @param sender <#sender description#>
  261. */
  262. - (void)LoadMoreList:(RefreshTableView *)sender {
  263. pageNumber++;
  264. [self startLoading];
  265. [self reloadData];
  266. }
  267. /**
  268. 下拉刷新
  269. @param sender <#sender description#>
  270. */
  271. - (void)ReloadList:(RefreshTableView *)sender{
  272. pageNumber = 1;
  273. [_dataList removeAllObjects];
  274. [_newdataList removeAllObjects];
  275. [customTableView reloadData];
  276. customTableView.mbMoreHidden=YES;
  277. [self startLoading];
  278. [self reloadData];
  279. }
  280. /**
  281. 隐藏进度条
  282. */
  283. - (void)cancel {
  284. [self stopLoading];
  285. }
  286. /**
  287. 隐藏键盘
  288. @param scrollView <#scrollView description#>
  289. */
  290. -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
  291. {
  292. [self.view endEditing:YES];
  293. }
  294. #pragma mark - 私有函数
  295. /**
  296. 返回
  297. */
  298. - (void)goBack
  299. {
  300. [self.navigationController popViewControllerAnimated:YES];
  301. }
  302. /**
  303. 安全区视图发生变化
  304. */
  305. -(void)viewSafeAreaInsetsDidChange{
  306. self.view.backgroundColor = [UIColor whiteColor];
  307. customTableView.frame = CGRectMake(0, 50, Screen_Width, self.view.safeAreaLayoutGuide.layoutFrame.size.height-50);
  308. [super viewSafeAreaInsetsDidChange];
  309. }
  310. /**
  311. 导航按钮样式
  312. */
  313. -(void)loadNavStyle
  314. {
  315. self.navigationItem.title = @"库存盘点";
  316. //右边
  317. UIButton *btnAdd = [UIButton buttonWithType:UIButtonTypeCustom];
  318. [btnAdd addTarget:self action:@selector(add)
  319. forControlEvents:UIControlEventTouchUpInside];
  320. UIImage *pic =[UIImage imageNamed:@"title_add"];
  321. btnAdd.frame =CGRectMake(0, 0, 18, 18);
  322. [btnAdd setTitleColor:NavBarItemColor forState:UIControlStateNormal];
  323. [btnAdd setBackgroundImage:pic
  324. forState:UIControlStateNormal];
  325. UIBarButtonItem *menubtnAdd = [[UIBarButtonItem alloc] initWithCustomView:btnAdd];
  326. self.navigationItem.rightBarButtonItem = menubtnAdd;
  327. //返回
  328. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  329. [button setBackgroundImage:[UIImage imageNamed:@"icon_back"]
  330. forState:UIControlStateNormal];
  331. [button addTarget:self action:@selector(goBack)
  332. forControlEvents:UIControlEventTouchUpInside];
  333. button.frame = CGRectMake(0, 0, 15, 18);
  334. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  335. self.navigationItem.leftBarButtonItem = menuButton;
  336. }
  337. /**
  338. 新增
  339. */
  340. - (void)add{
  341. self.hidesBottomBarWhenPushed=YES;
  342. NewStockingViewController *vc=[[NewStockingViewController alloc] init];
  343. vc.stockDelegate = self;
  344. [self.navigationController pushViewController:vc animated:YES];
  345. }
  346. /**
  347. 初始化ui
  348. */
  349. - (void)initUI{
  350. CGFloat height = 40;
  351. UIView *searchView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_Width, 50)];
  352. searchView.backgroundColor = [UIColor whiteColor];
  353. UIButton *btnSearch = [UIButton buttonWithType:UIButtonTypeCustom];
  354. btnSearch.frame = CGRectMake(20, 5, Screen_Width-height, height);
  355. btnSearch.layer.cornerRadius = 6.0f;
  356. [btnSearch setTitle:@"搜索" forState:UIControlStateNormal];
  357. [btnSearch setTitleColor:NavBarUnEnbleItemColor forState:UIControlStateNormal];
  358. btnSearch.titleLabel.textAlignment = NSTextAlignmentCenter;
  359. btnSearch.titleLabel.font = [UIFont systemFontOfSize:LabelAndTextFontOfSize];
  360. btnSearch.backgroundColor = LineBackgroundColor;
  361. [btnSearch addTarget:self action:@selector(dataSearch) forControlEvents:UIControlEventTouchUpInside];
  362. [searchView addSubview:btnSearch];
  363. [self.view addSubview:searchView];
  364. _dataList=[[NSMutableArray alloc]init];
  365. _newdataList=[[NSMutableArray alloc]init];
  366. _infoModel=[[StockingModel alloc]init];
  367. customTableView = [[RefreshTableView alloc]
  368. initWithFrame:CGRectMake(0,
  369. CGRectGetMaxY(searchView.frame),
  370. self.view.frame.size.width,
  371. Screen_Height - CGRectGetMaxY(searchView.frame) + 5 )];
  372. customTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  373. customTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
  374. customTableView.backgroundColor = [UIColor whiteColor];
  375. customTableView.delegate = self;
  376. [self.view addSubview:customTableView];
  377. pageNumber = 1;
  378. }
  379. /**
  380. 加载数据
  381. */
  382. -(void)reloadData
  383. {
  384. //NSString *urlStr = ServerURL;
  385. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  386. [dict setObject:@"GetInventoryCheckDataIphone" forKey:@"Action"];
  387. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  388. [dict setObject:kkUserCode forKey:@"UserCode"];
  389. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  390. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  391. [dict setObject:[NSString stringWithFormat:@"%d",pageNumber] forKey:@"PageNum"];
  392. [dict setObject:[NSString stringWithFormat:@"%d",pageSize] forKey:@"PageSize"];
  393. [dict setObject:_stockNo forKeyedSubscript:@"CheckNo"];
  394. [dict setObject:_onlyCode forKeyedSubscript:@"OnlyCode"];
  395. [dict setObject:_warehouse forKeyedSubscript:@"WarehouseName"];
  396. //[dict setObject:@"1" forKeyedSubscript:@"DetailID"];
  397. self.downManager = [[ASIDownManager alloc] init];
  398. _downManager.delegate = self;
  399. _downManager.OnImageDown = @selector(onLoadFinish:);
  400. _downManager.OnImageFail = @selector(onLoadFail:);
  401. [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
  402. }
  403. /**
  404. 抽屉弹出
  405. */
  406. - (void)dataSearch{
  407. [_filterController show];
  408. }
  409. /**
  410. 抽屉初始化
  411. */
  412. - (void)initSlideSlip{
  413. // 抽屉对象
  414. __weak typeof(self) weakself=self;
  415. self.filterController = [[SideSlipFilterController alloc] initWithSponsor:self resetBlock:^(NSArray *dataList) {
  416. for (SideSlipModel *model in dataList) {
  417. //selectedItem
  418. model.selectedItemList = nil;
  419. model.customDict = nil;
  420. }
  421. } commitBlock:^(NSArray *dataList) {
  422. // 查询条件
  423. SideSlipModel *serviceRegionModel = dataList[0];
  424. StockingSearchModel *m = [serviceRegionModel.customDict objectForKey:STOCKING_SEARCH_RANGE_MODEL];
  425. // NSLog(@"%@--%@--%@--%@--%d",m.brandID,m.goodsCode,m.onlyCode,m.warehouseID,m.isfilterQuantityEqZero);
  426. self.stockNo = m.stockingNo;
  427. self.onlyCode = m.onlyCode;
  428. self.warehouse = m.warehouse;
  429. [weakself.filterController dismiss];
  430. [self ReloadList:self.customTableView];
  431. }];
  432. _filterController.animationDuration = AnimationDuration;
  433. _filterController.hasHeadView = YES;
  434. _filterController.sideSlipLeading = UIScreenSideSlipLeading*[UIScreen mainScreen].bounds.size.width;
  435. _filterController.dataList = [self packageDataList];
  436. }
  437. /**
  438. 数据源
  439. @return <#return value description#>
  440. */
  441. - (NSArray *)packageDataList {
  442. NSMutableArray *dataArray = [NSMutableArray array];
  443. SideSlipModel *model = [[SideSlipModel alloc] init];
  444. model.containerCellClass = @"StockingSearchCell";
  445. model.regionTitle = @"查询条件";
  446. [dataArray addObject:model];
  447. return [dataArray mutableCopy];
  448. }
  449. @end