Commit 94c9f6e5 authored by admin's avatar admin

修复首页 搜索 排名列表崩溃的bug

parent 04e044ce
......@@ -112,4 +112,7 @@
// 获取口碑列表
#define kQueryShortPraiseURL @"redstar-server/rest/praise/query_short?userUuid="
// 获取下级组织
#define kQueryLowerOrgsURL @"redstar-server/rest/organization/queryLowerOrgs"
#endif /* Url_h */
......@@ -15,7 +15,7 @@
if (!_checkBoxButton) {
_checkBoxButton = [[CheckBoxButton alloc] init];
[_checkBoxButton setTitleColor:kLightBlack forState:UIControlStateNormal];
// [_checkBoxButton setTitleColor:kSelectStoreColor forState:UIControlStateSelected];
[_checkBoxButton setTitleColor:kSelectStoreColor forState:UIControlStateSelected];
_checkBoxButton.titleLabel.font = [UIFont systemFontOfSize:17.0];
_checkBoxButton.translatesAutoresizingMaskIntoConstraints = NO;
[_checkBoxButton setImage:[UIImage imageNamed:@"uncheck_box"] forState:UIControlStateNormal];
......
......@@ -14,5 +14,4 @@
@property (nonatomic, strong) CheckBoxButton *checkBoxButton;
@property (nonatomic, strong) UIImageView *iconImageView;
@property (nonatomic, strong) ProvinceModel *provinceModel;
@end
......@@ -24,7 +24,6 @@
_checkBoxButton.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
_checkBoxButton.imageView.contentMode = UIViewContentModeRight;
_checkBoxButton.titleLabel.contentMode = UIViewContentModeLeft;
[_checkBoxButton addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:_checkBoxButton];
// 顶端
......@@ -45,10 +44,6 @@
}
return _checkBoxButton;
}
- (void)click:(CheckBoxButton *)sender
{
sender.selected = !sender.selected;
}
- (UIImageView *)iconImageView
{
......
......@@ -81,7 +81,6 @@
_checkBoxButton.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
_checkBoxButton.imageView.contentMode = UIViewContentModeRight;
_checkBoxButton.titleLabel.contentMode = UIViewContentModeLeft;
[_checkBoxButton addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:_checkBoxButton];
// 顶端
......@@ -102,10 +101,6 @@
}
return _checkBoxButton;
}
- (void)click:(CheckBoxButton *)sender
{
sender.selected = !sender.selected;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
......
......@@ -24,6 +24,8 @@
#import "SelectStoreHeadView.h"
#import "CheckBoxButton.h"
#import "HttpClient.h"
@interface SelectStoreViewController () <RATreeViewDelegate, RATreeViewDataSource>
@property (nonatomic, strong) RATreeView *treeView;
@property (nonatomic, strong) NSMutableArray *allAreaData;
......@@ -64,6 +66,8 @@
[self.treeView registerClass:[UITableViewCell class] forCellReuseIdentifier:NSStringFromClass([UITableViewCell class])];
self.treeView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.treeView reloadData];
[self requestQueryLowerOrgs];
}
- (void)doBack:(id)sender
......@@ -71,9 +75,18 @@
[self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
- (void)requestQueryLowerOrgs
{
NSString *url = [NSString stringWithFormat:@"%@%@", kRedStarURL, kQueryLowerOrgsURL];
HttpClient *httpClient = [[HttpClient alloc] initWithUrl:url];
NSDictionary *parameters = @{@"path":@"",
@"pageNumber":@(0),
@"pageSize":@(10)
};
[httpClient queryLowerOrgsWithParameters:parameters completion:^(id response, NSError *error) {
NSLog(@"查询下级组织 reponse = %@,error = %@", response, error);
}];
}
- (void)loadData
......@@ -107,27 +120,51 @@
}
#pragma mark - TreeView Cell Click
- (void)areaClick:(CheckBoxButton *)sender
{
sender.selected = !sender.selected;
NSLog(@"ender.title= %@", sender.titleLabel.text);
SelectAreaTableCell *cell = (SelectAreaTableCell *)sender.superview.superview;
NSArray *provinceArray = cell.areaModel.provinceArray;
id item = [_treeView itemForCell:cell];
AreaModel *area = cell.areaModel;
if (sender.selected) {
for (ProvinceModel *proVin in provinceArray) {
proVin.isChoose = YES;
for (ProvinceModel *pro in area.provinceArray) {
pro.isChoose = YES;
}
[sender setTitleColor:kLightBlack forState:UIControlStateNormal];
} else {
for (ProvinceModel *proVin in provinceArray) {
proVin.isChoose = NO;
for (ProvinceModel *pro in area.provinceArray) {
pro.isChoose = NO;
}
[sender setTitleColor:kSelectStoreColor forState:UIControlStateNormal];
}
[_treeView reloadRowsForItems:@[item] withRowAnimation:RATreeViewRowAnimationNone];
// [_treeView expandRowForItem:item withRowAnimation:RATreeViewRowAnimationNone];
//[_treeView expandRowForItem:item expandChildren:YES withRowAnimation:RATreeViewRowAnimationFade];
}
- (void)provinceClick:(CheckBoxButton *)sender
{
sender.selected = !sender.selected;
SelectProvinceTableCell *cell = (SelectProvinceTableCell *)sender.superview.superview;
ProvinceModel *province = cell.provinceModel;
if (sender.selected) {
for (StoreModel *store in province.storeArray) {
store.isChoose = YES;
}
} else {
for (StoreModel *store in province.storeArray) {
store.isChoose = NO;
}
}
[_treeView reloadRows];
//[_treeView reloadData];
}
- (void)storeClick:(CheckBoxButton *)sender
{
sender.selected = !sender.selected;
}
#pragma mark - RAtreeView Delegate/DataSource
- (NSInteger)treeView:(RATreeView *)treeView numberOfChildrenOfItem:(id)item
......@@ -171,8 +208,8 @@
SelectAreaTableCell *cell = [self.treeView dequeueReusableCellWithIdentifier:kSelectAreaTableCell];
cell.areaModel = data;
[cell.checkBoxButton setTitle:data.name forState:UIControlStateNormal];
[cell.checkBoxButton addTarget:self action:@selector(areaClick:) forControlEvents:UIControlEventTouchUpInside];
cell.iconImageView.image = [UIImage imageNamed:@"arrow_down"];
[cell.checkBoxButton addTarget:self action:@selector(areaClick:) forControlEvents:UIControlEventTouchUpInside];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
} else if (level == 1) {
......@@ -185,17 +222,17 @@
cell.checkBoxButton.selected = NO;
}
[cell.checkBoxButton setTitle:data.name forState:UIControlStateNormal];
[cell.checkBoxButton addTarget:self action:@selector(provinceClick:) forControlEvents:UIControlEventTouchUpInside];
cell.iconImageView.image = [UIImage imageNamed:@"grey-trilateral_down"];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
} else {
StoreModel *data = item;
SelectStoreTableCell *cell = [self.treeView dequeueReusableCellWithIdentifier:kSelectStoreTableCell];
cell.storeModel = data;
[cell.checkBoxButton setTitle:data.name forState:UIControlStateNormal];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[cell.checkBoxButton addTarget:self action:@selector(storeClick:) forControlEvents:UIControlEventTouchUpInside];
return cell;
}
}
......
......@@ -498,10 +498,10 @@
if (!_rankDetailHeaderView) {
_rankDetailHeaderView = [[RankDetailHeaderView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 298)];
if (self.indexRow < 3) {
NSString *imageName = [NSString stringWithFormat:@"medal_0%ld", (long)(_indexRow + 1)];
NSString *imageName = [NSString stringWithFormat:@"medal_0%ld", (long)(_indexRow)];
_rankDetailHeaderView.rankDetailView.gradeImageView.image = [UIImage imageNamed:imageName];
} else {
NSString *rankStr = [NSString stringWithFormat:@"第 %ld 名", (long)(_indexRow + 1)];
NSString *rankStr = [NSString stringWithFormat:@"第 %ld 名", (long)(_indexRow)];
NSMutableAttributedString *rankAttr = [[NSMutableAttributedString alloc] initWithString:rankStr];
[rankAttr addAttributes:@{NSForegroundColorAttributeName:kRankHeadTitleTextColor,NSFontAttributeName:[UIFont systemFontOfSize:14.0f]} range:NSMakeRange(0,1)];
[rankAttr addAttributes:@{NSForegroundColorAttributeName:kGradeNumberTextColor} range:NSMakeRange(1,rankStr.length - 2)];
......
......@@ -95,7 +95,6 @@
_pickRow = 0;
[self requestShortPraise];
[self requestRankingList];
self.shoppingLabel.text = @"商场名称";
self.scoreLabel.text = @"总分";
......@@ -116,12 +115,12 @@
}
#pragma mark - Private Methods
- (void)requestRankingList
- (void)requestRankingListWithPraiseUuid:(NSString *)praiseUuid
{
NSString *url = [NSString stringWithFormat:@"%@%@", kRedStarURL, kRankingListURL];
HttpClient *httpCilent = [[HttpClient alloc] initWithUrl:url];
NSDictionary *parameters = @{@"praiseUuid":@"5a7417015147f8eb0151482b2359005b",
NSDictionary *parameters = @{@"praiseUuid":praiseUuid,
@"statisMode":@(0),
};
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
......@@ -179,6 +178,13 @@
self.tableView.dataSource = self;
[self.tableView reloadData];
}
if (_titleArray.count == 0) {
return ;
} else {
NSDictionary *paDict = _titleArray[0];
[self requestRankingListWithPraiseUuid:paDict[@"uuid"]];
}
}];
}
......@@ -454,7 +460,6 @@
rankDetailVC.uuid = rankList.uuid;
rankDetailVC.store_uuid = rankList.store_uuid;
rankDetailVC.storeAddress = rankList.storeAddress;
NSLog(@"storeAddress = %@", rankList.storePictures);
rankDetailVC.storePictures = rankList.storePictures;
[self.navigationController pushViewController:rankDetailVC animated:YES];
}
......
......@@ -130,6 +130,7 @@ typedef NSComparisonResult (^NSComparator)(id obj1, id obj2);
}
[[NSUserDefaults standardUserDefaults] setObject:_titleArray forKey:@"function"];
NSLog(@"-title = =%@", _titleArray);
// 初始化容器
// self.btnTitleArray = [NSArray arrayWithObjects:@"在线抽查", @"口碑巡检",@"口碑标准",@"图说口碑",@"问题知识",@"口碑排名",@"查看抽查", nil];
......@@ -293,19 +294,16 @@ typedef NSComparisonResult (^NSComparator)(id obj1, id obj2);
NSString *url = [NSString stringWithFormat:@"%@%@", kRedStarURL, kRankingListURL];
HttpClient *httpCilent = [[HttpClient alloc] initWithUrl:url];
NSDictionary *parameters = @{
@"queryOrders":@[@{@"direction":@"asc"}],
@"pageNumber":@(0),
@"pageSize":@(3)
NSDictionary *parameters = @{@"praiseUuid":@"5a7417015157efa6015158f52be8004e",
@"statisMode":@(0),
};
[httpCilent getRankingListWithParameters:parameters completion:^(id response, NSError *error) {
NSLog(@"口碑排名response = %@", response);
NSLog(@"error = %@", error);
if ([(NSArray *)response[@"data"] count] == 0) {
return;
}
NSDictionary *dataDict = response[@"data"];
NSArray *dataArray = dataDict[@"records"];
NSArray *dataArray = response[@"data"];
NSMutableArray *tgArray = [NSMutableArray array];
......@@ -314,6 +312,17 @@ typedef NSComparisonResult (^NSComparator)(id obj1, id obj2);
[tgArray addObject:rankList];
}
_allRankListArray = (NSMutableArray *)[self sortRankListWithRankListArray:tgArray];
for (int i = 0 ; i < _allRankListArray.count; i++) {
RankListModel *rank = _allRankListArray[i];
if (i == 0) {
rank.index = i + 1;
} else {
RankListModel *prevRank = _allRankListArray[i-1];
rank.index = rank.score == prevRank.score ? prevRank.index: i + 1;
}
}
[self.tableView reloadData];
[MBProgressHUD hideHUDForView:self.view animated:YES];
......@@ -550,27 +559,6 @@ typedef NSComparisonResult (^NSComparator)(id obj1, id obj2);
} else {
return 0;
}
// if (_titleArray.count == 5) {
// if (section == 0) {
// return _taskListDataArray.count;
// } else {
// return _allQuestionArray.count;
// }
// } else {
//
// if (section == 0) {
// return _taskListDataArray.count;
//
// } else if (section == 1 ) {
// return _allRankListArray.count + 1;
//
// } else {
// return _allQuestionArray.count;
//
// }
// }
}
......@@ -608,8 +596,9 @@ typedef NSComparisonResult (^NSComparator)(id obj1, id obj2);
if (!cell) {
cell = [[RankingListCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kHomeRankingListCell];
}
cell.rankList = _allRankListArray[indexPath.row - 1];
cell.gradeImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"medal_0%d", (int)indexPath.row]];
RankListModel *rankList = _allRankListArray[indexPath.row - 1];
cell.rankList = rankList;
cell.gradeImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"medal_0%d", rankList.index]];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
......@@ -650,7 +639,7 @@ typedef NSComparisonResult (^NSComparator)(id obj1, id obj2);
} else if ([titleArray[indexPath.section] isEqualToString:@"口碑排名"] && indexPath.section == s2) {
RankListModel *rankList = _allRankListArray[indexPath.row - 1];
RankDetailViewController *rankDetailVC = [[RankDetailViewController alloc] init];
rankDetailVC.indexRow = indexPath.row - 1;
rankDetailVC.indexRow = rankList.index;
rankDetailVC.uuid = rankList.uuid;
rankDetailVC.store_uuid = rankList.store_uuid;
rankDetailVC.storeAddress = rankList.storeAddress;
......
......@@ -64,7 +64,8 @@
- (void)viewDidLoad {
[super viewDidLoad];
NSMutableArray *titleArray = [[NSUserDefaults standardUserDefaults] objectForKey:@"function"];
//NSMutableArray *titleArray = [[NSUserDefaults standardUserDefaults] objectForKey:@"function"];
NSArray *titleArray = [NSArray arrayWithObjects:@"口碑巡检",@"口碑排名",@"问题知识", nil];
self.titleArray = [NSMutableArray arrayWithArray:titleArray];
UILabel *customLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
......@@ -215,24 +216,33 @@
NSString *url1 = [NSString stringWithFormat:@"%@%@", kRedStarURL, kRankingListURL];
HttpClient *httpCilent1 = [[HttpClient alloc] initWithUrl:url1];
NSDictionary *parameters1 = @{
@"keyword":self.customStr,
@"queryOrders":@[@{@"direction":@"asc"}],
@"pageNumber":@(0),
@"pageSize":@(10)
};
__block SearchViewController *weakSelf = self;
@"praiseUuid":@"5a7417015157efa6015158f52be8004e",
@"statisMode":@(0),
@"keyword":self.customStr
};
[httpCilent1 getRankingListWithParameters:parameters1 completion:^(id response, NSError *error) {
NSLog(@"口碑排名response = %@", response);
NSDictionary *dataDict = response[@"data"];
NSArray *dataArray = dataDict[@"records"];
if ([(NSArray *)response[@"data"] count] == 0) {
return;
}
NSArray *dataArray = response[@"data"];
NSMutableArray *rankTempArr = [NSMutableArray array];
for (NSDictionary *ListDict in dataArray) {
RankListModel *rankList = [RankListModel rankListModelWithDict:ListDict];
[rankTempArr addObject:rankList];
}
weakSelf.allRankListArray = rankTempArr;
_allRankListArray = (NSMutableArray *)[self sortRankListWithRankListArray:rankTempArr];
for (int i = 0 ; i < _allRankListArray.count; i++) {
RankListModel *rank = _allRankListArray[i];
if (i == 0) {
rank.index = i + 1;
} else {
RankListModel *prevRank = _allRankListArray[i-1];
rank.index = rank.score == prevRank.score ? prevRank.index: i + 1;
}
}
if (_allRankListArray.count != 0) {
if (![_titleArray containsObject:@"口碑排名"]) {
......@@ -246,6 +256,14 @@
}
- (NSArray *)sortRankListWithRankListArray:(NSMutableArray *)allRanking
{
NSArray *sortedArray = [allRanking sortedArrayUsingComparator:^NSComparisonResult(RankListModel *p1, RankListModel *p2){
return [p2.score compare:p1.score];
}];
return sortedArray;
}
- (void)requestAllQuestion
{
NSString *url2 = [NSString stringWithFormat:@"%@%@", kRedStarURL, kQuestionListURL];
......@@ -351,8 +369,9 @@
if (!cell) {
cell = [[RankingListCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kHomeRankingListCell];
}
cell.rankList = _allRankListArray[indexPath.row - 1];
cell.gradeImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"medal_0%d", (int)indexPath.row]];
RankListModel *rankList = _allRankListArray[indexPath.row - 1];
cell.rankList = rankList;
cell.gradeImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"medal_0%d", rankList.index]];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
......
......@@ -119,4 +119,7 @@ typedef void (^completionBlock) (id response, NSError *error);
// 获取口碑列表
- (void)queryShortPraiseWithCompletion:(completionBlock)completion;
// 查询下级参数
- (void)queryLowerOrgsWithParameters:(id)parameters completion:(completionBlock)completion;
@end
......@@ -407,4 +407,14 @@
}];
}
//
- (void)queryLowerOrgsWithParameters:(id)parameters completion:(completionBlock)completion
{
[self postParameters:parameters completion:^(id response, NSError *error) {
if (completion) {
completion (response, error);
}
}];
}
@end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment