| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460 |
- //
- // ScanSearchViewController.m
- // HMLG Scan Order
- //
- // Created by Rui Zhang on 3/30/22.
- // Copyright © 2022 United Software Applications, Inc. All rights reserved.
- //
- #import "ScanSearchViewController.h"
- #import "ScanListCell.h"
- #import "RASingleton.h"
- #import "RADataProvider.h"
- #define PAGE_ITEM 20
- @interface ScanSearchViewController ()
- //@property (nonatomic,assign) UIInterfaceOrientation toOrientation;///<屏幕将要旋转到的方向
- @property (nonatomic,strong) NSOperationQueue *dataOperationQueue;
- @end
- @implementation ScanSearchViewController
- - (NSOperationQueue *)dataOperationQueue {
- if (!_dataOperationQueue) {
- _dataOperationQueue = [[NSOperationQueue alloc] init];
- _dataOperationQueue.maxConcurrentOperationCount = 1;
- }
- return _dataOperationQueue;
- }
- #ifndef RA_NOTIFICATION
- -(void) reload_container_getdata:(bool)update_data
- {
- if(self.disable_refresh)
- return;
- [super reload_container_getdata:update_data];
- if(update_data)
- {
- self.offset = 0;
- // [self.content_data removeAllObjects];
- [self reload];
- }
- else
- {
- [self.tableview reloadData];
- }
- return;
-
- // if(!self.showDetail)
- // return;
- // NSArray* a= self.childViewControllers;
- //
- // for (int i=0;i<a.count;i++)
- // {
- // if([a[i] isKindOfClass:[DetailViewController class]])
- // {
- // DetailViewController *detailvc=a[i];
- // [detailvc reload];
- // }
- // }
- }
- #endif
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- self.modellist = [NSMutableArray new];
- // Do any additional setup after loading the view.
- //添加四个边阴影
-
- // self.headerView.layer.shadowColor = [UIColor grayColor].CGColor;
- // self.headerView.layer.shadowOffset = CGSizeMake(0, 0);
- // self.headerView.layer.shadowOpacity = 0.5;
- // self.headerView.layer.shadowRadius = 2.0;
-
-
- //添加两个边阴影
- self.tableview.layer.masksToBounds = false;
- self.tableview.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.tableview.bounds].CGPath;
- self.tableview.layer.shadowColor = [UIColor grayColor].CGColor;
- self.tableview.layer.shadowOffset = CGSizeMake(0, 0);
- self.tableview.layer.shadowOpacity = 0.5;
- self.tableview.layer.shadowRadius = 2.0;
-
-
-
-
- //刷新
- UIRefreshControl *ref = [[UIRefreshControl alloc]init];
- ref.tag = 201 ;
- ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
- ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
- // ref.hidden = true;
- [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged];
- [self.tableview addSubview:ref];
- self.tableview.alwaysBounceVertical = YES;
- }
- -(void)manually_refresh
- {
- UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:201];
- if(self.isrefreshing)
- {
- [reF endRefreshing];
- return;
- }
- reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"];
- if ([self respondsToSelector:@selector(reload)])
- [self performSelector:@selector(reload) withObject:nil afterDelay:1];
-
- }
- -(void)viewWillLayoutSubviews
- {
- // if(self.showDetail==true)
- // {
- // UIInterfaceOrientation orientation =[UIApplication sharedApplication].statusBarOrientation;
- // int width=175;
- // // int height;
- // if(orientation == UIDeviceOrientationLandscapeLeft ||orientation == UIDeviceOrientationLandscapeRight)
- // {
- // width = 370;
- // // height = 400;
- // }
- // else
- // {
- // // height = 300;
- // width = 175;
- // }
- //
- //
- // CGRect frame = CGRectMake(0, 64, width, self.view.bounds.size.height-64);
- //
- // self.collectionview.frame=frame;
- //
- //
- //
- // CGRect framedetail = CGRectMake(width,64 ,self.view.bounds.size.width-width,self.view.bounds.size.height-64);
- // self.detailView.frame = framedetail;
- // }
-
-
- self.headerView.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.headerView.bounds].CGPath;
-
- self.tableview.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.tableview.bounds].CGPath;
- }
- /*
- #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.
- }
- */
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
-
- if( self.modellist.count==0)
- return 0;
- return self.modellist.count+1;
-
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- if(indexPath.row==self.modellist.count)
- return 44;
- else
- return 136.0f;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
-
-
- if(indexPath.row==self.modellist.count)
- {
- UITableViewCell *moreCell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"mores"];
- UILabel *moreDataLabel=[[UILabel alloc] init];
-
- moreDataLabel.tag=200;
- moreDataLabel.text=self.load_more_hint;
- [moreDataLabel setFont:[UIFont systemFontOfSize:14.0f]];
- [moreDataLabel setTextAlignment:NSTextAlignmentCenter];
- moreDataLabel.frame=CGRectMake(0, 10, self.tableview.bounds.size.width, 20);
- [moreDataLabel setBackgroundColor:[UIColor clearColor]];
- moreDataLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
- // [moreDataLabel addTarget:self action:@selector(changeCell) forControlEvents:UIControlEventValueChanged];
-
- [moreCell.contentView addSubview:moreDataLabel];
- if([self.load_more_hint isEqualToString:@"Load more..."])
- [self performSelector:@selector(loadMore) withObject:nil afterDelay:1];
- // DebugLog(@"更多...");
- moreCell.backgroundColor = [UIColor whiteColor];
- return moreCell;
- }
- else
- {
- ScanListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ScanListCell"];
- if (!cell) {
- cell = [[ScanListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ScanListCell"];
- }
- NSMutableArray* arr = self.modellist;
-
- [cell setModelJson:arr[indexPath.row]];
-
-
- return cell;
- }
- }
- -(void) loadMore {
- __weak typeof(self) weakself = self;
- NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
-
- if (weakself) {
- __strong typeof(weakself) strongself = weakself;
- [strongself operation_loadMore];
- }
-
- }];
-
- [self.dataOperationQueue addOperation:operation];
- }
- -(void) operation_loadMore
- {
- if (self.dataOperationQueue.operationCount > 1) {
- return;
- }
- dispatch_async(dispatch_get_main_queue(), ^{
-
- // if(self.loadall)
- // {
- //// if(self.showalert)
- // {
- //// self.showalert=false;
- // [RAUtils message_alert:@"All loaded" title:@"Loading items" controller:self] ;
- // }
- // return;
- // }
- //
- // self.mum.hidden = false;
- // [self.mum startAnimating];
- // self.mum.center = self.view.center;
-
- self.isrefreshing=true;
-
- [RADataProvider request_scansearch:self.offset limit:PAGE_ITEM keywords:self.keywords completionHandler:^(NSMutableDictionary *result) {
- NSMutableDictionary* category_more=result;
-
- // [self.mum stopAnimating];
- self.isrefreshing=false;
- if (self.dataOperationQueue.operationCount > 1) {
- return;
- }
-
- // NSDictionary* more_items=[category_more objectForKey:@"items"];
- if([[category_more valueForKey:@"result"] intValue]==2)
- {
- // self.category_data = category_data;
- // NSMutableDictionary* items_json= [[category_more objectForKey:@"items"] mutableCopy];
-
- int count =[[category_more valueForKey:@"count"] intValue];
-
- for(int i=0;i<count;i++)
- {
-
- NSMutableDictionary* item = [category_more[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
- [self.modellist addObject:item];
-
- }
- // long newcount=count;
- // [items_json setValue: [NSString stringWithFormat:@"%ld",newcount] forKey:@"count"];
- // [self.category_data setObject:items_json forKey:@"items"];
- self.offset+=count;
-
- if(count<PAGE_ITEM)
- {
-
- // int i =self.btnrefresh.state;
- self.load_more_hint=@"All loaded";
- // self.btnrefresh.titleLabel.text =NSLocalizedString(@"no_more", nil);
- // [self.btnrefresh setTitle:@"No more" forState:UIControlStateNormal];
- }
- else
- {
- self.load_more_hint=@"Load more...";
- // self.btnrefresh.enabled = true;
- // self.btnrefresh.titleLabel.text =NSLocalizedString(@"load_more",nil);
- // [self.btnrefresh setTitle:@"Load more" forState:UIControlStateNormal];
- }
- // NSDictionary * item_json = [self.category_data objectForKey:@"items"];
-
-
-
-
- // DebugLog(@"%@",self.category_data);
-
- [self.tableview reloadData];
-
- }
- else
- {
- [RAUtils message_alert:[category_more valueForKey:@"err_msg"] title:@"Search" controller:self] ;
- }
- self.isrefreshing=false;
-
-
- }];
-
- return;
-
- });
- }
- -(void) reload {
- __weak typeof(self) weakself = self;
- NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
-
- if (weakself) {
- __strong typeof(weakself) strongself = weakself;
- [strongself operation_reload];
- }
-
- }];
-
- [self.dataOperationQueue addOperation:operation];
- }
- -(void) operation_reload
- {
- if (self.dataOperationQueue.operationCount > 1) {
- return;
- }
- dispatch_async(dispatch_get_main_queue(), ^{
- if(self.isrefreshing)
- return;
- // self.showalert=true;
- self.isrefreshing=true;
- // self.loadall = false;
- UIRefreshControl *reF = (UIRefreshControl *)[self.tableview viewWithTag:201];
-
- [reF endRefreshing];
-
- reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
- // self.label_net_err.hidden=true;
- // self.collectionview.hidden=true;
- // self.mum.center = self.view.center;
- // self.mum.hidden = false;
- // [self.mum startAnimating];
- // self.loadmore_matchfull = self.switch_matchfull.isOn;
- [RADataProvider request_scansearch:0 limit:PAGE_ITEM keywords:self.keywords completionHandler:^(NSMutableDictionary *result) {
- NSMutableDictionary* category_data=result;
-
-
- // [self.mum stopAnimating];
- self.isrefreshing=false;
- if (self.dataOperationQueue.operationCount > 1) {
- return;
- }
-
- // self.category_data = [category_data mutableCopy];
- // [self.collectionview reloadData];
-
- if([[category_data valueForKey:@"result"] intValue]==2)
- {
- // self.collectionview.hidden=false;
- // NSDictionary * item_json = [category_data objectForKey:@"items"];
-
-
- int c=[[category_data valueForKey:@"count"] intValue];
- self.offset = c;
- for (int i=0;i<c;i++)
- {
- NSMutableDictionary* item = [category_data[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
- [self.modellist addObject:item];
- }
-
-
-
- if(c<PAGE_ITEM)
- {
-
- // int i =self.btnrefresh.state;
- self.load_more_hint=@"All loaded";
- // self.btnrefresh.titleLabel.text =NSLocalizedString(@"no_more", nil);
- // [self.btnrefresh setTitle:@"No more" forState:UIControlStateNormal];
- }
- else
- {
- self.load_more_hint=@"Load more...";
- // self.btnrefresh.enabled = true;
- // self.btnrefresh.titleLabel.text =NSLocalizedString(@"load_more",nil);
- // [self.btnrefresh setTitle:@"Load more" forState:UIControlStateNormal];
- }
-
- [self.tableview reloadData];
-
- // int total = [[self.category_data valueForKey:@"item_total_count"]intValue];
- //
- // if(total<2)
- // {
- // self.labelTotal.text = [NSString stringWithFormat:@"Total %d item",total];
- // if(total==1)
- // {
- // NSDictionary * detail_item = [item_json objectForKey:@"item_0"];
- // NSString* detail_id= [detail_item valueForKey:@"product_id"] ;
- //
- // [self showDetailat:detail_id category_id:nil name:[detail_item objectForKey:@"fash_name"] index:0];
- // }
- // }
- // else
- // self.labelTotal.text = [NSString stringWithFormat:@"Total %d items",total];
- }
- else
- {
- [RAUtils message_alert:[category_data valueForKey:@"err_msg"] title:@"Search" controller:self] ;
- }
-
- self.isrefreshing=false;
-
-
- }];
-
- return;
-
- });
- }
-
-
-
-
- #pragma mark - searchBar delegate;
- - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
- {
-
-
- self.keywords=searchBar.text;
- self.offset = 0;
- // [self.content_data removeAllObjects];
- [self reload];
-
- }
- @end
|