NewSalesOutStorageGoodsDetailVC.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. //
  2. // NewSalesOutStorageGoodsDetailVC.m
  3. // IBOSSmini
  4. //
  5. // Created by guan hong hou on 2018/4/12.
  6. // Copyright © 2018年 elongtian. All rights reserved.
  7. //
  8. #import "NewSalesOutStorageGoodsDetailVC.h"
  9. #import "NewSalesOutStorageListVC.h"
  10. @interface NewSalesOutStorageGoodsDetailVC (){
  11. }
  12. @end
  13. @implementation NewSalesOutStorageGoodsDetailVC
  14. #pragma mark 公共函数
  15. /**
  16. 视图加载完成函数
  17. */
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. [self initUI];
  21. [self registerKeybordNotification];
  22. }
  23. /**
  24. 安全区变化函数
  25. */
  26. -(void)viewSafeAreaInsetsDidChange{
  27. _vTableView.frame=CGRectMake(0,10,self.view.frame.size.width,self.view.safeAreaLayoutGuide.layoutFrame.size.height-10);
  28. [super viewSafeAreaInsetsDidChange];
  29. }
  30. - (void)didReceiveMemoryWarning {
  31. [super didReceiveMemoryWarning];
  32. }
  33. #pragma mark 委托函数
  34. /**
  35. 单元格cell个数
  36. @param tableView <#tableView description#>
  37. @param section <#section description#>
  38. @return <#return value description#>
  39. */
  40. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  41. {
  42. return [_goodsList count];
  43. }
  44. /**
  45. tableview的分区数
  46. @param tableView <#tableView description#>
  47. @return <#return value description#>
  48. */
  49. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  50. return 1;
  51. }
  52. /**
  53. 高度
  54. @param tableView <#tableView description#>
  55. @param indexPath <#indexPath description#>
  56. @return <#return value description#>
  57. */
  58. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  59. return 260;
  60. }
  61. /**
  62. 每个单元格cell
  63. @param tableView <#tableView description#>
  64. @param indexPath <#indexPath description#>
  65. @return <#return value description#>
  66. */
  67. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  68. {
  69. NSString *cellIdentifier = @"GoodsDetailListCell";
  70. NewSalesOutStorageGoodsListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier ];
  71. if (!cell) {
  72. cell=[[NewSalesOutStorageGoodsListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
  73. cell.selectionStyle=UITableViewCellSelectionStyleNone;
  74. }
  75. else
  76. //当页面拉动的时候 当cell存在并且最后一个存在 把它进行删除就出来一个独特的cell我们在进行数据配置即可避免
  77. {
  78. while ([cell.contentView.subviews lastObject] != nil) {
  79. [(UIView *)[cell.contentView.subviews lastObject] removeFromSuperview];
  80. }
  81. }
  82. SalesOutStorageSalesSlipGoodsListModel *goodsListModel= [_goodsList objectAtIndex:indexPath.row];
  83. [cell setNewSalesOutStorageGoodsDetailListModel:goodsListModel];
  84. cell.goodsDelegate=self;
  85. cell.index=indexPath.row;
  86. return cell;
  87. }
  88. /**
  89. 删除商品
  90. @param position <#position description#>
  91. */
  92. -(void)deleteGoods:(NSInteger)position{
  93. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:@"确定要删除吗?" preferredStyle:UIAlertControllerStyleAlert];
  94. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  95. }];
  96. UIAlertAction *otherAction = [UIAlertAction actionWithTitle:@"确定"
  97. style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  98. [ _goodsList removeObjectAtIndex:position];
  99. if(_goodsList.count==0){
  100. ((NewSalesOutStorageListVC*)_salesSlipListVc).lblOutStorageNo.text=@"";
  101. ((NewSalesOutStorageListVC*)_salesSlipListVc).lblCustomerCode.text=@"";
  102. ((NewSalesOutStorageListVC*)_salesSlipListVc).lblCustomerName.text=@"";
  103. ((NewSalesOutStorageListVC*)_salesSlipListVc).lblTelephone.text=@"";
  104. ((NewSalesOutStorageListVC*)_salesSlipListVc).lblDriver.text=@"请选择运输司机";
  105. ((NewSalesOutStorageListVC*)_salesSlipListVc).driverId=@"";
  106. ((NewSalesOutStorageListVC*)_salesSlipListVc).driverName=@"";
  107. ((NewSalesOutStorageListVC*)_salesSlipListVc).lblDocker.text=@"请选择装卸工人";
  108. ((NewSalesOutStorageListVC*)_salesSlipListVc).dockerId=@"";
  109. ((NewSalesOutStorageListVC*)_salesSlipListVc).dockerName=@"";
  110. ((NewSalesOutStorageListVC*)_salesSlipListVc).lblCustomerAddress.text=@"";
  111. ((NewSalesOutStorageListVC*)_salesSlipListVc).txtRemarks.text=@"";
  112. }
  113. [ _vTableView reloadData];
  114. }];
  115. UIColor *cancelColor=[UIColor blackColor];
  116. UIColor *sureColor=[UIColor redColor];
  117. [cancelAction setValue:cancelColor forKey:@"titleTextColor"];
  118. [otherAction setValue:sureColor forKey:@"titleTextColor"];
  119. [alertController addAction:cancelAction];
  120. [alertController addAction:otherAction];
  121. [self presentViewController:alertController animated:YES completion:nil];
  122. }
  123. /**
  124. 跳转到色号函数
  125. @param position <#position description#>
  126. */
  127. -(void)goColorNumber:(NSInteger)position{
  128. UpdateColorNumberVC *colorNumberVc=[[UpdateColorNumberVC alloc]init];
  129. SalesOutStorageSalesSlipGoodsListModel *goodsListModel= [_goodsList objectAtIndex:position];
  130. colorNumberVc.goodsListModel=goodsListModel;
  131. colorNumberVc.index=position;
  132. colorNumberVc.colorNumberDelegate=self;
  133. [self.nav pushViewController:colorNumberVc animated:YES];
  134. }
  135. /**
  136. 色号更新回调函数
  137. @param position <#position description#>
  138. @param colorNumber <#colorNumber description#>
  139. */
  140. -(void)updateColorNumber:(NSInteger)position colorNumber:(ColorNumberModel *)colorNumber{
  141. SalesOutStorageSalesSlipGoodsListModel *goodsListModel= [_goodsList objectAtIndex:position];
  142. goodsListModel.inventoryId=colorNumber.inventoryId;
  143. goodsListModel.warehouseId=colorNumber.warehouseId;
  144. goodsListModel.warehouseName=colorNumber.warehouseName;
  145. goodsListModel.positionNumber=colorNumber.positionNumber;
  146. goodsListModel.colorNumber=colorNumber.colorNumber;
  147. [_vTableView reloadData];
  148. }
  149. /**
  150. 隐藏键盘
  151. @param scrollView <#scrollView description#>
  152. */
  153. -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
  154. {
  155. [self.view endEditing:YES];
  156. }
  157. #pragma mark 私有函数
  158. /**
  159. 初始化UI
  160. */
  161. -(void)initUI{
  162. [self.view setBackgroundColor:[UIColor whiteColor]];
  163. UIView *topSeparatorView = [UIView new];
  164. topSeparatorView.frame=CGRectMake(0,3, Screen_Width, 10);
  165. topSeparatorView.backgroundColor = LineBackgroundColor;
  166. [self.view addSubview:topSeparatorView];
  167. _vTableView = [[UITableView alloc]
  168. initWithFrame:CGRectMake(0,
  169. 10,
  170. self.view.frame.size.width,
  171. self.view.frame.size.height-10)];
  172. _vTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  173. _vTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
  174. _vTableView.dataSource=self;
  175. _vTableView.delegate=self;
  176. [self.view addSubview:_vTableView];
  177. }
  178. /**
  179. 注册键盘通知
  180. */
  181. - (void)registerKeybordNotification {
  182. NSNotificationCenter *notification = [NSNotificationCenter defaultCenter];
  183. [notification removeObserver:self];
  184. [notification addObserver:self
  185. selector:@selector(showKeyboard:)
  186. name:UIKeyboardWillShowNotification
  187. object:nil];
  188. [notification addObserver:self
  189. selector:@selector(hideKeyboard:)
  190. name:UIKeyboardWillHideNotification
  191. object:nil];
  192. #ifdef __IPHONE_5_0
  193. // 5.0以上系统中文键盘高度与4.0系统不一样
  194. float version = [[[UIDevice currentDevice] systemVersion] floatValue];
  195. if (version >= 5.0) {
  196. [notification addObserver:self
  197. selector:@selector(showKeyboard:)
  198. name:UIKeyboardWillChangeFrameNotification
  199. object:nil];
  200. }
  201. #endif
  202. }
  203. /**
  204. 弹出键盘
  205. @param notification <#notification description#>
  206. */
  207. - (void)showKeyboard:(NSNotification *)notification {
  208. NSDictionary *userInfo = [notification userInfo];
  209. NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
  210. CGFloat keyboardHeight = CGRectGetHeight([aValue CGRectValue]);
  211. //50底部保存按钮 40为切换按钮
  212. CGFloat height = SCREENHEIGHT-rectStatusHeight-rectNavHeight-_vTableView.frame.origin.y - keyboardHeight-40-50;
  213. /* 使用动画效果,过度更加平滑 */
  214. [UIView beginAnimations:nil context:nil];
  215. [UIView setAnimationDuration:0.1];
  216. CGRect rect = _vTableView.frame;
  217. rect.size.height = height;
  218. _vTableView.frame = rect;
  219. [UIView commitAnimations];
  220. }
  221. /**
  222. 隐藏键盘
  223. @param notification <#notification description#>
  224. */
  225. - (void)hideKeyboard:(NSNotification *)notification {
  226. [UIView beginAnimations:nil context:nil];
  227. [UIView setAnimationDuration:0.1];
  228. {
  229. CGRect rect = _vTableView.frame;
  230. rect.size.height = CGRectGetHeight(self.view.frame)-10;
  231. _vTableView.frame = rect;
  232. }
  233. [UIView commitAnimations];
  234. }
  235. @end