cdts/xdts-ios 3/TreeHole/Code/Features/Bottle/ViewController/BottleNerbyViewController.m
2023-07-31 09:33:00 +08:00

797 lines
35 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// BottleNerbyViewController.m
// TreeHole
//
// Created by 郑创权 on 2022/10/6.
//
#import "BottleNerbyViewController.h"
#import "userNearbyModel.h"
#import "BottleUserNearbyTableViewCell.h"
#import <SDCycleScrollView/SDCycleScrollView.h>
#import "UserService.h"
#import "BottleUserNearbyShaiXuanAlertView.h"
#import "PYAppService.h"
#import <CoreLocation/CoreLocation.h>
#import <MJRefresh.h>
#import "MTPickerView.h"
#import "THLVTipView.h"
#import "BRPickerView.h"
@interface BottleNerbyViewController ()<UITableViewDelegate,UITableViewDataSource,CLLocationManagerDelegate,SDCycleScrollViewDelegate,UITextFieldDelegate>
@property (nonatomic, assign) NSInteger nextPage;
@property (nonatomic, strong) UIView* topHeaderView;
@property (nonatomic, strong) NSMutableArray* tableMDataArray;
@property (nonatomic, strong) NSMutableArray* photosM;
@property (nonatomic, strong) SDCycleScrollView* cycleScrollView;
@property (nonatomic, strong) UIView* openVipAlertView;
@property (nonatomic, strong) THLVTipView* lvTipView;
@property (nonatomic, strong) NSMutableDictionary* nearbyParamDict;
@property (nonatomic, strong) CLLocationManager *cLLocationManager;
@property (nonatomic, strong) NSDictionary* shaiXuanDict;
@property (nonatomic,strong) UIButton *leftBtn;
@property (nonatomic,strong) NSString *city;
@property (nonatomic,copy) NSArray *bannerArr;
@property (nonatomic, copy) NSArray <NSNumber *> *linkage3SelectIndexs;
@end
@implementation BottleNerbyViewController
- (BOOL)mt_nagationBarTransparent{
return YES;
}
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
if ([UserService currentUser].isVIP) {
_contentTableView.mj_footer.hidden = NO;
[self loadPhotosData];
}else{
_contentTableView.mj_footer.hidden = YES;
self.lvTipView.descLbl.text = @"开通年VIP提升您的账号权重进而提升排名哦";
[self.lvTipView.tipBtn setTitle:@"开年VIP" forState:UIControlStateNormal];
}
[self loadBannerData];
}
- (void)loadBannerData {
[PYHTTPManager getWithPath:@"appconfig" params:nil callback:^(id _Nullable rsp, NSError * _Nullable error) {
if (rsp[@"banners"] != nil) {
NSArray *bannerArr = rsp[@"banners"];
self.bannerArr = bannerArr;
NSMutableArray *imgArr = [NSMutableArray array];
for (NSDictionary *info in bannerArr) {
[imgArr addObject:info[@"image"]];
}
self.cycleScrollView.imageURLStringsGroup = imgArr;
}
}];
}
- (void)loadPhotosData {
[UserService getUserPhotosWithUserID:[UserService currentUserID] completion:^(NSArray<ProfilePhoto *> * _Nonnull photos) {
self.photosM = [photos mutableCopy];
[self endLoading:nil];
if (self.photosM.count < 3) {
[self.lvTipView.tipBtn setTitle:@"更新形象照" forState:UIControlStateNormal];
self.lvTipView.descLbl.text = @"更新形象照完善您的个人形象进而提升排名哦~";
} else {
[self.lvTipView.tipBtn setTitle:@"查看瓶子" forState:UIControlStateNormal];
self.lvTipView.descLbl.text = @"多查看瓶子并回应增加互动值进而提升排名哦~";
}
}];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"附近同好";
UIImageView *bgImgView = [UIImageView creatViewInSuperView:self.view];
bgImgView.frame = self.view.bounds;
bgImgView.image = UIImageMake(@"TH_BaseLocalBg");
// UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
// self.leftBtn = leftBtn;
// leftBtn.frame = CGRectMake(0, 0, FIX_SIZE(86), FIX_SIZE(24));
// [leftBtn setImage:ImageNamed(@"TH_TabBarNearSelected") forState:UIControlStateNormal];
// [leftBtn setTitle:@"全国" forState:UIControlStateNormal];
// leftBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 0);
//
// leftBtn.titleLabel.font = [UIFont systemFontOfSize:14];
// [leftBtn addTarget:self action:@selector(locaClick) forControlEvents:UIControlEventTouchUpInside];
// [leftBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
// [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:@"nearCity"];
//
// [[NSUserDefaults standardUserDefaults] synchronize];
UIView *leftView = [[UIView alloc]init];
leftView.frame = CGRectMake(0, 0, FIX_SIZE(120), FIX_SIZE(44));
leftView.backgroundColor = [UIColor clearColor];
UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
leftBtn.backgroundColor = [UIColor clearColor];
self.leftBtn = leftBtn;
[leftView addSubview:leftBtn];
leftBtn.frame = CGRectMake(0, FIX_SIZE(12), FIX_SIZE(22), FIX_SIZE(20));
[leftBtn setImage:ImageNamed(@"TH_TabBarNearSelected") forState:UIControlStateNormal];
User *user = [UserService currentUser];
UITextField *locationTextField = [[UITextField alloc] init];
[leftView addSubview:locationTextField];
locationTextField.frame = CGRectMake(0, 0, FIX_SIZE(120), FIX_SIZE(44));
// locationTextField.backgroundColor = [UIColor clearColor];
locationTextField.delegate = self;
// locationTextField.backgroundColor = [UIColor w];
locationTextField.text = @" 全国(切换)";
locationTextField.inputView = [MTPickerView pickerViewWithType:MTPickerViewTypeLocation defaultValues:[@"全国-" componentsSeparatedByString:@"-"] valueDidChange:^(NSArray<NSString *> * _Nonnull values) {
NSLog(@"改成数据.%@",values);
} done:^(NSArray<NSString *> * _Nonnull selectedValues) {
NSLog(@"选择.");
if (selectedValues.count == 3) {
[UserService updateUserToRemoteWithParams:@{
@"province": selectedValues[0]?:@"",
@"city": selectedValues[1]?:@"",
@"district": selectedValues[2]?:@"",
} completion:^(id _Nullable rsp, NSError * _Nullable error) {
if (!error) {
user.province = selectedValues[0];
user.city = selectedValues[1];
user.district = selectedValues[2];
locationTextField.text = [NSString stringWithFormat:@" %@",user.city];
// [weakself reloadData];
NSLog(@"user.city===%@",user.city);
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
[ud setObject:user.city forKey:@"nearCity"];
[ud synchronize];
self.nextPage = 1;
[self reloadDataTableViewNT:self.nextPage withCity:user.city isRecommend:@""];
}else{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[SVProgressHUD showErrorWithStatus:[error.userInfo objectForKey:@"message"]];
});
}
}];
}
}];
self.leftView = leftView;
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:leftView];
UIButton *navBottleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
navBottleBtn.frame = CGRectMake(0, 0, FIX_SIZE(24), FIX_SIZE(24));
[navBottleBtn setImage:ImageNamed(@"TH_bottle_shaiXuan_icon") forState:UIControlStateNormal];
[navBottleBtn addTarget:self action:@selector(shaiXuanClick) forControlEvents:UIControlEventTouchUpInside];
self.navBottleBtn = navBottleBtn;
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:navBottleBtn];
// Do any additional setup after loading the view.
_nextPage = 1;
_tableMDataArray = [NSMutableArray arrayWithArray:@[]];
_shaiXuanDict = [[NSUserDefaults standardUserDefaults]objectForKey:@"UserNearbyShaiXuanDict"];
// [[NSUserDefaults standardUserDefaults]setObject:weakself.nearbyParamDict forKey:@"UserNearbyShaiXuanParamDict"];
WeakSelf(self);
[self.view addSubview:self.contentTableView];
// [self.contentTableView addSubview:self.openVipAlertView];
//因为原图的TabBar是圆角要设置VC颜色就要超过原有高度.
// _contentTableView.sd_layout.leftSpaceToView(self.view, 0).bottomSpaceToView(self.view, 0).rightSpaceToView(self.view, 0).topSpaceToView(self.view, 0);
_contentTableView.tableHeaderView = self.topHeaderView;
if(![PYAppService showAuthorizationWithTypeIfNeed:AuthorizationTypeLocation]){
//如果不用展示授权定位则代表可以定位了.
// [PYAppService sharedService].cLLocationManager
_cLLocationManager = [[CLLocationManager alloc] init];
[_cLLocationManager requestAlwaysAuthorization];
[_cLLocationManager requestWhenInUseAuthorization];
_cLLocationManager.delegate = self;
[_cLLocationManager startUpdatingLocation];
// [PYAppService sharedService].cLLocationManager.delegate = self;
// [[PYAppService sharedService].cLLocationManager startUpdatingLocation];
}else{
[self.contentTableView.mj_header beginRefreshing];
};
// NSString *usDefaultCity = [[NSUserDefaults standardUserDefaults]objectForKey:@"nearCity"];
_contentTableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
weakself.nextPage = 1;
[self reloadDataTableViewNT:weakself.nextPage withCity:self.city isRecommend:@""];
});
}];
NSString *ud = [[NSUserDefaults standardUserDefaults] objectForKey:@"isRecommend"];
MJWeakSelf
_contentTableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
if ([UserService currentUser].isVIP) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
#pragma mark -- 之前这个地方city传空
[self reloadDataTableViewNT:weakself.nextPage withCity:self.city isRecommend:ud];
});
} else {
// [weakself.contentTableView.mj_footer endRefreshing];
}
}];
[_contentTableView.mj_header beginRefreshing];
// [self reloadDataTableViewNT];
}
-(void)locaClick
{
/// 三级联动选择
BRStringPickerView *stringPickerView = [[BRStringPickerView alloc]init];
stringPickerView.pickerMode = BRStringPickerComponentLinkage;
stringPickerView.title = @"";
stringPickerView.dataSourceArr = [self getLinkag3DataSource];
// self.linkage3SelectIndexs = @[@2,@0,@0];
stringPickerView.selectIndexs = self.linkage3SelectIndexs;
// [stringPickerView.selectIndexs = @[@"2",@"0",@"0"];
stringPickerView.resultModelArrayBlock = ^(NSArray<BRResultModel *> *resultModelArr) {
// 1.选择的索引
NSMutableArray *selectIndexs = [[NSMutableArray alloc]init];
// 2.选择的值
NSString *selectValue = @"";
// 提示:【广东省-东莞市】,【广东省-中山市】 没有对应的区数据,三级联动会自动变成二级联动,使用 for循环遍历 获取选择的值而不直接使用数组下标,可以避免数组越界。如果想始终保持三级联动,在包装数据源时 可以把没有区数据用空字符串补上。
for (BRResultModel *model in resultModelArr) {
[selectIndexs addObject:@(model.index)];
selectValue = [NSString stringWithFormat:@"%@%@", selectValue, model.value];
if (selectValue.length>7) {
NSString *cityString = [selectValue substringWithRange:NSMakeRange(3, 3)];
NSLog(@"cityString%@",cityString);
[self.leftBtn setTitle:cityString forState:UIControlStateNormal];
self.nextPage = 1;
[self reloadDataTableViewNT:self.nextPage withCity:cityString isRecommend:@""];
}
}
if ([selectValue hasPrefix:@" "]) {
selectValue = [selectValue substringFromIndex:1];
}
self.linkage3SelectIndexs = selectIndexs;
// textField.text = selectValue;
};
// 设置选择器中间选中行的样式
BRPickerStyle *customStyle = [[BRPickerStyle alloc]init];
customStyle.selectRowTextFont = [UIFont boldSystemFontOfSize:20.0f];
customStyle.selectRowTextColor = [UIColor whiteColor];
stringPickerView.pickerStyle = customStyle;
[stringPickerView show];
return;
// WeakSelf(self);
// UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0,24, 24)];
// [self.view addSubview:view];
User *user = [UserService currentUser];
UITextField *locationTextField = [[UITextField alloc] init];
[self.view addSubview:locationTextField];
locationTextField.delegate = self;
locationTextField.text = user.location ?: @"选择城市-省市";
locationTextField.inputView = [MTPickerView pickerViewWithType:MTPickerViewTypeLocation defaultValues:[user.location ?: @"北京市-北京市-东城区" componentsSeparatedByString:@"-"] valueDidChange:^(NSArray<NSString *> * _Nonnull values) {
NSLog(@"改成数据.%@",values);
} done:^(NSArray<NSString *> * _Nonnull selectedValues) {
NSLog(@"选择.");
if (selectedValues.count == 3) {
[UserService updateUserToRemoteWithParams:@{
@"province": selectedValues[0]?:@"",
@"city": selectedValues[1]?:@"",
@"district": selectedValues[2]?:@"",
} completion:^(id _Nullable rsp, NSError * _Nullable error) {
if (!error) {
user.province = selectedValues[0];
user.city = selectedValues[1];
user.district = selectedValues[2];
// [weakself.contentTableView.mj_header beginRefreshing];
}else{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[SVProgressHUD showErrorWithStatus:[error.userInfo objectForKey:@"message"]];
});
}
}];
}
}];
// User *user = [UserService currentUser];
// UITextField *locationTextField = [[UITextField alloc] init];
// [self.contentTableView addSubview:locationTextField];
// locationTextField.frame = CGRectMake(0, 0, 24, 24);
// locationTextField.delegate = self;
// locationTextField.text = user.location ?: @"选择城市-省市";
// locationTextField.inputView =[MTPickerView pickerViewWithType:MTPickerViewTypeLocation defaultValues:[user.location ?: @"北京市-北京市-东城区" componentsSeparatedByString:@"-"] valueDidChange:^(NSArray<NSString *> * _Nonnull values) {
// NSLog(@"改成数据.%@",values);
// } done:^(NSArray<NSString *> * _Nonnull selectedValues) {
// NSLog(@"选择.");
// if (selectedValues.count == 3) {
// [UserService updateUserToRemoteWithParams:@{
// @"province": selectedValues[0]?:@"",
// @"city": selectedValues[1]?:@"",
// @"district": selectedValues[2]?:@"",
// } completion:^(id _Nullable rsp, NSError * _Nullable error) {
// if (!error) {
// user.province = selectedValues[0];
// user.city = selectedValues[1];
// user.district = selectedValues[2];
//// [weakself.contentTableView.mj_header beginRefreshing];
//
// }else{
// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// [SVProgressHUD showErrorWithStatus:[error.userInfo objectForKey:@"message"]];
// });
// }
// }];
// }
// }];
}
#pragma mark - 获取三级联动的数据源
- (NSArray <BRResultModel *>*)getLinkag3DataSource {
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"linkage3_data.json" ofType:nil];
NSData *data = [NSData dataWithContentsOfFile:filePath];
NSDictionary *responseObj = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
NSMutableArray *allRegionModelArr = [[NSMutableArray alloc]init];
// 省
NSArray *provinceArr = responseObj[@"Result"][@"Province"];
for (NSInteger i = 0; i < provinceArr.count; i++) {
BRResultModel *model = [[BRResultModel alloc]init];
model.parentKey = @"-1";
model.parentValue = @"";
model.key = [NSString stringWithFormat:@"%@", provinceArr[i][@"ProvinceID"]];
model.value = provinceArr[i][@"Province"];
[allRegionModelArr addObject:model];
}
// 市
NSArray *cityArr = responseObj[@"Result"][@"City"];
for (NSInteger i = 0; i < cityArr.count; i++) {
BRResultModel *model = [[BRResultModel alloc]init];
model.parentKey = [NSString stringWithFormat:@"%@", cityArr[i][@"ProvinceID"]];
model.parentValue = @"";
model.key = [NSString stringWithFormat:@"%@", cityArr[i][@"CityID"]];
model.value = cityArr[i][@"City"];
[allRegionModelArr addObject:model];
}
// 区
NSArray *areaArr = responseObj[@"Result"][@"Area"];
for (NSInteger i = 0; i < areaArr.count; i++) {
BRResultModel *model = [[BRResultModel alloc]init];
model.parentKey = [NSString stringWithFormat:@"%@", areaArr[i][@"CityID"]];;
model.parentValue = @"";
model.key = [NSString stringWithFormat:@"%@", areaArr[i][@"AreaID"]];
model.value = areaArr[i][@"Area"];
[allRegionModelArr addObject:model];
}
return [allRegionModelArr copy];
}
-(void)reloadDataTableViewNT:(NSInteger)nextPage withCity:(NSString *)city isRecommend:(NSString *)isRecommend{
NSLog(@"nextPage===%zd",nextPage);
__weak typeof(self) _blockSelf = self;
NSDictionary* tempDict = [[NSUserDefaults standardUserDefaults]objectForKey:@"UserNearbyShaiXuanParamDict"];
if (!tempDict) {
_nearbyParamDict = [NSMutableDictionary dictionaryWithDictionary:@{}];
}else{
_nearbyParamDict = [NSMutableDictionary dictionaryWithDictionary:tempDict];
NSString* vipStr = _nearbyParamDict[@"vip"];
NSString* onlineStr = _nearbyParamDict[@"online"];
NSString* newStr = _nearbyParamDict[@"new"];
// NSString* city = _nearbyParamDict[@"city"];
_nearbyParamDict[@"vip"] = [NSNumber numberWithInteger:vipStr.integerValue];
_nearbyParamDict[@"online"] = [NSNumber numberWithInteger:onlineStr.integerValue];
_nearbyParamDict[@"new"] = [NSNumber numberWithInteger:newStr.integerValue];
_nearbyParamDict[@"version"] = @"1";
_nearbyParamDict[@"isRecommend"] = isRecommend;
//
// _nearbyParamDict[@"version"]
_nearbyParamDict[@"city"] = city ?: @"全国";
}
_nearbyParamDict[@"page"] = [NSNumber numberWithInteger:nextPage];
_nearbyParamDict[@"perpage"] = @(10);
NSLog(@"_nearbyParamDict : %@",_nearbyParamDict);
// NSData *data = [NSJSONSerialization dataWithJSONObject:_nearbyParamDict options:NSJSONWritingPrettyPrinted error:nil];
// [SVProgressHUD showSuccessWithStatus:[NSString stringWithFormat:@"_nearbyParamDict : %@ \n data.length : %lu",_nearbyParamDict,(unsigned long)data.length]];
[PYHTTPManager postWithPath:@"usernearby1" params:_nearbyParamDict callback:^(id _Nullable rsp, NSError * _Nullable error) {
// NSLog(@"是的rsp : %@==%@",rsp[@"isRecommend"],error);
if (!error) {
self.city = city;
[[NSUserDefaults standardUserDefaults]setObject:rsp[@"isRecommend"] forKey:@"isRecommend"];
[[NSUserDefaults standardUserDefaults] synchronize];
if (nextPage == 1) {
_blockSelf.tableMDataArray = [NSMutableArray arrayWithArray:@[]];
}
NSArray* listArray = rsp[@"list"];
if (![listArray isKindOfClass:[NSNull class]]) {
if(listArray.count == 0){
[SVProgressHUD showErrorWithStatus:@"暂时没有更多数据"];
return;
}
}else{
[SVProgressHUD showErrorWithStatus:@"暂时没有更多数据"];
return;
}
_blockSelf.nextPage ++;
[_blockSelf.tableMDataArray addObjectsFromArray:[userNearbyModel mj_objectArrayWithKeyValuesArray:listArray]];
NSMutableArray *newArray = [NSMutableArray array];
for (int i = 0; i < _blockSelf.tableMDataArray.count; i++) {
userNearbyModel *tempModel = _blockSelf.tableMDataArray[i];
if (![newArray containsObject:tempModel]) {
[newArray addObject:tempModel];
NSLog(@"user_local==%@",tempModel.user_local);
}else{
NSLog(@"有相同数据.");
}
}
_blockSelf.tableMDataArray = newArray;
[_blockSelf.contentTableView reloadData];
} else {
NSString *code = [NSString stringWithFormat:@"%@",error.userInfo[@"code"]];
if(code.intValue == 1300) {
NSString *msg = error.userInfo[@"message"];
[MTAlertView showWithSetupBlcok:^(MTAlertViewConfig *config) {
config.message = msg;
config.otherTitle = @"去开通会员";
config.cancelTitle = @"取消";
config.otherHandler = ^(MTAlertButton *button) {
[PYAppService showVipVC:@"vip_page"];
};
}];
}
}
[_blockSelf.contentTableView.mj_header endRefreshing];
[_blockSelf.contentTableView.mj_footer endRefreshing];
}];
}
-(void)shaiXuanClick{
// NSLog(@"筛选.");
BottleUserNearbyShaiXuanAlertView* alertView = [[BottleUserNearbyShaiXuanAlertView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
WeakSelf(self);
alertView.sureClickBlock = ^(NSDictionary * _Nonnull dict) {
NSLog(@"dataDict SureClickBlock:%@",dict);
if ([dict[@"sx_gender"] isEqualToString:@"全部"]) {
weakself.nearbyParamDict[@"gender_str"] = @"";
}else{
weakself.nearbyParamDict[@"gender_str"] = dict[@"sx_gender"] ;
}
if ([dict[@"sx_age"] isEqualToString:@"全部"]) {
weakself.nearbyParamDict[@"age"] = @"";
}else{
weakself.nearbyParamDict[@"age"] = dict[@"sx_age"];
}
NSString *usDefaultCity = [[NSUserDefaults standardUserDefaults]objectForKey:@"nearCity"];
NSString *city;
if (usDefaultCity) {
city = usDefaultCity;
}else{
city = @"";
}
if ([dict[@"sx_gjsx"] isEqualToString:@"全部"]) {
weakself.nearbyParamDict[@"online"] = @"1";
weakself.nearbyParamDict[@"new"] = @"1";
weakself.nearbyParamDict[@"vip"] = @"1";
weakself.nearbyParamDict[@"city"] = city;
[weakself.nearbyParamDict removeObjectForKey:@"online"];
[weakself.nearbyParamDict removeObjectForKey:@"new"];
[weakself.nearbyParamDict removeObjectForKey:@"vip"];
}else if ([dict[@"sx_gjsx"] isEqualToString:@"VIP"]) {
weakself.nearbyParamDict[@"online"] = @"0";
weakself.nearbyParamDict[@"new"] = @"0";
weakself.nearbyParamDict[@"vip"] = @"1";
weakself.nearbyParamDict[@"city"] = city;
[weakself.nearbyParamDict removeObjectForKey:@"new"];
[weakself.nearbyParamDict removeObjectForKey:@"online"];
}else if ([dict[@"sx_gjsx"] isEqualToString:@"在线"]) {
weakself.nearbyParamDict[@"online"] = @"1";
weakself.nearbyParamDict[@"new"] = @"0";
weakself.nearbyParamDict[@"vip"] = @"0";
weakself.nearbyParamDict[@"city"] = city;
[weakself.nearbyParamDict removeObjectForKey:@"new"];
[weakself.nearbyParamDict removeObjectForKey:@"vip"];
}else if ([dict[@"sx_gjsx"] isEqualToString:@"新人"]) {
weakself.nearbyParamDict[@"online"] = @"0";
weakself.nearbyParamDict[@"new"] = @"1";
weakself.nearbyParamDict[@"vip"] = @"0";
weakself.nearbyParamDict[@"city"] = city;
[weakself.nearbyParamDict removeObjectForKey:@"online"];
[weakself.nearbyParamDict removeObjectForKey:@"vip"];
}
weakself.shaiXuanDict = dict;
[[NSUserDefaults standardUserDefaults]setObject:weakself.nearbyParamDict forKey:@"UserNearbyShaiXuanParamDict"];
[[NSUserDefaults standardUserDefaults] synchronize];
self.nextPage = 1;
[weakself reloadDataTableViewNT:self.nextPage withCity:city isRecommend:@""];
// [weakself.contentTableView.mj_header beginRefreshing];
};
[[ZcqVender theTopviewControler].view addSubview:alertView];
}
-(UITableView *)contentTableView{
if(!_contentTableView){
_contentTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, self.qmui_navigationBarMaxYInViewCoordinator, SCREEN_WIDTH, SCREEN_HEIGHT - self.qmui_navigationBarMaxYInViewCoordinator) style:UITableViewStyleGrouped];
_contentTableView.scrollEnabled = NO;
_contentTableView.backgroundColor = [UIColor clearColor];
_contentTableView.delegate = self;
_contentTableView.dataSource = self;
_contentTableView.scrollEnabled = YES;
_contentTableView.showsVerticalScrollIndicator = NO;
_contentTableView.showsHorizontalScrollIndicator = NO;
_contentTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_contentTableView.contentInset = UIEdgeInsetsZero;
// _contentTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
if (@available(iOS 11.0, *)) {
} else {
// Fallback on earlier versions
}//安全边距
[_contentTableView registerClass:[BottleUserNearbyTableViewCell class] forCellReuseIdentifier:@"BottleUserNearbyTableViewCell"];
}
return _contentTableView;
}
-(SDCycleScrollView *)cycleScrollView{
if (!_cycleScrollView) {
_cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(17, 10, SCREEN_WIDTH - 34, (SCREEN_WIDTH - 34)*0.45-5) imageNamesGroup:@[@"TH_nearbyBanner00", @"TH_nearbyBanner01", @"TH_nearbyBanner02", @"TH_nearbyBanner03"]];
_cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
_cycleScrollView.autoScrollTimeInterval = 6;
_cycleScrollView.currentPageDotColor = COLOR_WITH_RGB(0xFFFFFF);
_cycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;
_cycleScrollView.pageDotColor =COLOR_WITH_RGB_A(0x000000, 0.7);
// _cycleScrollView.showPageControl
// UIPageControlContentView
_cycleScrollView.delegate = self;
_cycleScrollView.backgroundColor = [UIColor whiteColor];
_cycleScrollView.layer.cornerRadius = 8;
_cycleScrollView.layer.masksToBounds = YES;
}
return _cycleScrollView;
}
-(UIView *)topHeaderView{
if (!_topHeaderView) {
_topHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, self.cycleScrollView.qmui_height + 20)];
_topHeaderView.contentMode = UIViewContentModeScaleAspectFill;
[_topHeaderView addSubview:self.cycleScrollView];
}
return _topHeaderView;
}
-(UIView *)openVipAlertView{
if (!_openVipAlertView) {
// float tabBarHeight = isIphoneX?83:48 + 44 - 44;
_openVipAlertView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 200)];
_openVipAlertView.backgroundColor = COLOR_WITH_RGB_A(0x000000, 0.8);
UILabel* titleLab = [[UILabel alloc]initWithFrame:CGRectMake(0, 20, SCREEN_WIDTH, 28)];
titleLab.text = @"数十万同好等您查看";
titleLab.textAlignment = NSTextAlignmentCenter;
titleLab.font = MT_FONT_BOLD_NO_SCALE_SIZE(20);
titleLab.textColor = COLOR_WITH_RGB(0xFFFFFF);
[_openVipAlertView addSubview:titleLab];
UILabel* subTitleLab = [[UILabel alloc]initWithFrame:CGRectMake(0, titleLab.bottom + 20, SCREEN_WIDTH, 60)];
subTitleLab.text = @"开通VIP后才能查看更多附近的同好也可以根据您的喜好、年龄等筛选想要认识的人还可以获得其他九大会员特权拥有更多不一样的体验~";
subTitleLab.textAlignment = NSTextAlignmentCenter;
subTitleLab.numberOfLines = 0;
subTitleLab.font = MT_FONT_MEDIUM_NO_SCALE_SIZE(14);
subTitleLab.textColor = COLOR_WITH_RGB(0xFFFFFF);
[_openVipAlertView addSubview:subTitleLab];
UIButton* openVipBtn = [[UIButton alloc]initWithFrame:CGRectMake((SCREEN_WIDTH - 132)/2.0, subTitleLab.bottom + 20, 132, 36)];
[openVipBtn setTitle:@"前往开通VIP" forState:UIControlStateNormal];
[openVipBtn setTitleColor:COLOR_WITH_RGB(0x000000) forState:UIControlStateNormal];
openVipBtn.titleLabel.font = MT_FONT_MEDIUM_NO_SCALE_SIZE(14);
openVipBtn.backgroundColor = COLOR_WITH_RGB(0xFFB902);
openVipBtn.layer.cornerRadius = 18;
openVipBtn.layer.masksToBounds = YES;
[openVipBtn addTarget:self action:@selector(openVipBtnClick:) forControlEvents:UIControlEventTouchUpInside];
[_openVipAlertView addSubview:openVipBtn];
}
return _openVipAlertView;
}
- (THLVTipView *)lvTipView {
if (_lvTipView == nil) {
NSArray * xibArray = [[NSBundle mainBundle]loadNibNamed:NSStringFromClass(THLVTipView.class) owner:nil options:nil] ;
_lvTipView = xibArray[0];
_lvTipView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 60);
}
return _lvTipView;
}
-(void)openVipBtnClick:(UIButton*)sender{
[PYAppService showVipVC:@"vip_page"];
}
#pragma mark -tableViewDelegate
//组
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return _tableMDataArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
if (section == 0) {
return 60;
}
return 5;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
if (section == 0) {
return self.lvTipView;
}
return [UIView new];
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
if ([UserService currentUser].isVIP) {
return 0.01;
}
return 200;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
if (![UserService currentUser].isVIP) {
return self.openVipAlertView;
}
return [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 20)];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
userNearbyModel* model = _tableMDataArray[indexPath.row];
if(model.user_photo.length > 0){
return 172 + 15 - 83 + FIX_SIZE(83);
}else{
return 75 + 15;
}
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
userNearbyModel* model = _tableMDataArray[indexPath.row];
[PYAppService showUserCardVCWithUserID:[UserService userIDFromIMUserID:model.nearbyId].intValue];
}
//cell样式
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
BottleUserNearbyTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"BottleUserNearbyTableViewCell"];
if (!cell) {
cell = [[BottleUserNearbyTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"BottleUserNearbyTableViewCell"];
}
cell.shaiXuanDict = _shaiXuanDict;
cell.dataModel = _tableMDataArray[indexPath.row];
return cell;
}
//定位.
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations{
CLLocation* location = [locations lastObject];
CLLocationDegrees lat = location.coordinate.latitude;
CLLocationDegrees lng = location.coordinate.longitude;
NSDictionary* tempDict = [[NSUserDefaults standardUserDefaults]objectForKey:@"UserNearbyShaiXuanParamDict"];
if (!tempDict) {
_nearbyParamDict = [NSMutableDictionary dictionaryWithDictionary:@{}];
}else{
_nearbyParamDict = [NSMutableDictionary dictionaryWithDictionary:tempDict];
}
_nearbyParamDict[@"lat"] = [NSNumber numberWithFloat:lat];
_nearbyParamDict[@"lng"] = [NSNumber numberWithFloat:lng];
[[NSUserDefaults standardUserDefaults]setObject:_nearbyParamDict forKey:@"UserNearbyShaiXuanParamDict"];
[self.contentTableView.mj_header beginRefreshing];
[_cLLocationManager stopUpdatingLocation];
}
//SDCycleScrollViewDelegate
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index{
if (self.bannerArr.count >= index) {
NSString *url = self.bannerArr[index][@"link"];
if ([url isEqualToString: @"https://ikuayou.com/"]) {
UIApplication *app = [UIApplication sharedApplication];
NSURL *URL = [NSURL URLWithString:url];
if ([app canOpenURL:URL]) {
if (@available(iOS 10.0,*)) {
[app openURL:URL options:@{} completionHandler:nil];
} else {
[app openURL:URL];
}
}
} else {
[PYAppService openWebVCWithTitle:self.bannerArr[index][@"title"] url:url];
}
}
// NSArray* dataArray = @[
// @{@"title":@"产品介绍",@"urlStr":@"https://iquanpai.com/app-h5/4_141.html"},
// @{@"title":@"文明公约",@"urlStr":@"https://iquanpai.com/app-h5/4_142.html"},
// @{@"title":@"精选推荐",@"urlStr":@"https://iquanpai.com/app-h5/4_143.html"},
// @{@"title":@"谨防诈骗",@"urlStr":@"https://iquanpai.com/app-h5/4_152.html"},
// ];
// NSDictionary* dataDict = dataArray[index];
// [PYAppService openWebVCWithTitle:dataDict[@"title"] url:dataDict[@"urlStr"]];
}
@end