NewInventoryUnfreezeViewController.m 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. //
  2. // NewInventoryUnfreezeViewController.m
  3. // IBOSS
  4. //
  5. // Created by 关宏厚 on 2020/5/15.
  6. // Copyright © 2020 elongtian. All rights reserved.
  7. //
  8. #import "NewInventoryUnfreezeViewController.h"
  9. @interface NewInventoryUnfreezeViewController ()
  10. @end
  11. @implementation NewInventoryUnfreezeViewController
  12. - (void)viewDidLoad {
  13. [super viewDidLoad];
  14. [self loadNavStyle];
  15. [self initTableView];
  16. [self initUI];
  17. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
  18. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
  19. if(_editFlag)
  20. {
  21. _unfreezeGoodsList=[[NSMutableArray alloc]init];
  22. [self loadEditData];
  23. }
  24. else
  25. {
  26. if(_unfreezeGoodsList!=nil&&_unfreezeGoodsList.count>0)
  27. {
  28. [_tableView reloadData];
  29. }
  30. }
  31. }
  32. /**
  33. 安全区视图发生变化
  34. */
  35. -(void)viewSafeAreaInsetsDidChange{
  36. _tableView.frame =CGRectMake(0, 0, self.view.frame.size.width,self.view.safeAreaLayoutGuide.layoutFrame.size.height-40);
  37. _btnSubmit.frame=CGRectMake(0, self.view.safeAreaLayoutGuide.layoutFrame.size.height-40, self.view.frame.size.width, 40);
  38. [super viewSafeAreaInsetsDidChange];
  39. }
  40. /**
  41. 导航按钮样式
  42. */
  43. - (void)loadNavStyle
  44. {
  45. if(_editFlag)
  46. {
  47. self.navigationItem.title =@"编辑库存解冻";
  48. }
  49. else
  50. {
  51. self.navigationItem.title =@"新建库存解冻";
  52. }
  53. //返回
  54. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  55. [button setImage:[UIImage imageNamed:@"icon_back"] forState:UIControlStateNormal];
  56. [button addTarget:self action:@selector(goBack)
  57. forControlEvents:UIControlEventTouchUpInside];
  58. button.frame = CGRectMake(0, 0,45,22);
  59. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  60. self.navigationItem.leftBarButtonItem = menuButton;
  61. }
  62. -(void)loadEditData
  63. {
  64. [self startLoading];
  65. _downManager = [[ASIDownManager alloc] init];
  66. _downManager.delegate = self;
  67. _downManager.onRequestSuccess = @selector(onEditDataLoadFinish:);
  68. _downManager.onRequestFail = @selector(onEditDataLoadFail:);
  69. NSString *urlStr = ServerURL;
  70. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  71. [dict setObject:@"GetUnFreezeEditDataIPhone" forKey:@"Action"];
  72. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  73. [dict setObject:kkUserCode forKey:@"UserCode"];
  74. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  75. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  76. [dict setObject:_unfreezeId forKey:@"UnFreezeID"];
  77. [_downManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];
  78. }
  79. /**
  80. 初始化tableview
  81. */
  82. - (void)initTableView
  83. {
  84. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-40)];
  85. _tableView.backgroundColor = [UIColor redColor];
  86. _tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
  87. _tableView.backgroundColor = [UIColor whiteColor];
  88. _tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
  89. _tableView.delegate = self;
  90. _tableView.dataSource=self;
  91. [self.view addSubview:_tableView];
  92. }
  93. -(void)initUI
  94. {
  95. _headerView = [UIView new];
  96. _headerView.frame=CGRectZero;
  97. [self.view addSubview:_headerView];
  98. UIView *vInvoiceStyle = [UIView new];
  99. vInvoiceStyle.frame=CGRectMake(0, 0,Screen_Width, 51);
  100. [_headerView addSubview:vInvoiceStyle];
  101. UILabel *lblInvoiceStyle = [UILabel new];
  102. lblInvoiceStyle.frame=CGRectMake(15, 16, 100, 25);
  103. lblInvoiceStyle.text = @"票据样式";
  104. lblInvoiceStyle.textColor=[UIColor redColor];
  105. lblInvoiceStyle.font=orderTextFont;
  106. [vInvoiceStyle addSubview:lblInvoiceStyle];
  107. _btnInvoiceStyle = [UIButton buttonWithType:UIButtonTypeCustom];
  108. _btnInvoiceStyle.frame=CGRectMake(CGRectGetMaxX(lblInvoiceStyle.frame)+10, 16, 150, 25);
  109. _btnInvoiceStyle.titleLabel.font=orderTextFont;
  110. _btnInvoiceStyle.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  111. [_btnInvoiceStyle setTitle:@"请选择票据样式" forState:UIControlStateNormal];
  112. [_btnInvoiceStyle setTitleColor:ButtonTitleColor forState:UIControlStateNormal];
  113. [vInvoiceStyle addSubview:_btnInvoiceStyle];
  114. [_btnInvoiceStyle addTarget:self action:@selector(selectInvoiceStyle) forControlEvents:UIControlEventTouchUpInside];
  115. UIImageView *invoiceStyleImg = [[UIImageView alloc] initWithFrame:CGRectMake(Screen_Width-25, 20,7,12)];
  116. [invoiceStyleImg setImage:[UIImage imageNamed:@"rightarrow"] ];
  117. [vInvoiceStyle addSubview:invoiceStyleImg];
  118. UIView *separator1 = [UIView new];
  119. separator1.backgroundColor=LineBackgroundColor;
  120. separator1.frame=CGRectMake(CGRectGetMaxX( lblInvoiceStyle.frame)+10,CGRectGetMaxY(_btnInvoiceStyle.frame)+10,Screen_Width-CGRectGetMaxX( lblInvoiceStyle.frame)+10, 1);
  121. [vInvoiceStyle addSubview:separator1];
  122. [_headerView addSubview:vInvoiceStyle];
  123. UIView *vRemarks = [UIView new];
  124. vRemarks.frame=CGRectMake(0,CGRectGetMaxY(vInvoiceStyle.frame),Screen_Width, 51);
  125. [_headerView addSubview:vRemarks];
  126. UILabel *lblRemarks = [UILabel new];
  127. lblRemarks.frame=CGRectMake(15, 16, 100, 25);
  128. lblRemarks.text = @"备注";
  129. lblRemarks.font=orderTextFont;
  130. [vRemarks addSubview: lblRemarks];
  131. _txtRemarks = [UITextField new];
  132. _txtRemarks.tag=1302;
  133. _txtRemarks.frame=CGRectMake(CGRectGetMaxX(lblRemarks.frame)+10, 16, 150, 25);
  134. _txtRemarks.placeholder = @"请输入备注";
  135. _txtRemarks.font=orderTextFont;
  136. [vRemarks addSubview:_txtRemarks];
  137. UIView *separator2 = [UIView new];
  138. separator2.backgroundColor=LineBackgroundColor;
  139. separator2.frame=CGRectMake(CGRectGetMaxX( lblRemarks.frame)+10,CGRectGetMaxY(_txtRemarks.frame)+10,Screen_Width-CGRectGetMaxX( lblRemarks.frame)+10, 1);
  140. [vRemarks addSubview:separator2];
  141. [_headerView addSubview:vRemarks];
  142. UIView *separator3 = [UIView new];
  143. separator3.backgroundColor=LineBackgroundColor;
  144. separator3.frame=CGRectMake(0,CGRectGetMaxY(vRemarks.frame)+10,Screen_Width, 10);
  145. [_headerView addSubview:separator3];
  146. _headerView.frame=CGRectMake(0, 0, Screen_Width, CGRectGetMaxY(separator3.frame));
  147. _tableView.tableHeaderView=_headerView;
  148. //提交订单
  149. _btnSubmit = [UIButton buttonWithType:UIButtonTypeCustom];
  150. _btnSubmit.frame=CGRectMake(0,Screen_Height-40-rectStatusHeight-rectNavHeight, Screen_Width, 40);
  151. [_btnSubmit setBackgroundImage:[UIImage imageNamed:@"bt_datasave"] forState:UIControlStateNormal];
  152. [_btnSubmit addTarget:self action:@selector(reallySubmitOrder) forControlEvents:UIControlEventTouchUpInside];
  153. [self.view addSubview:_btnSubmit];
  154. }
  155. -(void)reallySubmitOrder
  156. {
  157. if(_unfreezeGoodsList!=nil&&_unfreezeGoodsList.count>0)
  158. {
  159. for(int i=0;i<_unfreezeGoodsList.count;i++)
  160. {
  161. InventoryFrozenGoodsModel *goodsModel=[_unfreezeGoodsList objectAtIndex:i];
  162. NSString *unfreezeQuantity=[goodsModel unfreezeQuantity];
  163. NSString *freezeQuantity=[goodsModel freezeQuantity];
  164. NSString *okUnfreezeQuantity=[goodsModel allUnfreezeQuantity];
  165. if([unfreezeQuantity doubleValue]<=0)
  166. {
  167. [self showAlertViewText:@"解冻量不能小于等于0"];
  168. return;
  169. }
  170. if([unfreezeQuantity doubleValue]>[freezeQuantity doubleValue]-[okUnfreezeQuantity doubleValue])
  171. {
  172. [self showAlertViewText:@"最大解冻量不能超过冻结数量-已解冻数量"];
  173. return;
  174. }
  175. }
  176. }
  177. [self startLoading];
  178. [self submitData];
  179. }
  180. -(void)submitData
  181. {
  182. _downManager = [[ASIDownManager alloc] init];
  183. _downManager.delegate = self;
  184. _downManager.onRequestSuccess = @selector(onSubmitOrderLoadFinish:);
  185. _downManager.onRequestFail = @selector(onSubmitOrderLoadFail:);
  186. NSString *urlStr = ServerURL;
  187. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  188. [dict setObject:@"SaveUnFreezeDataIPhone" forKey:@"Action"];
  189. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  190. [dict setObject:kkUserCode forKey:@"UserCode"];
  191. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  192. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  193. if(!_editFlag)
  194. {
  195. [dict setObject:_freezeId forKey:@"FreezeID"];
  196. }
  197. [dict setObject:(_unfreezeId==nil?@"":_unfreezeId) forKey:@"UnFreezeID"];
  198. [dict setObject:(_styleId==nil?@"":_styleId) forKey:@"InvoiceLayoutID"];
  199. [dict setObject:(_txtRemarks.text==nil?@"":_txtRemarks.text) forKey:@"Remarks"];
  200. NSMutableArray *unfreezeArray = [[NSMutableArray alloc]init];
  201. if(_unfreezeGoodsList!=nil&&_unfreezeGoodsList.count>0)
  202. {
  203. for(int i=0;i<_unfreezeGoodsList.count;i++)
  204. {
  205. NSMutableDictionary *unfreezeDic=[NSMutableDictionary new];
  206. InventoryFrozenGoodsModel *goodsModel=[_unfreezeGoodsList objectAtIndex:i];
  207. NSString *codeId=goodsModel.codeId;
  208. NSString *code=goodsModel.code;
  209. NSString *freezeQuantity=goodsModel.freezeQuantity;
  210. NSString *unfreezeQuantity=goodsModel.unfreezeQuantity;
  211. NSString *remarks=goodsModel.remarks;
  212. NSString *detailId=goodsModel.detailId;
  213. NSString *freezeDetailId=goodsModel.freezeDetailId;
  214. [unfreezeDic setObject:freezeQuantity forKey:@"FreezeQuantity"];
  215. [unfreezeDic setObject:(detailId==nil?@"":detailId) forKey:@"DetailID"];
  216. [unfreezeDic setObject:(freezeDetailId==nil?@"":freezeDetailId) forKey:@"FreezeDetailID"];
  217. [unfreezeDic setObject:unfreezeQuantity forKey:@"OKUnFreezeQuantity"];
  218. [unfreezeDic setObject:codeId forKey:@"CodeID"];
  219. [unfreezeDic setObject:code forKey:@"Code"];
  220. [unfreezeDic setObject:remarks forKey:@"Remarks"];
  221. [unfreezeArray addObject:unfreezeDic];
  222. }
  223. SBJsonWriter *write = [[SBJsonWriter alloc] init];
  224. NSString *value = [write stringWithObject:unfreezeArray];
  225. [dict setObject:value forKey:@"FreezeDetailDataTable"];
  226. [_downManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];
  227. }
  228. }
  229. -(void)selectInvoiceStyle
  230. {
  231. InvoiceStyleViewController *styleVC = [[ InvoiceStyleViewController alloc] init];
  232. styleVC.inventoryDelegate=self;
  233. [self.navigationController pushViewController:styleVC animated:YES];
  234. }
  235. -(void)onEditDataLoadFinish:(ASIDownManager*)sender {
  236. [self cancel];
  237. RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
  238. int iStatus = resultModel.status;
  239. // 服务器返回数据消息
  240. NSString *message = resultModel.message;
  241. if(iStatus==0)
  242. {
  243. NSDictionary *resultDic=( NSDictionary*) resultModel.result;
  244. NSArray *headArray=[resultDic objectForKey:@"Table"];
  245. if(headArray!=nil&&headArray.count>0)
  246. {
  247. NSDictionary *headDic=[headArray objectAtIndex:0];
  248. _styleId = [headDic objectForKey:@"InvoiceLayoutID"];
  249. _styleName=[headDic objectForKey:@"InvoiceLayoutName"];
  250. NSString *remarks=[headDic objectForKey:@"Remarks"];
  251. if(![_styleName isEqualToString:@""])
  252. {
  253. [_btnInvoiceStyle setTitle:_styleName forState:UIControlStateNormal];
  254. }
  255. if(![remarks isEqualToString:@""])
  256. {
  257. [_txtRemarks setText:remarks];
  258. }
  259. NSArray *detailArray=[resultDic objectForKey:@"Table1"];
  260. if(detailArray!=nil&&detailArray.count>0)
  261. {
  262. for(int i=0;i<detailArray.count;i++)
  263. {
  264. NSDictionary *detailDic=[detailArray objectAtIndex:i];
  265. InventoryFrozenGoodsModel *goodsModel=[InventoryFrozenGoodsModel dk_modelWithDictionary:detailDic];
  266. OrderQuantity *quantity=[OrderQuantity new];
  267. [quantity setBoxAndPiece:[goodsModel.unfreezeQuantity doubleValue] model:goodsModel];
  268. [_unfreezeGoodsList addObject:goodsModel];
  269. }
  270. [_tableView reloadData];
  271. }
  272. }
  273. }
  274. // 服务器返回数据状态值异常
  275. else if(iStatus == ActionResultStatusAuthError
  276. ||iStatus == ActionResultStatusNoLogin
  277. ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){
  278. [self showReLoginDialog:message];
  279. }
  280. else{
  281. [self showAlertViewText:message];
  282. }
  283. }
  284. -(void)onEditDataLoadFail:(ASIDownManager*)sender {
  285. [self cancel];
  286. [self showAlertViewText:@"网络异常"];
  287. }
  288. -(void)getInvoiceStyle:(NSString*)invoiceStyleId name:(NSString*)invoiceStyleName
  289. {
  290. _styleId=invoiceStyleId;
  291. _styleName=invoiceStyleName;
  292. [_btnInvoiceStyle setTitle:_styleName forState:UIControlStateNormal];
  293. [_btnInvoiceStyle setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  294. }
  295. -(void)onSubmitOrderLoadFinish:(ASIDownManager*)sender {
  296. [self cancel];
  297. RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
  298. int iStatus = resultModel.status;
  299. // 服务器返回数据消息
  300. NSString *message = resultModel.message;
  301. if(iStatus==0)
  302. {
  303. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"保存成功" preferredStyle:UIAlertControllerStyleAlert];
  304. UIAlertAction *otherAction = [UIAlertAction actionWithTitle:@"确定"
  305. style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  306. if([self.inventoryDelegate respondsToSelector:@selector(refreshData)])
  307. {
  308. [self.inventoryDelegate refreshData];
  309. } [self goBack];
  310. }];
  311. UIColor *sureColor = [UIColor redColor];
  312. [otherAction setValue:sureColor forKey:@"titleTextColor"];
  313. [alertController addAction:otherAction];
  314. [self presentViewController:alertController animated:YES completion:nil];
  315. }
  316. else if(iStatus == ActionResultStatusAuthError
  317. ||iStatus == ActionResultStatusNoLogin
  318. ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){
  319. [self showReLoginDialog:message];
  320. }
  321. else{
  322. [self showAlertViewText:message];
  323. return;
  324. }
  325. }
  326. -(void)onSubmitOrderLoadFail:(ASIDownManager *)sender {
  327. [self cancel];
  328. [self showAlertViewText:@"网络异常"];
  329. }
  330. /**
  331. 隐藏进度条
  332. */
  333. - (void)cancel {
  334. [self stopLoading];
  335. }
  336. /**
  337. 单元格cell个数
  338. @param tableView <#tableView description#>
  339. @param section <#section description#>
  340. @return <#return value description#>
  341. */
  342. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  343. {
  344. return [_unfreezeGoodsList count];
  345. }
  346. /**
  347. table view 分区数
  348. @param tableView <#tableView description#>
  349. @return <#return value description#>
  350. */
  351. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  352. return 1;
  353. }
  354. /**
  355. cell 高度
  356. @param tableView <#tableView description#>
  357. @param indexPath <#indexPath description#>
  358. @return <#return value description#>
  359. */
  360. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  361. return [self.heights[@(indexPath.row)] doubleValue];;
  362. }
  363. /**
  364. 高度
  365. @return <#return value description#>
  366. */
  367. - (NSMutableDictionary *)heights{
  368. if (_heights == nil){
  369. _heights = [NSMutableDictionary dictionary];
  370. }
  371. return _heights;
  372. }
  373. /**
  374. 预防高度
  375. @param tableView <#tableView description#>
  376. @param indexPath <#indexPath description#>
  377. @return <#return value description#>
  378. */
  379. -(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
  380. return 250;
  381. }
  382. /**
  383. 每个单元格cell
  384. @param tableView <#tableView description#>
  385. @param indexPath <#indexPath description#>
  386. @return <#return value description#>
  387. */
  388. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  389. {
  390. static NSString *cellIdentifier = @"NewInventoryUnfreezeGoodsListCell";
  391. NewInventoryUnfreezeGoodsListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier ];
  392. cell = [[NewInventoryUnfreezeGoodsListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
  393. cell.selectionStyle=UITableViewCellSelectionStyleNone;
  394. InventoryFrozenGoodsModel *inventoryGoodsModel= [_unfreezeGoodsList objectAtIndex:indexPath.row];
  395. [cell setNewInventoryUnfreezeGoodsListCell:&inventoryGoodsModel];
  396. self.heights[@(indexPath.row)] = @(cell.height);
  397. return cell;
  398. }
  399. /**
  400. 键盘弹出
  401. @param note
  402. */
  403. - (void)keyboardWillShow:(NSNotification *)note
  404. {
  405. CGRect keyBoardRect = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
  406. _tableView.contentInset = UIEdgeInsetsMake(0, 0, keyBoardRect.size.height, 0);
  407. }
  408. /**
  409. 键盘隐藏
  410. @param note
  411. */
  412. - (void)keyboardWillHide:(NSNotification *)note
  413. {
  414. _tableView.contentInset = UIEdgeInsetsZero;
  415. }
  416. /**
  417. 屏幕触摸回调函数
  418. @param touches <#touches description#>
  419. @param event <#event description#>
  420. */
  421. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
  422. {
  423. [self.view endEditing:YES];
  424. }
  425. /**
  426. scrollview回调函数
  427. @param scrollView <#scrollView description#>
  428. */
  429. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
  430. [self.view endEditing:YES];
  431. }
  432. -(void)goBack
  433. {
  434. [self.navigationController popViewControllerAnimated:YES];
  435. }
  436. @end