| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- //
- // GoodsModel.m
- // IBOSSIPAD
- //
- // Created by iHope on 14-7-24.
- // Copyright (c) 2014年 elongtian. All rights reserved.
- //
- #import "GoodsSearchModel.h"
- #import "GoodsSearchItemModel.h"
- #import "SBJsonWriter.h"
- #import "OrderQuantity.h"
- #import "OrderSearchFrame.h"
- @interface GoodsSearchModel()
- {
- BOOL isCheckAll;
- MBProgressHUD *HUD;
- UIView *view;
- }
- @end
- @implementation GoodsSearchModel
- -(id)init
- {
- self =[super init];
- if(self){
- _workflowArr=[NSMutableArray new];
- isCheckAll=YES;
- }
- return self;
- }
- //获得选中的集合
- -(NSArray *)checkedArr
- {
- NSMutableArray *tempArr=[NSMutableArray new];
- for(int i=0;i<_workflowArr.count;i++)
- {
- GoodsSearchItemModel *model= [_workflowArr objectAtIndex:i] ;
- if(model.isChecked){
- [tempArr addObject:model];
- }
- }
- return tempArr;
- }
- -(BOOL)isSelectAtLeastOne
- {
- BOOL s=NO;
- for(GoodsSearchItemModel *wf in _workflowArr) {
- if(wf.isChecked)
- {
- s=YES;
- break;
- }
- }
- return s;
- }
- //检查选中的商品 价格和可售量的填写格式是否正确
- -(BOOL)checkFormat
- { BOOL end=YES;
- NSArray *arr=[self checkedArr];
- //数量数目不能为0
- for(int i=0;i<arr.count;i++)
- {
- GoodsSearchItemModel *model= [arr objectAtIndex:i] ;
-
- //NSLog(@"[model.SalesQuantity intValue]%i",[model.SalesQuantity intValue]);
- if([model.salesQuantity intValue]<=0)
- {
- end=NO;
- break;
- }
- }
- //数量必须小于等于可售量
- /* for(int i=0;i<arr.count;i++)
- {
- GoodsSearchItemModel *model= [arr objectAtIndex:i] ;
- if([model.SalesQuantity intValue]>[model.BalanceQuantity intValue])
- {
- end=NO;
- break;
- }
- }
- */
- return end;
- }
- -(void)parseWorkFlowArr:(NSArray *)arr
- {
- if(arr!=nil)
- {
- [_workflowArr removeAllObjects];
- for(int i=0;i<arr.count;i++)
- {
- NSDictionary * dic=arr[i];
- GoodsSearchItemModel *infoModel=[GoodsSearchItemModel new];
- [infoModel parseDic:dic];
- OrderSearchFrame *orderFrame=[[OrderSearchFrame alloc]init];
- [orderFrame setOrderSearchModel:infoModel];
- [_workflowArr addObject:orderFrame];
- }
-
- }
- }
- //看是否全选
- -(BOOL)isCheckedALL
- {
- BOOL ischecked=YES;
- for(GoodsSearchItemModel *wf in _workflowArr) {
- if( wf.isChecked==NO)
- {
- ischecked=NO;
- break;
- }
- }
- return ischecked;
-
- }
- //全选或者全不选
- -(BOOL)updateAllCellCheck
- {
- if(!isCheckAll){
- isCheckAll=YES;
- for(GoodsSearchItemModel *wf in _workflowArr) {
- wf.isChecked =YES;
- }
- }
- else
- {
- isCheckAll=NO;
- for(GoodsSearchItemModel *wf in _workflowArr) {
- wf.isChecked =NO;
- }
- }
- return NO;
- }
- -(BOOL)updateCellChecked : (NSString *) checkDocId
- {
- for(GoodsSearchItemModel *wf in _workflowArr) {
- if([wf.inventoryID intValue]==[checkDocId intValue] ) {
- wf.isChecked = !wf.isChecked;
- return wf.isChecked;
- }
- }
-
-
- return NO;
-
- }
- -(void)showAlertViewText:(NSString *)text
- {
- UIAlertView*alert = [[UIAlertView alloc]initWithTitle:@"提示"
- message:text
- delegate:nil
- cancelButtonTitle:@"确定"
- otherButtonTitles:nil];
- [alert show];
-
-
- }
- //更新文本信息,分为销售量和销售价格
- -(void)updateCellSaleText:(UITextField*)txtfield checkeId:(NSString *) checkDocId
- {
- if(!txtfield){
- return;
- }
- for(OrderSearchFrame *wf in _workflowArr) {
-
- if([ wf.searchModel.inventoryID intValue]==[checkDocId intValue] ) {
- if(txtfield.tag==1001)
- {
- if(txtfield.text.length>0){
- wf.searchModel.salesPrice=txtfield.text;
- }
- else{
- wf.searchModel.salesPrice=@"0";
- }
- }
-
- else if(txtfield.tag==1002)
- {
-
- if (txtfield.text.length>0) {
- NSString *saleQuantity=txtfield.text;
- double acreage= wf.searchModel.acreage;
- OrderQuantity *quantity=[OrderQuantity new];
- NSInteger decimalPlaces=wf.searchModel.decimalPlaces;
- NSString *calculateQuantity= [quantity calculateOrderQuantity: wf.searchModel.circulateType decimalPlaces:[NSString stringWithFormat:@"%ld",(long)decimalPlaces] quantity:saleQuantity acreage:acreage];
- if ([calculateQuantity doubleValue] >MAXIMUM_QUANTITY) {
- NSNumber *number = [NSNumber numberWithDouble:MAXIMUM_QUANTITY];
- calculateQuantity = [number stringValue];
- wf.searchModel.salesQuantity=calculateQuantity;
- txtfield.text=calculateQuantity;
- //[self showAlertViewText:@"已超出最大数量"];
- // return;
- }
- wf.searchModel.salesQuantity=calculateQuantity;
- txtfield.text=calculateQuantity;
- }
-
- else
-
- {
- wf.searchModel.salesQuantity=@"1";
- txtfield.text=@"1";
- }
-
- }
-
- }
-
-
-
- }
- }
- @end
|