// // MorShopViewController.m // Ifish // // Created by imac on 15/10/24. // Copyright © 2015年 imac. All rights reserved. // #import "MorShopViewController.h" #import "ShopModel.h" #import "MerchantCell.h" #import "AFNetworking.h" #import "DetailViewController.h" @interface MorShopViewController () { BOOL _isRefreshing; BOOL _isLoadMore; } @property(nonatomic)BOOL isRefreshing; @property(nonatomic)BOOL isLoadMore; //@property(nonatomic) NSInteger start; @property(nonatomic,strong)NSMutableDictionary*para; @property(nonatomic,copy)NSString* total; @property(nonatomic) int page; @end @implementation MorShopViewController - (void)viewDidLoad { [super viewDidLoad]; [self addTitleViewWithTitle:@"更多店铺"]; self.shopArr=[[NSMutableArray alloc]init]; [self.tableView registerNib:[UINib nibWithNibName:@"MerchantCell" bundle:nil] forCellReuseIdentifier:@"MerchantCell"]; [self getMoreShop]; [self creatReatRefreshView]; _para=[NSMutableDictionary dictionary]; } -(void)getMoreShop{ AFHTTPRequestOperationManager*mannager=[AFHTTPRequestOperationManager manager]; mannager.responseSerializer=[AFHTTPResponseSerializer serializer]; NSMutableDictionary * para = [NSMutableDictionary dictionary]; _page=0; [para setValue:@"0" forKey:@"firstResult"]; [para setValue:@"10" forKey:@"pageSize"]; __weak typeof (self)weakSelf=self; [mannager POST:kMoreMerChantListInf parameters:para success:^(AFHTTPRequestOperation *operation, id responseObject) { if (responseObject) { NSDictionary*dict=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil]; NSArray*dataArr=dict[@"data"]; weakSelf.total=dict[@"total"]; NSLog(@"dic%@",dict); for (NSDictionary*dictData in dataArr) { ShopModel*model=[[ShopModel alloc]init]; model.merchantId=dictData[@"merchantId"]; model.shopName=dictData[@"shopName"]; model.mainBusiness=dictData[@"mainBusiness"]; model.startTime=dictData[@"startTime"]; model.endTime=dictData[@"endTime"]; model.appShow=dictData[@"appShow"]; model.salutation=dictData[@"salutation"]; model.contactPhone=dictData[@"contactPhone"]; model.provinceName=dictData[@"provinceName"]; model.cityName=dictData[@"cityName"]; model.areaName=dictData[@"areaName"]; model.road=dictData[@"road"]; // [self showTitle:@"" messsage:@"请求成功"]; [weakSelf.shopArr addObject:model]; } [weakSelf.tableView reloadData]; } } failure:^(AFHTTPRequestOperation *operation, NSError *error) { [self showTitle:@"提醒" messsage:@"请求出错"]; }]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.shopArr.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { MerchantCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MerchantCell"]; if (cell==nil) { cell=[[MerchantCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MerchantCell"]; } ShopModel*model=self.shopArr[indexPath.row]; cell.shopName.text=model.shopName; return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ DetailViewController*storeDetail=[[DetailViewController alloc]init]; ShopModel*model=self.shopArr[indexPath.row]; storeDetail.shopModel=model; [self.navigationController pushViewController:storeDetail animated:YES]; } -(void)creatReatRefreshView{ __weak typeof (self)weskSelf=self; // 下拉刷新 [weskSelf.tableView addRefreshHeaderViewWithAniViewClass:[JHRefreshCommonAniView class] beginRefresh:^{ if (weskSelf.isRefreshing) { return ; } weskSelf.isRefreshing=YES; _page=0; [_para setValue:@"0" forKey:@"firstResult"]; [_para setValue:@"10" forKey:@"pageSize"]; [weskSelf addTaskWithUrl:kMoreMerChantListInf isRefresh:YES]; [self.tableView reloadData]; }]; //上拉加载更多 [weskSelf.tableView addRefreshFooterViewWithAniViewClass:[JHRefreshCommonAniView class] beginRefresh:^{ if (weskSelf.isLoadMore) { return ; } weskSelf.isLoadMore=YES; NSInteger pagecount =[_total integerValue]/10+1; if (_page