MyCollectController.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. //
  2. // MyCollectController.m
  3. // ZhongJingLianMeng
  4. //
  5. // Created by vinDesel on 2018/11/16.
  6. // Copyright © 2018年 youke. All rights reserved.
  7. //
  8. #import "MyCollectController.h"
  9. #import "HttpRequestManger.h"
  10. #import "OrderListEmptyView.h"
  11. #import "newNoImageCell.h"
  12. #import "newImageCell.h"
  13. #import "MyClollectModel.h"
  14. #import "newsDetailVController.h"
  15. #import "activityDetailVController.h"
  16. @interface MyCollectController ()<UITableViewDelegate,UITableViewDataSource>
  17. {
  18. CGFloat viewHeight;
  19. }
  20. @property (nonatomic, strong) UITableView *TableView;
  21. @property (nonatomic, strong) NSMutableArray *listArray;
  22. @property (nonatomic, strong) NSMutableArray *ListDataSource;
  23. @property (strong, nonatomic) HttpRequestManger *sessionManager;
  24. @property (strong, nonatomic) OrderListEmptyView *saleEmpty;
  25. //列表上一次的请求参数
  26. @property (nonatomic, strong) NSDictionary *params;
  27. //当前页码
  28. @property (nonatomic, assign) NSInteger Page;
  29. @property (nonatomic, assign) BOOL isLoading;
  30. @property (nonatomic, strong) MyClollectModel *MyClollectModel;
  31. @end
  32. @implementation MyCollectController
  33. - (OrderListEmptyView *)saleEmpty
  34. {
  35. if (!_saleEmpty) {
  36. _saleEmpty = [[NSBundle mainBundle]loadNibNamed:@"OrderListEmptyView" owner:self options:nil].firstObject;
  37. _saleEmpty.signLabel.text = @"暂无数据";
  38. [_saleEmpty.actionButton setTitle:@"立即关注" forState:UIControlStateNormal];
  39. _saleEmpty.actionButton.layer.masksToBounds = YES;
  40. _saleEmpty.actionButton.layer.cornerRadius = 2.0f;
  41. // [_collectEmpty.actionButton addTarget:self action:@selector(actionButtonClick:) forControlEvents:UIControlEventTouchUpInside];
  42. }
  43. return _saleEmpty;
  44. }
  45. - (HttpRequestManger*) sessionManager{
  46. if (!_sessionManager) {
  47. _sessionManager = [[HttpRequestManger alloc]init];
  48. }
  49. return _sessionManager;
  50. }
  51. - (NSMutableArray *)ListDataSource
  52. {
  53. if (!_ListDataSource) {
  54. _ListDataSource = [NSMutableArray array];
  55. }
  56. return _ListDataSource;
  57. }
  58. - (void)viewDidLoad {
  59. [super viewDidLoad];
  60. // Do any additional setup after loading the view.
  61. WS(weakSelf);
  62. self.navigationView.hidden = NO;
  63. [self.navigationView setNavigationBackgroundColor:[UIColor colorWithHexValue:0x3C915C]];
  64. [self.navigationView removeAllLeftButton];
  65. [self.navigationView addLeftButtonWithImage:[UIImage imageNamed:@"whiteBack"] clickCallBack:^(UIView *view) {
  66. [weakSelf.navigationController popViewControllerAnimated:YES];
  67. }];
  68. [self.navigationView setTitle:@"我的收藏"];
  69. self.navigationView.titleLabel.textColor=[UIColor whiteColor];
  70. if (IS_IPHONE_X) {
  71. viewHeight =88;
  72. }else{
  73. viewHeight = 64;
  74. }
  75. [self setupView];
  76. }
  77. - (void)viewWillAppear:(BOOL)animated
  78. {
  79. [super viewWillAppear:animated];
  80. [self TabSetupRefresh];
  81. }
  82. #pragma 列表数据请求
  83. - (void)TabSetupRefresh
  84. {
  85. [self.TableView.mj_header beginRefreshing];
  86. }
  87. //加载最新数据
  88. - (void)TabloadNews
  89. {
  90. WS(weakSelf);
  91. NSMutableDictionary *params = [NSMutableDictionary dictionary];
  92. params[@"pageNum"] = @"1";
  93. params[@"pageSize"] = @"10";
  94. weakSelf.params = params;
  95. [ProgressHUD show];
  96. [self.sessionManager sendPostHttpRequestWithUrl:Mycollect params:params bodyBlock:nil progress:nil success:^(NSDictionary *response) {
  97. [ProgressHUD hide];
  98. [weakSelf.TableView.mj_header endRefreshing];
  99. weakSelf.listArray = [response objectForKeySafely:@"collectList"];
  100. weakSelf.ListDataSource = [MyClollectModel mj_objectArrayWithKeyValuesArray:weakSelf.listArray];
  101. if (weakSelf.listArray.count == 0) {
  102. weakSelf.saleEmpty.frame = weakSelf.view.bounds;
  103. weakSelf.saleEmpty.actionButton.hidden = YES;
  104. [weakSelf.TableView addSubview:weakSelf.saleEmpty];
  105. }else{
  106. [weakSelf.saleEmpty removeFromSuperview];
  107. }
  108. [weakSelf.TableView reloadData];
  109. weakSelf.Page = 1;
  110. } failure:^(NSError *error) {
  111. [ProgressHUD hide];
  112. [weakSelf.TableView.mj_header endRefreshing];
  113. }];
  114. }
  115. //加载更多
  116. - (void)TabloadMoreTopics
  117. {
  118. WS(weakSelf);
  119. _isLoading = YES;
  120. self.Page ++;
  121. NSNumber *current = [NSNumber numberWithInt:(int)self.Page];
  122. NSMutableDictionary *params = [NSMutableDictionary dictionary];
  123. params[@"pageNum"] = current;
  124. params[@"pageSize"] = @"10";
  125. [ProgressHUD show];
  126. weakSelf.params = params;
  127. [self.sessionManager sendPostHttpRequestWithUrl:Mycollect params:params bodyBlock:nil progress:nil success:^(NSDictionary *response) {
  128. [ProgressHUD hide];
  129. [weakSelf.TableView.mj_footer endRefreshing];
  130. if (weakSelf.params != params) return;
  131. weakSelf.listArray = [response objectForKeySafely:@"collectList"];
  132. if (weakSelf.listArray.count > 0) {
  133. NSArray *array = [MyClollectModel mj_objectArrayWithKeyValuesArray:weakSelf.listArray];
  134. [weakSelf.ListDataSource addObjectsFromArray:array];
  135. }else{
  136. if (weakSelf.Page > 1) {
  137. weakSelf.Page--;
  138. [ToastView showToast:@"暂无更多数据"];
  139. }
  140. }
  141. [weakSelf.TableView reloadData];
  142. } failure:^(NSError *error) {
  143. [ProgressHUD hide];
  144. [weakSelf.TableView.mj_footer endRefreshing];
  145. }];
  146. }
  147. - (void)setupView
  148. {
  149. _TableView = [[UITableView alloc] initWithFrame:CGRectMake(0, viewHeight, SCREEN_WIDTH, SCREEN_HEIGHT - viewHeight)];
  150. _TableView.delegate = self;
  151. _TableView.dataSource = self;
  152. _TableView.showsVerticalScrollIndicator = NO;
  153. _TableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  154. _TableView.backgroundColor = RGBColor(243, 244, 246);
  155. //去掉多余的分割线
  156. WS(weakSelf);
  157. weakSelf.TableView.tableFooterView = [[UIView alloc]init];
  158. // 下拉刷新
  159. weakSelf.TableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(TabloadNews)];
  160. weakSelf.TableView.mj_header.automaticallyChangeAlpha = YES;
  161. // 上拉加载
  162. weakSelf.TableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(TabloadMoreTopics)];
  163. if (@available(iOS 11.0, *)) {
  164. _TableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  165. }else {
  166. self.automaticallyAdjustsScrollViewInsets = NO;
  167. }
  168. [self.view addSubview:_TableView];
  169. }
  170. #pragma mark - TableViewDelegate & TableViewDataSource
  171. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  172. {
  173. return 1;
  174. }
  175. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  176. {
  177. return self.ListDataSource.count;
  178. }
  179. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  180. {
  181. return 115;
  182. }
  183. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  184. {
  185. // if (indexPath.row%2 !=0) {
  186. // newImageCell *cell = [newImageCell cellWith:nil tableView:tableView];
  187. // tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  188. // cell.selectionStyle = UITableViewCellSelectionStyleNone;
  189. // return cell;
  190. // }else{
  191. // newNoImageCell *cell = [newNoImageCell cellWith:nil tableView:tableView];
  192. // tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  193. // cell.selectionStyle = UITableViewCellSelectionStyleNone;
  194. // return cell;
  195. // }
  196. _MyClollectModel = self.ListDataSource[indexPath.row];
  197. newNoImageCell *cell = [newNoImageCell cellWith:nil tableView:tableView];
  198. cell.titleLb.text = _MyClollectModel.title;
  199. cell.timeLb.text = _MyClollectModel.createTime;
  200. return cell;
  201. }
  202. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  203. {
  204. _MyClollectModel = self.ListDataSource[indexPath.row];
  205. if ([_MyClollectModel.collect_type isEqualToString:@"0"]) {
  206. newsDetailVController *newsDetail = [[newsDetailVController alloc]init];
  207. newsDetail.newsId = _MyClollectModel.collect_id;
  208. newsDetail.titleStr = _MyClollectModel.title;
  209. newsDetail.shareTitle = _MyClollectModel.title;
  210. newsDetail.typeStr = _MyClollectModel.collect_type;
  211. newsDetail.ImgUrl = _MyClollectModel.img_path;
  212. newsDetail.index =@"0";
  213. newsDetail.urlStr = [NSString stringWithFormat:@"%@/newsInfo?id=%@&move=ios",baseH5,_MyClollectModel.collect_id];
  214. newsDetail.shareUrl = [NSString stringWithFormat:@"%@/newsInfo?id=%@",baseH5,_MyClollectModel.collect_id];
  215. [self.navigationController pushViewController:newsDetail animated:YES];
  216. }else if ([_MyClollectModel.collect_type isEqualToString:@"1"]){
  217. activityDetailVController *activityDetail = [[activityDetailVController alloc]init];
  218. activityDetail.newsId = _MyClollectModel.collect_id;
  219. activityDetail.ImgUrl = _MyClollectModel.img_path;
  220. activityDetail.titleStr = _MyClollectModel.title;
  221. activityDetail.shareTitle = _MyClollectModel.title;
  222. activityDetail.index =@"0";
  223. activityDetail.urlStr = [NSString stringWithFormat:@"%@/applyDetail?id=%@&move=ios",baseH5,_MyClollectModel.collect_id];
  224. activityDetail.shareUrl = [NSString stringWithFormat:@"%@/applyDetail?id=%@",baseH5,_MyClollectModel.collect_id];
  225. [self.navigationController pushViewController:activityDetail animated:YES];
  226. }else if ([_MyClollectModel.collect_type isEqualToString:@"2"]){
  227. newsDetailVController *newsDetail = [[newsDetailVController alloc]init];
  228. newsDetail.newsId = _MyClollectModel.collect_id;
  229. newsDetail.titleStr = _MyClollectModel.title;
  230. newsDetail.shareTitle = _MyClollectModel.title;
  231. newsDetail.typeStr = _MyClollectModel.collect_type;
  232. newsDetail.ImgUrl = _MyClollectModel.img_path;
  233. newsDetail.index =@"0";
  234. newsDetail.urlStr = [NSString stringWithFormat:@"%@/reviewDetail?id=%@",baseH5,_MyClollectModel.collect_id];
  235. newsDetail.shareUrl = [NSString stringWithFormat:@"%@/reviewDetail?id=%@",baseH5,_MyClollectModel.collect_id];
  236. [self.navigationController pushViewController:newsDetail animated:YES];
  237. }
  238. }
  239. - ( UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath {
  240. //删除
  241. UIContextualAction *deleteRowAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"取消" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
  242. completionHandler (YES);
  243. _MyClollectModel = self.ListDataSource[indexPath.row];
  244. [self deleteattention:_MyClollectModel.collect_id type:_MyClollectModel.collect_type];
  245. }];
  246. deleteRowAction.image = [UIImage imageNamed:@"取消"];
  247. deleteRowAction.backgroundColor = [UIColor redColor];
  248. UISwipeActionsConfiguration *config = [UISwipeActionsConfiguration configurationWithActions:@[deleteRowAction]];
  249. return config;
  250. }
  251. - (void)deleteattention:(NSString *)projectId type:(NSString *)type
  252. {
  253. NSMutableDictionary *params = [NSMutableDictionary dictionary];
  254. params[@"id"] = projectId;
  255. params[@"collectType"] = type;
  256. [ProgressHUD show];
  257. [self.sessionManager sendPostHttpRequestWithUrl:cancelCollection params:params bodyBlock:nil progress:nil success:^(NSDictionary *response) {
  258. [ProgressHUD hide];
  259. NSString *message = [response objectForKeySafely:@"message"];
  260. [ToastView showToast:message];
  261. } failure:^(NSError *error) {
  262. [ProgressHUD hide];
  263. }];
  264. }
  265. - (void)didReceiveMemoryWarning {
  266. [super didReceiveMemoryWarning];
  267. // Dispose of any resources that can be recreated.
  268. }
  269. - (void)dealloc {
  270. if (_sessionManager) {
  271. [_sessionManager cancelAllTask];
  272. }
  273. [[NSNotificationCenter defaultCenter] removeObserver:self];
  274. DebugLog(@"%@没有造成循环引用", [self class]);
  275. }
  276. @end