123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- //
- // 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 ()<UITableViewDelegate,UITableViewDataSource,DZNEmptyDataSetDelegate,DZNEmptyDataSetSource>
- @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];
- [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
|