483 lines
16 KiB
Objective-C
483 lines
16 KiB
Objective-C
//
|
|
// KanHuFuWuViewController.m
|
|
// Ifish
|
|
//
|
|
// Created by imac on 17/1/13.
|
|
// Copyright © 2017年 lianlian. All rights reserved.
|
|
//
|
|
|
|
#import "KanHuFuWuViewController.h"
|
|
#import "IFishShopsViewCell.h"
|
|
#import "IfishShopInfo.h"
|
|
#import "KanHuFirstSectionViewCell.h"
|
|
#import "IfishShopDetailViewController.h"
|
|
#import "CertificationShopModel.h"
|
|
#import "ShopCertificationIntroduceController.h"
|
|
#import "ShopCertifyFailViewController.h"
|
|
#import "JHRefresh.h"
|
|
#import "WoShiShangJiaViewController.h"
|
|
#import "IfishZiXunAdViewCell.h"
|
|
#import "PushMasssageWebViewController.h"
|
|
#import "IfishAlibcWebViewController.h"
|
|
#import <AlibcTradeSDK/AlibcTradeSDK.h>
|
|
@interface KanHuFuWuViewController ()<UITableViewDelegate,UITableViewDataSource>
|
|
{
|
|
BOOL _isRefreshing;
|
|
BOOL _isLoadMore;
|
|
BOOL _isPushed;
|
|
}
|
|
@property(nonatomic)BOOL isRefreshing;
|
|
@property(nonatomic)BOOL isLoadMore;
|
|
@property(nonatomic,copy) NSString* total;
|
|
@property(nonatomic) int page;
|
|
@property(nonatomic,strong)NSDictionary*para;
|
|
@property(nonatomic,strong)UITableView *tableView;
|
|
@property(nonatomic,strong) NSMutableArray *dataArr;
|
|
@property (nonatomic,strong) NSMutableArray *bannerDataArr;
|
|
|
|
@end
|
|
|
|
@implementation KanHuFuWuViewController
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
// Do any additional setup after loading the view.
|
|
[self addTitleViewWithTitle:@"优选商家"];
|
|
self.dataArr = [[NSMutableArray alloc] init];
|
|
_bannerDataArr = [[NSMutableArray alloc] init];
|
|
_isPushed = NO;
|
|
[self loadData];
|
|
[self creatTab];
|
|
[self creatReatRefreshView];
|
|
[self initBannerData];
|
|
|
|
}
|
|
|
|
-(void)viewWillAppear:(BOOL)animated{
|
|
[super viewWillAppear:animated];
|
|
if (_isPushed ) {
|
|
NSIndexSet *asset = [NSIndexSet indexSetWithIndex:0];
|
|
[self.tableView reloadSections:asset withRowAnimation:UITableViewRowAnimationNone];
|
|
}
|
|
|
|
}
|
|
|
|
-(void)loadData{
|
|
_page = 0;
|
|
NSInteger first = 0;
|
|
NSInteger pageSize= 10;
|
|
[self addTaskWithfirsStr:first pageSize:pageSize isRefresh:YES];
|
|
|
|
}
|
|
|
|
-(void)creatReatRefreshView{
|
|
__weak typeof (self)weskSelf=self;
|
|
// 下拉刷新
|
|
|
|
[weskSelf.tableView addRefreshHeaderViewWithAniViewClass:[JHRefreshAmazingAniView class] beginRefresh:^{
|
|
if (weskSelf.isRefreshing) {
|
|
return ;
|
|
}
|
|
weskSelf.isRefreshing=YES;
|
|
[weskSelf loadData];
|
|
|
|
}];
|
|
|
|
|
|
//上拉加载更多
|
|
|
|
[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;
|
|
NSInteger pageSize= 10;
|
|
[weskSelf addTaskWithfirsStr:first pageSize:pageSize isRefresh:NO];
|
|
|
|
}else{
|
|
[weskSelf endRefreshing];
|
|
[weskSelf.view makeToast:@"已无更多数据"];
|
|
}
|
|
|
|
}];
|
|
|
|
|
|
}
|
|
|
|
-(void)endRefreshing{
|
|
if (self.isRefreshing) {
|
|
self.isRefreshing=NO;
|
|
[self.tableView headerEndRefreshingWithResult:JHRefreshResultNone];
|
|
}
|
|
|
|
if (self.isLoadMore) {
|
|
self.isLoadMore=NO;
|
|
[self.tableView footerEndRefreshing];
|
|
}
|
|
}
|
|
-(void)addTaskWithfirsStr:(NSInteger)firsStr pageSize:(NSInteger)pageSize isRefresh:(BOOL)isRefresh{
|
|
|
|
__weak typeof (self)weskSelf=self;
|
|
|
|
NSString *userId= [dataContorl dataControlGetUserIdInfo];
|
|
[AFHttpTool getShopsinfo:userId firstResult:firsStr pageSize:pageSize success:^(id response) {
|
|
|
|
NSDictionary *reDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
|
|
if (isRefresh) {
|
|
[weskSelf.dataArr removeAllObjects];
|
|
}
|
|
|
|
if ([reDic[@"result"] isEqualToString:@"100"]) {
|
|
|
|
NSLog(@"reDidata%@",reDic[@"data"]);
|
|
NSArray *arr = reDic[@"data"];
|
|
_total = reDic[@"total"];
|
|
for (NSDictionary *dict in arr) {
|
|
IfishShopInfo *ShopInfo = [[IfishShopInfo alloc] init];
|
|
ShopInfo.shopsId = dict[@"shopsId"];
|
|
ShopInfo.userId = dict[@"userId"];
|
|
ShopInfo.userImg = dict[@"userImg"];
|
|
ShopInfo.userName = dict[@"userName"];
|
|
ShopInfo.shopsName = dict[@"shopsName"];
|
|
ShopInfo.shopsPhone = dict[@"shopsPhone"];
|
|
ShopInfo.shopsCity = dict[@"shopsCity"];
|
|
ShopInfo.shopsArea = dict[@"shopsArea"];
|
|
ShopInfo.shopsProvince = dict[@"shopsProvince"];
|
|
ShopInfo.shopsAddress = dict[@"shopsAddress"];
|
|
ShopInfo.picture4 = dict[@"picture4"];
|
|
ShopInfo.remark = dict[@"remark"];
|
|
ShopInfo.distance = dict[@"distance"];
|
|
ShopInfo.weixinCode =dict[@"weixinCode"];
|
|
ShopInfo.shopLink = dict[@"shopLink"];
|
|
[weskSelf.dataArr addObject:ShopInfo];
|
|
|
|
}
|
|
|
|
[weskSelf.tableView reloadData];
|
|
|
|
}else if ([reDic[@"result"] isEqualToString:@"101"]){
|
|
|
|
[weskSelf.view makeToast:@"请求失败101"];
|
|
}
|
|
|
|
[weskSelf endRefreshing];
|
|
|
|
} failure:^(NSError *err) {
|
|
[weskSelf endRefreshing];
|
|
[weskSelf.view makeToast:@"没有加载成功"];
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
-(void)creatTab{
|
|
|
|
self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
|
|
self.tableView.delegate = self;
|
|
self.tableView.dataSource = self;
|
|
self.tableView.scrollEnabled = YES;
|
|
self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
|
|
self.tableView.showsVerticalScrollIndicator = NO;
|
|
self.tableView.backgroundColor = TABLE_BACKGROUD_COLOR;
|
|
[self.view addSubview:self.tableView];
|
|
|
|
}
|
|
|
|
#pragma mark - Table view data source
|
|
|
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
|
|
|
|
return 3;
|
|
}
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
|
|
if (section ==0 ||section ==1) {
|
|
|
|
return 1;
|
|
|
|
}else
|
|
{
|
|
return [self.dataArr count];
|
|
}
|
|
}
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
if (indexPath.section ==0) {
|
|
IfishZiXunAdViewCell*cell =[tableView dequeueReusableCellWithIdentifier:@"IfishZiXunAdViewCell"];
|
|
if (!cell) {
|
|
cell = [[[NSBundle mainBundle]loadNibNamed:@"IfishZiXunAdViewCell" owner:self options:nil]lastObject];
|
|
|
|
}
|
|
if (_bannerDataArr.count !=0) {
|
|
NSArray *ads =self.bannerDataArr;
|
|
NSMutableArray *imgs = [[NSMutableArray alloc] init];
|
|
[ads enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
if ([obj isKindOfClass:[IfishBannerData class]]) {
|
|
IfishBannerData *banner = (IfishBannerData *)obj;
|
|
[imgs addObject:banner.adImage];
|
|
}
|
|
|
|
}];
|
|
|
|
cell.newsAdview.adList = imgs;
|
|
__weak typeof (self)weakSelf = self;
|
|
cell.newsAdview.tapActionBlock =^(LXAdScrollView *adScrollView) {
|
|
IfishBannerData *bdata = _bannerDataArr[adScrollView.currentPage];
|
|
[weakSelf tapAdWithLink:bdata.adLink];
|
|
};
|
|
|
|
}else{
|
|
//默认加载本地
|
|
cell.newsAdview.adList = @[@"Ifishbanner_shops.jpg"];
|
|
cell.newsAdview.tapActionBlock =^(LXAdScrollView *adScrollView) {
|
|
|
|
};
|
|
}
|
|
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
|
return cell;
|
|
|
|
}else if (indexPath.section ==1){
|
|
KanHuFirstSectionViewCell *cell =[tableView dequeueReusableCellWithIdentifier:@"KanHuFirstSectionViewCell"];
|
|
if (!cell) {
|
|
cell = [[[NSBundle mainBundle]loadNibNamed:@"KanHuFirstSectionViewCell" owner:self options:nil]lastObject];
|
|
|
|
}
|
|
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
|
return cell;
|
|
}else{
|
|
|
|
IFishShopsViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"IFishShopsViewCell"];
|
|
if (!cell) {
|
|
cell = [[[NSBundle mainBundle]loadNibNamed:@"IFishShopsViewCell" owner:self options:nil]lastObject];
|
|
}
|
|
IfishShopInfo *shopinfo = self.dataArr[indexPath.row];
|
|
|
|
[cell loadDataWtih:shopinfo];
|
|
[cell subviewsCorner];
|
|
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
|
|
{
|
|
if (indexPath.section ==0) {
|
|
return self.view.frame.size.width * 0.427;
|
|
}
|
|
return 70.0f;
|
|
}
|
|
|
|
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
|
|
return 0.01f;
|
|
}
|
|
|
|
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
|
|
return 0.01f;
|
|
}
|
|
|
|
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
|
|
|
|
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
|
if (indexPath.section ==0) {
|
|
return;
|
|
}
|
|
if (indexPath.section ==1) {
|
|
//商户验证
|
|
UserModel *user = [dataContorl getUserInfo];
|
|
if ([user.userType isEqualToString:@"0"]) {
|
|
|
|
WoShiShangJiaViewController *shangjiaVC = [[WoShiShangJiaViewController alloc] init];
|
|
self.hidesBottomBarWhenPushed = YES;
|
|
_isPushed = YES;
|
|
[self.navigationController pushViewController:shangjiaVC animated:YES];
|
|
|
|
}else{
|
|
|
|
[self.view makeToast:@"您已完成认证"];
|
|
}
|
|
|
|
}else if(indexPath.section ==2){
|
|
IfishShopInfo *shopinfo = self.dataArr [indexPath.row];
|
|
IfishShopDetailViewController *shopdetail = [[IfishShopDetailViewController alloc] init];
|
|
shopdetail.shopInfo = shopinfo;
|
|
self.hidesBottomBarWhenPushed = YES;
|
|
_isPushed = YES;
|
|
[self.navigationController pushViewController:shopdetail animated:YES];
|
|
|
|
}
|
|
|
|
}
|
|
- (void)didReceiveMemoryWarning {
|
|
[super didReceiveMemoryWarning];
|
|
// Dispose of any resources that can be recreated.
|
|
}
|
|
|
|
#pragma mark - 审核状态查询
|
|
|
|
-(void)testShopStatus:(CertificationShopModel *)CSModel{
|
|
|
|
|
|
|
|
// [IFISHHTTPTOOL shopCertifyStausWith:CSModel.shopsId huishuiShiJian:^(ShopCertifyStausModel *shopCertifyd) {
|
|
|
|
// ShopCertifyStausModel *statusmodel = [[ShopCertifyStausModel alloc] init];
|
|
// statusmodel=shopCertifyd;
|
|
// [self pushStatusViewWith:statusmodel];
|
|
|
|
// }];
|
|
__weak typeof (self)weskSelf=self;
|
|
[IFISHHTTPTOOL newshopCertifyStausWith:CSModel.shopsId huishuiShiJian:^(ShopCertifyStausModel *shopCertifyd) {
|
|
|
|
ShopCertifyStausModel *statusmodel = [[ShopCertifyStausModel alloc] init];
|
|
statusmodel=shopCertifyd;
|
|
[weskSelf pushStatusViewWith:statusmodel];
|
|
|
|
}];
|
|
|
|
|
|
}
|
|
|
|
-(void)pushStatusViewWith:(ShopCertifyStausModel*)model{
|
|
|
|
UIViewController *puVC;
|
|
Class cls= nil;
|
|
//model.status = nil;
|
|
if (model.status) {
|
|
|
|
//model.status =@"0";
|
|
|
|
if ([model.status isEqualToString:@"0"]){
|
|
//审核不通过
|
|
// cls=NSClassFromString(@"ShopCertifyFailViewController");
|
|
|
|
ShopCertifyFailViewController *puVC=[[ ShopCertifyFailViewController alloc] init];
|
|
puVC.statusModel = model;
|
|
_isPushed = YES;
|
|
self.hidesBottomBarWhenPushed = YES;
|
|
[self.navigationController pushViewController:puVC animated:YES];
|
|
|
|
|
|
}else if ([model.status isEqualToString:@"1"]){
|
|
|
|
cls=NSClassFromString(@"ShopCertifySucssesViewController");
|
|
puVC=[[cls alloc] initWithNibName:@"ShopCertifyFailViewController" bundle:nil];
|
|
_isPushed = YES;
|
|
self.hidesBottomBarWhenPushed = YES;
|
|
[self.navigationController pushViewController:puVC animated:YES];
|
|
|
|
|
|
}else if ([model.status isEqualToString:@"2"]){
|
|
|
|
|
|
cls=NSClassFromString(@"ShopCertifyCheckViewController");
|
|
puVC=[[cls alloc] initWithNibName:@"ShopCertifyFailViewController" bundle:nil];
|
|
_isPushed = YES;
|
|
self.hidesBottomBarWhenPushed = YES;
|
|
[self.navigationController pushViewController:puVC animated:YES];
|
|
|
|
|
|
}else if ([model.status isEqualToString:@"3"]){
|
|
//禁用
|
|
[self.view makeToast:@"已禁用"];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
[self.view makeToast:@"请求错误"];
|
|
}
|
|
|
|
}
|
|
|
|
#pragma mark - 广告栏
|
|
-(void)initBannerData{
|
|
__weak typeof (self)weakSelf = self;
|
|
[AFHttpTool getIfishBannerData:IfishAdTypeYouXuanShop success:^(id response) {
|
|
NSDictionary *reDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
|
|
NSString *result=reDic[@"result"];
|
|
if ([result isEqualToString:@"100"]) {
|
|
NSArray *data= reDic[@"data"];
|
|
if (data&&data.count!=0) {
|
|
for (NSDictionary *dic in data) {
|
|
IfishBannerData *bannerdata = [[IfishBannerData alloc] initWithDict:dic];
|
|
[_bannerDataArr addObject:bannerdata];
|
|
}
|
|
NSIndexSet *asset = [NSIndexSet indexSetWithIndex:0];
|
|
[weakSelf.tableView reloadSections:asset withRowAnimation:UITableViewRowAnimationNone];
|
|
}
|
|
|
|
}else{
|
|
|
|
//[weakSelf.view makeToast:@"广告位获取失败"];
|
|
}
|
|
|
|
} failure:^(NSError *err) {
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
-(void)tapAdWithLink:(NSString *)pushlink
|
|
{
|
|
|
|
if (![pushlink isKindOfClass:[NSNull class]] && pushlink && ![pushlink isEqualToString:@""]) {
|
|
_isPushed = YES;
|
|
//字条串是否包含有某字符串
|
|
if ([pushlink rangeOfString:@"taobao"].location == NSNotFound) {
|
|
self.hidesBottomBarWhenPushed = YES;
|
|
PushMasssageWebViewController*webVC=[[PushMasssageWebViewController alloc]init];
|
|
webVC.pushlink =pushlink;
|
|
webVC.pushtitle = @"详情";
|
|
[self.navigationController pushViewController:webVC animated:YES];
|
|
|
|
} else {
|
|
|
|
[self openAliBCWithLink:pushlink];
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
-(void)openAliBCWithLink:(NSString *)linkUrl{
|
|
|
|
//535991514644
|
|
//根据商品ID
|
|
//id<AlibcTradePage> page = [AlibcTradePageFactory itemDetailPage: @"535991514644"];
|
|
//根据链接打开页面
|
|
id<AlibcTradePage> page = [AlibcTradePageFactory page:linkUrl];
|
|
AlibcTradeShowParams* showParam = [[AlibcTradeShowParams alloc] init];
|
|
//app 内闭环交易 强制H5 打开
|
|
showParam.openType = AlibcOpenTypeH5;
|
|
|
|
//AlibcWebViewController* myView = [[AlibcWebViewController alloc] init];
|
|
//自定义web
|
|
IfishAlibcWebViewController* myView = [[IfishAlibcWebViewController alloc] init];
|
|
NSInteger ret = [[AlibcTradeSDK sharedInstance].tradeService show:self.navigationController webView:myView.webView page:page showParams:showParam taoKeParams:nil trackParam:nil tradeProcessSuccessCallback:^(AlibcTradeResult * _Nullable result) {
|
|
|
|
} tradeProcessFailedCallback:^(NSError * _Nullable error) {
|
|
|
|
}]; //返回1,说明h5打开,否则不应该展示页面
|
|
|
|
|
|
if (ret == 1) {
|
|
|
|
self.hidesBottomBarWhenPushed = YES;
|
|
[self.navigationController pushViewController:myView animated:YES];
|
|
}
|
|
}
|
|
|
|
@end
|