酷店

KDPCollectHistoryVC.m 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. //
  2. // KDPCollectHistoryVC.m
  3. // KuDianProject
  4. //
  5. // Created by 学丽 on 2019/7/9.
  6. // Copyright © 2019 KDP. All rights reserved.
  7. //
  8. #import "KDPCollectHistoryVC.h"
  9. #import "KDPHistoryListCell.h"
  10. #import "KDPCollectHistoryVC.h"
  11. @interface KDPCollectHistoryVC ()<UITableViewDelegate,UITableViewDataSource,DZNEmptyDataSetDelegate,DZNEmptyDataSetSource>
  12. @property(nonatomic,assign)NSInteger page_num;
  13. @property(nonatomic,strong)UITableView *collectView;
  14. @property(nonatomic,strong)NSMutableArray *dataArray;
  15. @end
  16. @implementation KDPCollectHistoryVC
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. self.page_num = 1;
  20. [self setNavUI];
  21. [self.navBar addleftReturnButton:self selector:@selector(returnClickBtn)];
  22. [self reqeustData];
  23. }
  24. -(void)reqeustData
  25. {
  26. if ([self.pagetype isEqualToString:@"浏览记录"] )
  27. {
  28. [self getCollectAndHistoryDataURL:HisttoryListURL Dic:nil];
  29. }else{
  30. [self getCollectAndHistoryDataURL:CollectURLLIST Dic:@{@"page":@(self.page_num)}];
  31. }
  32. }
  33. #pragma mark---获取数据
  34. -(void)getCollectAndHistoryDataURL:(NSString *)URL Dic:(NSDictionary *)dic
  35. {
  36. [LoadingView show];
  37. [KDPNetworkRequestHTTP postURL:URL params:dic success:^(id _Nonnull json) {
  38. if ([self.pagetype isEqualToString:@"浏览记录"] || self.page_num == 1) {
  39. //灭有分页
  40. [self.dataArray removeAllObjects];
  41. }
  42. NSArray *array =[NSArray yy_modelArrayWithClass:[KDPGoodsModel class] json:json[@"data"]];
  43. [self.collectView.mj_header endRefreshing];
  44. [self.collectView.mj_footer endRefreshing];
  45. if (array.count == 0) {
  46. [self.collectView.mj_footer endRefreshingWithNoMoreData];
  47. }
  48. [self.dataArray addObjectsFromArray:array];
  49. [self.collectView reloadData];
  50. [LoadingView dismiss];
  51. } failure:^(NSError * _Nonnull error) {
  52. [LoadingView dismiss];
  53. }];
  54. }
  55. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  56. {
  57. KDPHistoryListCell *listC=[tableView dequeueReusableCellWithIdentifier:@"hist"];
  58. if (!listC) {
  59. listC=[[KDPHistoryListCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"hist"];
  60. listC.selectionStyle=UITableViewCellSelectionStyleNone;
  61. }
  62. listC.deleteBlock = ^(KDPGoodsModel * _Nonnull deleteModel) {
  63. [self delectListModel:deleteModel];
  64. };
  65. listC.model=self.dataArray[indexPath.row];
  66. return listC;
  67. }
  68. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  69. {
  70. return self.dataArray.count;
  71. }
  72. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  73. {
  74. KDPGoodDetailVC *goodDetail=[[KDPGoodDetailVC alloc]init];
  75. goodDetail.model=self.dataArray[indexPath.row];
  76. [self.navigationController pushViewController:goodDetail animated:YES];
  77. }
  78. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  79. {
  80. return 112;
  81. }
  82. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  83. {
  84. return 1;
  85. }
  86. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView{
  87. return [UIImage imageNamed:@"no_order"];
  88. }
  89. - (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView{
  90. return YES;
  91. }
  92. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView{
  93. return [[NSAttributedString alloc] initWithString:@"还没有记录" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHex:0x333333],NSFontAttributeName:FONT_SYS(12)}];
  94. }
  95. - (CGFloat )spaceHeightForEmptyDataSet:(UIScrollView *)scrollView{
  96. return 30;
  97. }
  98. -(UITableView *)collectView
  99. {
  100. if (!_collectView) {
  101. _collectView=[[UITableView alloc]initWithFrame:CGRectMake(0, KDNavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-KDNavBarHeight)];
  102. _collectView.backgroundColor=[UIColor clearColor];
  103. _collectView.showsVerticalScrollIndicator=NO;
  104. _collectView.showsHorizontalScrollIndicator=NO;
  105. _collectView.emptyDataSetDelegate = self;
  106. _collectView.emptyDataSetSource = self;
  107. _collectView.separatorStyle=UITableViewCellSeparatorStyleNone;
  108. _collectView.delegate=self;
  109. if (@available(iOS 11.0, *)) {
  110. _collectView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  111. } else {
  112. self.automaticallyAdjustsScrollViewInsets = NO;
  113. }
  114. _collectView.dataSource=self;
  115. _collectView.mj_header=[MJRefreshNormalHeader headerWithRefreshingBlock:^{
  116. self.page_num = 1;
  117. [self reqeustData];
  118. }];
  119. _collectView.mj_footer=[MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  120. self.page_num++;
  121. [self reqeustData];
  122. }];
  123. }
  124. return _collectView;
  125. }
  126. -(void)setNavUI
  127. {
  128. self.navBar.hidden=YES;
  129. self.view.backgroundColor=[UIColor colorWithHexString:LineColor];
  130. [self.view addSubview:self.collectView];
  131. }
  132. -(void)returnClickBtn
  133. {
  134. [self.navigationController popViewControllerAnimated:YES];
  135. }
  136. -(void)viewWillAppear:(BOOL)animated
  137. {
  138. [super viewWillAppear:animated];
  139. self.navigationController.navigationBar.hidden=NO;
  140. self.tabBarController.tabBar.hidden=YES;
  141. }
  142. -(NSMutableArray *)dataArray
  143. {
  144. if (!_dataArray) {
  145. _dataArray =[NSMutableArray array];
  146. }
  147. return _dataArray;
  148. }
  149. -(void)delectListModel:(KDPGoodsModel *)model
  150. {
  151. NSString *url =@"";
  152. NSDictionary *dic;
  153. if ([self.pagetype isEqualToString:@"收藏夹"]) {//收藏
  154. url =[NSString stringWithFormat:@"%@api/goods_collect/handelCollection",KDURL];
  155. dic=@{@"goods_id":model.goods_id,@"is_add":@"0"};
  156. }else{
  157. url =[NSString stringWithFormat:@"%@api/brower/recordDelete",KDURL];
  158. dic=@{@"id":model.Id};
  159. }
  160. [LoadingView show];
  161. [KDPNetworkRequestHTTP postURL:url params:dic success:^(id _Nonnull json) {
  162. [self.dataArray removeObject:model];
  163. [self.collectView reloadData];
  164. [LoadingView dismiss];
  165. } failure:^(NSError * _Nonnull error) {
  166. [LoadingView dismiss];
  167. }];
  168. }
  169. @end