123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- //
- // MyCollectController.m
- // ZhongJingLianMeng
- //
- // Created by vinDesel on 2018/11/16.
- // Copyright © 2018年 youke. All rights reserved.
- //
- #import "MyCollectController.h"
- #import "HttpRequestManger.h"
- #import "OrderListEmptyView.h"
- #import "newNoImageCell.h"
- #import "newImageCell.h"
- #import "MyClollectModel.h"
- #import "newsDetailVController.h"
- #import "activityDetailVController.h"
- @interface MyCollectController ()<UITableViewDelegate,UITableViewDataSource>
- {
- CGFloat viewHeight;
- }
- @property (nonatomic, strong) UITableView *TableView;
- @property (nonatomic, strong) NSMutableArray *listArray;
- @property (nonatomic, strong) NSMutableArray *ListDataSource;
- @property (strong, nonatomic) HttpRequestManger *sessionManager;
- @property (strong, nonatomic) OrderListEmptyView *saleEmpty;
- //列表上一次的请求参数
- @property (nonatomic, strong) NSDictionary *params;
- //当前页码
- @property (nonatomic, assign) NSInteger Page;
- @property (nonatomic, assign) BOOL isLoading;
- @property (nonatomic, strong) MyClollectModel *MyClollectModel;
- @end
- @implementation MyCollectController
- - (OrderListEmptyView *)saleEmpty
- {
- if (!_saleEmpty) {
- _saleEmpty = [[NSBundle mainBundle]loadNibNamed:@"OrderListEmptyView" owner:self options:nil].firstObject;
- _saleEmpty.signLabel.text = @"暂无数据";
- [_saleEmpty.actionButton setTitle:@"立即关注" forState:UIControlStateNormal];
- _saleEmpty.actionButton.layer.masksToBounds = YES;
- _saleEmpty.actionButton.layer.cornerRadius = 2.0f;
- // [_collectEmpty.actionButton addTarget:self action:@selector(actionButtonClick:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _saleEmpty;
- }
- - (HttpRequestManger*) sessionManager{
- if (!_sessionManager) {
- _sessionManager = [[HttpRequestManger alloc]init];
- }
- return _sessionManager;
- }
- - (NSMutableArray *)ListDataSource
- {
- if (!_ListDataSource) {
- _ListDataSource = [NSMutableArray array];
- }
- return _ListDataSource;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- WS(weakSelf);
- self.navigationView.hidden = NO;
- [self.navigationView setNavigationBackgroundColor:[UIColor colorWithHexValue:0x3C915C]];
- [self.navigationView removeAllLeftButton];
- [self.navigationView addLeftButtonWithImage:[UIImage imageNamed:@"whiteBack"] clickCallBack:^(UIView *view) {
- [weakSelf.navigationController popViewControllerAnimated:YES];
- }];
- [self.navigationView setTitle:@"我的收藏"];
- self.navigationView.titleLabel.textColor=[UIColor whiteColor];
- if (IS_IPHONE_X) {
- viewHeight =88;
- }else{
- viewHeight = 64;
- }
- [self setupView];
- }
- - (void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- [self TabSetupRefresh];
- }
- #pragma 列表数据请求
- - (void)TabSetupRefresh
- {
- [self.TableView.mj_header beginRefreshing];
- }
- //加载最新数据
- - (void)TabloadNews
- {
- WS(weakSelf);
- NSMutableDictionary *params = [NSMutableDictionary dictionary];
- params[@"pageNum"] = @"1";
- params[@"pageSize"] = @"10";
- weakSelf.params = params;
- [ProgressHUD show];
- [self.sessionManager sendPostHttpRequestWithUrl:Mycollect params:params bodyBlock:nil progress:nil success:^(NSDictionary *response) {
- [ProgressHUD hide];
- [weakSelf.TableView.mj_header endRefreshing];
- weakSelf.listArray = [response objectForKeySafely:@"collectList"];
- weakSelf.ListDataSource = [MyClollectModel mj_objectArrayWithKeyValuesArray:weakSelf.listArray];
- if (weakSelf.listArray.count == 0) {
- weakSelf.saleEmpty.frame = weakSelf.view.bounds;
- weakSelf.saleEmpty.actionButton.hidden = YES;
- [weakSelf.TableView addSubview:weakSelf.saleEmpty];
- }else{
- [weakSelf.saleEmpty removeFromSuperview];
- }
- [weakSelf.TableView reloadData];
- weakSelf.Page = 1;
- } failure:^(NSError *error) {
- [ProgressHUD hide];
- [weakSelf.TableView.mj_header endRefreshing];
- }];
- }
- //加载更多
- - (void)TabloadMoreTopics
- {
- WS(weakSelf);
- _isLoading = YES;
- self.Page ++;
- NSNumber *current = [NSNumber numberWithInt:(int)self.Page];
- NSMutableDictionary *params = [NSMutableDictionary dictionary];
- params[@"pageNum"] = current;
- params[@"pageSize"] = @"10";
- [ProgressHUD show];
- weakSelf.params = params;
- [self.sessionManager sendPostHttpRequestWithUrl:Mycollect params:params bodyBlock:nil progress:nil success:^(NSDictionary *response) {
- [ProgressHUD hide];
- [weakSelf.TableView.mj_footer endRefreshing];
- if (weakSelf.params != params) return;
- weakSelf.listArray = [response objectForKeySafely:@"collectList"];
- if (weakSelf.listArray.count > 0) {
- NSArray *array = [MyClollectModel mj_objectArrayWithKeyValuesArray:weakSelf.listArray];
- [weakSelf.ListDataSource addObjectsFromArray:array];
- }else{
- if (weakSelf.Page > 1) {
- weakSelf.Page--;
- [ToastView showToast:@"暂无更多数据"];
- }
- }
- [weakSelf.TableView reloadData];
- } failure:^(NSError *error) {
- [ProgressHUD hide];
- [weakSelf.TableView.mj_footer endRefreshing];
- }];
- }
- - (void)setupView
- {
- _TableView = [[UITableView alloc] initWithFrame:CGRectMake(0, viewHeight, SCREEN_WIDTH, SCREEN_HEIGHT - viewHeight)];
- _TableView.delegate = self;
- _TableView.dataSource = self;
- _TableView.showsVerticalScrollIndicator = NO;
- _TableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _TableView.backgroundColor = RGBColor(243, 244, 246);
- //去掉多余的分割线
- WS(weakSelf);
- weakSelf.TableView.tableFooterView = [[UIView alloc]init];
- // 下拉刷新
- weakSelf.TableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(TabloadNews)];
- weakSelf.TableView.mj_header.automaticallyChangeAlpha = YES;
- // 上拉加载
- weakSelf.TableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(TabloadMoreTopics)];
- if (@available(iOS 11.0, *)) {
- _TableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- }else {
- self.automaticallyAdjustsScrollViewInsets = NO;
- }
- [self.view addSubview:_TableView];
- }
- #pragma mark - TableViewDelegate & TableViewDataSource
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return self.ListDataSource.count;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return 115;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- // if (indexPath.row%2 !=0) {
- // newImageCell *cell = [newImageCell cellWith:nil tableView:tableView];
- // tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- // cell.selectionStyle = UITableViewCellSelectionStyleNone;
- // return cell;
- // }else{
- // newNoImageCell *cell = [newNoImageCell cellWith:nil tableView:tableView];
- // tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- // cell.selectionStyle = UITableViewCellSelectionStyleNone;
- // return cell;
- // }
- _MyClollectModel = self.ListDataSource[indexPath.row];
- newNoImageCell *cell = [newNoImageCell cellWith:nil tableView:tableView];
- cell.titleLb.text = _MyClollectModel.title;
- cell.timeLb.text = _MyClollectModel.createTime;
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- _MyClollectModel = self.ListDataSource[indexPath.row];
- if ([_MyClollectModel.collect_type isEqualToString:@"0"]) {
- newsDetailVController *newsDetail = [[newsDetailVController alloc]init];
- newsDetail.newsId = _MyClollectModel.collect_id;
- newsDetail.titleStr = _MyClollectModel.title;
- newsDetail.shareTitle = _MyClollectModel.title;
- newsDetail.typeStr = _MyClollectModel.collect_type;
- newsDetail.ImgUrl = _MyClollectModel.img_path;
- newsDetail.index =@"0";
- newsDetail.urlStr = [NSString stringWithFormat:@"%@/newsInfo?id=%@&move=ios",baseH5,_MyClollectModel.collect_id];
- newsDetail.shareUrl = [NSString stringWithFormat:@"%@/newsInfo?id=%@",baseH5,_MyClollectModel.collect_id];
- [self.navigationController pushViewController:newsDetail animated:YES];
- }else if ([_MyClollectModel.collect_type isEqualToString:@"1"]){
- activityDetailVController *activityDetail = [[activityDetailVController alloc]init];
- activityDetail.newsId = _MyClollectModel.collect_id;
- activityDetail.ImgUrl = _MyClollectModel.img_path;
- activityDetail.titleStr = _MyClollectModel.title;
- activityDetail.shareTitle = _MyClollectModel.title;
- activityDetail.index =@"0";
- activityDetail.urlStr = [NSString stringWithFormat:@"%@/applyDetail?id=%@&move=ios",baseH5,_MyClollectModel.collect_id];
- activityDetail.shareUrl = [NSString stringWithFormat:@"%@/applyDetail?id=%@",baseH5,_MyClollectModel.collect_id];
- [self.navigationController pushViewController:activityDetail animated:YES];
- }else if ([_MyClollectModel.collect_type isEqualToString:@"2"]){
- newsDetailVController *newsDetail = [[newsDetailVController alloc]init];
- newsDetail.newsId = _MyClollectModel.collect_id;
- newsDetail.titleStr = _MyClollectModel.title;
- newsDetail.shareTitle = _MyClollectModel.title;
- newsDetail.typeStr = _MyClollectModel.collect_type;
- newsDetail.ImgUrl = _MyClollectModel.img_path;
- newsDetail.index =@"0";
- newsDetail.urlStr = [NSString stringWithFormat:@"%@/reviewDetail?id=%@",baseH5,_MyClollectModel.collect_id];
- newsDetail.shareUrl = [NSString stringWithFormat:@"%@/reviewDetail?id=%@",baseH5,_MyClollectModel.collect_id];
- [self.navigationController pushViewController:newsDetail animated:YES];
- }
- }
- - ( UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath {
- //删除
- UIContextualAction *deleteRowAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"取消" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
- completionHandler (YES);
-
- _MyClollectModel = self.ListDataSource[indexPath.row];
- [self deleteattention:_MyClollectModel.collect_id type:_MyClollectModel.collect_type];
- }];
- deleteRowAction.image = [UIImage imageNamed:@"取消"];
- deleteRowAction.backgroundColor = [UIColor redColor];
- UISwipeActionsConfiguration *config = [UISwipeActionsConfiguration configurationWithActions:@[deleteRowAction]];
- return config;
- }
- - (void)deleteattention:(NSString *)projectId type:(NSString *)type
- {
- NSMutableDictionary *params = [NSMutableDictionary dictionary];
- params[@"id"] = projectId;
- params[@"collectType"] = type;
- [ProgressHUD show];
- [self.sessionManager sendPostHttpRequestWithUrl:cancelCollection params:params bodyBlock:nil progress:nil success:^(NSDictionary *response) {
- [ProgressHUD hide];
- NSString *message = [response objectForKeySafely:@"message"];
- [ToastView showToast:message];
- } failure:^(NSError *error) {
- [ProgressHUD hide];
- }];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (void)dealloc {
- if (_sessionManager) {
- [_sessionManager cancelAllTask];
- }
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- DebugLog(@"%@没有造成循环引用", [self class]);
- }
- @end
|