NewOtherInStorageHomeVC.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. //
  2. // NewOtherInStorageHomeVC.m
  3. // IBOSSmini
  4. //
  5. // Created by guan hong hou on 2018/4/24.
  6. // Copyright © 2018年 elongtian. All rights reserved.
  7. //
  8. #import "NewOtherInStorageHomeVC.h"
  9. @interface NewOtherInStorageHomeVC (){
  10. NewOtherInStorageVC *otherInStorageVc;
  11. NewOtherInStorageGoodsDetailVC *otherInStorageGoodsDetailVc;
  12. }
  13. @end
  14. @implementation NewOtherInStorageHomeVC
  15. #pragma mark 公共函数
  16. /**
  17. 视图加载完成函数
  18. */
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. [self loadNavStyle];
  22. [self initUI];
  23. }
  24. - (void)didReceiveMemoryWarning {
  25. [super didReceiveMemoryWarning];
  26. }
  27. #pragma mark 委托函数
  28. /**
  29. 加载总数数据成功回调
  30. @param sender <#sender description#>
  31. */
  32. - (void)onSaveDataLoadFinish:(ASIDownManager *)sender {
  33. NSDictionary *dic = [sender.mWebStr JSONValue];
  34. [self stopLoading];
  35. // 服务器返回数据是否正确
  36. if (dic && [dic isKindOfClass:[NSDictionary class]]) {
  37. // 服务器返回数据状态值
  38. int iStatus = [[dic objectForKey:@"Status"] intValue];
  39. // 服务器返回数据消息
  40. NSString *message=[dic objectForKey:@"Message"];
  41. // 服务器返回数据状态值正确
  42. if (iStatus == 0) {
  43. __weak typeof (self)weakself = self;
  44. //初始化->
  45. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示"
  46. message:@"保存成功!" preferredStyle:
  47. UIAlertControllerStyleAlert ];
  48. // addAction->
  49. [alert addAction:[UIAlertAction actionWithTitle:@"确定"
  50. style:UIAlertActionStyleDefault
  51. handler:^(UIAlertAction *action)
  52. {
  53. [weakself.navigationController popViewControllerAnimated:YES];
  54. //关闭当前页面 刷新一览主界面
  55. if([self.refreshDelegate respondsToSelector:@selector(refreshData)]){
  56. [self.refreshDelegate refreshData];
  57. }
  58. }]];
  59. //展示->
  60. [self presentViewController:alert animated:YES completion:nil];
  61. }
  62. else if(iStatus==ActionResultStatusAuthError
  63. ||iStatus==ActionResultStatusNoLogin
  64. ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid){
  65. [self showReLoginDialog:message];
  66. }
  67. else{
  68. [self showAlertViewText:message];
  69. }
  70. }
  71. }
  72. /**
  73. 加载总数数据失败回调
  74. @param sender <#sender description#>
  75. */
  76. - (void)onSaveDataLoadFail:(ASIDownManager *)sender {
  77. [self stopLoading];
  78. [self showAlertViewText:@"加载失败"];
  79. }
  80. #pragma mark 私有函数
  81. /**
  82. 导航按钮样式
  83. */
  84. -(void)loadNavStyle
  85. {
  86. self.navigationItem.title=@"新建其他入库";
  87. //返回
  88. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  89. [button setBackgroundImage:[UIImage imageNamed:@"icon_back"]
  90. forState:UIControlStateNormal];
  91. [button addTarget:self action:@selector(goBack)
  92. forControlEvents:UIControlEventTouchUpInside];
  93. button.frame = CGRectMake(0, 0, 15, 18);
  94. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  95. self.navigationItem.leftBarButtonItem = menuButton;
  96. }
  97. /**
  98. 初始化UI
  99. */
  100. -(void)initUI{
  101. [self.view setBackgroundColor:[UIColor whiteColor]];
  102. self.page = [[PageSwitchView alloc] init];
  103. [self.view addSubview:self.page];
  104. otherInStorageVc = [[NewOtherInStorageVC alloc] init];
  105. otherInStorageVc.listNavVc=self.navigationController;
  106. otherInStorageGoodsDetailVc = [[NewOtherInStorageGoodsDetailVC alloc] init];
  107. otherInStorageGoodsDetailVc.nav=self.navigationController;
  108. otherInStorageGoodsDetailVc.otherInStorageVc=otherInStorageVc;
  109. NSMutableArray *arr=[[NSMutableArray alloc]init];
  110. PageSwitchModel *model = [[PageSwitchModel alloc] init];
  111. model.title = @"其它入库";
  112. model.controller = otherInStorageVc;
  113. [arr addObject:model];
  114. model = [[PageSwitchModel alloc] init];
  115. model.title = @"商品明细";
  116. model.controller = otherInStorageGoodsDetailVc;
  117. [arr addObject:model];
  118. self.page.datas = arr;
  119. UIView *bottomView= [UIView new];
  120. [self.view addSubview:bottomView];
  121. bottomView.translatesAutoresizingMaskIntoConstraints=NO;
  122. UIView *bottomSeparatorView = [UIView new];
  123. bottomSeparatorView.frame=CGRectMake(0, 0, Screen_Width, 1);
  124. bottomSeparatorView.backgroundColor = LineBackgroundColor;
  125. [bottomView addSubview:bottomSeparatorView];
  126. //提交结算
  127. _btnSave=[UIButton buttonWithType:UIButtonTypeCustom];
  128. [_btnSave setTitle:@"保存" forState:UIControlStateNormal];
  129. [_btnSave setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  130. _btnSave.frame=CGRectMake(20,7, Screen_Width-40,40);
  131. [_btnSave setBackgroundColor:[UIColor colorWithRed:189.0/255.0 green:0 blue:7.0/255.0 alpha:1]];
  132. [_btnSave addTarget:self action:@selector(saveInStorage) forControlEvents:UIControlEventTouchUpInside];
  133. [bottomView addSubview:_btnSave];
  134. [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_page]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_page)]];
  135. [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[bottomView]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(bottomView)]];
  136. NSArray *arr1 = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_page][bottomView(55)]-marg-|" options:0 metrics:@{@"marg":@(SCREENHEIGHT >= 812 ? 34 : 0)} views:NSDictionaryOfVariableBindings(_page,bottomView)];
  137. [self.view addConstraints:arr1];
  138. }
  139. /**
  140. 返回函数
  141. */
  142. - (void)goBack
  143. {
  144. [self.navigationController popViewControllerAnimated:YES];
  145. }
  146. /**
  147. 保存函数
  148. */
  149. -(void)saveInStorage{
  150. if(otherInStorageGoodsDetailVc.dataList==nil||otherInStorageGoodsDetailVc.dataList.count==0){
  151. [self showAlertViewText:@"商品明细不能为空"];
  152. return;
  153. }
  154. [otherInStorageGoodsDetailVc.view endEditing:YES];
  155. [otherInStorageVc.view endEditing:YES];
  156. if(otherInStorageVc.lblCustomerCode.text!=nil&&otherInStorageVc.lblCustomerCode.text.length>0){
  157. if([otherInStorageVc.lblCustomerCode.text isEqualToString:@"请选择客户编码"]){
  158. otherInStorageVc.customerCode=@"";
  159. }
  160. }
  161. for(OtherInStorageGoodsSearchListModel *goodsListModel in otherInStorageGoodsDetailVc.dataList){
  162. if(goodsListModel.enterQuantity==nil||[goodsListModel.enterQuantity isEqualToString:@""]){
  163. [self showAlertViewText:@"入库数量不能为空"];
  164. return;
  165. }
  166. if(goodsListModel.enterPrice==nil||[goodsListModel.enterPrice isEqualToString:@""]){
  167. [self showAlertViewText:@"入库价格不能为空"];
  168. return;
  169. }
  170. if(goodsListModel.code==nil||[goodsListModel.code isEqualToString:@""]){
  171. [self showAlertViewText:@"商品编码不能为空"];
  172. return;
  173. }
  174. if(goodsListModel.onlyCode==nil||[goodsListModel.onlyCode isEqualToString:@""]){
  175. [self showAlertViewText:@"唯一编码不能为空"];
  176. return;
  177. }
  178. if(goodsListModel.gradeName==nil||[goodsListModel.gradeName isEqualToString:@""]){
  179. [self showAlertViewText:@"等级不能为空"];
  180. return;
  181. }
  182. if(goodsListModel.warehouseName==nil||[goodsListModel.warehouseName isEqualToString:@""]){
  183. [self showAlertViewText:@"库区不能为空"];
  184. return;
  185. }
  186. if(goodsListModel.positionNumberId==nil||[goodsListModel.positionNumberId isEqualToString:@""]){
  187. [self showAlertViewText:@"仓位号不能为空"];
  188. return;
  189. }
  190. if([goodsListModel.enterQuantity doubleValue]<=0){
  191. [self showAlertViewText:@"入库数量必须大于零"];
  192. return;
  193. }
  194. if ([goodsListModel.enterQuantity doubleValue] >MAXIMUM_QUANTITY) {
  195. NSString *quantityHint=[NSString stringWithFormat:@"入库数量超过最大值%f",MAXIMUM_QUANTITY];
  196. [self showAlertViewText:quantityHint];
  197. return;
  198. }
  199. if([goodsListModel.enterPrice doubleValue]>MAXIMUM_PRICE){
  200. NSString *priceHint=[NSString stringWithFormat:@"入库价格超过最大值%f",MAXIMUM_PRICE];
  201. [self showAlertViewText:priceHint];
  202. return;
  203. }
  204. }
  205. otherInStorageVc.remarks=otherInStorageVc.txtRemarks.text;
  206. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  207. [dict setObject:@"SaveEnterDataIphone" forKey:@"Action"];
  208. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  209. [dict setObject:kkUserCode forKey:@"UserCode"];
  210. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  211. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  212. [dict setObject:@"1" forKey:@"IDevicesType"];
  213. [dict setObject:@"1" forKey:@"EnterType"];
  214. [dict setObject:otherInStorageVc.dockerId==nil?@"":otherInStorageVc.dockerId forKey:@"Docker"];
  215. [dict setObject:otherInStorageVc.driverId==nil?@"":otherInStorageVc.driverId forKey:@"Driver"];
  216. [dict setObject: otherInStorageVc.remarks==nil?@"": otherInStorageVc.remarks forKey:@"Remarks"];
  217. [dict setObject: otherInStorageVc.customerId==nil?@"": otherInStorageVc.customerId forKey:@"CustomerID"];
  218. [dict setObject: otherInStorageVc.customerCode==nil?@"": otherInStorageVc.customerCode forKey:@"CustomerCode"];
  219. [dict setObject: otherInStorageVc.customerName==nil?@"": otherInStorageVc.customerName forKey:@"CustomerName"];
  220. [dict setObject: otherInStorageVc.telephone==nil?@"": otherInStorageVc.telephone forKey:@"Telephone"];
  221. [dict setObject: otherInStorageVc.address==nil?@"": otherInStorageVc.address forKey:@"Address"];
  222. [dict setObject: otherInStorageVc.contacts==nil?@"": otherInStorageVc.contacts forKey:@"Contacts"];
  223. [dict setObject: otherInStorageVc.staffId==nil?@"": otherInStorageVc.staffId forKey:@"StaffID"];
  224. [dict setObject: otherInStorageVc.organizationId==nil?@"": otherInStorageVc.organizationId forKey:@"BusinessOrganizationID"];
  225. [dict setObject: otherInStorageVc.organizationCode==nil?@"": otherInStorageVc.organizationCode forKey:@"OrganizationCode"];
  226. [dict setObject: otherInStorageVc.organizationName==nil?@"": otherInStorageVc.organizationName forKey:@"OrganizationName"];
  227. [dict setObject: otherInStorageVc.supplierId==nil?@"": otherInStorageVc.supplierId forKey:@"SupplierID"];
  228. NSMutableArray *goodsListArray=[[NSMutableArray alloc]init];
  229. if(otherInStorageGoodsDetailVc.dataList!=nil&&otherInStorageGoodsDetailVc.dataList.count>0){
  230. for(OtherInStorageGoodsSearchListModel *goodsListModel in otherInStorageGoodsDetailVc.dataList){
  231. NSDictionary *dic=[NSDictionary new];
  232. dic=@{@"InventoryID":goodsListModel.inventoryId,@"CodeID":goodsListModel.codeId,@"Code":goodsListModel.code,@"PositionNumber":goodsListModel.positionNumberName==nil?@"":goodsListModel.positionNumberName,@"EnterQuantity":goodsListModel.enterQuantity,@"EnterPrice":goodsListModel.enterPrice,@"OnlyCode":goodsListModel.onlyCode,@"Specification":goodsListModel.specification==nil?@"":goodsListModel.specification,@"ColorNumber":goodsListModel.colorNumber==nil?@"":goodsListModel.colorNumber,@"BrandID":goodsListModel.brandId==nil?@"":goodsListModel.brandId,@"BrandName":goodsListModel.brandName==nil?@"":goodsListModel.brandName,@"GradeID":goodsListModel.gradeId==nil?@"":goodsListModel.gradeId,@"GradeName":goodsListModel.gradeName==nil?@"":goodsListModel.gradeName,@"KindID":goodsListModel.kindId==nil?@"":goodsListModel.kindId,@"KindName":goodsListModel.kindName==nil?@"":goodsListModel.kindName,@"VarietyID":goodsListModel.varietyId==nil?@"":goodsListModel.varietyId,@"VarietyName":goodsListModel.varietyName==nil?@"":goodsListModel.varietyName,@"SeriesID":goodsListModel.seriesId==nil?@"":goodsListModel.seriesId,@"SeriesName":goodsListModel.seriesName==nil?@"":goodsListModel.seriesName,@"UnitID":goodsListModel.unitId==nil?@"":goodsListModel.unitId,@"UnitName":goodsListModel.unitName==nil?@"":goodsListModel.unitName,@"Package":goodsListModel.package==nil?@"":goodsListModel.package,@"Weight":goodsListModel.weight==nil?@"":goodsListModel.weight,@"Specification":goodsListModel.specification==nil?@"":goodsListModel.specification,@"Volume":goodsListModel.volume==nil?@"":goodsListModel.volume,@"Acreage":goodsListModel.acreage==nil?@"":goodsListModel.acreage,@"WarehouseID":goodsListModel.warehouseId==nil?@"":goodsListModel.warehouseId,@"WarehouseName":goodsListModel.warehouseName==nil?@"":goodsListModel.warehouseName,@"SourceDetailID":@"",@"Remarks":@""};
  233. [goodsListArray addObject:dic];
  234. }
  235. SBJsonWriter *write = [[SBJsonWriter alloc] init];
  236. NSString *value = [write stringWithObject:goodsListArray];
  237. [dict setObject:value forKeyedSubscript:@"DetailData"];
  238. }
  239. [self startLoading];
  240. _downManager = [[ASIDownManager alloc] init];
  241. _downManager.delegate = self;
  242. _downManager.OnImageDown = @selector(onSaveDataLoadFinish:);
  243. _downManager.OnImageFail = @selector(onSaveDataLoadFail:);
  244. [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
  245. }
  246. @end