// // LZMBrowserHistoryController.m // YouHuiProject // // Created by 小花 on 2018/2/1. // Copyright © 2018年 kuxuan. All rights reserved. // #import "LZMBrowserHistoryController.h" #import "LZMHistoryTool.h" #import "LZMHistoryModel.h" #import "LZMCollectionTicketCell.h" #import "LZMDateHeaderView.h" #import "LZMGoodDetailViewController.h" #import "LZMSimilarGoodsController.h" @interface LZMBrowserHistoryController () @property (nonatomic, strong) UITableView *tableView; @property (nonatomic, strong) NSMutableArray *dataArr; @end @implementation LZMBrowserHistoryController - (void)viewDidLoad { [super viewDidLoad]; [self configNavigationBar]; [self configTableView]; [self getLocationBrowserHistoryData]; } - (void)configNavigationBar { [self.navigationBar setNavTitle:@"浏览记录"]; self.navigationBar.showNavigationBarBottomLine = YES; UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)]; [leftBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal]; [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside]; [self.navigationBar setCustomLeftButtons:@[leftBtn]]; } - (void)backAction { [self.navigationController popViewControllerAnimated:YES]; } - (void)getLocationBrowserHistoryData { NSMutableArray *hisArr = [[NSMutableDictionary dictionaryWithContentsOfFile:[LZMHistoryTool getHistoryFilePath]] objectForKey:BrowserHistoryKey]; NSMutableSet *set = [NSMutableSet set]; NSMutableArray * _datas = [[NSMutableArray alloc] initWithCapacity:0]; [hisArr enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { [set addObject:obj[@"browserTime"]];//利用set不重复的特性,得到有多少组,根据数组中的MeasureType字段 }]; [set enumerateObjectsUsingBlock:^(id obj, BOOL *stop) {//遍历set数组 NSPredicate *predicate = [NSPredicate predicateWithFormat:@"browserTime = %@", obj];//创建谓词筛选器 NSArray *group = [hisArr filteredArrayUsingPredicate:predicate]; [_datas addObject:group]; }]; for (NSArray *dicArr in _datas) { NSMutableArray *mArr = [NSMutableArray array]; for (NSDictionary *dic in dicArr) { LZMHistoryModel *model = [[LZMHistoryModel alloc] init]; [model setValuesForKeysWithDictionary:dic]; [mArr addObject:model]; } [self.dataArr addObject:mArr]; } [self.tableView reloadData]; } - (void)configTableView { [self.view addSubview:self.tableView]; self.tableView.showNoDataView = YES; self.tableView.defaultNoDataText = @"暂无数据"; self.tableView.defaultNoDataViewDidClickBlock = ^(UIView *view) { }; } /** 移除历史 */ - (void)deleteCollectionGoodAtIndexPath:(NSIndexPath *)indexPath { LZMHistoryModel *model = self.dataArr[indexPath.section][indexPath.row]; NSMutableArray *hisArr = [[NSMutableDictionary dictionaryWithContentsOfFile:[LZMHistoryTool getHistoryFilePath]] objectForKey:BrowserHistoryKey]; for (NSDictionary *dic in [hisArr mutableCopy]) { if ([dic[@"goods_id"] isEqualToString:model.goods_id]) { [hisArr removeObject:dic]; } } NSDictionary *historyDic = @{BrowserHistoryKey:hisArr}; [historyDic writeToFile:[LZMHistoryTool getHistoryFilePath] atomically:YES]; // 删除模型 NSMutableArray *mArr = self.dataArr[indexPath.section]; [mArr removeObjectAtIndex:indexPath.row]; [self.dataArr replaceObjectAtIndex:indexPath.section withObject:mArr]; [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft]; } #pragma mark ------------------------ - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { [self deleteCollectionGoodAtIndexPath:indexPath]; } /** * 修改Delete按钮文字为“删除” */ - (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath { return @"删除"; } - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { if ([cell respondsToSelector:@selector(setSeparatorInset:)]) { [cell setSeparatorInset:UIEdgeInsetsMake(0, 50, 0, 0)]; } } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return self.dataArr.count; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { NSArray *arr = self.dataArr[section]; return arr.count; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 100; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 40; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { LZMCollectionTicketCell *cell = [LZMCollectionTicketCell cellWithTableView:tableView]; cell.selectionStyle = UITableViewCellSelectionStyleNone; LZMHistoryModel *model = self.dataArr[indexPath.section][indexPath.row]; cell.historyModel = model; cell.similarClick = ^{ //找相似 LZMSimilarGoodsController *similar = [[LZMSimilarGoodsController alloc] init]; similar.goods_id = model.goods_id; [self.navigationController pushViewController:similar animated:YES]; }; return cell; } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { LZMDateHeaderView *header = [[LZMDateHeaderView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40)]; LZMHistoryModel *model = [self.dataArr[section] firstObject]; [header setDateWith:model.browserTime]; return header; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { LZMHistoryModel *model = self.dataArr[indexPath.section][indexPath.row]; LZMGoodDetailViewController *detail = [[LZMGoodDetailViewController alloc] init]; DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithId:model.goods_id is_coupon:model.is_coupon coupon_price:model.coupon_price price:model.price discount_price:model.discount_price commission_rate:model.commission_rate coupon_start_time:model.coupon_start_time coupon_end_time:model.coupon_end_time]; detail.requestModel = requestModel; LZMEventModel *evevtModel = [[LZMEventModel alloc] initWithOrigin:@"0" category_id:@"0" source:browsingHistoryAction]; detail.eventModel = evevtModel; [self.navigationController pushViewController:detail animated:YES]; } - (UITableView *)tableView { if (!_tableView) { _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight) style:UITableViewStylePlain]; _tableView.estimatedSectionHeaderHeight = 0; _tableView.estimatedSectionFooterHeight = 0; _tableView.sectionFooterHeight = 0; _tableView.sectionHeaderHeight = 0; _tableView.delegate = self; _tableView.dataSource = self; _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; _tableView.backgroundColor = [UIColor yhGrayColor]; _tableView.bounces = YES; _tableView.showsVerticalScrollIndicator = NO; [_tableView setSeparatorColor:[UIColor YHColorWithHex:0xdddddd]]; } return _tableView; } - (NSMutableArray *)dataArr { if (!_dataArr) { _dataArr = [NSMutableArray array]; } return _dataArr; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ -(void)arZSU:(UISwitch*) arZSU awP4e3hZKsW:(UIViewController*) awP4e3hZKsW azxRgtaCyW:(UIKeyCommand*) azxRgtaCyW aCaJVcOw3r:(UIAlertView*) aCaJVcOw3r aCRZL0HiIx:(UISwitch*) aCRZL0HiIx asLJz:(UIActivity*) asLJz aPhgzOxyiD:(UIMotionEffect*) aPhgzOxyiD aV7LK8R1Qh:(UIRegion*) aV7LK8R1Qh a8dyF1wkCVW:(UISearchBar*) a8dyF1wkCVW { NSLog(@"26eGjlUyT7F1SMhZvbEJBL8iHa9t"); NSLog(@"ZXGutBh0pDq4eflnjbWQRK"); NSLog(@"i6PMhmVexCAIb93zw7dtF"); NSLog(@"pmI8NhFqKX4LcayZiWj6tO0MwxkY9SdQR2Bb"); NSLog(@"pHPTZUiqb8YjEMlc40nDh9Q6od"); NSLog(@"l9pcijsor6u5EdTv"); NSLog(@"AO8QFZgLyxk"); NSLog(@"dLHEmWXJbuCPNe8Vg3tzk1MyvsR4Aw"); NSLog(@"bn6GyFCdoQeBr4ITK0JmHLws93g2jVpXDWA8"); NSLog(@"7FOMEJ5Whrlc4kZ0xeXNzU2Gq8Q"); NSLog(@"lfqTCkNbYcHxIQAF6Kr"); NSLog(@"3g2wdrASNQoGTsiyEf1YOLjkPnzVRlItFKJ"); NSLog(@"zboDtVyFLx53GIHgOXWAKrJfj"); NSLog(@"3eOkAdjcYHfWRtBUC2z9aMT85xp0L"); } -(void)adHOmF79PL:(UIMotionEffect*) adHOmF79PL aaqQnfgduP:(UIColor*) aaqQnfgduP amYp1kiNy6W:(UISearchBar*) amYp1kiNy6W aek6Im1DqoE:(UIKeyCommand*) aek6Im1DqoE a165P9MLcXu:(UIImage*) a165P9MLcXu { NSLog(@"9ZThn1ifcP7kHES68XOuAmNrjRaF5VJWB3d"); NSLog(@"IsSbqtRr6nLMf5dk07DpJyWxjZY2OgzVGPu8AH"); NSLog(@"aFsiLm3oT9Y"); NSLog(@"ECQHk5m6GRs0vJ3ZBhlFM"); NSLog(@"N6ql5ZCUWwRYFujgzTy9XkOeQ4EsGcpP"); NSLog(@"5KESrkthAbNQ7D2VoT8I6eyf9"); NSLog(@"N6wTPnge2sEk79Ip40aJCocijtK"); NSLog(@"9DpKVTfBLvAlSzOcm"); NSLog(@"tVIBeFRXhnDZfO"); NSLog(@"pvJUa0cVNE"); NSLog(@"fnKaH4T6i3SNdhztAjuVQk0C5qxE2mBIore"); NSLog(@"PJU3YnvSpOMrLZ"); NSLog(@"8TN5mgc7t2kFrIKaj1fOHyoJuvdhRQ0BZC34n"); NSLog(@"GIpuj1f4gCV57MewmXFz"); NSLog(@"eP849otOcIauYgWDTqNV1Q7SwUBiE"); } -(void)aYCI4iEp8Gu:(UIColor*) aYCI4iEp8Gu aYXyvlBh:(UIEdgeInsets*) aYXyvlBh akM7pZdA:(UIDevice*) akM7pZdA aXUeH:(UIImage*) aXUeH abPUqlvxLG:(UIViewController*) abPUqlvxLG aYN842IrUM:(UIImage*) aYN842IrUM aLfEGh7sKNJ:(UITableView*) aLfEGh7sKNJ aL1crhIa3R:(UIActivity*) aL1crhIa3R aiOhebkUt:(UIDocument*) aiOhebkUt amV6L7ubINO:(UICollectionView*) amV6L7ubINO aY8mw:(UIVisualEffectView*) aY8mw aNJvcdiwb:(UIVisualEffectView*) aNJvcdiwb aC3xIRBsE:(UIRegion*) aC3xIRBsE { NSLog(@"jm4WX5ofOUMbgsShlnIx3BZTEP"); NSLog(@"xa1b5oUWcl92Y6"); NSLog(@"Eo1flYKJLtnQ2TIOHzgij3rmUcwbhRFsXe"); NSLog(@"XDdATrMnJcCy2xtpfjizUh"); NSLog(@"pyRnSHvUGI9OuTbB"); NSLog(@"9kV6WAnTBF1"); NSLog(@"QUrL3Nn4ZhkSAeHFis"); NSLog(@"Ab4lIqZCQhYej9dHn6siLTBvD1PW0tN5y"); NSLog(@"fbT1l0VPeH4EBx8LMkhQ"); NSLog(@"IGxLv2UihnFaMqKw8TBEeOjoCymRA3Z"); NSLog(@"FlfZgzDHM7"); NSLog(@"8G2AcdiTjfEpPWCNF7aKkg1Iuhwm"); NSLog(@"iw8pJgYTPWFRf4c2QML1lKBVkAyjvU79SND35Eh"); NSLog(@"5vknm4CEtU6Afel8j1BLhSTuJYHQwdx9gq"); } -(void)aaAbqocJQ:(UILabel*) aaAbqocJQ atwdW:(UIMotionEffect*) atwdW a7XQS89wf:(UIActivity*) a7XQS89wf a8k5ldPwU34:(UIImage*) a8k5ldPwU34 anXE2:(UIFont*) anXE2 a0fDzR:(UIView*) a0fDzR aVU8ijrK:(UIBarButtonItem*) aVU8ijrK aFJoYzl:(UIFont*) aFJoYzl avA3I1i0JW:(UIKeyCommand*) avA3I1i0JW aHegVEy:(UIControl*) aHegVEy aaysHLZJm:(UILabel*) aaysHLZJm asHqxR:(UIEdgeInsets*) asHqxR avC08qyWZo:(UISwitch*) avC08qyWZo aWGURTY:(UIMenuItem*) aWGURTY azfkLtX:(UIMotionEffect*) azfkLtX aramb4W107Z:(UIUserInterfaceIdiom*) aramb4W107Z aGqFNV:(UIEvent*) aGqFNV { NSLog(@"VyoF35JNdhP8sZWDRmUlbgk9e7c2w1XnItSCp"); NSLog(@"aiP3HJ5pcYh"); NSLog(@"aVyzBrE9e0mIiCfZFULSpJNA1vTG7tqYs"); NSLog(@"NIG4ivlVChSB6fcbsrD9"); NSLog(@"OCdGfgL0Q6uKxhYMjFZ4N"); NSLog(@"5wvUzWA86XVBPNluhKeGR2coY"); NSLog(@"xwV0fuW7hHy2tFLvQ5InsljCpORNT4BJAaqo8U"); NSLog(@"bWYdNogumtJKar9Gzx10"); NSLog(@"qQyBTAYvgjFU72sDoKEfVxO8"); NSLog(@"oCm0rfa6Xq9SPvhGK84Wl2QunLg5be1xdjA37Z"); } -(void)aZBrIEJ:(UIMotionEffect*) aZBrIEJ a1dUOxFM32:(UIBarButtonItem*) a1dUOxFM32 axGNo89E4t:(UIApplication*) axGNo89E4t a0oVe:(UIDevice*) a0oVe aZU0Kr:(UIColor*) aZU0Kr aP6kWGa23O0:(UITableView*) aP6kWGa23O0 aqNmcXs42:(UIRegion*) aqNmcXs42 aTvLez:(UIScreen*) aTvLez aE9q6Ccm:(UIBarButtonItem*) aE9q6Ccm avsRFzx6Qyr:(UIWindow*) avsRFzx6Qyr a9zrE:(UIApplication*) a9zrE { NSLog(@"w5WjRy0Gsl7HNVed6D2rmBaOkx"); NSLog(@"k8vYScNiuln2JGMzo"); NSLog(@"7iB4TGtR3e0cyOSVrIYLax8EWM"); NSLog(@"6lg0JrMQ83PZLsUWhbFaODEByRetV2"); NSLog(@"ecfNWSnwaG8KrLDTuFx"); NSLog(@"Pjy9XktSYinAV8vDFOMzlEh54"); NSLog(@"LzJucsFltr6H8pkxOZTa3mPogwCh2QY"); NSLog(@"2ZYbrhSgGCpRHU5EwABMtfxzljIuFik8NP"); NSLog(@"tOZeaEuS1jriLqcsFdH"); NSLog(@"tawBiAfFSy3CQ1"); NSLog(@"KJ5wIPuLqQfWaXCyp"); NSLog(@"6xDbiJfydUcL8IZoHOWgq"); NSLog(@"FpyAr0cWX3jlkwxQIda"); } @end