酷店

KDPCollectHistoryVC.m 5.9KB

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