SaleSlipExternalCoordinateGoodsVC.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. //
  2. // NewSalesExternalCoordinateVC.m
  3. // IBOSSmini
  4. //
  5. // Created by ssl on 2018/2/24.
  6. // Copyright © 2018年 elongtian. All rights reserved.
  7. //
  8. #import "SaleSlipExternalCoordinateGoodsVC.h"
  9. @interface SaleSlipExternalCoordinateGoodsVC (){
  10. UIView *_middleSeparatorView;
  11. }
  12. @end
  13. @implementation SaleSlipExternalCoordinateGoodsVC
  14. - (void)viewDidLoad {
  15. [super viewDidLoad];
  16. _externalCoordinateGoodsList=[[NSMutableArray alloc]init];
  17. _externalCoordinateGoodsDeleteList=[[NSMutableArray alloc]init];
  18. [self initUI];
  19. [self registerKeybordNotification];
  20. }
  21. - (void)didReceiveMemoryWarning {
  22. [super didReceiveMemoryWarning];
  23. }
  24. -(void)initUI{
  25. [self.view setBackgroundColor:[UIColor whiteColor]];
  26. UIView *topSeparatorView = [UIView new];
  27. topSeparatorView.frame=CGRectMake(0,3, Screen_Width, 10);
  28. topSeparatorView.backgroundColor = LineBackgroundColor;
  29. [self.view addSubview:topSeparatorView];
  30. CGFloat height = 40;
  31. UIView *searchView = [[UIView alloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(topSeparatorView.frame)+5, Screen_Width, 50)];
  32. searchView.backgroundColor = [UIColor whiteColor];
  33. UIButton *btnSearch = [UIButton buttonWithType:UIButtonTypeCustom];
  34. btnSearch.frame = CGRectMake(20, 5, Screen_Width-height, height);
  35. btnSearch.layer.cornerRadius = 6.0f;
  36. [btnSearch setTitle:@"新增商品" forState:UIControlStateNormal];
  37. [btnSearch setTitleColor:NavBarUnEnbleItemColor forState:UIControlStateNormal];
  38. btnSearch.titleLabel.textAlignment = NSTextAlignmentCenter;
  39. btnSearch.titleLabel.font = [UIFont systemFontOfSize:LabelAndTextFontOfSize];
  40. btnSearch.backgroundColor = LineBackgroundColor;
  41. [btnSearch addTarget:self action:@selector(addExternalCoordinateGoods) forControlEvents:UIControlEventTouchUpInside];
  42. [searchView addSubview:btnSearch];
  43. [self.view addSubview:searchView];
  44. _middleSeparatorView = [UIView new];
  45. _middleSeparatorView.frame=CGRectMake(0, CGRectGetMaxY(searchView.frame)+5, Screen_Width, 10);
  46. _middleSeparatorView.backgroundColor = LineBackgroundColor;
  47. [self.view addSubview:_middleSeparatorView];
  48. _vTableView = [[UITableView alloc]
  49. initWithFrame:CGRectMake(0,
  50. CGRectGetMaxY(_middleSeparatorView.frame),
  51. self.view.frame.size.width,
  52. Screen_Height - CGRectGetMaxY(_middleSeparatorView.frame))];
  53. _vTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  54. _vTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
  55. _vTableView.backgroundColor = [UIColor whiteColor];
  56. _vTableView.delegate = self;
  57. _vTableView.dataSource=self;
  58. [self.view addSubview:_vTableView];
  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 [_externalCoordinateGoodsList count];
  71. }
  72. /**
  73. <#Description#>
  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 210;
  88. }
  89. /**
  90. 每个单元格cell
  91. @param tableView <#tableView description#>
  92. @param indexPath <#indexPath description#>
  93. @return <#return value description#>
  94. */
  95. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  96. {
  97. static NSString *CellIdentifier = @"InventoryListCell1";
  98. NewSalesExternalCoordinateCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier ];
  99. cell=[[NewSalesExternalCoordinateCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  100. cell.selectionStyle=UITableViewCellSelectionStyleNone;
  101. cell.orderDelegate=self;
  102. cell.cellIndex=indexPath.row;
  103. ExternalCoordinateGoodsModel *externalModel= [_externalCoordinateGoodsList objectAtIndex:indexPath.row];
  104. [cell setNewExternalCoordinateGoodsCell:externalModel editStatus:_editStatus editFlag:_editFlag];
  105. return cell;
  106. }
  107. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  108. {
  109. _currentPosition=indexPath.row;
  110. self.hidesBottomBarWhenPushed=YES;
  111. NewSaleSlipExternalCoordinateGoodsVC *vc=[[NewSaleSlipExternalCoordinateGoodsVC alloc] init];
  112. _externalCoordinateEditFlag=@"edit";
  113. vc.externalCoordinateGoodsModel= _externalCoordinateGoodsList[_currentPosition];
  114. vc.externalCoordinateEditFlag=_externalCoordinateEditFlag;
  115. vc.editStatus=_editStatus;
  116. vc.orderNo=_orderNo;
  117. vc.editFlag=_editFlag;
  118. vc.orderListDelegate=self;
  119. [self.orderNav pushViewController:vc animated:YES];
  120. }
  121. -(void)updateNewSalesExternalCoordinateGoodsCell:(NewSalesExternalCoordinateCell*)cell textField:(UITextField*)field{
  122. _externalCoordinateGoodsList[cell.cellIndex]=cell.externalCoordinateModel;
  123. if(field.tag==1001||field.tag==1002){
  124. [self.homeVC calculate:@""];
  125. }
  126. }
  127. -(void)deleteOrderDetail:(NSInteger)cellIndex{
  128. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"是否要删除?" preferredStyle:UIAlertControllerStyleAlert];
  129. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  130. }];
  131. UIAlertAction *otherAction = [UIAlertAction actionWithTitle:@"确定"
  132. style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  133. if(_editFlag==2){
  134. ExternalCoordinateGoodsModel *externalGoodsModel= _externalCoordinateGoodsList[cellIndex];
  135. if([externalGoodsModel.editFlag isEqualToString:@"add"]){
  136. [_externalCoordinateGoodsList removeObjectAtIndex:cellIndex];
  137. }
  138. else if([externalGoodsModel.editFlag isEqualToString:@"modify"])
  139. {
  140. externalGoodsModel.editFlag=@"Deleted";
  141. [_externalCoordinateGoodsDeleteList addObject:externalGoodsModel];
  142. [_externalCoordinateGoodsList removeObjectAtIndex:cellIndex];
  143. }
  144. }
  145. else{
  146. [_externalCoordinateGoodsList removeObjectAtIndex:cellIndex];
  147. }
  148. [_vTableView reloadData];
  149. [self.homeVC calculate:@""];
  150. }];
  151. UIColor *cancelColor=[UIColor blackColor];
  152. UIColor *sureColor=[UIColor redColor];
  153. [cancelAction setValue:cancelColor forKey:@"titleTextColor"];
  154. [otherAction setValue:sureColor forKey:@"titleTextColor"];
  155. [alertController addAction:cancelAction];
  156. [alertController addAction:otherAction];
  157. [self presentViewController:alertController animated:YES completion:nil];
  158. }
  159. -(void)addExternalCoordinateGoods{
  160. if (_editStatus == 4||_editStatus == 5||_editStatus == 7
  161. || _editStatus == 10||_editFlag == 3) {
  162. return;
  163. }
  164. self.hidesBottomBarWhenPushed=YES;
  165. NewSaleSlipExternalCoordinateGoodsVC *vc=[[NewSaleSlipExternalCoordinateGoodsVC alloc] init];
  166. _externalCoordinateEditFlag=@"add";
  167. vc.orderListDelegate=self;
  168. vc.externalCoordinateEditFlag=_externalCoordinateEditFlag;
  169. [self.orderNav pushViewController:vc animated:YES];
  170. }
  171. -(void)addExternalCoordinateGoods:(ExternalCoordinateGoodsModel*)externalCoordinateGoodsModel resultCode:(NSString *)resultCode{
  172. //大编辑
  173. if(_editFlag==2)
  174. {
  175. //去的时候是新增页面,回来的时候是新增保存回来
  176. if([_externalCoordinateEditFlag isEqualToString:@"add"] && [resultCode isEqualToString:@"resultAdd"])
  177. {
  178. [_externalCoordinateGoodsList addObject:externalCoordinateGoodsModel];
  179. }
  180. if([_externalCoordinateEditFlag isEqualToString:@"edit"]&&[resultCode isEqualToString:@"resultEdit"]){
  181. [_externalCoordinateGoodsList setObject:externalCoordinateGoodsModel atIndexedSubscript:_currentPosition];
  182. }
  183. }
  184. //新增
  185. else {
  186. if([_externalCoordinateEditFlag isEqualToString:@"add"]&&[resultCode isEqualToString:@"resultAdd"]){
  187. [_externalCoordinateGoodsList addObject:externalCoordinateGoodsModel];
  188. }
  189. if([_externalCoordinateEditFlag isEqualToString:@"edit"]&&[resultCode isEqualToString:@"resultEdit"]){
  190. [_externalCoordinateGoodsList setObject:externalCoordinateGoodsModel atIndexedSubscript:_currentPosition];
  191. }
  192. }
  193. [self.homeVC calculate:@""];
  194. [_vTableView reloadData];
  195. }
  196. -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
  197. [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
  198. }
  199. // 键盘弹出改变tableview高度
  200. - (void)registerKeybordNotification {
  201. NSNotificationCenter *notification = [NSNotificationCenter defaultCenter];
  202. [notification removeObserver:self];
  203. [notification addObserver:self
  204. selector:@selector(showKeyboard:)
  205. name:UIKeyboardWillShowNotification
  206. object:nil];
  207. [notification addObserver:self
  208. selector:@selector(hideKeyboard:)
  209. name:UIKeyboardWillHideNotification
  210. object:nil];
  211. #ifdef __IPHONE_5_0
  212. // 5.0以上系统中文键盘高度与4.0系统不一样
  213. float version = [[[UIDevice currentDevice] systemVersion] floatValue];
  214. if (version >= 5.0) {
  215. [notification addObserver:self
  216. selector:@selector(showKeyboard:)
  217. name:UIKeyboardWillChangeFrameNotification
  218. object:nil];
  219. }
  220. #endif
  221. }
  222. - (void)showKeyboard:(NSNotification *)notification {
  223. NSDictionary *userInfo = [notification userInfo];
  224. NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
  225. CGFloat keyboardHeight = CGRectGetHeight([aValue CGRectValue]);
  226. //50底部保存按钮 40为切换按钮
  227. CGFloat height = SCREENHEIGHT-rectStatusHeight-rectNavHeight-_vTableView.frame.origin.y - keyboardHeight-40-50;
  228. /* 使用动画效果,过度更加平滑 */
  229. [UIView beginAnimations:nil context:nil];
  230. [UIView setAnimationDuration:0.1];
  231. {
  232. if(!self.homeVC.roundAmountTxtFlag){
  233. CGRect rect = _vTableView.frame;
  234. rect.size.height = height;
  235. _vTableView.frame = rect;
  236. }
  237. }
  238. [UIView commitAnimations];
  239. }
  240. - (void)hideKeyboard:(NSNotification *)notification {
  241. [UIView beginAnimations:nil context:nil];
  242. [UIView setAnimationDuration:0.1];
  243. {
  244. if(!self.homeVC.roundAmountTxtFlag){
  245. CGRect rect = _vTableView.frame;
  246. rect.size.height = CGRectGetHeight(self.view.frame)-CGRectGetMaxY(_middleSeparatorView.frame);
  247. _vTableView.frame = rect;
  248. }
  249. }
  250. [UIView commitAnimations];
  251. }
  252. @end