NewOtherInStorageGoodsDetailVC.m 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. //
  2. // NewOtherInStorageGoodsDetailVC.m
  3. // IBOSSmini
  4. //
  5. // Created by guan hong hou on 2018/4/24.
  6. // Copyright © 2018年 elongtian. All rights reserved.
  7. //
  8. #import "NewOtherInStorageGoodsDetailVC.h"
  9. @interface NewOtherInStorageGoodsDetailVC ()
  10. @end
  11. @implementation NewOtherInStorageGoodsDetailVC
  12. #pragma mark 公共函数
  13. /**
  14. 视图加载完成函数
  15. */
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. [self initUI];
  19. _dataList=[[NSMutableArray alloc]init];
  20. [self initSlideSlip];
  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. - (void)didReceiveMemoryWarning {
  31. [super didReceiveMemoryWarning];
  32. }
  33. #pragma mark 委托函数
  34. /**
  35. 扫描回调函数
  36. @param code <#code description#>
  37. */
  38. -(void)reloadDataWithOnlyCode:(NSString *)code
  39. {
  40. _onlyCode=code;
  41. if((_goodsCode==nil||[_goodsCode isEqualToString:@""])&&(_onlyCode==nil||[_onlyCode isEqualToString:@""])){
  42. [self showAlertViewText:@"商品编码或唯一编码至少输入一个"];
  43. return;
  44. }
  45. NewOtherInStorageGoodsSearchVC *goodsSearchVc=[[NewOtherInStorageGoodsSearchVC alloc]init];
  46. goodsSearchVc.onlyCode=_onlyCode;
  47. goodsSearchVc.goodsDetailList=_dataList;
  48. goodsSearchVc.goodsDelegate=self;
  49. [self.nav pushViewController:goodsSearchVc animated:YES];
  50. }
  51. /**
  52. 单元格cell个数
  53. @param tableView <#tableView description#>
  54. @param section <#section description#>
  55. @return <#return value description#>
  56. */
  57. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  58. {
  59. return [_dataList count];
  60. }
  61. /**
  62. tableview的分区数
  63. @param tableView <#tableView description#>
  64. @return <#return value description#>
  65. */
  66. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  67. return 1;
  68. }
  69. /**
  70. 高度
  71. @param tableView <#tableView description#>
  72. @param indexPath <#indexPath description#>
  73. @return <#return value description#>
  74. */
  75. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  76. return 287;
  77. }
  78. /**
  79. 隐藏键盘
  80. @param scrollView <#scrollView description#>
  81. */
  82. -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
  83. {
  84. [self.view endEditing:YES];
  85. }
  86. /**
  87. 每个单元格cell
  88. @param tableView <#tableView description#>
  89. @param indexPath <#indexPath description#>
  90. @return <#return value description#>
  91. */
  92. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  93. {
  94. static NSString *CellIdentifier = @"OtherInStorageGoodsListCell";
  95. OtherInStorageGoodsListCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier ];
  96. if (!cell) {
  97. cell=[[OtherInStorageGoodsListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  98. cell.selectionStyle=UITableViewCellSelectionStyleNone;
  99. }
  100. else
  101. //当页面拉动的时候 当cell存在并且最后一个存在 把它进行删除就出来一个独特的cell我们在进行数据配置即可避免
  102. {
  103. while ([cell.contentView.subviews lastObject] != nil) {
  104. [(UIView *)[cell.contentView.subviews lastObject] removeFromSuperview];
  105. }
  106. }
  107. _goodsListModel= [_dataList objectAtIndex:indexPath.row];
  108. cell.inStorageDelegate = self;
  109. cell.index=indexPath.row;
  110. [cell setOtherInStorageGoodsModel:_goodsListModel];
  111. return cell;
  112. }
  113. /**
  114. 刷新tableview
  115. */
  116. -(void)refreshTable{
  117. [_vTableView reloadData];
  118. }
  119. /**
  120. 点击单元格事件
  121. @param tableView tableView description
  122. @param indexPath indexPath description
  123. */
  124. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  125. {
  126. [self.view endEditing:YES];
  127. self.hidesBottomBarWhenPushed=YES;
  128. OtherInStorageGoodsDetailVC *detailVc=[[OtherInStorageGoodsDetailVC alloc] init];
  129. OtherInStorageGoodsSearchListModel *salesInStorageDetailModel= [_dataList objectAtIndex:indexPath.row];
  130. detailVc.goodsDetailModel= salesInStorageDetailModel;
  131. [self.nav pushViewController:detailVc animated:YES];
  132. }
  133. /**
  134. 显示选中的商品列表
  135. @param checkedGoodsList <#checkedGoodsList description#>
  136. */
  137. -(void)showSelectedGoods:(NSMutableArray*)checkedGoodsList{
  138. [_dataList addObjectsFromArray:checkedGoodsList];
  139. _vTableView.dataSource=self;
  140. _vTableView.delegate=self;
  141. [_vTableView reloadData];
  142. }
  143. /**
  144. 库区回调函数
  145. @param model <#model description#>
  146. @param value <#value description#>
  147. */
  148. - (void) baseIDAndNameDoneDatas: (BaseIDAndNameModel *)model BaseIDAndName:(baseIdAndName) value{
  149. if(value==baseIdAndNameWare){
  150. _goodsListModel= [_dataList objectAtIndex:_position];
  151. _goodsListModel.warehouseId=model.warehouseId;
  152. _goodsListModel.warehouseName=model.name;
  153. _goodsListModel.warehouseCode=model.id;
  154. _goodsListModel.positionNumberName=@"";
  155. _goodsListModel.positionNumberId=@"";
  156. [_vTableView reloadData];
  157. _positionNumberList= [self filterPositionNumber: _goodsListModel.warehouseId positionNumberArray:_otherInStorageVc.positionNumberList];
  158. }
  159. }
  160. /**
  161. 产品等级和仓位号回调函数
  162. @param model <#model description#>
  163. @param cr <#cr description#>
  164. */
  165. - (void)customerReportTextDoneDatas:(CustomerReportTextInfoModel *)model CustomerReport:(CustomerReport)cr
  166. {
  167. if (model==nil) {
  168. return;
  169. }
  170. if(cr==ReportGrade){
  171. _goodsListModel= [_dataList objectAtIndex:_position];
  172. _goodsListModel.gradeId=model.idCode;
  173. _goodsListModel.gradeName=model.name;
  174. }
  175. if(cr==ReportPositionNumber){
  176. _goodsListModel= [_dataList objectAtIndex:_position];
  177. _goodsListModel.positionNumberId=model.idCode;
  178. _goodsListModel.positionNumberName=model.name;
  179. }
  180. [_vTableView reloadData];
  181. }
  182. #pragma mark 私有函数
  183. /**
  184. 抽屉初始化
  185. */
  186. - (void)initSlideSlip{
  187. // 抽屉对象
  188. __weak typeof(self) weakself=self;
  189. self.filterController = [[SideSlipFilterController alloc]
  190. initWithSponsor:self
  191. resetBlock:^(NSArray *dataList) {
  192. for (SideSlipModel *model in dataList) {
  193. model.selectedItemList = nil;
  194. model.customDict = nil;
  195. }
  196. } commitBlock:^(NSArray *dataList) {
  197. // 查询条件
  198. SideSlipModel *serviceRegionModel = dataList[0];
  199. OtherInStorageGoodsSearchModel *m = [serviceRegionModel.customDict objectForKey:In_STORAGE_SEARCH_RANGE_MODEL];
  200. _goodsCode = m.goodsCode;
  201. _goodsName=m.goodsName;
  202. _onlyCode=m.onlyCode;
  203. _brandId=m.brandId;
  204. _kindId=m.kindId;
  205. _kindCode=m.kindCode;
  206. _varietyId=m.varietyId;
  207. if((_goodsCode==nil||[_goodsCode isEqualToString:@""])&&(_onlyCode==nil||[_onlyCode isEqualToString:@""])){
  208. [self showAlertViewText:@"商品编码或唯一编码至少输入一个"];
  209. return;
  210. }
  211. NewOtherInStorageGoodsSearchVC *goodsSearchVc=[[NewOtherInStorageGoodsSearchVC alloc]init];
  212. goodsSearchVc.goodsCode=_goodsCode;
  213. goodsSearchVc.goodsName=_goodsName;
  214. goodsSearchVc.onlyCode=_onlyCode;
  215. goodsSearchVc.kindId=_kindId;
  216. goodsSearchVc.kindCode=_kindCode;
  217. goodsSearchVc.brandId=_brandId;
  218. goodsSearchVc.goodsDetailList=_dataList;
  219. goodsSearchVc.varietyId=_varietyId;
  220. goodsSearchVc.goodsDelegate=self;
  221. [self.nav pushViewController:goodsSearchVc animated:YES];
  222. [weakself.filterController dismiss];
  223. }];
  224. _filterController.animationDuration = AnimationDuration;
  225. _filterController.hasHeadView = YES;
  226. _filterController.sideSlipLeading = UIScreenSideSlipLeading*[UIScreen mainScreen].bounds.size.width;
  227. _filterController.dataList = [self packageDataList];
  228. }
  229. /**
  230. 抽屉数据源
  231. @return <#return value description#>
  232. */
  233. - (NSArray *)packageDataList {
  234. NSMutableArray *dataArray = [NSMutableArray array];
  235. SideSlipModel *model = [[SideSlipModel alloc] init];
  236. model.containerCellClass = @"SalesInStorageGoodsSearchCell";
  237. model.regionTitle = @"查询条件";
  238. [dataArray addObject:model];
  239. return [dataArray mutableCopy];
  240. }
  241. /**
  242. 初始化UI
  243. */
  244. -(void)initUI{
  245. [self.view setBackgroundColor:[UIColor whiteColor]];
  246. UIView *topSeparatorView = [UIView new];
  247. topSeparatorView.frame=CGRectMake(0,3, Screen_Width, 10);
  248. topSeparatorView.backgroundColor = LineBackgroundColor;
  249. [self.view addSubview:topSeparatorView];
  250. CGFloat height = 40;
  251. _searchView = [[UIView alloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(topSeparatorView.frame), Screen_Width, 50)];
  252. _searchView.backgroundColor = [UIColor whiteColor];
  253. UIButton *btnSearch = [UIButton buttonWithType:UIButtonTypeCustom];
  254. btnSearch.frame = CGRectMake(5, 5, Screen_Width-45, height);
  255. btnSearch.layer.cornerRadius = 6.0f;
  256. [btnSearch setTitle:@"搜索" forState:UIControlStateNormal];
  257. [btnSearch setTitleColor:NavBarUnEnbleItemColor forState:UIControlStateNormal];
  258. btnSearch.titleLabel.textAlignment = NSTextAlignmentCenter;
  259. btnSearch.titleLabel.font = [UIFont systemFontOfSize:LabelAndTextFontOfSize];
  260. btnSearch.backgroundColor = LineBackgroundColor;
  261. [btnSearch addTarget:self action:@selector(dataSearch) forControlEvents:UIControlEventTouchUpInside];
  262. [_searchView addSubview:btnSearch];
  263. [self.view addSubview:_searchView];
  264. UIButton *scan=[UIButton buttonWithType:UIButtonTypeCustom];
  265. scan.frame=CGRectMake(_searchView.frame.size.width-35,8,35,35);
  266. scan.contentHorizontalAlignment=UIControlContentHorizontalAlignmentRight;
  267. [scan setImage:[UIImage imageNamed:@"scan"] forState:UIControlStateNormal];
  268. [_searchView addSubview:scan];
  269. [scan addTarget:self action:@selector(btnScanCilck) forControlEvents:UIControlEventTouchUpInside];
  270. _topSeparatorView = [UIView new];
  271. _topSeparatorView.frame=CGRectMake(0, CGRectGetMaxY(_searchView.frame), Screen_Width, 10);
  272. _topSeparatorView.backgroundColor = LineBackgroundColor;
  273. [self.view addSubview:_topSeparatorView];
  274. _vTableView = [[UITableView alloc]
  275. initWithFrame:CGRectMake(0,
  276. CGRectGetMaxY(_topSeparatorView.frame),
  277. self.view.frame.size.width,
  278. self.view.frame.size.height-CGRectGetMaxY(_topSeparatorView.frame))];
  279. _vTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  280. _vTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
  281. _vTableView.dataSource=self;
  282. _vTableView.delegate=self;
  283. [self.view addSubview:_vTableView];
  284. }
  285. /**
  286. 扫描点击事件
  287. */
  288. -(void)btnScanCilck{
  289. ScanViewController *scanVc=[[ScanViewController alloc]init];
  290. scanVc.rootVC=self;
  291. [self.nav pushViewController:scanVc animated:YES];
  292. }
  293. /**
  294. 跳转到产品等级页面
  295. @param pos <#pos description#>
  296. */
  297. -(void)goGrade:(NSInteger)pos{
  298. _position=pos;
  299. [self.view endEditing:YES];
  300. CustomerReportTextVC *tc=[[CustomerReportTextVC alloc] init];
  301. tc.delegate=self;
  302. tc.dataSourceCode=@"T_MST_Goods_Grade";
  303. tc.showDialogViewTag=ReportGrade;
  304. [self.nav pushViewController:tc animated:YES];
  305. }
  306. /**
  307. 跳转到库区页面
  308. @param pos <#pos description#>
  309. */
  310. -(void)goWareHouse:(NSInteger)pos{
  311. _position=pos;
  312. [self.view endEditing:YES];
  313. WareSearchViewController *tc=[[WareSearchViewController alloc ]init];
  314. tc.bDelegate = self;
  315. tc.jsonArr=_otherInStorageVc.warehouseList;
  316. tc.showDialogViewTag = baseIdAndNameWare;
  317. [self.nav pushViewController:tc animated:YES];
  318. }
  319. /**
  320. 跳转到仓位号页面
  321. @param pos <#pos description#>
  322. */
  323. -(void)goPositionNumber:(NSInteger)pos{
  324. _position=pos;
  325. [self.view endEditing:YES];
  326. _goodsListModel= [_dataList objectAtIndex:_position];
  327. NSString *warehouseId= _goodsListModel.warehouseId;
  328. if(warehouseId==nil||[warehouseId isEqualToString:@""]){
  329. [self showAlertViewText:@"请选择库区"];
  330. return;
  331. }
  332. if([warehouseId isEqualToString:@"0"]){
  333. [self showAlertViewText:@"请选择库区"];
  334. return;
  335. }
  336. if(_positionNumberList==nil||_positionNumberList.count==0){
  337. [self showAlertViewText:@"仓位号数据源不能为空"];
  338. return;
  339. }
  340. CustomerReportTextVC *tc=[[CustomerReportTextVC alloc] init];
  341. tc.delegate=self;
  342. tc.jsonArr=_positionNumberList;
  343. tc.showDialogViewTag=ReportPositionNumber;
  344. [self.nav pushViewController:tc animated:YES];
  345. }
  346. /**
  347. 过滤仓位号
  348. @param warehouseId <#warehouseId description#>
  349. @param positionNumberArray <#positionNumberArray description#>
  350. @return <#return value description#>
  351. */
  352. -(NSMutableArray*) filterPositionNumber:(NSString*)warehouseId positionNumberArray:(NSArray*)positionNumberArray{
  353. NSMutableArray *positionNumberFilterArray=[[NSMutableArray alloc]init];
  354. for(int i=0;i<positionNumberArray.count;i++){
  355. NSDictionary *dic=positionNumberArray[i];
  356. NSInteger warehouseIdValue= [[dic objectForKey:@"WarehouseID"]integerValue];
  357. if([warehouseId integerValue]==warehouseIdValue){
  358. [ positionNumberFilterArray addObject:dic];
  359. }
  360. }
  361. return positionNumberFilterArray;
  362. }
  363. /**
  364. 打开抽屉
  365. */
  366. -(void)dataSearch{
  367. [_filterController showPagerView:self.nav];
  368. }
  369. /**
  370. 删除商品
  371. @param position <#position description#>
  372. */
  373. -(void)deleteGoods:(NSInteger)position{
  374. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:@"确定要删除吗?" preferredStyle:UIAlertControllerStyleAlert];
  375. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  376. }];
  377. UIAlertAction *otherAction = [UIAlertAction actionWithTitle:@"确定"
  378. style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  379. [ _dataList removeObjectAtIndex:position];
  380. [ _vTableView reloadData];
  381. }];
  382. UIColor *cancelColor=[UIColor blackColor];
  383. UIColor *sureColor=[UIColor redColor];
  384. [cancelAction setValue:cancelColor forKey:@"titleTextColor"];
  385. [otherAction setValue:sureColor forKey:@"titleTextColor"];
  386. [alertController addAction:cancelAction];
  387. [alertController addAction:otherAction];
  388. [self presentViewController:alertController animated:YES completion:nil];
  389. }
  390. /**
  391. 注册键盘通知
  392. */
  393. - (void)registerKeybordNotification {
  394. NSNotificationCenter *notification = [NSNotificationCenter defaultCenter];
  395. [notification removeObserver:self];
  396. [notification addObserver:self
  397. selector:@selector(showKeyboard:)
  398. name:UIKeyboardWillShowNotification
  399. object:nil];
  400. [notification addObserver:self
  401. selector:@selector(hideKeyboard:)
  402. name:UIKeyboardWillHideNotification
  403. object:nil];
  404. #ifdef __IPHONE_5_0
  405. // 5.0以上系统中文键盘高度与4.0系统不一样
  406. float version = [[[UIDevice currentDevice] systemVersion] floatValue];
  407. if (version >= 5.0) {
  408. [notification addObserver:self
  409. selector:@selector(showKeyboard:)
  410. name:UIKeyboardWillChangeFrameNotification
  411. object:nil];
  412. }
  413. #endif
  414. }
  415. /**
  416. 出示键盘
  417. @param notification <#notification description#>
  418. */
  419. - (void)showKeyboard:(NSNotification *)notification {
  420. NSDictionary *userInfo = [notification userInfo];
  421. NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
  422. CGFloat keyboardHeight = CGRectGetHeight([aValue CGRectValue]);
  423. //50底部保存按钮 40为切换按钮
  424. CGFloat height = SCREENHEIGHT-rectStatusHeight-rectNavHeight-_vTableView.frame.origin.y - keyboardHeight-40-50;
  425. /* 使用动画效果,过度更加平滑 */
  426. [UIView beginAnimations:nil context:nil];
  427. [UIView setAnimationDuration:0.1];
  428. CGRect rect = _vTableView.frame;
  429. rect.size.height = height;
  430. _vTableView.frame = rect;
  431. [UIView commitAnimations];
  432. }
  433. /**
  434. 隐藏键盘
  435. @param notification <#notification description#>
  436. */
  437. - (void)hideKeyboard:(NSNotification *)notification {
  438. [UIView beginAnimations:nil context:nil];
  439. [UIView setAnimationDuration:0.1];
  440. {
  441. CGRect rect = _vTableView.frame;
  442. rect.size.height = CGRectGetHeight(self.view.frame)- CGRectGetMaxY(_topSeparatorView.frame);
  443. _vTableView.frame = rect;
  444. }
  445. [UIView commitAnimations];
  446. }
  447. @end