StockingViewController.m 15 KB

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