InventoryFreezeGoodsSearchViewController.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. //
  2. // InventoryFreezeGoodsSearchViewController.m
  3. // IBOSS
  4. //
  5. // Created by 关宏厚 on 2020/4/28.
  6. // Copyright © 2020 elongtian. All rights reserved.
  7. //
  8. #import "InventoryFreezeGoodsSearchViewController.h"
  9. @interface InventoryFreezeGoodsSearchViewController ()
  10. @end
  11. @implementation InventoryFreezeGoodsSearchViewController
  12. - (void)viewDidLoad {
  13. [super viewDidLoad];
  14. _inventoryGoodsList=[[NSMutableArray alloc]init];
  15. [self initUI];
  16. [self initSlideSlip];
  17. [self changeCheckAllUnSelect];
  18. }
  19. /**
  20. 安全区视图发生变化
  21. */
  22. -(void)viewSafeAreaInsetsDidChange{
  23. _tableView.frame =CGRectMake(0,CGRectGetMaxY(_searchView.frame)+10, self.view.frame.size.width,self.view.superview.frame.size.height-60-CGRectGetMaxY(_searchView.frame));
  24. _bottomView.frame=CGRectMake(0, self.view.superview.frame.size.height-50, self.view.frame.size.width, 50);
  25. [super viewSafeAreaInsetsDidChange];
  26. }
  27. /**
  28. 抽屉初始化
  29. */
  30. - (void)initSlideSlip{
  31. // 抽屉对象
  32. __weak typeof(self) weakself = self;
  33. self.filterController = [[SideSlipFilterController alloc]
  34. initWithSponsor:self
  35. resetBlock:^(NSArray *dataList) {
  36. for (SideSlipModel *model in dataList)
  37. {
  38. model.selectedItemList = nil;
  39. model.customDict = nil;
  40. }
  41. }
  42. commitBlock:^(NSArray *dataList) {
  43. // 查询条件
  44. SideSlipModel *serviceRegionModel = dataList[0];
  45. InventoryFreezeGoodsSearchModel *searchModel = [serviceRegionModel.customDict objectForKey:INVENTORY_FREEZE_GOODS_SEARCH_MODEL];
  46. self->_goodsCode=searchModel.goodsCode;
  47. self->_onlyCode=searchModel.onlyCode;
  48. self->_goodsName=searchModel.goodsName;
  49. if([ self->_goodsCode isEqualToString:@""]&&[ self->_onlyCode isEqualToString:@""]&&[ self->_goodsName isEqualToString:@""])
  50. {
  51. [self showAlertViewText:@"产品编码,唯一编,产品名称至少输入一项"];
  52. return;
  53. }
  54. [weakself.filterController dismiss];
  55. if(self->_inventoryGoodsList!=nil&&self->_inventoryGoodsList.count>0)
  56. {
  57. [self->_inventoryGoodsList removeAllObjects];
  58. [self->_tableView reloadData];
  59. }
  60. [self loadData];
  61. }];
  62. _filterController.animationDuration = AnimationDuration;
  63. _filterController.hasHeadView = YES;
  64. _filterController.sideSlipLeading = UIScreenSideSlipLeading*[UIScreen mainScreen].bounds.size.width;
  65. _filterController.dataList = [self packageDataList];
  66. }
  67. /**
  68. 抽屉数据源
  69. @return <#return value description#>
  70. */
  71. - (NSArray *)packageDataList {
  72. NSMutableArray *dataArray = [NSMutableArray array];
  73. SideSlipModel *model = [[SideSlipModel alloc] init];
  74. model.containerCellClass = @"InventoryFreezeGoodsSearchCell";
  75. model.regionTitle = @"查询条件";
  76. [dataArray addObject:model];
  77. return [dataArray mutableCopy];
  78. }
  79. //看是否全选
  80. - (BOOL)isCheckedAll
  81. {
  82. BOOL ischecked=YES;
  83. for(int i=0;i<_inventoryGoodsList.count;i++) {
  84. InventoryGoodsModel *goodsModel= [_inventoryGoodsList objectAtIndex:i];
  85. if(goodsModel.isChecked == NO)
  86. {
  87. ischecked=NO;
  88. break;
  89. }
  90. }
  91. return ischecked;
  92. }
  93. -(void)btnCheckPressed:(InventoryGoodsListCell*)cell
  94. {
  95. NSInteger pos= cell.position;
  96. InventoryGoodsModel *goodsModel= [_inventoryGoodsList objectAtIndex:pos];
  97. goodsModel.isChecked=!goodsModel.isChecked;
  98. [cell setCheckBackground: goodsModel.isChecked];
  99. int num=0;
  100. for(int i=0;i<_inventoryGoodsList.count;i++)
  101. {
  102. InventoryGoodsModel *goodsModel= [_inventoryGoodsList objectAtIndex:i];
  103. BOOL isChecked=goodsModel.isChecked;
  104. if(isChecked)
  105. {
  106. ++num;
  107. }
  108. }
  109. NSString *saveTxt=[NSString stringWithFormat:@"确定(%d)",num];
  110. [_btnSave setTitle:saveTxt forState:UIControlStateNormal];
  111. if(![self isCheckedAll])
  112. {
  113. [self changeCheckAllUnSelect];
  114. }
  115. else{
  116. [self changeCheckALLSelect];
  117. }
  118. }
  119. -(void)loadData
  120. {
  121. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  122. [dict setObject:@"GetInventoryGoods" forKey:@"Action"];
  123. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  124. [dict setObject:kkUserCode forKey:@"UserCode"];
  125. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  126. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  127. [dict setObject:_goodsCode forKey:@"Code"];
  128. [dict setObject:_onlyCode forKey:@"OnlyCode"];
  129. [dict setObject:_goodsName forKey:@"GoodsName"];
  130. _downManager = [[ASIDownManager alloc] init];
  131. [self startLoading];
  132. _downManager.delegate = self;
  133. _downManager.onRequestSuccess = @selector(onGoodsListLoadFinish:);
  134. _downManager.onRequestFail = @selector(onGoodsListLoadFail:);
  135. [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
  136. }
  137. -(void)dataSearch
  138. {
  139. [_filterController showPagerView:self.cNav];
  140. }
  141. -(void)initUI
  142. {
  143. self.view.backgroundColor = [UIColor whiteColor];
  144. _searchView = [[UIView alloc] init];
  145. _searchView.frame = CGRectMake(15,10,Screen_Width-30,35);
  146. _searchView.backgroundColor = LineBackgroundColor;
  147. _searchView.layer.cornerRadius = 10;
  148. _searchView.layer.masksToBounds = YES;
  149. UIButton *btnSearch = [UIButton buttonWithType:UIButtonTypeCustom];
  150. btnSearch.frame = CGRectMake(20,0, Screen_Width-40, 35);
  151. btnSearch.layer.cornerRadius = 6.0f;
  152. [btnSearch setTitle:@"产品查询" forState:UIControlStateNormal];
  153. [btnSearch setTitleColor:NavBarUnEnbleItemColor forState:UIControlStateNormal];
  154. btnSearch.titleLabel.textAlignment = NSTextAlignmentCenter;
  155. btnSearch.titleLabel.font = [UIFont systemFontOfSize:LabelAndTextFontOfSize];
  156. [btnSearch addTarget:self action:@selector(dataSearch) forControlEvents:UIControlEventTouchUpInside];
  157. [_searchView addSubview:btnSearch];
  158. [self.view addSubview:_searchView];
  159. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_searchView.frame)+10,self.view.frame.size.width, self.view.frame.size.height-140-rectStatusHeight-rectNavHeight)];
  160. _tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
  161. _tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
  162. _tableView.delegate = self;
  163. _tableView.dataSource=self;
  164. [self.view addSubview:_tableView];
  165. //保存
  166. _bottomView = [UIView new];
  167. [_bottomView setBackgroundColor:[UIColor whiteColor]];
  168. _bottomView.frame=CGRectMake(0, Screen_Height-140-rectStatusHeight-rectNavHeight, self.view.frame.size.width, 50);
  169. [self.view addSubview:_bottomView];
  170. UIView *bottomSeparator= [UIView new];
  171. bottomSeparator.frame=CGRectMake(0, 0, Screen_Width, 1);
  172. bottomSeparator.backgroundColor = LineBackgroundColor;
  173. [_bottomView addSubview:bottomSeparator];
  174. _btnCheckAll = [UIButton buttonWithType:UIButtonTypeCustom];
  175. _btnCheckAll.frame=CGRectMake(15,15, 25, 25);
  176. [_btnCheckAll addTarget:self action:@selector(checkAll)
  177. forControlEvents:UIControlEventTouchUpInside];
  178. [_bottomView addSubview:_btnCheckAll];
  179. UILabel *lblall = [UILabel new];
  180. lblall.frame=CGRectMake(CGRectGetMaxX(_btnCheckAll.frame)+3,15, 60, 25);
  181. lblall.text = @"全选";
  182. [_bottomView addSubview:lblall];
  183. [ self changeCheckAllUnSelect];
  184. _btnSave = [UIButton buttonWithType:UIButtonTypeCustom];
  185. [_btnSave setTitle:@"确定" forState:UIControlStateNormal];
  186. [_btnSave setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  187. _btnSave.frame=CGRectMake(Screen_Width-114,0, 114,50);
  188. [_btnSave setBackgroundColor:[UIColor colorWithRed:189.0/255.0 green:0 blue:7.0/255.0 alpha:1]];
  189. [_btnSave addTarget:self action:@selector(submitFreezeData) forControlEvents:UIControlEventTouchUpInside];
  190. [_bottomView addSubview:_btnSave];
  191. }
  192. -(void)onGoodsListLoadFinish:(ASIDownManager*)sender {
  193. [self cancel];
  194. RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
  195. int iStatus = resultModel.status;
  196. NSString *message=resultModel.message;
  197. if(iStatus==0)
  198. {
  199. NSArray *resultArray=(NSArray*)resultModel.result;
  200. if(resultArray!=nil&&resultArray.count>0)
  201. {
  202. for(int i=0;i<resultArray.count;i++)
  203. {
  204. NSDictionary *resultDic=[resultArray objectAtIndex:i];
  205. InventoryGoodsModel *model = [InventoryGoodsModel dk_modelWithDictionary:resultDic];
  206. [model setFreezeQuantity:@"0"];
  207. [model setBox:@"0"];
  208. [model setPiece:@"0"];
  209. [model setM2:@"0"];
  210. [model setUnfreezeQuantity:@"0"];
  211. [_inventoryGoodsList addObject:model];
  212. }
  213. [_tableView reloadData];
  214. }
  215. }
  216. // 服务器返回数据状态值异常
  217. else if(iStatus == ActionResultStatusAuthError
  218. ||iStatus == ActionResultStatusNoLogin
  219. ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){
  220. [self showReLoginDialog:message];
  221. }
  222. else{
  223. [self showAlertViewText:message];
  224. }
  225. }
  226. -(void)onGoodsListLoadFail:(ASIDownManager *)sender {
  227. [self cancel];
  228. [self showAlertViewText:@"网络异常"];
  229. }
  230. -(void)submitFreezeData
  231. {
  232. if(_inventoryGoodsList==nil||_inventoryGoodsList.count==0)
  233. {
  234. [self showAlertViewText:@"没有可提交的商品!"];
  235. return;
  236. }
  237. int num=0;
  238. for(int i=0;i<_inventoryGoodsList.count;i++)
  239. {
  240. InventoryGoodsModel *goodsModel= [_inventoryGoodsList objectAtIndex:i];
  241. if(goodsModel.isChecked)
  242. {
  243. ++num;
  244. }
  245. }
  246. if(num==0)
  247. {
  248. [self showAlertViewText:@"至少选择一种商品!"];
  249. return;
  250. }
  251. _submitInventoryGoodsList=[[NSMutableArray alloc]init];
  252. for(int i=0;i<_inventoryGoodsList.count;i++)
  253. {
  254. InventoryGoodsModel *goodsModel= [_inventoryGoodsList objectAtIndex:i];
  255. if(goodsModel.isChecked)
  256. {
  257. [_submitInventoryGoodsList addObject:goodsModel];
  258. }
  259. }
  260. self.cNav.visibleViewController.hidesBottomBarWhenPushed=YES;
  261. NewInventoryFreezeViewController *newVc=[[NewInventoryFreezeViewController alloc] init];
  262. newVc.submitInventoryGoodsList=_submitInventoryGoodsList;
  263. newVc.inventoryDelegate=self;
  264. newVc.editFlag=NO;
  265. [self.cNav pushViewController:newVc animated:YES];
  266. }
  267. -(void)checkAll
  268. {
  269. [self updateAllCellCheck];
  270. [_tableView reloadData];
  271. int num=0;
  272. for(int i=0;i<_inventoryGoodsList.count;i++)
  273. {
  274. InventoryGoodsModel *goodsModel= [_inventoryGoodsList objectAtIndex:i];
  275. BOOL isChecked=goodsModel.isChecked;
  276. if(isChecked)
  277. {
  278. ++num;
  279. }
  280. }
  281. NSString *saveTxt=[NSString stringWithFormat:@"确定(%d)",num];
  282. [_btnSave setTitle:saveTxt forState:UIControlStateNormal];
  283. if(![self isCheckedAll])
  284. {
  285. [self changeCheckAllUnSelect];
  286. }
  287. else{
  288. [self changeCheckALLSelect];
  289. }
  290. }
  291. //全选或者全不选
  292. - (BOOL)updateAllCellCheck
  293. {
  294. if(!_isCheckAll){
  295. _isCheckAll=YES;
  296. for(int i=0;i<_inventoryGoodsList.count;i++) {
  297. InventoryGoodsModel *goodsModel= [_inventoryGoodsList objectAtIndex:i];
  298. goodsModel.isChecked =YES;
  299. }
  300. }
  301. else
  302. {
  303. _isCheckAll=NO;
  304. for(int i=0;i<_inventoryGoodsList.count;i++) {
  305. InventoryGoodsModel *goodsModel= [_inventoryGoodsList objectAtIndex:i];
  306. goodsModel.isChecked =NO;
  307. }
  308. }
  309. return NO;
  310. }
  311. /**
  312. 隐藏进度条
  313. */
  314. - (void)cancel {
  315. [self stopLoading];
  316. }
  317. -(void) refreshData
  318. {
  319. if(_inventoryGoodsList!=nil&&_inventoryGoodsList.count>0)
  320. {
  321. [_inventoryGoodsList removeAllObjects];
  322. [_tableView reloadData];
  323. [self startLoading];
  324. [self loadData];
  325. }
  326. }
  327. /**
  328. 单元格cell个数
  329. @param tableView <#tableView description#>
  330. @param section <#section description#>
  331. @return <#return value description#>
  332. */
  333. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  334. {
  335. return [_inventoryGoodsList count];
  336. }
  337. /**
  338. table view 分区数
  339. @param tableView <#tableView description#>
  340. @return <#return value description#>
  341. */
  342. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  343. return 1;
  344. }
  345. /**
  346. cell 高度
  347. @param tableView <#tableView description#>
  348. @param indexPath <#indexPath description#>
  349. @return <#return value description#>
  350. */
  351. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  352. return [self.heights[@(indexPath.row)] doubleValue];
  353. }
  354. /**
  355. 高度
  356. @return <#return value description#>
  357. */
  358. - (NSMutableDictionary *)heights{
  359. if (_heights == nil){
  360. _heights = [NSMutableDictionary dictionary];
  361. }
  362. return _heights;
  363. }
  364. /**
  365. 预防高度
  366. @param tableView <#tableView description#>
  367. @param indexPath <#indexPath description#>
  368. @return <#return value description#>
  369. */
  370. -(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
  371. return 250;
  372. }
  373. /**
  374. 每个单元格cell
  375. @param tableView <#tableView description#>
  376. @param indexPath <#indexPath description#>
  377. @return <#return value description#>
  378. */
  379. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  380. {
  381. static NSString *cellIdentifier = @"InventoryGoodsListCell";
  382. InventoryGoodsListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier ];
  383. cell = [[InventoryGoodsListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
  384. cell.selectionStyle=UITableViewCellSelectionStyleNone;
  385. InventoryGoodsModel *inventoryGoodsModel= [_inventoryGoodsList objectAtIndex:indexPath.row];
  386. cell.delegate = self;
  387. [cell setInventoryGoodsListCell:inventoryGoodsModel];
  388. cell.position = (int)indexPath.row;
  389. self.heights[@(indexPath.row)] = @(cell.height);
  390. BOOL isChecked= inventoryGoodsModel.isChecked;
  391. [cell setCheckBackground:isChecked];
  392. return cell;
  393. }
  394. /**
  395. 全部选中
  396. */
  397. - (void)changeCheckALLSelect
  398. {
  399. [_btnCheckAll setBackgroundImage:[UIImage imageNamed:@"order_checked"] forState:UIControlStateNormal];
  400. }
  401. /**
  402. 全部未选中
  403. */
  404. - (void)changeCheckAllUnSelect
  405. {
  406. [_btnCheckAll setBackgroundImage:[UIImage imageNamed:@"order_unchecked"] forState:UIControlStateNormal];
  407. }
  408. @end