NewOtherOutStorageGoodsDetailVC.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. //
  2. // NewOtherOutStorageGoodsDetailVC.m
  3. // IBOSSmini
  4. //
  5. // Created by guan hong hou on 2018/4/28.
  6. // Copyright © 2018年 elongtian. All rights reserved.
  7. //
  8. #import "NewOtherOutStorageGoodsDetailVC.h"
  9. @interface NewOtherOutStorageGoodsDetailVC ()
  10. @end
  11. @implementation NewOtherOutStorageGoodsDetailVC
  12. #pragma mark 公共函数
  13. /**
  14. 视图加载完成函数
  15. */
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. [self initUI];
  19. [self initSlideSlip];
  20. _dataList=[[NSMutableArray alloc]init];
  21. [self registerKeybordNotification];
  22. }
  23. /**
  24. 安全区变化函数
  25. */
  26. -(void)viewSafeAreaInsetsDidChange{
  27. _vTableView.frame=CGRectMake(0, CGRectGetMaxY(_topSeparatorView.frame),self.view.frame.size.width,self.view.safeAreaLayoutGuide.layoutFrame.size.height-CGRectGetMaxY(_topSeparatorView.frame));
  28. [super viewSafeAreaInsetsDidChange];
  29. }
  30. /**
  31. 内存警告函数
  32. */
  33. - (void)didReceiveMemoryWarning {
  34. [super didReceiveMemoryWarning];
  35. }
  36. #pragma mark 委托函数
  37. -(void)showSelectedGoods:(NSMutableArray*)checkedGoodsList{
  38. [_dataList addObjectsFromArray:checkedGoodsList];
  39. _vTableView.dataSource=self;
  40. _vTableView.delegate=self;
  41. [_vTableView reloadData];
  42. }
  43. -(void)deleteGoods:(NSInteger)position{
  44. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:@"确定要删除吗?" preferredStyle:UIAlertControllerStyleAlert];
  45. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  46. }];
  47. UIAlertAction *otherAction = [UIAlertAction actionWithTitle:@"确定"
  48. style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  49. [ _dataList removeObjectAtIndex:position];
  50. [ _vTableView reloadData];
  51. }];
  52. UIColor *cancelColor=[UIColor blackColor];
  53. UIColor *sureColor=[UIColor redColor];
  54. [cancelAction setValue:cancelColor forKey:@"titleTextColor"];
  55. [otherAction setValue:sureColor forKey:@"titleTextColor"];
  56. [alertController addAction:cancelAction];
  57. [alertController addAction:otherAction];
  58. [self presentViewController:alertController animated:YES completion:nil];
  59. }
  60. #pragma mark - 委托回调函数
  61. #pragma mark - tableView回调
  62. /**
  63. 单元格cell个数
  64. @param tableView <#tableView description#>
  65. @param section <#section description#>
  66. @return <#return value description#>
  67. */
  68. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  69. {
  70. return [_dataList count];
  71. }
  72. /**
  73. tableview 的分区数
  74. @param tableView <#tableView description#>
  75. @return <#return value description#>
  76. */
  77. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  78. return 1;
  79. }
  80. /**
  81. 高度
  82. @param tableView <#tableView description#>
  83. @param indexPath <#indexPath description#>
  84. @return <#return value description#>
  85. */
  86. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  87. return 242;
  88. }
  89. /**
  90. 点击单元格事件
  91. @param tableView tableView description
  92. @param indexPath indexPath description
  93. */
  94. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  95. {
  96. self.hidesBottomBarWhenPushed=YES;
  97. OtherOutStorageInventoryDetailVC *detailVc=[[OtherOutStorageInventoryDetailVC alloc] init];
  98. InventoryModel *otherOutStorageDetailModel= [_dataList objectAtIndex:indexPath.row];
  99. detailVc.goodsDetailModel= otherOutStorageDetailModel;
  100. [self.nav pushViewController:detailVc animated:YES];
  101. }
  102. /**
  103. 扫描回调函数
  104. @param code <#code description#>
  105. */
  106. -(void)reloadDataWithOnlyCode:(NSString *)code
  107. {
  108. _onlyCode=code;
  109. if((_goodsCode==nil||[_goodsCode isEqualToString:@""])&&(_onlyCode==nil||[_onlyCode isEqualToString:@""])){
  110. [self showAlertViewText:@"商品编码或唯一编码至少输入一个"];
  111. return;
  112. }
  113. NewOtherOutStorageGoodsSearchVC *goodsSearchVc=[[NewOtherOutStorageGoodsSearchVC alloc]init];
  114. goodsSearchVc.onlyCode=_onlyCode;
  115. _isfilterQuantityEqZero=YES;
  116. goodsSearchVc.goodsDetailList=_dataList;
  117. goodsSearchVc.isfilterQuantityEqZero=_isfilterQuantityEqZero;
  118. goodsSearchVc.goodsDelegate=self;
  119. [self.nav pushViewController:goodsSearchVc animated:YES];
  120. }
  121. /**
  122. 隐藏键盘
  123. @param scrollView <#scrollView description#>
  124. */
  125. -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
  126. {
  127. [self.view endEditing:YES];
  128. }
  129. /**
  130. 每个单元格cell
  131. @param tableView <#tableView description#>
  132. @param indexPath <#indexPath description#>
  133. @return <#return value description#>
  134. */
  135. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  136. {
  137. static NSString *CellIdentifier = @"OtherOutStorageGoodsListCell";
  138. NewOtherOutStorageGoodsListCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier ];
  139. if (!cell) {
  140. cell=[[NewOtherOutStorageGoodsListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  141. cell.selectionStyle=UITableViewCellSelectionStyleNone;
  142. }
  143. else
  144. //当页面拉动的时候 当cell存在并且最后一个存在 把它进行删除就出来一个独特的cell我们在进行数据配置即可避免
  145. {
  146. while ([cell.contentView.subviews lastObject] != nil) {
  147. [(UIView *)[cell.contentView.subviews lastObject] removeFromSuperview];
  148. }
  149. }
  150. InventoryModel *goodsListModel= [_dataList objectAtIndex:indexPath.row];
  151. cell.outStorageDelegate = self;
  152. cell.index=indexPath.row;
  153. [cell setOtherOutStorageGoodsListModel:goodsListModel];
  154. return cell;
  155. }
  156. /**
  157. 刷新tableview
  158. */
  159. -(void)refreshTable{
  160. [_vTableView reloadData];
  161. }
  162. #pragma mark 私有函数
  163. /**
  164. 抽屉初始化
  165. */
  166. - (void)initSlideSlip{
  167. // 抽屉对象
  168. __weak typeof(self) weakself=self;
  169. self.filterController = [[SideSlipFilterController alloc]
  170. initWithSponsor:self
  171. resetBlock:^(NSArray *dataList) {
  172. for (SideSlipModel *model in dataList) {
  173. model.selectedItemList = nil;
  174. model.customDict = nil;
  175. }
  176. } commitBlock:^(NSArray *dataList) {
  177. [self.view endEditing:YES];
  178. // 查询条件
  179. SideSlipModel *serviceRegionModel = dataList[0];
  180. InventorySearchModel *m = [serviceRegionModel.customDict objectForKey:OTHER_OUT_STORAGE_SEARCH_RANGE_MODEL];
  181. _goodsCode = m.goodsCode;
  182. _goodsName=m.goodsName;
  183. _onlyCode=m.onlyCode;
  184. _brandId=m.brandId;
  185. _warehouseId=m.warehouseId;
  186. _isfilterQuantityEqZero=m.isfilterQuantityEqZero;
  187. if((_goodsCode==nil||[_goodsCode isEqualToString:@""])&&(_onlyCode==nil||[_onlyCode isEqualToString:@""])){
  188. [self showAlertViewText:@"商品编码或唯一编码至少输入一个"];
  189. return;
  190. }
  191. NewOtherOutStorageGoodsSearchVC *goodsSearchVc=[[NewOtherOutStorageGoodsSearchVC alloc]init];
  192. goodsSearchVc.goodsCode=_goodsCode;
  193. goodsSearchVc.goodsName=_goodsName;
  194. goodsSearchVc.onlyCode=_onlyCode;
  195. goodsSearchVc.warehouseId=_warehouseId;
  196. goodsSearchVc.goodsDetailList=_dataList; goodsSearchVc.isfilterQuantityEqZero=_isfilterQuantityEqZero;
  197. goodsSearchVc.brandId=_brandId;
  198. goodsSearchVc.goodsDelegate=self;
  199. [self.nav pushViewController:goodsSearchVc animated:YES];
  200. [weakself.filterController dismiss];
  201. }];
  202. _filterController.animationDuration = AnimationDuration;
  203. _filterController.hasHeadView = YES;
  204. _filterController.sideSlipLeading = UIScreenSideSlipLeading*[UIScreen mainScreen].bounds.size.width;
  205. _filterController.dataList = [self packageDataList];
  206. }
  207. /**
  208. 打开抽屉
  209. */
  210. -(void)dataSearch{
  211. [_filterController showPagerView:self.nav];
  212. }
  213. /**
  214. 注册键盘通知
  215. */
  216. - (void)registerKeybordNotification {
  217. NSNotificationCenter *notification = [NSNotificationCenter defaultCenter];
  218. [notification removeObserver:self];
  219. [notification addObserver:self
  220. selector:@selector(showKeyboard:)
  221. name:UIKeyboardWillShowNotification
  222. object:nil];
  223. [notification addObserver:self
  224. selector:@selector(hideKeyboard:)
  225. name:UIKeyboardWillHideNotification
  226. object:nil];
  227. #ifdef __IPHONE_5_0
  228. // 5.0以上系统中文键盘高度与4.0系统不一样
  229. float version = [[[UIDevice currentDevice] systemVersion] floatValue];
  230. if (version >= 5.0) {
  231. [notification addObserver:self
  232. selector:@selector(showKeyboard:)
  233. name:UIKeyboardWillChangeFrameNotification
  234. object:nil];
  235. }
  236. #endif
  237. }
  238. /**
  239. 出示键盘
  240. @param notification <#notification description#>
  241. */
  242. - (void)showKeyboard:(NSNotification *)notification {
  243. NSDictionary *userInfo = [notification userInfo];
  244. NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
  245. CGFloat keyboardHeight = CGRectGetHeight([aValue CGRectValue]);
  246. //50底部保存按钮 40为切换按钮
  247. CGFloat height = SCREENHEIGHT-rectStatusHeight-rectNavHeight-_vTableView.frame.origin.y - keyboardHeight-40-50;
  248. /* 使用动画效果,过度更加平滑 */
  249. [UIView beginAnimations:nil context:nil];
  250. [UIView setAnimationDuration:0.1];
  251. CGRect rect = _vTableView.frame;
  252. rect.size.height = height;
  253. _vTableView.frame = rect;
  254. [UIView commitAnimations];
  255. }
  256. /**
  257. 隐藏键盘
  258. @param notification <#notification description#>
  259. */
  260. - (void)hideKeyboard:(NSNotification *)notification {
  261. [UIView beginAnimations:nil context:nil];
  262. [UIView setAnimationDuration:0.1];
  263. {
  264. CGRect rect = _vTableView.frame;
  265. rect.size.height = CGRectGetHeight(self.view.frame)-CGRectGetMaxY(_topSeparatorView.frame);
  266. _vTableView.frame = rect;
  267. }
  268. [UIView commitAnimations];
  269. }
  270. /**
  271. 抽屉 数据源
  272. @return <#return value description#>
  273. */
  274. - (NSArray *)packageDataList {
  275. NSMutableArray *dataArray = [NSMutableArray array];
  276. SideSlipModel *model = [[SideSlipModel alloc] init];
  277. model.containerCellClass = @"NewOtherOutStorageGoodsDetailSearchCell";
  278. model.regionTitle = @"查询条件";
  279. [dataArray addObject:model];
  280. return [dataArray mutableCopy];
  281. }
  282. /**
  283. 扫描点击事件
  284. */
  285. -(void)btnScanCilck{
  286. ScanViewController *scanVc=[[ScanViewController alloc]init];
  287. scanVc.rootVC=self;
  288. [self.nav pushViewController:scanVc animated:YES];
  289. }
  290. /**
  291. 初始化UI
  292. */
  293. -(void)initUI{
  294. [self.view setBackgroundColor:[UIColor whiteColor]];
  295. UIView *topSeparatorView = [UIView new];
  296. topSeparatorView.frame=CGRectMake(0,3, Screen_Width, 10);
  297. topSeparatorView.backgroundColor = LineBackgroundColor;
  298. [self.view addSubview:topSeparatorView];
  299. CGFloat height = 40;
  300. _searchView = [[UIView alloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(topSeparatorView.frame), Screen_Width, 50)];
  301. _searchView.backgroundColor = [UIColor whiteColor];
  302. UIButton *btnSearch = [UIButton buttonWithType:UIButtonTypeCustom];
  303. btnSearch.frame = CGRectMake(5, 5, Screen_Width-45, height);
  304. btnSearch.layer.cornerRadius = 6.0f;
  305. [btnSearch setTitle:@"搜索" forState:UIControlStateNormal];
  306. [btnSearch setTitleColor:NavBarUnEnbleItemColor forState:UIControlStateNormal];
  307. btnSearch.titleLabel.textAlignment = NSTextAlignmentCenter;
  308. btnSearch.titleLabel.font = [UIFont systemFontOfSize:LabelAndTextFontOfSize];
  309. btnSearch.backgroundColor = LineBackgroundColor;
  310. [btnSearch addTarget:self action:@selector(dataSearch) forControlEvents:UIControlEventTouchUpInside];
  311. [_searchView addSubview:btnSearch];
  312. UIButton *scan=[UIButton buttonWithType:UIButtonTypeCustom];
  313. scan.frame=CGRectMake(_searchView.frame.size.width-35,8,35,35);
  314. scan.contentHorizontalAlignment=UIControlContentHorizontalAlignmentRight;
  315. [scan setImage:[UIImage imageNamed:@"scan"] forState:UIControlStateNormal];
  316. [_searchView addSubview:scan];
  317. [scan addTarget:self action:@selector(btnScanCilck) forControlEvents:UIControlEventTouchUpInside];
  318. [self.view addSubview:_searchView];
  319. _topSeparatorView = [UIView new];
  320. _topSeparatorView.frame=CGRectMake(0, CGRectGetMaxY(_searchView.frame), Screen_Width, 10);
  321. _topSeparatorView.backgroundColor = LineBackgroundColor;
  322. [self.view addSubview:_topSeparatorView];
  323. _vTableView = [[UITableView alloc]
  324. initWithFrame:CGRectMake(0,
  325. CGRectGetMaxY(_topSeparatorView.frame),
  326. self.view.frame.size.width,
  327. Screen_Height-CGRectGetMaxY(_topSeparatorView.frame))];
  328. _vTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  329. _vTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
  330. _vTableView.dataSource=self;
  331. _vTableView.delegate=self;
  332. [self.view addSubview:_vTableView];
  333. }
  334. @end