| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859 |
- //
- // EnumSelectOnlineViewController.m
- // RA TradeFiling
- //
- // Created by Rui Zhang on 5/14/21.
- //
- #import "EnumSelectOnlineViewController.h"
- #import "EnumSelectorCell.h"
- #import "RAUtils.h"
- #import "AppDelegate.h"
- #import "RADataProvider.h"
- #import "ResultPresenter.h"
- #import "JLRefreshHeader.h"
- #import "JLRefreshFooter.h"
- #define DEF_CELL_HEIGHT 44
- //#define DEF_TABLE_HEIGHT 44
- //#define LINE_WIDTH 0
- //#define CELL_MARGIN 0
- #define LABEL_MARGIN 15
- @interface EnumSelectOnlineViewController ()<JLRefreshDelegate>
- @property (nonatomic,weak) JLRefreshBasis *curRefresh;
- @property (nonatomic,weak) RAProgressHUD *curHUD;
- @property (strong,nonatomic) NSMutableDictionary* cadedate;
- @property (strong,nonatomic) NSMutableDictionary* online_cadedate;
- @property int offset ;
- @property int limit ;
- //@property (nonatomic,strong) NSArray<NSMutableDictionary *> *dataArray;
- @end
- @implementation EnumSelectOnlineViewController
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- {
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
- // Custom initialization
- }
- return self;
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
-
-
- self.limit = 20;
-
- // self.automaticallyAdjustsScrollViewInsets = NO;
- // self.max_select = 0;
-
- self.navi_item.title = self.title;
-
- // self.navigationItem.title = self.title;
- // Do any additional setup after loading the view.
- self.auto_close = true;
-
- if(self.is_dialog)
- {
- UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"close"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector( onCloseClick:)];
- // [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Close", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onCloseClick:)];
- self.navi_item.rightBarButtonItem = closeButton;
- }
- else
- {
- UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector( onBackClick:)];
- // [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Back", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onBackClick:)];
-
- self.navigationItem.leftBarButtonItem = backButton;
- }
- self.dirty = false;
-
- NSString *model = [UIDevice currentDevice].model;
- if ([model isEqualToString:@"iPhone"]) {
-
- } else {
- UILabel* titleLabel= [[UILabel alloc] initWithFrame:CGRectMake(100, 0, 200
-
- , 44)];
- titleLabel.text=self.title;
- // titleLabel.backgroundColor =[UIColor yellowColor];
- titleLabel.textAlignment=NSTextAlignmentCenter;
-
-
- //将搜索条放在一个UIView上
- UIView *searchView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 1768, 44)];
-
-
-
-
- searchView.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin|UIViewAutoresizingFlexibleWidth;
-
- titleLabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
- titleLabel.center=searchView.center;
-
-
-
- UISearchBar *searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(searchView.frame.size.width-200.0f-8.0f,0.0f,200.0f,44.0f)];
- searchBar.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
- searchBar.delegate = self;
- [searchBar setPlaceholder:@"filter"];
- //searchBar.barTintColor=[UIColor clearColor];
- searchBar.searchBarStyle=UISearchBarStyleMinimal;
- [searchView addSubview:titleLabel];
- [searchView addSubview:searchBar];
-
- self.navigationItem.titleView = searchView;
- }
- [[self navigationController] setNavigationBarHidden:self.hide_navibar animated:NO];
-
-
- JLRefreshHeader *header = [[JLRefreshHeader alloc] init];
- header.refreshDelegate = self;
- self.tableEnum.jl_header = header;
-
- JLRefreshFooter *footer = [[JLRefreshFooter alloc] init];
- footer.refreshDelegate = self;
- self.tableEnum.jl_footer = footer;
-
- [self loadData];
-
- }
- - (void)onBackClick:(UIButton *)sender {
-
-
- [self.navigationController popViewControllerAnimated:(false)];
- // [self.navigationController dismissViewControllerAnimated:true completion:^{
- // ;
- // }];
- }
- - (void)onCloseClick:(UIButton *)sender {
- [self dismissViewControllerAnimated:YES
- completion:^{
-
-
- }];
- }
- - (void)viewWillDisappear:(BOOL)animated
- {
- [super viewWillDisappear:animated];
- if(self.dirty == false)
- return;
- if (self.delegate && [self.delegate respondsToSelector:@selector(EnumValueChanged:indexPath:)]) {
- [self.delegate EnumValueChanged:self.online_cadedate indexPath:self.updatePosition];
- }
- if(self.returnValue)
- self.returnValue(self.online_cadedate,self.from);
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- //-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
- //{
- //
- // [self.tableEnum reloadData];
- ////
- //// UIApplication * app = [UIApplication sharedApplication];
- //// AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- //// [appDelegate didRotated];
- //
- //
- //
- //}
- - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
- [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
- [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
- // what ever you want to prepare
- } completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
- [self.tableEnum reloadData];
- }];
- }
- #pragma mark - Table view data source
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
-
- // if(self.canbeEmpty)
- // return [[self.cadedate valueForKey:@"count"] intValue]+1;
- // else
-
-
- if(self.keywords==nil || self.keywords.length==0)
- {
- self.filter_count = 0;
- return [[self.cadedate valueForKey:@"count"] intValue];
- }
- else
- {
-
- int count = 0;
-
- for (int i=0; i<[[self.cadedate valueForKey:@"count"] intValue]; i++)
- {
- NSDictionary* val_json = [self.cadedate objectForKey:[NSString stringWithFormat:@"val_%d",i ]];
-
- NSString* value = [val_json valueForKey:@"value"];
-
- NSUInteger location=[[value uppercaseString] rangeOfString:self.keywords].location;
- if(location!= NSNotFound)
- count++;
- }
- self.filter_count = count;
- return count;
- }
-
-
-
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
- {
-
- NSDictionary* val_json =nil;
-
-
- if(self.keywords==nil || self.keywords.length==0)
- {
- val_json=[self.cadedate objectForKey:[NSString stringWithFormat:@"val_%ld",(long)indexPath.row ]];
- }
- else
- {
-
- int count = 0;
-
- for (int i=0; i<[[self.cadedate valueForKey:@"count"] intValue]; i++)
- {
- if(count>= self.filter_count)
- break;
- NSDictionary* search_json = [self.cadedate objectForKey:[NSString stringWithFormat:@"val_%d",i ]];
-
- NSString* value = [search_json valueForKey:@"value"];
-
- NSUInteger location=[[value uppercaseString] rangeOfString:self.keywords].location;
- if(location!= NSNotFound)
- count++;
-
- if(count-1==indexPath.row)
- val_json=search_json;
- }
-
- }
-
-
-
-
- NSString* value = [val_json valueForKey:@"value"];
-
-
- float width = tableView.frame.size.width;
- width-=40;
- CGSize constraintkey = CGSizeMake(width-2*LABEL_MARGIN, 10.0f);//key label width is 40% cell width;
- // CGSize constraintval = CGSizeMake(width*0.6-2*LABEL_MARGIN, 20000.0f);//val label width is 60% cell width;
-
-
-
- // NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
- // NSString* key =[self.content_data valueForKey:@"order_info"];
-
- // [cell.keyLabel sizeToFit];
- // NSString* val=[item_json valueForKey:@"val"] ;
-
- // if([val isEqual:[NSNull null]])
- // val=@"";
- // if(val==nil)
- // val=@"";
- // if([val isEqualToString:@"null"])
- // val=@"";
-
-
-
- CGRect frame;
- frame.size = constraintkey;
- frame.origin.x=0;
- frame.origin.y=0;
-
-
-
- RTLabel* rtlabel = [[RTLabel alloc] initWithFrame:frame];
-
- // rtlabel.lineSpacing = 10;
- // [rtlabel setLineBreakMode: RTTextLineBreakModeWordWrapping];
- // rtlabel.lineSpacing = 20.0;
- [rtlabel setText: value];
- CGSize optimumSize = [rtlabel optimumSize];
- // DebugLog(@"%@",key);
-
- // [rtlabel sizeThatFits:constraintkey];
-
- // rtlabel frameHeight:<#(CTFrameRef)#>
- // rtlabel
- // [rtlabel sizeToFit];
- //CGSize newsize= rtlabel.frame.size;
- // CGSize sizeval=rtlabel.optimumSize;
-
-
- // CGSize sizekey = [key sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
- // CGSize sizeval = [val sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintval lineBreakMode:NSLineBreakByWordWrapping];
- float height = optimumSize.height;
- height = MAX(height+2*LABEL_MARGIN, DEF_CELL_HEIGHT);
-
-
- return height;
-
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
-
-
-
- NSDictionary* val_json =nil;
-
-
- if(self.keywords==nil || self.keywords.length==0)
- {
- val_json=[self.cadedate objectForKey:[NSString stringWithFormat:@"val_%ld",(long)indexPath.row ]];
- }
- else
- {
-
- int count = 0;
-
- for (int i=0; i<[[self.cadedate valueForKey:@"count"] intValue]; i++)
- {
- if(count>= self.filter_count)
- break;
- NSDictionary* search_json = [self.cadedate objectForKey:[NSString stringWithFormat:@"val_%d",i ]];
-
- NSString* value = [search_json valueForKey:@"value"];
-
- NSUInteger location=[[value uppercaseString] rangeOfString:self.keywords].location;
- if(location!= NSNotFound)
- count++;
-
- if(count-1==indexPath.row)
- {
- val_json=search_json;
- break;
- }
- }
-
- }
-
-
-
- NSString* CellIdentifier = @"EnumSelectorCell";
-
- EnumSelectorCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- // NSDictionary* val_json = [self.cadedate objectForKey:[NSString stringWithFormat:@"val_%ld",(long)indexPath.row ]];
-
- NSString* value = [val_json valueForKey:@"value"];
- // cell.rtLabel.lineSpacing=10;
- cell.rtLabel.text = value;
- // cell.labelValue.text = value;
- int check = [[val_json valueForKey:@"check" ] intValue];
- if(check==1)
- cell.img_checkmark.hidden=false;
- else
- cell.img_checkmark.hidden=true;
-
- return cell;
-
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
-
- EnumSelectorCell* cell = (EnumSelectorCell*)[tableView cellForRowAtIndexPath:indexPath];
-
- cell.selected = false;
- self.dirty = true;
-
- if(self.single_select)
- {
-
-
-
-
-
- if(self.keywords==nil || self.keywords.length==0)
- {
-
- NSMutableDictionary* val_json = [[self.cadedate objectForKey:[NSString stringWithFormat:@"val_%ld",indexPath.row]] mutableCopy];
- [val_json setValue:@true forKey:@"check"];
-
- self.online_cadedate = [NSMutableDictionary new];
-
- self.online_cadedate[@"count"]=@1;
- self.online_cadedate[@"val_0"]=val_json;
- // for(int i=0;i<[[self.cadedate valueForKey:@"count"] intValue];i++)
- // {
- //
- //
- //
- //
- // NSMutableDictionary* val_json = [[self.cadedate objectForKey:[NSString stringWithFormat:@"val_%d",i]] mutableCopy];
- // if(i==indexPath.row)
- // [val_json setValue:@"1" forKey:@"check"];
- // else
- // [val_json setValue:@"0" forKey:@"check"];
- // [self.cadedate setObject:val_json forKey:[NSString stringWithFormat:@"val_%d",i]];
- // }
- }
- else
- {
- NSAssert(true, @"NOT IMPL");
-
- NSMutableDictionary* val_json =nil;
-
- int count = 0;
-
- for (int cc=0; cc<[[self.cadedate valueForKey:@"count"] intValue]; cc++)
- {
- if(count>= self.filter_count)
- break;
- NSMutableDictionary* search_json = [[self.cadedate objectForKey:[NSString stringWithFormat:@"val_%d",cc ]] mutableCopy];
-
- NSString* value = [search_json valueForKey:@"value"];
-
- NSUInteger location=[[value uppercaseString] rangeOfString:self.keywords].location;
- if(location!= NSNotFound)
- count++;
-
- if(count-1==indexPath.row)
- val_json=search_json;
- }
-
- for (int sc=0;sc<[[self.cadedate valueForKey:@"count"] intValue];sc++)
- {
- NSMutableDictionary* sc_json = [[self.cadedate objectForKey:[NSString stringWithFormat:@"val_%d",sc ]] mutableCopy];
-
- if ([[sc_json valueForKey:@"value" ] isEqual:[val_json valueForKey:@"value"]] )
- [sc_json setValue:@"1" forKey:@"check"];
- else
- [sc_json setValue:@"0" forKey:@"check"];
- [self.cadedate setObject:sc_json forKey:[NSString stringWithFormat:@"val_%d",sc]];
- }
-
- }
-
- if(self.auto_close)
- {
- if(self.navigationController!=nil)
- [self.navigationController popViewControllerAnimated:YES];
-
- // [self.navigationController dismissViewControllerAnimated:YES
- // completion:^{
- //
- //
- // }];
- else
- [self dismissViewControllerAnimated:YES
- completion:^{
-
-
- }];
- }
- }
- else
- {
-
-
-
- NSMutableDictionary* val_json =nil;
-
-
- if(self.keywords==nil || self.keywords.length==0)
- {
- val_json=[[self.cadedate objectForKey:[NSString stringWithFormat:@"val_%ld",(long)indexPath.row ]] mutableCopy];
- }
- else
- {
-
- int count = 0;
-
- for (int i=0; i<[[self.cadedate valueForKey:@"count"] intValue]; i++)
- {
- if(count>= self.filter_count)
- break;
- NSMutableDictionary* search_json = [[self.cadedate objectForKey:[NSString stringWithFormat:@"val_%d",i ]] mutableCopy];
-
- NSString* value = [search_json valueForKey:@"value"];
-
- NSUInteger location=[[value uppercaseString] rangeOfString:self.keywords].location;
- if(location!= NSNotFound)
- count++;
-
- if(count-1==indexPath.row)
- val_json=search_json;
- }
-
- }
-
- // NSMutableDictionary* val_json = [[self.cadedate objectForKey:[NSString stringWithFormat:@"val_%ld",(long)indexPath.row]] mutableCopy];
- int check = [[val_json valueForKey:@"check"] intValue];
- if(check==1)
- [val_json setValue:@"0" forKey:@"check"];
- else
- {
- if([self check_count]>=self.max_select && self.max_select>0)
- {
-
- // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: message:[NSString stringWithFormat: delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
- // // UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Error!" message:@"User&Password can not be empty!" delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", nil) , nil];
- // [alert show];
-
- [RAUtils message_alert:[NSString stringWithFormat:@"%d items at most for this field.",self.max_select ] title:@"Max count reached" controller:self];
- // [RAUtils alert_view:[NSString stringWithFormat:@"%d items at most for this field.",self.max_select ] title:@"Max count reached"];
-
- return;
- }
- [val_json setValue:@"1" forKey:@"check"];
- }
- [self.cadedate setObject:val_json forKey:[NSString stringWithFormat:@"val_%ld",(long)indexPath.row]];
-
-
- }
- [self.tableEnum reloadData];
-
- }
- -(int) check_count
- {
- int check_count=0;
- // int count = 0;
-
- for (int i=0; i<[[self.cadedate valueForKey:@"count"] intValue]; i++)
- {
- NSMutableDictionary* val_json = [[self.cadedate objectForKey:[NSString stringWithFormat:@"val_%d",i ]] mutableCopy];
-
- int check = [[val_json valueForKey:@"check"] intValue];
- if(check==1)
- check_count++;
- }
- return check_count;
- }
- #pragma mark - searchBar delegate;
- - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
- {
- self.online_keywords=[searchBar.text uppercaseString];
-
- [self loadData];
- // [self.tableEnum reloadData];
- // self.offset = 0;
- // [self.content_data removeAllObjects];
- // [self loadpage];
- // DebugLog(@"search");
- }
- - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
- {
-
-
- if([searchText isEqualToString:@""] && !self.reset)
- {
- self.keywords=nil;
- [self.tableEnum reloadData];
- self.reset=true;
-
- }
- else
- self.reset = false;
- }
- /*
- #pragma mark - Navigation
-
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
- {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- - (void)loadData:(RAResultFetchDataType)option {
-
-
- [self onStartLoading];
-
- __weak typeof(self) weakSelf = self;
-
-
- NSMutableDictionary *params = [self.online_params mutableCopy];
- if(params==nil)
- params=[NSMutableDictionary new];
- [params setObject:[NSNumber numberWithInteger:self.offset] forKey:@"offset"];
- [params setObject:[NSNumber numberWithInteger:self.limit] forKey:@"limit"];
-
- if(self.online_keywords.length>0)
- params[@"keywords"]=self.online_keywords;
- [RADataProvider GetCadedate:params completionHandler:^(NSMutableDictionary *result) {
-
- NSMutableDictionary * json = result;
- __strong typeof(weakSelf) strongSelf = weakSelf;
-
- int resultcode = [[json objectForKey:@"result"] intValue];
- if (resultcode == RESULT_TRUE) {
-
- // NSMutableArray *modelsArr = [NSMutableArray array];
- // if (option == RAResultFetchDataTypeLoadMore && strongSelf.dataArray != nil && strongSelf.dataArray.count > 0) {
- // [modelsArr addObjectsFromArray:strongSelf.dataArray];
- // }
-
- if (option != RAResultFetchDataTypeLoadMore) {
- self.cadedate = [NSMutableDictionary new];
- }
-
- int count = [json[@"count"] intValue];
- for (int i=0;i<count;i++)
- {
- NSMutableDictionary* item = [json[[NSString stringWithFormat:@"val_%d",i]] mutableCopy];
- self.cadedate[[NSString stringWithFormat:@"val_%d",i]]=item;
- }
-
- self.cadedate[@"count"]= @([self.cadedate[@"count"] intValue]+count);
-
- strongSelf.offset = [self.cadedate[@"count"] intValue];
-
- NSString *title = [json objectForKey:@"title"];
-
-
- // refresh UI
- dispatch_async(dispatch_get_main_queue(), ^{
-
- if (weakSelf) {
- __strong typeof(weakSelf) strongSelf = weakSelf;
-
- // strongSelf.dataArray = [modelsArr copy];
-
- [strongSelf onStopLoading];
- [strongSelf onSuccess:title];
- if (count < self.limit) {
- [strongSelf onNoMoreData];
- }
-
- }
-
- });
-
- } else {
-
- NSString *msg = [json objectForKey:@"err_msg"];
- if(msg.length==0)
- {
- msg=@"Sorry, can not connect to the server, please try again later.";
- }
- __weak typeof(self) weakSelf = self;
- dispatch_async(dispatch_get_main_queue(), ^{
- if (weakSelf) {
- __strong typeof(weakSelf) strongSelf = weakSelf;
- [strongSelf onStopLoading];
- [strongSelf onFailed:msg];
- }
- });
- }
-
- }];
-
- return;
- //
- // dispatch_async(dispatch_get_global_queue(0, 0), ^{
- //
- // NSMutableDictionary *params = [weakSelf.params mutableCopy];
- // [params setObject:[NSNumber numberWithInteger:offset] forKey:@"offset"];
- // [params setObject:[NSNumber numberWithInteger:detal] forKey:@"limit"];
- // [params setObject:displayFields forKey:@"columns"];
- //
- // NSDictionary *json = [RANetwork fetchResultParameters:params];
- // if (weakSelf) {
- // __strong typeof(weakSelf) strongSelf = weakSelf;
- //
- // int result = [[json objectForKey:@"result"] intValue];
- // if (result == RESULT_TRUE) {
- //
- // NSMutableArray *modelsArr = [NSMutableArray array];
- // if (option == ApexResultFetchDataTypeLoadMore && strongSelf.dataArray != nil && strongSelf.dataArray.count > 0) {
- // [modelsArr addObjectsFromArray:strongSelf.dataArray];
- // }
- //
- // NSArray *items = [json objectForKey:@"items"];
- // for (NSDictionary *item in items) {
- //
- // NSInteger type = [[item objectForKey:@"type"] integerValue];
- //
- // switch (type) {
- // case ApexResultTypeBooking: {
- // ApexResultBookingModel *model = [ApexResultBookingModel new];
- // [model setValuesForKeysWithDictionary:item];
- // [modelsArr addObject:model];
- // }
- // break;
- // case ApexResultTypeBLInfo: {
- // ApexResultBLInfoModel *model = [ApexResultBLInfoModel new];
- // [model setValuesForKeysWithDictionary:item];
- // [modelsArr addObject:model];
- // }
- // break;
- // case ApexResultTypeContainer: {
- // ApexResultContainerModel *model = [ApexResultContainerModel new];
- // [model setValuesForKeysWithDictionary:item];
- // [modelsArr addObject:model];
- // }
- // break;
- // case ApexResultTypeDocument: {
- // ApexResultDocumentModel *model = [ApexResultDocumentModel new];
- // [model setValuesForKeysWithDictionary:item];
- // [modelsArr addObject:model];
- // }
- // break;
- // default:
- // break;
- // }
- //
- // } // for
- // strongSelf.offset = modelsArr.count;
- //
- // NSString *title = [json objectForKey:@"title"];
- // strongSelf.rowActions = [json objectForKey:@"row_actions"];
- // strongSelf.actions = [json objectForKey:@"actions"];
- //
- // // menu
- // NSArray *menuArr = [json objectForKey:@"menu"];
- // if (menuArr) {
- // NSMutableArray *tmpArr = [NSMutableArray array];
- // for (NSDictionary *item in menuArr) {
- //
- // ApexResultMenuItem *menuItem = [ApexResultMenuItem new];
- // [menuItem setValuesForKeysWithDictionary:item];
- // [tmpArr addObject:menuItem];
- // }
- // strongSelf.menuItems = [tmpArr copy];
- // }
- //
- // // refresh UI
- // [strongSelf loadDataSuccessWithTitle:title itemsArray:modelsArr itemCount:items.count];
- //
- // } else {
- // [strongSelf loadDataFailed];
- // }
- // }
- //
- // });
- }
- - (void)loadData {
-
- if (self.dirty) {
- self.dirty = NO;
-
-
- }
-
- self.offset = 0;
- [self loadData:RAResultFetchDataTypeInitial];
- }
- - (void)refreshData {
- self.offset = 0;
- [self loadData: RAResultFetchDataTypeRefresh];
- }
- - (void)loadMoreData {
- [self loadData: RAResultFetchDataTypeLoadMore];
- }
- #pragma mark - Presenter
- - (void)onStartLoading {
- self.curHUD = [RAProgressHUD showHUDOnView:self.view];
- }
- - (void)onStopLoading {
- [self.curHUD dismiss];
- }
- - (void)onNoMoreData {
- [(JLRefreshFooter *)self.tableEnum.jl_footer noMoreData];
- }
- - (void)onSuccess:(NSString *)title {
- [self.curRefresh endRefresh];
- [self.tableEnum reloadData];
-
-
-
- if([self.cadedate[@"count"] intValue]==0)
- self.labelNoRecord.hidden=false;
- else
- self.labelNoRecord.hidden=true;
- self.title = title;
- }
- - (void)onFailed:(NSString *)errMsg {
- [self.curRefresh endRefresh];
- // [RAUtils message_alert:errMsg title:@"Warning" controller:self];
- [RAUtils ra_showAlertTitle:@"Warning" message:errMsg withViewController:self];
- }
- #pragma mark - Refresh Delegate
- - (void)jl_pullRefresh:(JLRefreshBasis *)refresh state:(JLRefreshState)state percentage:(float)percentage {
-
- }
- - (void)jl_beginRefresh:(JLRefreshBasis *)refresh {
-
- self.curRefresh = refresh;
- if (refresh == self.tableEnum.jl_header) {
-
- [self refreshData];
- [(JLRefreshFooter *)self.tableEnum.jl_footer enableLoadMore];
-
- } else if (refresh == self.tableEnum.jl_footer) {
-
- [self loadMoreData];
- }
- }
- - (void)jl_endRefresh:(JLRefreshBasis *)refresh {
-
- }
- @end
|