// // KBMessageListController.m // YouHuiProject // // Created by 小花 on 2018/5/21. // Copyright © 2018年 kuxuan. All rights reserved. // #import "KBMessageListController.h" #import "KBMessageListCell.h" #import "KBMessageModel.h" #import "KBGoodDetailViewController.h" #import "KBCommissionMainViewController.h" #import "KBOrderMainViewController.h" #import "KBMyFansViewController.h" #import "KBCollectionMainViewController.h" #import "KBAccountDetailController.h" #import "KBGoodListViewController.h" @interface KBMessageListController () { NSInteger _page; ActivityIndicatorView *_indicatorView; } @property (nonatomic, strong) UITableView *tableView; @property (nonatomic, strong) NSMutableArray *dataArr; @end @implementation KBMessageListController - (void)viewDidLoad { [super viewDidLoad]; [self configNavigationBar]; [self configTableView]; [self initHUD]; [self requestData]; } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; } -(void)viewDidDisappear:(BOOL)animated{ [super viewDidDisappear:animated]; [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault]; [SVProgressHUD dismiss]; } - (void)configTableView { _page = 1; [self.view addSubview:self.tableView]; } - (void)configNavigationBar { [self.navigationBar setNavTitle:@"我的消息"]; self.navigationBar.backgroundColor = [UIColor changeColor]; self.navigationBar.navTitleLabel.textColor = [UIColor whiteColor]; UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)]; [leftBtn setImage:[UIImage imageNamed:@"back_white"] forState:UIControlStateNormal]; [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside]; [self.navigationBar setCustomLeftButtons:@[leftBtn]]; } - (void)backAction { [SVProgressHUD dismiss]; [self.navigationController popViewControllerAnimated:YES]; } - (void)initHUD { ActivityIndicatorView *indicatorView = [ActivityIndicatorView showInView:self.view frame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)]; _indicatorView = indicatorView; } - (void)requestData { NSString *url = [NSString stringWithFormat:@"%@/api/v2/message_push/pocketMessagePushList",BaseURL]; [KBHttp post:url params:@{@"page":@(_page)} success:^(id json) { NSArray *list = [NSArray yy_modelArrayWithClass:[KBMessageModel class] json:json[@"data"]]; if (list.count>0) { [self.dataArr addObjectsFromArray:list]; [self.tableView.mj_footer endRefreshing];; }else { if (_page==1) { [self setUpNoDataView]; } [self.tableView.mj_footer endRefreshingWithNoMoreData]; } [self.tableView reloadData]; [_indicatorView stopAnimating]; } failure:^(NSError *error) { [self.tableView.mj_footer endRefreshing]; [_indicatorView stopAnimating]; }]; } - (void)setUpNoDataView { self.tableView.showNoDataView = YES; self.tableView.defaultNoDataText = @"您还没有任何记录"; self.tableView.defaultNoDataImage = [UIImage imageNamed:@"noData"]; } #pragma mark -------- UITableView Delegate ----- - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { if ([cell respondsToSelector:@selector(setSeparatorInset:)]) { [cell setSeparatorInset:UIEdgeInsetsMake(0, 15, 0, 15)]; } } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.dataArr.count; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 120; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return .1; } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return 0.1; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { KBMessageModel *model = self.dataArr[indexPath.row]; KBMessageListCell *cell = [KBMessageListCell cellWithTableView:tableView]; cell.model = model; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { KBMessageModel *model = self.dataArr[indexPath.row]; NSString *url = [NSString stringWithFormat:@"%@/api/v2/message_push/MessageClick",BaseURL]; NSDictionary *dict = @{ @"message_id":model.Id, @"person_group":model.person_group, @"is_view":model.is_view }; [KBHttp post:url params:dict success:^(id json) { KBMessageListCell *cell = [tableView cellForRowAtIndexPath:indexPath]; [cell isRead]; } failure:^(NSError *error) { }]; switch ([model.message_type integerValue]) { case 1: [self gotoMyFans]; //我的粉丝 break; case 2: [self gotoGoodDetailPage:model]; //商品详情或列表 break; case 3: [self gotoUpdateApp]; //更新app break; case 4: [self gotoMyOrderPage]; // 收入结算 break; case 5: [self gotoBackMoneyPage]; //提现完成 break; case 6: [self gotoMyCollectionPage]; //我的收藏 break; default: break; } } /** 去我的粉丝 */ - (void)gotoMyFans { KBMyFansViewController *myFans = [[KBMyFansViewController alloc] init]; [self.navigationController pushViewController:myFans animated:YES]; } /** 打开详情页 */ - (void)gotoGoodDetailPage:(KBMessageModel *)model { if ([model.goods_or_group isEqualToString:@"1"]) { KBGoodDetailViewController *goodDetail = [[KBGoodDetailViewController alloc] init]; DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithId:model.goods_id is_coupon:model.is_coupon coupon_price:model.coupon_price price:model.price discount_price:model.discount_price commission_rate:model.commission_rate coupon_start_time:model.coupon_start_time coupon_end_time:model.coupon_end_time]; goodDetail.requestModel = requestModel; [self.navigationController pushViewController:goodDetail animated:YES]; }else { //列表页 KBGoodListViewController *list = [[KBGoodListViewController alloc] init]; list.cate_id = model.group_id; [self.navigationController pushViewController:list animated:YES]; } } /** 版本更新 */ - (void)gotoUpdateApp { [[UIApplication sharedApplication] openURL:[NSURL URLWithString:APP_STORE_URL]]; } /** 我的订单 */ - (void)gotoMyOrderPage { KBAccountDetailController *orderMain = [[KBAccountDetailController alloc] init]; [self.navigationController pushViewController:orderMain animated:YES]; } /** 提现完成 */ - (void)gotoBackMoneyPage { [self gotoMyOrderPage]; } /** 我的收藏 */ - (void)gotoMyCollectionPage { KBCollectionMainViewController *collection = [[KBCollectionMainViewController alloc] init]; [self.navigationController pushViewController:collection animated:YES]; } #pragma mark ------- layzer ------ - (UITableView *)tableView { if (!_tableView) { _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight) style:UITableViewStyleGrouped]; _tableView.estimatedSectionHeaderHeight = 0; _tableView.estimatedSectionFooterHeight = 0; _tableView.sectionFooterHeight = 0; _tableView.sectionHeaderHeight = 0; _tableView.estimatedRowHeight = 0; _tableView.delegate = self; _tableView.dataSource = self; _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; _tableView.backgroundColor = [UIColor yhGrayColor]; _tableView.showsVerticalScrollIndicator = NO; _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine; _tableView.separatorColor = [UIColor YHColorWithHex:0xEEEEEE]; _tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{ _page ++; [self requestData]; }]; } return _tableView; } - (NSMutableArray *)dataArr { if (!_dataArr) { _dataArr = [NSMutableArray array]; } return _dataArr; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end