NewOtherOutStorageGoodsSearchVC.m 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. //
  2. // NewOtherOutStorageGoodsSearchVC.m
  3. // IBOSSmini
  4. //
  5. // Created by guan hong hou on 2018/4/28.
  6. // Copyright © 2018年 elongtian. All rights reserved.
  7. //
  8. #import "NewOtherOutStorageGoodsSearchVC.h"
  9. @interface NewOtherOutStorageGoodsSearchVC (){
  10. int pageNumber;
  11. Boolean isCheckAll;
  12. }
  13. @end
  14. @implementation NewOtherOutStorageGoodsSearchVC
  15. #pragma mark 公共函数
  16. /**
  17. 视图加载完成函数
  18. */
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. [self loadNavStyle];
  22. [self initUI];
  23. }
  24. /**
  25. 安全区变化函数
  26. */
  27. -(void)viewSafeAreaInsetsDidChange{
  28. _vTableView.frame=CGRectMake(0,0,self.view.frame.size.width,self.view.safeAreaLayoutGuide.layoutFrame.size.height-40);
  29. _bottomView.frame=CGRectMake(0, self.view.safeAreaLayoutGuide.layoutFrame.size.height-40, self.view.frame.size.width, 40);
  30. [super viewSafeAreaInsetsDidChange];
  31. }
  32. /**
  33. 内存警告函数
  34. */
  35. - (void)didReceiveMemoryWarning {
  36. [super didReceiveMemoryWarning];
  37. }
  38. #pragma mark 委托函数
  39. /**
  40. 其它出库列表加载成功回调
  41. @param sender <#sender description#>
  42. */
  43. - (void)onLoadFinish:(ASIDownManager *)sender {
  44. [self Cancel];
  45. NSDictionary *dic = [sender.mWebStr JSONValue];
  46. _vTableView.backgroundView = nil;
  47. // 服务器返回数据是否正确
  48. if (dic && [dic isKindOfClass:[NSDictionary class]])
  49. {
  50. // 服务器返回数据状态值
  51. int iStatus = [[dic objectForKey:@"Status"] intValue];
  52. // 服务器返回数据消息
  53. NSString *message=[dic objectForKey:@"Message"];
  54. // 服务器返回数据状态值正确
  55. if (iStatus == 0) {
  56. NSArray * infoArr=[dic objectForKey:@"Result"];
  57. if(infoArr!=nil&& infoArr.count>0)
  58. {
  59. // 转换model对象
  60. if(infoArr.count > 0 ){
  61. for (int i = 0; i < infoArr.count; i++) {
  62. NSDictionary *str=infoArr[i];
  63. InventoryModel *model = [InventoryModel new];
  64. model.code=[str objectForKey:@"Code"];
  65. model.inventoryId=[NSString stringWithFormat:@"%ld",[[str objectForKey:@"InventoryID"]integerValue]];
  66. model.codeId=[[str objectForKey:@"CodeID"]integerValue];
  67. model.kindId=[NSString stringWithFormat:@"%ld",[[str objectForKey:@"KindID"]integerValue]];
  68. model.kindName=[str objectForKey:@"KindName"];
  69. model.varietyId=[NSString stringWithFormat:@"%ld",[[str objectForKey:@"VarietyID"]integerValue]];
  70. model.varietyName=[str objectForKey:@"VarietyName"];
  71. model.seriesId=[NSString stringWithFormat:@"%ld",[[str objectForKey:@"SeriesID"]integerValue]];
  72. model.seriesName=[str objectForKey:@"SeriesName"];
  73. model.onlyCode=[str objectForKey:@"OnlyCode"];
  74. model.unitId=[NSString stringWithFormat:@"%ld",[[str objectForKey:@"UnitID"]integerValue]];
  75. model.unitName=[str objectForKey:@"UnitName"];
  76. model.weight=[NSString stringWithFormat:@"%lf",[[str objectForKey:@"Weight"]doubleValue]];
  77. model.goodsName=[str objectForKey:@"GoodsName"];
  78. model.acreage=[[str objectForKey:@"Acreage"]doubleValue];
  79. model.specification=[str objectForKey:@"Specification"];
  80. model.colorNumber=[str objectForKey:@"ColorNumber"];
  81. model.decimalPlaces=[NSString stringWithFormat:@"%d",[[str objectForKey:@"DecimalPlaces"]intValue]];
  82. model.brandName=[str objectForKey:@"BrandName"];
  83. model.gradeName=[str objectForKey:@"GradeName"];
  84. model.warehouseId=[NSString stringWithFormat:@"%ld",[[str objectForKey:@"WarehouseID"]integerValue]];
  85. model.wareHouseName=[str objectForKey:@"WarehouseName"];
  86. model.priorColorNumber=[NSString stringWithFormat:@"%ld",[[str objectForKey:@"PriorColorNumber"]integerValue]];
  87. model.priorInventoryId=[NSString stringWithFormat:@"%ld",[[str objectForKey:@"PriorInventoryID"]integerValue]];
  88. model.goodsRemarks=[str objectForKey:@"GoodsRemarks"];
  89. model.remarks=[str objectForKey:@"Remarks"];
  90. model.expandAtrribute=[str objectForKey:@"ExpandAtrribute"];
  91. model.expandAtrribute2=[str objectForKey:@"ExpandAtrribute2"];
  92. model.positionNumber=[str objectForKey:@"PositionNumber"];
  93. NSInteger circulateType=[[str objectForKey:@"CirculateType"]integerValue];
  94. model.circulateType=circulateType;
  95. NSInteger package= [[str objectForKey:@"Package"]integerValue];
  96. model.package=[NSString stringWithFormat:@"%ld",package];
  97. model.outQuantity=@"1";
  98. NSString *InventoryQuantity = [[str objectForKey:@"InventoryQuantity"]stringValue];
  99. model.inventoryQuantity=InventoryQuantity == nil?@"0":InventoryQuantity;
  100. double CanSaleQuantity = [[str objectForKey:@"BalanceQuantity"]doubleValue];
  101. model.canSaleQuantity=[NSString stringWithFormat:@"%lf",CanSaleQuantity];
  102. NSString *jzj = [[str objectForKey:@"jzj"]stringValue];
  103. model.price=jzj==nil?@"0":jzj;
  104. [_dataList addObject:model];
  105. }
  106. }
  107. [_vTableView reloadData];
  108. }
  109. else{
  110. _vTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  111. if(self.dataList.count==0){
  112. UIView *noDataView=[[UIView alloc]init];
  113. noDataView.frame= _vTableView.bounds;
  114. UIImageView *nodataImgView=[[UIImageView alloc] initWithFrame:CGRectMake(noDataView.frame.size.width/2-16,noDataView.frame.size.height/2-16,32,32)];
  115. [nodataImgView setImage:[UIImage imageNamed:@"icon_no_data"]];
  116. [noDataView addSubview:nodataImgView];
  117. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(noDataView.frame.size.width/2-16-12,CGRectGetMaxY(nodataImgView.frame)+3,70, 25)];
  118. label.font=[UIFont systemFontOfSize:NoDataFontOfSize];
  119. label.text = @"无数据";
  120. label.numberOfLines = 2;
  121. label.textColor = [UIColor lightGrayColor];
  122. [noDataView addSubview:label];
  123. _vTableView.backgroundView =noDataView;
  124. [self showAlertViewBackText:@"未找到匹配结果"];
  125. }
  126. }
  127. }
  128. // 服务器返回数据状态值异常
  129. else if(iStatus==ActionResultStatusAuthError
  130. ||iStatus==ActionResultStatusNoLogin
  131. ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid){
  132. [self showReLoginDialog:message];
  133. }
  134. else{
  135. [self showAlertViewText:message];
  136. }
  137. }
  138. }
  139. /**
  140. 其它出库列表加载失败回调
  141. @param sender <#sender description#>
  142. */
  143. - (void)onLoadFail:(ASIDownManager *)sender {
  144. [self Cancel];
  145. [self showAlertViewText:@"加载失败"];
  146. }
  147. /**
  148. checkbox点击回调函数
  149. @param index <#index description#>
  150. */
  151. -(void)btnCheckPressed:(NSInteger)index{
  152. _inventoryModel= [_dataList objectAtIndex:index];
  153. _inventoryModel.isCheckedStatus=!_inventoryModel.isCheckedStatus;
  154. //1.当前所要刷新的cell,传入要刷新的 行数 和 组数
  155. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:index inSection:0];
  156. //2.将indexPath添加到数组
  157. NSArray <NSIndexPath *> *indexPathArray = @[indexPath];
  158. //3.传入数组,对当前cell进行刷新
  159. [_vTableView reloadRowsAtIndexPaths:indexPathArray withRowAnimation:UITableViewRowAnimationAutomatic];
  160. if([self isCheckedAll]){
  161. isCheckAll=YES;
  162. [_btnCheckAll setImage:[UIImage imageNamed:@"check_round"] forState:UIControlStateNormal];
  163. }
  164. else{
  165. isCheckAll=NO;
  166. [_btnCheckAll setImage:[UIImage imageNamed:@"uncheck_round"] forState:UIControlStateNormal];
  167. }
  168. NSInteger num=[self getCheckedGoodsCount:_dataList];
  169. NSString *sureCount=[NSString stringWithFormat:@"%@%ld%@",@"确定(",num,@")"];
  170. [_sureBtn setTitle:sureCount forState:UIControlStateNormal];
  171. }
  172. /**
  173. 单元格cell个数
  174. @param tableView <#tableView description#>
  175. @param section <#section description#>
  176. @return <#return value description#>
  177. */
  178. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  179. {
  180. return [self.dataList count];
  181. }
  182. /**
  183. tableview的分区数
  184. @param tableView <#tableView description#>
  185. @return <#return value description#>
  186. */
  187. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  188. return 1;
  189. }
  190. /**
  191. 高度
  192. @param tableView <#tableView description#>
  193. @param indexPath <#indexPath description#>
  194. @return <#return value description#>
  195. */
  196. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  197. return 220;
  198. }
  199. /**
  200. 每个单元格cell
  201. @param tableView <#tableView description#>
  202. @param indexPath <#indexPath description#>
  203. @return <#return value description#>
  204. */
  205. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  206. {
  207. static NSString *cellIdentifier = @"OtherOutStorageSearchCell";
  208. OtherOutStorageGoodsSearchCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
  209. if (!cell) {
  210. cell=[[OtherOutStorageGoodsSearchCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
  211. cell.selectionStyle=UITableViewCellSelectionStyleNone;
  212. }
  213. else
  214. //当页面拉动的时候 当cell存在并且最后一个存在 把它进行删除就出来一个独特的cell我们在进行数据配置即可避免
  215. {
  216. while ([cell.contentView.subviews lastObject] != nil) {
  217. [(UIView *)[cell.contentView.subviews lastObject] removeFromSuperview];
  218. }
  219. }
  220. InventoryModel *infoModel = [_dataList objectAtIndex:indexPath.row];
  221. [cell setOtherOutStorageGoodsListModel:infoModel];
  222. cell.checkDelegate=self;
  223. cell.cellIndex=indexPath.row;
  224. [cell setCheckBackground:infoModel.isCheckedStatus];
  225. return cell;
  226. }
  227. /**
  228. 隐藏键盘
  229. @param scrollView <#scrollView description#>
  230. */
  231. -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
  232. {
  233. [self.view endEditing:YES];
  234. }
  235. #pragma mark 私有函数
  236. /**
  237. 导航按钮样式
  238. */
  239. -(void)loadNavStyle
  240. {
  241. self.navigationItem.title=@"库存商品";
  242. //返回
  243. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  244. [button setBackgroundImage:[UIImage imageNamed:@"icon_back"]
  245. forState:UIControlStateNormal];
  246. [button addTarget:self action:@selector(goBack)
  247. forControlEvents:UIControlEventTouchUpInside];
  248. button.frame = CGRectMake(0, 0, 15, 18);
  249. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  250. self.navigationItem.leftBarButtonItem = menuButton;
  251. }
  252. /**
  253. 返回函数
  254. */
  255. - (void)goBack
  256. {
  257. [self.navigationController popViewControllerAnimated:YES];
  258. }
  259. /**
  260. 初始化UI
  261. */
  262. -(void)initUI{
  263. [self.view setBackgroundColor:[UIColor whiteColor]];
  264. _vTableView = [[UITableView alloc]
  265. initWithFrame:CGRectMake(0,
  266. 0,
  267. self.view.frame.size.width,
  268. Screen_Height-40)];
  269. [_vTableView setBackgroundColor:[UIColor whiteColor]];
  270. _vTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  271. _vTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
  272. _vTableView.dataSource=self;
  273. _vTableView.delegate = self;
  274. [self.view addSubview:_vTableView];
  275. //保存
  276. _bottomView=[UIView new];
  277. _bottomView.frame=CGRectMake(0, Screen_Height-103, self.view.frame.size.width, 40);
  278. [self.view addSubview:_bottomView];
  279. _btnCheckAll=[UIButton buttonWithType:UIButtonTypeCustom];
  280. _btnCheckAll.frame=CGRectMake(15,8, 25, 25);
  281. [_btnCheckAll setImage:[UIImage imageNamed:@"uncheck_round"] forState:UIControlStateNormal];
  282. [_btnCheckAll addTarget:self action:@selector(btnCheckall)
  283. forControlEvents:UIControlEventTouchUpInside];
  284. [_bottomView addSubview:_btnCheckAll];
  285. UILabel *lblall=[UILabel new];
  286. lblall.frame=CGRectMake(CGRectGetMaxX(_btnCheckAll.frame)+3,8, 60, 25);
  287. lblall.text=@"全选";
  288. [_bottomView addSubview:lblall];
  289. _sureBtn=[UIButton buttonWithType:UIButtonTypeCustom];
  290. [_sureBtn setTitle:@"确定" forState:UIControlStateNormal];
  291. [_sureBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  292. _sureBtn.frame=CGRectMake(Screen_Width-114,0, 114,40);
  293. [_sureBtn setBackgroundColor:[UIColor colorWithRed:189.0/255.0 green:0 blue:7.0/255.0 alpha:1]];
  294. [_sureBtn addTarget:self action:@selector(submitData) forControlEvents:UIControlEventTouchUpInside];
  295. [_bottomView addSubview:_sureBtn];
  296. _dataList=[[NSMutableArray alloc]init];
  297. pageNumber=1;
  298. [self startLoading];
  299. [self loadData];
  300. }
  301. /**
  302. 加载数据源
  303. */
  304. -(void)loadData{
  305. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  306. [dict setObject:@"GetInventoryDataIphone" forKey:@"Action"];
  307. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  308. [dict setObject:kkUserCode forKey:@"UserCode"];
  309. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  310. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  311. [dict setObject:_goodsName forKeyedSubscript:@"GoodsName"];
  312. [dict setObject:_goodsCode forKeyedSubscript:@"Code"];
  313. [dict setObject:_onlyCode forKeyedSubscript:@"OnlyCode"];
  314. [dict setObject:_warehouseId forKeyedSubscript:@"WarehouseID"];
  315. [dict setObject:_brandId forKeyedSubscript:@"BrandID"];
  316. if(_isfilterQuantityEqZero){
  317. [dict setObject:@"1" forKey:@"isfilterQuantityEqZero"];
  318. }else{
  319. [dict setObject:@"" forKey:@"isfilterQuantityEqZero"];
  320. }
  321. _downManager = [[ASIDownManager alloc] init];
  322. _downManager.delegate = self;
  323. _downManager.OnImageDown = @selector(onLoadFinish:);
  324. _downManager.OnImageFail = @selector(onLoadFail:);
  325. [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
  326. }
  327. -(void)submitData{
  328. if(_dataList!=nil&&_dataList.count>0){
  329. NSInteger num= [self getCheckedGoodsCount:_dataList];
  330. if(num==0){
  331. [self showAlertViewText:@"请选择商品"];
  332. return;
  333. }
  334. NSMutableArray *checkedGoodsList=[[NSMutableArray alloc]init];
  335. for(InventoryModel *model in _dataList){
  336. if(model.isCheckedStatus){
  337. [checkedGoodsList addObject:model];
  338. }
  339. }
  340. if(_goodsDetailList!=nil&&_goodsDetailList.count>0){
  341. for(InventoryModel *model in checkedGoodsList.reverseObjectEnumerator){
  342. for(InventoryModel *inventoryModel in _goodsDetailList.reverseObjectEnumerator){
  343. if([model.inventoryId isEqualToString: inventoryModel.inventoryId] &&model.isCheckedStatus) {
  344. [checkedGoodsList removeObject:model];
  345. break;
  346. }
  347. }
  348. }
  349. }
  350. if([self.goodsDelegate respondsToSelector:@selector(showSelectedGoods: )]){
  351. [self.goodsDelegate showSelectedGoods:checkedGoodsList];
  352. }
  353. [self.navigationController popViewControllerAnimated:YES];
  354. }
  355. }
  356. /**
  357. 选中所有数据函数
  358. */
  359. -(void)btnCheckall{
  360. [self updateAllCellCheck];
  361. NSInteger num= [self getCheckedGoodsCount:_dataList];
  362. NSString *sureCount=[NSString stringWithFormat:@"%@%ld%@",@"确定(",num,@")"];
  363. [_sureBtn setTitle:sureCount forState:UIControlStateNormal];
  364. [_vTableView reloadData];
  365. }
  366. -(NSInteger) getCheckedGoodsCount:(NSMutableArray*)goodsList{
  367. int num=0;
  368. NSMutableArray *goodsSubmitList=[[NSMutableArray alloc]init];
  369. NSInteger count=goodsList.count;
  370. for(int i=0;i<count;i++){
  371. InventoryModel *model= goodsList[i];
  372. if(model.isCheckedStatus){
  373. num++;
  374. [goodsSubmitList addObject:model];
  375. }
  376. }
  377. NSInteger checkedCount=goodsSubmitList.count;
  378. return checkedCount;
  379. }
  380. /**
  381. 全选或者全不选
  382. @param BOOL <#BOOL description#>
  383. @return <#return value description#>
  384. */
  385. -(BOOL)updateAllCellCheck
  386. {
  387. if(!isCheckAll){
  388. isCheckAll=YES;
  389. [_btnCheckAll setImage:[UIImage imageNamed:@"check_round"] forState:UIControlStateNormal];
  390. for(InventoryModel *goodsModel in _dataList) {
  391. goodsModel.isCheckedStatus=YES;
  392. }
  393. }
  394. else
  395. {
  396. [_btnCheckAll setImage:[UIImage imageNamed:@"uncheck_round"] forState:UIControlStateNormal];
  397. isCheckAll=NO;
  398. for(InventoryModel *goodsModel in _dataList) {
  399. goodsModel.isCheckedStatus=NO;
  400. }
  401. }
  402. return NO;
  403. }
  404. /**
  405. 看是否全选
  406. @return <#return value description#>
  407. */
  408. -(BOOL)isCheckedAll
  409. {
  410. BOOL ischecked=YES;
  411. for(InventoryModel *model in _dataList) {
  412. if( !model.isCheckedStatus)
  413. {
  414. ischecked=NO;
  415. break;
  416. }
  417. }
  418. return ischecked;
  419. }
  420. /**
  421. 隐藏进度条
  422. */
  423. - (void)Cancel {
  424. [self stopLoading];
  425. }
  426. @end