GoodsSearchModel.m 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. //
  2. // GoodsModel.m
  3. // IBOSSIPAD
  4. //
  5. // Created by iHope on 14-7-24.
  6. // Copyright (c) 2014年 elongtian. All rights reserved.
  7. //
  8. #import "GoodsSearchModel.h"
  9. #import "GoodsSearchItemModel.h"
  10. #import "SBJsonWriter.h"
  11. #import "OrderQuantity.h"
  12. #import "OrderSearchFrame.h"
  13. @interface GoodsSearchModel()
  14. {
  15. BOOL isCheckAll;
  16. MBProgressHUD *HUD;
  17. UIView *view;
  18. }
  19. @end
  20. @implementation GoodsSearchModel
  21. -(id)init
  22. {
  23. self =[super init];
  24. if(self){
  25. _workflowArr=[NSMutableArray new];
  26. isCheckAll=YES;
  27. }
  28. return self;
  29. }
  30. //获得选中的集合
  31. -(NSArray *)checkedArr
  32. {
  33. NSMutableArray *tempArr=[NSMutableArray new];
  34. for(int i=0;i<_workflowArr.count;i++)
  35. {
  36. GoodsSearchItemModel *model= [_workflowArr objectAtIndex:i] ;
  37. if(model.isChecked){
  38. [tempArr addObject:model];
  39. }
  40. }
  41. return tempArr;
  42. }
  43. -(BOOL)isSelectAtLeastOne
  44. {
  45. BOOL s=NO;
  46. for(GoodsSearchItemModel *wf in _workflowArr) {
  47. if(wf.isChecked)
  48. {
  49. s=YES;
  50. break;
  51. }
  52. }
  53. return s;
  54. }
  55. //检查选中的商品 价格和可售量的填写格式是否正确
  56. -(BOOL)checkFormat
  57. { BOOL end=YES;
  58. NSArray *arr=[self checkedArr];
  59. //数量数目不能为0
  60. for(int i=0;i<arr.count;i++)
  61. {
  62. GoodsSearchItemModel *model= [arr objectAtIndex:i] ;
  63. //NSLog(@"[model.SalesQuantity intValue]%i",[model.SalesQuantity intValue]);
  64. if([model.salesQuantity intValue]<=0)
  65. {
  66. end=NO;
  67. break;
  68. }
  69. }
  70. //数量必须小于等于可售量
  71. /* for(int i=0;i<arr.count;i++)
  72. {
  73. GoodsSearchItemModel *model= [arr objectAtIndex:i] ;
  74. if([model.SalesQuantity intValue]>[model.BalanceQuantity intValue])
  75. {
  76. end=NO;
  77. break;
  78. }
  79. }
  80. */
  81. return end;
  82. }
  83. -(void)parseWorkFlowArr:(NSArray *)arr
  84. {
  85. if(arr!=nil)
  86. {
  87. [_workflowArr removeAllObjects];
  88. for(int i=0;i<arr.count;i++)
  89. {
  90. NSDictionary * dic=arr[i];
  91. GoodsSearchItemModel *infoModel=[GoodsSearchItemModel new];
  92. [infoModel parseDic:dic];
  93. OrderSearchFrame *orderFrame=[[OrderSearchFrame alloc]init];
  94. [orderFrame setOrderSearchModel:infoModel];
  95. [_workflowArr addObject:orderFrame];
  96. }
  97. }
  98. }
  99. //看是否全选
  100. -(BOOL)isCheckedALL
  101. {
  102. BOOL ischecked=YES;
  103. for(GoodsSearchItemModel *wf in _workflowArr) {
  104. if( wf.isChecked==NO)
  105. {
  106. ischecked=NO;
  107. break;
  108. }
  109. }
  110. return ischecked;
  111. }
  112. //全选或者全不选
  113. -(BOOL)updateAllCellCheck
  114. {
  115. if(!isCheckAll){
  116. isCheckAll=YES;
  117. for(GoodsSearchItemModel *wf in _workflowArr) {
  118. wf.isChecked =YES;
  119. }
  120. }
  121. else
  122. {
  123. isCheckAll=NO;
  124. for(GoodsSearchItemModel *wf in _workflowArr) {
  125. wf.isChecked =NO;
  126. }
  127. }
  128. return NO;
  129. }
  130. -(BOOL)updateCellChecked : (NSString *) checkDocId
  131. {
  132. for(GoodsSearchItemModel *wf in _workflowArr) {
  133. if([wf.inventoryID intValue]==[checkDocId intValue] ) {
  134. wf.isChecked = !wf.isChecked;
  135. return wf.isChecked;
  136. }
  137. }
  138. return NO;
  139. }
  140. -(void)showAlertViewText:(NSString *)text
  141. {
  142. UIAlertView*alert = [[UIAlertView alloc]initWithTitle:@"提示"
  143. message:text
  144. delegate:nil
  145. cancelButtonTitle:@"确定"
  146. otherButtonTitles:nil];
  147. [alert show];
  148. }
  149. //更新文本信息,分为销售量和销售价格
  150. -(void)updateCellSaleText:(UITextField*)txtfield checkeId:(NSString *) checkDocId
  151. {
  152. if(!txtfield){
  153. return;
  154. }
  155. for(OrderSearchFrame *wf in _workflowArr) {
  156. if([ wf.searchModel.inventoryID intValue]==[checkDocId intValue] ) {
  157. if(txtfield.tag==1001)
  158. {
  159. if(txtfield.text.length>0){
  160. wf.searchModel.salesPrice=txtfield.text;
  161. }
  162. else{
  163. wf.searchModel.salesPrice=@"0";
  164. }
  165. }
  166. else if(txtfield.tag==1002)
  167. {
  168. if (txtfield.text.length>0) {
  169. NSString *saleQuantity=txtfield.text;
  170. double acreage= wf.searchModel.acreage;
  171. OrderQuantity *quantity=[OrderQuantity new];
  172. NSInteger decimalPlaces=wf.searchModel.decimalPlaces;
  173. NSString *calculateQuantity= [quantity calculateOrderQuantity: wf.searchModel.circulateType decimalPlaces:[NSString stringWithFormat:@"%ld",(long)decimalPlaces] quantity:saleQuantity acreage:acreage];
  174. if ([calculateQuantity doubleValue] >MAXIMUM_QUANTITY) {
  175. NSNumber *number = [NSNumber numberWithDouble:MAXIMUM_QUANTITY];
  176. calculateQuantity = [number stringValue];
  177. wf.searchModel.salesQuantity=calculateQuantity;
  178. txtfield.text=calculateQuantity;
  179. //[self showAlertViewText:@"已超出最大数量"];
  180. // return;
  181. }
  182. wf.searchModel.salesQuantity=calculateQuantity;
  183. txtfield.text=calculateQuantity;
  184. }
  185. else
  186. {
  187. wf.searchModel.salesQuantity=@"1";
  188. txtfield.text=@"1";
  189. }
  190. }
  191. }
  192. }
  193. }
  194. @end