// // KDPCollectHistoryVC.m // KuDianProject // // Created by 学丽 on 2019/7/9. // Copyright © 2019 KDP. All rights reserved. // #import "KDPCollectHistoryVC.h" #import "KDPHistoryListCell.h" #import "KDPCollectHistoryVC.h" @interface KDPCollectHistoryVC () @property(nonatomic,assign)NSInteger page_num; @property(nonatomic,strong)UITableView *collectView; @property(nonatomic,strong)NSMutableArray *dataArray; @end @implementation KDPCollectHistoryVC - (void)viewDidLoad { [super viewDidLoad]; self.page_num = 1; [self setNavUI]; UIButton *returnBtn =[[UIButton alloc]initWithFrame:CGRectMake(0, KDStatusHeight, 0, 0)]; [returnBtn setImage:[UIImage imageNamed:@"return_white"] forState:UIControlStateNormal]; [returnBtn addTarget:self action:@selector(returnClickBtn) forControlEvents:UIControlEventTouchUpInside]; self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithCustomView:returnBtn]; [self reqeustData]; } -(void)reqeustData { if ([self.pagetype isEqualToString:@"浏览记录"] ) { [self getCollectAndHistoryDataURL:HisttoryListURL Dic:nil]; }else{ [self getCollectAndHistoryDataURL:CollectURLLIST Dic:@{@"page":@(self.page_num)}]; } } #pragma mark---获取数据 -(void)getCollectAndHistoryDataURL:(NSString *)URL Dic:(NSDictionary *)dic { [LoadingView show]; [KDPNetworkRequestHTTP postURL:URL params:dic success:^(id _Nonnull json) { if ([self.pagetype isEqualToString:@"浏览记录"] || self.page_num == 1) { //灭有分页 [self.dataArray removeAllObjects]; } NSArray *array =[NSArray yy_modelArrayWithClass:[KDPGoodsModel class] json:json[@"data"]]; [self.collectView.mj_header endRefreshing]; [self.collectView.mj_footer endRefreshing]; if (array.count == 0) { [self.collectView.mj_footer endRefreshingWithNoMoreData]; } [self.dataArray addObjectsFromArray:array]; [self.collectView reloadData]; [LoadingView dismiss]; } failure:^(NSError * _Nonnull error) { [LoadingView dismiss]; }]; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { KDPHistoryListCell *listC=[tableView dequeueReusableCellWithIdentifier:@"hist"]; if (!listC) { listC=[[KDPHistoryListCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"hist"]; listC.selectionStyle=UITableViewCellSelectionStyleNone; } listC.deleteBlock = ^(KDPGoodsModel * _Nonnull deleteModel) { [self delectListModel:deleteModel]; }; listC.model=self.dataArray[indexPath.row]; return listC; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.dataArray.count; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { KDPGoodDetailVC *goodDetail=[[KDPGoodDetailVC alloc]init]; goodDetail.model=self.dataArray[indexPath.row]; [self.navigationController pushViewController:goodDetail animated:YES]; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 112; } -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView{ return [UIImage imageNamed:@"no_order"]; } - (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView{ return YES; } - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView{ return [[NSAttributedString alloc] initWithString:@"还没有记录" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHex:0x333333],NSFontAttributeName:FONT_SYS(12)}]; } - (CGFloat )spaceHeightForEmptyDataSet:(UIScrollView *)scrollView{ return 30; } -(UITableView *)collectView { if (!_collectView) { _collectView=[[UITableView alloc]initWithFrame:CGRectMake(0, KDNavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-KDNavBarHeight)]; _collectView.backgroundColor=[UIColor clearColor]; _collectView.showsVerticalScrollIndicator=NO; _collectView.showsHorizontalScrollIndicator=NO; _collectView.emptyDataSetDelegate = self; _collectView.emptyDataSetSource = self; _collectView.separatorStyle=UITableViewCellSeparatorStyleNone; _collectView.delegate=self; if (@available(iOS 11.0, *)) { _collectView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; } else { self.automaticallyAdjustsScrollViewInsets = NO; } _collectView.dataSource=self; _collectView.mj_header=[MJRefreshNormalHeader headerWithRefreshingBlock:^{ self.page_num = 1; [self reqeustData]; }]; _collectView.mj_footer=[MJRefreshBackNormalFooter footerWithRefreshingBlock:^{ self.page_num++; [self reqeustData]; }]; } return _collectView; } -(void)setNavUI { self.navBar.hidden=YES; self.view.backgroundColor=[UIColor colorWithHexString:LineColor]; [self.view addSubview:self.collectView]; } -(void)returnClickBtn { [self.navigationController popViewControllerAnimated:YES]; } -(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; self.navigationController.navigationBar.hidden=NO; self.tabBarController.tabBar.hidden=YES; } -(NSMutableArray *)dataArray { if (!_dataArray) { _dataArray =[NSMutableArray array]; } return _dataArray; } -(void)delectListModel:(KDPGoodsModel *)model { NSString *url =@""; NSDictionary *dic; if ([self.pagetype isEqualToString:@"收藏夹"]) {//收藏 url =[NSString stringWithFormat:@"%@api/goods_collect/handelCollection",KDURL]; dic=@{@"goods_id":model.goods_id,@"is_add":@"0"}; }else{ url =[NSString stringWithFormat:@"%@api/brower/recordDelete",KDURL]; dic=@{@"id":model.Id}; } [LoadingView show]; [KDPNetworkRequestHTTP postURL:url params:dic success:^(id _Nonnull json) { [self.dataArray removeObject:model]; [self.collectView reloadData]; [LoadingView dismiss]; } failure:^(NSError * _Nonnull error) { [LoadingView dismiss]; }]; } @end