NewOtherInStorageGoodsSearchVC.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. //
  2. // NewOtherInStorageGoodsSearchVCViewController.m
  3. // IBOSSmini
  4. //
  5. // Created by guan hong hou on 2018/4/25.
  6. // Copyright © 2018年 elongtian. All rights reserved.
  7. //
  8. #import "NewOtherInStorageGoodsSearchVC.h"
  9. @interface NewOtherInStorageGoodsSearchVC (){
  10. int pageNumber;
  11. BOOL isCheckAll;
  12. }
  13. @end
  14. @implementation NewOtherInStorageGoodsSearchVC
  15. #pragma mark 公共函数
  16. /**
  17. 视图加载完成函数
  18. */
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. [self loadNavStyle];
  22. [self initUI];
  23. isCheckAll=NO;
  24. }
  25. /**
  26. 安全区变化函数
  27. */
  28. -(void)viewSafeAreaInsetsDidChange{
  29. _vTableView.frame=CGRectMake(0,0,self.view.frame.size.width,self.view.safeAreaLayoutGuide.layoutFrame.size.height-40);
  30. _bottomView.frame=CGRectMake(0, self.view.safeAreaLayoutGuide.layoutFrame.size.height-40, self.view.frame.size.width, 40);
  31. [super viewSafeAreaInsetsDidChange];
  32. }
  33. - (void)didReceiveMemoryWarning {
  34. [super didReceiveMemoryWarning];
  35. }
  36. #pragma mark 委托函数
  37. /**
  38. 产品列表加载成功回调
  39. @param sender sender description
  40. */
  41. - (void)onGoodsListLoadFinish:(ASIDownManager *)sender {
  42. NSDictionary *dic = [sender.mWebStr JSONValue];
  43. [self stopLoading];
  44. // 服务器返回数据是否正确
  45. if (dic && [dic isKindOfClass:[NSDictionary class]]) {
  46. // 服务器返回数据状态值
  47. int iStatus = [[dic objectForKey:@"Status"] intValue];
  48. int iNewCount = 0;
  49. // 服务器返回数据消息
  50. NSString *message=[dic objectForKey:@"Message"];
  51. // 服务器返回数据状态值正确
  52. if (iStatus == 0) {
  53. NSArray * infoArr=[dic objectForKey:@"Result"];
  54. // 返回结果
  55. if(infoArr!=nil&& infoArr.count>0)
  56. {
  57. for (int i = 0; i < infoArr.count; i++) {
  58. NSDictionary * dic=infoArr[i];
  59. OtherInStorageGoodsSearchListModel *otherInStorageListModel=[OtherInStorageGoodsSearchListModel new];
  60. [otherInStorageListModel parseDic:dic];
  61. [_dataList addObject:otherInStorageListModel];
  62. }
  63. iNewCount =(int)infoArr.count;
  64. _vTableView.mbMoreHidden = (iNewCount == 0);
  65. [_vTableView FinishLoading];
  66. [_vTableView reloadData];
  67. }
  68. else{
  69. if(pageNumber==1){
  70. [self showAlertViewText:@"无数据"];
  71. }
  72. else{
  73. _vTableView.mbMoreHidden=YES;
  74. }
  75. return;
  76. }
  77. }
  78. else if(iStatus==ActionResultStatusAuthError
  79. ||iStatus==ActionResultStatusNoLogin
  80. ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid){
  81. [self showReLoginDialog:message];
  82. }
  83. else{
  84. [self showAlertViewText:message];
  85. }
  86. }
  87. }
  88. /**
  89. 隐藏键盘
  90. @param scrollView <#scrollView description#>
  91. */
  92. -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
  93. {
  94. [self.view endEditing:YES];
  95. }
  96. /**
  97. 产品列表加载失败回调
  98. @param sender <#sender description#>
  99. */
  100. - (void)onGoodsListLoadFail:(ASIDownManager *)sender {
  101. [self stopLoading];
  102. [self showAlertViewText:@"加载失败"];
  103. }
  104. /**
  105. 单元格cell个数
  106. @param tableView <#tableView description#>
  107. @param section <#section description#>
  108. @return <#return value description#>
  109. */
  110. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  111. {
  112. return [_dataList count];
  113. }
  114. /**
  115. <#Description#>
  116. @param tableView <#tableView description#>
  117. @return <#return value description#>
  118. */
  119. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  120. return 1;
  121. }
  122. /**
  123. 高度
  124. @param tableView <#tableView description#>
  125. @param indexPath <#indexPath description#>
  126. @return <#return value description#>
  127. */
  128. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  129. return 224;
  130. }
  131. /**
  132. 每个单元格cell
  133. @param tableView <#tableView description#>
  134. @param indexPath <#indexPath description#>
  135. @return <#return value description#>
  136. */
  137. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  138. {
  139. static NSString *CellIdentifier = @"SalesInStorageGoodsSearchCell";
  140. OtherInStorageGoodsSearchCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier ];
  141. if (!cell) {
  142. cell=[[OtherInStorageGoodsSearchCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  143. cell.selectionStyle=UITableViewCellSelectionStyleNone;
  144. }
  145. else
  146. //当页面拉动的时候 当cell存在并且最后一个存在 把它进行删除就出来一个独特的cell我们在进行数据配置即可避免
  147. {
  148. while ([cell.contentView.subviews lastObject] != nil) {
  149. [(UIView *)[cell.contentView.subviews lastObject] removeFromSuperview];
  150. }
  151. }
  152. _goodsSearchListModel= [_dataList objectAtIndex:indexPath.row];
  153. cell.inStorageDelegate = self;
  154. cell.index=indexPath.row;
  155. [cell setOtherInStorageGoodsSearchModel:_goodsSearchListModel];
  156. [cell setCheckBackground:_goodsSearchListModel.checkedFlag];
  157. return cell;
  158. }
  159. /**
  160. 取消刷新
  161. @param sender sender description
  162. @return return value description
  163. */
  164. - (BOOL)CanRefreshTableView:(RefreshTableView *)sender {
  165. return YES;
  166. }
  167. /**
  168. 加载更多
  169. @param sender sender description
  170. */
  171. - (void)LoadMoreList:(RefreshTableView *)sender {
  172. pageNumber++;
  173. [self startLoading];
  174. [self loadData];
  175. }
  176. /**
  177. 下拉刷新
  178. @param sender <#sender description#>
  179. */
  180. - (void)ReloadList:(RefreshTableView *)sender{
  181. pageNumber = 1;
  182. [_dataList removeAllObjects];
  183. [_vTableView reloadData];
  184. _vTableView.mbMoreHidden=YES;
  185. [self startLoading];
  186. [self loadData];
  187. }
  188. #pragma mark 私有函数
  189. /**
  190. 导航按钮样式
  191. */
  192. -(void)loadNavStyle
  193. {
  194. self.navigationItem.title=@"商品信息";
  195. //返回
  196. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  197. [button setBackgroundImage:[UIImage imageNamed:@"icon_back"]
  198. forState:UIControlStateNormal];
  199. [button addTarget:self action:@selector(goBack)
  200. forControlEvents:UIControlEventTouchUpInside];
  201. button.frame = CGRectMake(0, 0, 15, 18);
  202. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  203. self.navigationItem.leftBarButtonItem = menuButton;
  204. }
  205. /**
  206. 初始化UI
  207. */
  208. -(void)initUI{
  209. [self.view setBackgroundColor:[UIColor whiteColor]];
  210. _vTableView = [[RefreshTableView alloc]
  211. initWithFrame:CGRectMake(0,
  212. 0,
  213. self.view.frame.size.width,
  214. Screen_Height-40)];
  215. [_vTableView setBackgroundColor:[UIColor whiteColor]];
  216. _vTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  217. _vTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
  218. _vTableView.delegate = self;
  219. [self.view addSubview:_vTableView];
  220. //保存
  221. _bottomView=[UIView new];
  222. _bottomView.frame=CGRectMake(0, Screen_Height-103, self.view.frame.size.width, 40);
  223. [self.view addSubview:_bottomView];
  224. _btnCheckAll=[UIButton buttonWithType:UIButtonTypeCustom];
  225. _btnCheckAll.frame=CGRectMake(15,8, 25, 25);
  226. [_btnCheckAll setImage:[UIImage imageNamed:@"uncheck_round"] forState:UIControlStateNormal];
  227. [_btnCheckAll addTarget:self action:@selector(btnCheckall)
  228. forControlEvents:UIControlEventTouchUpInside];
  229. [_bottomView addSubview:_btnCheckAll];
  230. UILabel *lblall=[UILabel new];
  231. lblall.frame=CGRectMake(CGRectGetMaxX(_btnCheckAll.frame)+3,8, 60, 25);
  232. lblall.text=@"全选";
  233. [_bottomView addSubview:lblall];
  234. _sureBtn=[UIButton buttonWithType:UIButtonTypeCustom];
  235. [_sureBtn setTitle:@"确定" forState:UIControlStateNormal];
  236. [_sureBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  237. _sureBtn.frame=CGRectMake(Screen_Width-114,0, 114,40);
  238. [_sureBtn setBackgroundColor:[UIColor colorWithRed:189.0/255.0 green:0 blue:7.0/255.0 alpha:1]];
  239. [_sureBtn addTarget:self action:@selector(submitData) forControlEvents:UIControlEventTouchUpInside];
  240. [_bottomView addSubview:_sureBtn];
  241. _dataList=[[NSMutableArray alloc]init];
  242. pageNumber=1;
  243. [self loadData];
  244. }
  245. /**
  246. 提交数据
  247. */
  248. -(void)submitData{
  249. if(_dataList!=nil&&_dataList.count>0){
  250. NSInteger num= [self getCheckedGoodsCount:_dataList];
  251. if(num==0){
  252. [self showAlertViewText:@"请选择商品"];
  253. return;
  254. }
  255. NSMutableArray *checkedGoodsList=[[NSMutableArray alloc]init];
  256. for(int i=0;i<_dataList.count;i++){
  257. OtherInStorageGoodsSearchListModel *model=[_dataList objectAtIndex:i];
  258. if(model.checkedFlag){
  259. [checkedGoodsList addObject:model];
  260. }
  261. }
  262. if(_goodsDetailList!=nil&&_goodsDetailList.count>0){
  263. for(OtherInStorageGoodsSearchListModel *checkedGoodsModel in checkedGoodsList.reverseObjectEnumerator ){
  264. for(OtherInStorageGoodsSearchListModel *goodsModel in _goodsDetailList.reverseObjectEnumerator){
  265. if([checkedGoodsModel.codeId integerValue] ==[goodsModel.codeId integerValue]){
  266. [checkedGoodsList removeObject:checkedGoodsModel];
  267. break;
  268. }
  269. }
  270. }
  271. }
  272. if([self.goodsDelegate respondsToSelector:@selector(showSelectedGoods: )]){
  273. [self.goodsDelegate showSelectedGoods:checkedGoodsList];
  274. }
  275. [self.navigationController popViewControllerAnimated:YES];
  276. }
  277. }
  278. /**
  279. 返回函数
  280. */
  281. - (void)goBack
  282. {
  283. [self.navigationController popViewControllerAnimated:YES];
  284. }
  285. /**
  286. 加载产品列表数据源
  287. */
  288. -(void)loadData{
  289. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  290. [dict setObject:@"GetGoodsCodeByConditionIphone" forKey:@"Action"];
  291. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  292. [dict setObject:kkUserCode forKey:@"UserCode"];
  293. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  294. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  295. [dict setObject:_goodsCode== nil? @"" : _goodsCode forKey:@"GoodsCode"];
  296. [dict setObject:_onlyCode== nil? @"" : _onlyCode forKey:@"OnlyCode"];
  297. [dict setObject:@"" forKey:@"WarehouseCode"];
  298. [dict setObject:_brandId== nil? @"" : _brandId forKey:@"BrandID"];
  299. [dict setObject:@"" forKey:@"isFilterQuantityEqZero"];
  300. [dict setObject:_kindCode == nil? @"" : _kindCode forKey:@"KindCode"];
  301. [dict setObject:_goodsName == nil? @"" : _goodsName forKey:@"GoodsName"];
  302. [dict setObject:_varietyId == nil? @"" : _varietyId forKey:@"VarietyID"];
  303. [dict setObject:@"20" forKey:@"PageSize"];
  304. [dict setObject:[NSString stringWithFormat:@"%d",pageNumber] forKey:@"PageNum"];
  305. _downManager = [[ASIDownManager alloc] init];
  306. [self startLoading];
  307. _downManager.delegate = self;
  308. _downManager.OnImageDown = @selector(onGoodsListLoadFinish:);
  309. _downManager.OnImageFail = @selector(onGoodsListLoadFail:);
  310. [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
  311. }
  312. /**
  313. 选中所有的产品
  314. */
  315. -(void)btnCheckall{
  316. [self updateAllCellCheck];
  317. NSInteger num= [self getCheckedGoodsCount:_dataList];
  318. NSString *sureCount=[NSString stringWithFormat:@"%@%d%@",@"确定(",num,@")"];
  319. [_sureBtn setTitle:sureCount forState:UIControlStateNormal];
  320. [_vTableView reloadData];
  321. }
  322. /**
  323. 全选或者不选
  324. @return <#return value description#>
  325. */
  326. -(BOOL)updateAllCellCheck
  327. {
  328. if(!isCheckAll){
  329. isCheckAll=YES;
  330. [_btnCheckAll setImage:[UIImage imageNamed:@"check_round"] forState:UIControlStateNormal];
  331. for(OtherInStorageGoodsSearchListModel *goodsModel in _dataList) {
  332. goodsModel.checkedFlag=YES;
  333. }
  334. }
  335. else
  336. {
  337. [_btnCheckAll setImage:[UIImage imageNamed:@"uncheck_round"] forState:UIControlStateNormal];
  338. isCheckAll=NO;
  339. for(OtherInStorageGoodsSearchListModel *goodsModel in _dataList) {
  340. goodsModel.checkedFlag=NO;
  341. }
  342. }
  343. return NO;
  344. }
  345. /**
  346. checkbox点击回调函数
  347. @param index <#index description#>
  348. */
  349. -(void)btnCheckPressed:(NSInteger)index{
  350. _goodsSearchListModel= [_dataList objectAtIndex:index];
  351. _goodsSearchListModel.checkedFlag=!_goodsSearchListModel.checkedFlag;
  352. [_vTableView reloadData];
  353. if([self isCheckedAll]){
  354. isCheckAll=YES;
  355. [_btnCheckAll setImage:[UIImage imageNamed:@"check_round"] forState:UIControlStateNormal];
  356. }
  357. else{
  358. isCheckAll=NO;
  359. [_btnCheckAll setImage:[UIImage imageNamed:@"uncheck_round"] forState:UIControlStateNormal];
  360. }
  361. NSInteger num=[self getCheckedGoodsCount:_dataList];
  362. NSString *sureCount=[NSString stringWithFormat:@"%@%ld%@",@"确定(",num,@")"];
  363. [_sureBtn setTitle:sureCount forState:UIControlStateNormal];
  364. }
  365. /**
  366. 获取选中的产品数
  367. @param goodsList <#goodsList description#>
  368. @return <#return value description#>
  369. */
  370. -(NSInteger) getCheckedGoodsCount:(NSMutableArray*)goodsList{
  371. int num=0;
  372. NSMutableArray *goodsSubmitList=[[NSMutableArray alloc]init];
  373. NSInteger count=goodsList.count;
  374. for(int i=0;i<count;i++){
  375. OtherInStorageGoodsSearchListModel *model= goodsList[i];
  376. if(model.checkedFlag){
  377. num++;
  378. [goodsSubmitList addObject:model];
  379. }
  380. }
  381. NSInteger checkedCount=goodsSubmitList.count;
  382. return checkedCount;
  383. }
  384. /**
  385. 判断是否全选
  386. @return <#return value description#>
  387. */
  388. -(BOOL)isCheckedAll
  389. {
  390. BOOL ischecked=YES;
  391. for(OtherInStorageGoodsSearchListModel *model in _dataList) {
  392. if( !model.checkedFlag)
  393. {
  394. ischecked=NO;
  395. break;
  396. }
  397. }
  398. return ischecked;
  399. }
  400. @end