InventoryViewController.m 19 KB

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