Initial commit
This commit is contained in:
@@ -0,0 +1,243 @@
|
||||
//
|
||||
// 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<pagecount-1) {
|
||||
_page++;
|
||||
|
||||
NSInteger first=(NSInteger)_page*10;
|
||||
NSString*firsStr=[NSString stringWithFormat:@"%ld",(long)first];
|
||||
// NSString*first=(NSString*)(_page*10+9);
|
||||
[_para setValue:firsStr forKey:@"firstResult"];
|
||||
[_para setValue:@"10" forKey:@"pageSize"];
|
||||
NSString*url=kMoreMerChantListInf;
|
||||
[weskSelf addTaskWithUrl:url isRefresh:NO];
|
||||
|
||||
|
||||
}else{
|
||||
[self endRefreshing];
|
||||
[self showTitle:@"" messsage:@"没有了"];
|
||||
}
|
||||
|
||||
|
||||
|
||||
}];
|
||||
|
||||
|
||||
}
|
||||
-(void)endRefreshing{
|
||||
if (self.isRefreshing) {
|
||||
self.isRefreshing=NO;
|
||||
[self.tableView headerEndRefreshingWithResult:JHRefreshResultNone];
|
||||
}
|
||||
if (self.isLoadMore) {
|
||||
self.isLoadMore=NO;
|
||||
[self.tableView footerEndRefreshing];
|
||||
}
|
||||
}
|
||||
-(void)addTaskWithUrl:(NSString *)url isRefresh:(BOOL)isRefresh{
|
||||
AFHTTPRequestOperationManager*mannager=[AFHTTPRequestOperationManager manager];
|
||||
mannager.responseSerializer=[AFHTTPResponseSerializer serializer];
|
||||
|
||||
// [_para setValue:@"0" forKey:@"firstResult"];
|
||||
// [_para setValue:@"10" forKey:@"pageSize"];
|
||||
|
||||
__weak typeof (self)weakSelf=self;
|
||||
if (isRefresh) {
|
||||
[weakSelf.shopArr removeAllObjects];
|
||||
}
|
||||
|
||||
|
||||
[mannager POST:url parameters:_para success:^(AFHTTPRequestOperation *operation, id responseObject) {
|
||||
if (responseObject) {
|
||||
NSDictionary*dict=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
|
||||
NSArray*dataArr=dict[@"data"];
|
||||
NSLog(@"dic1%@",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];
|
||||
[weakSelf endRefreshing];
|
||||
}
|
||||
|
||||
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
||||
[self showTitle:@"提醒" messsage:@"请求出错"];
|
||||
[weakSelf endRefreshing];
|
||||
}];
|
||||
|
||||
}
|
||||
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
|
||||
|
||||
return 60;
|
||||
|
||||
}
|
||||
-(void)showTitle:(NSString*)title messsage:(NSString*)message{
|
||||
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:title message:message delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];
|
||||
NSTimeInterval dismissSeconds=1.0;
|
||||
[alert show];
|
||||
[self performSelector:@selector(dismissAlert:) withObject:alert afterDelay:dismissSeconds];
|
||||
|
||||
// UIAlertController *alertContorller=[UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
|
||||
// UIAlertAction*cancleAction=[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
|
||||
//
|
||||
// UIAlertAction *sureAction=[UIAlertAction actionWithTitle:@"好的" style:UIAlertActionStyleDefault handler:nil];
|
||||
// [alertContorller addAction:cancleAction];
|
||||
// [alertContorller addAction:sureAction];
|
||||
// [self presentViewController:alertContorller animated:YES completion:nil];
|
||||
|
||||
|
||||
}
|
||||
-(void)dismissAlert:(UIAlertView*)alertView{
|
||||
|
||||
[alertView dismissWithClickedButtonIndex:[alertView cancelButtonIndex] animated:YES];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user