// // YOUPAILPGuardBordeVC.m // livePro // // Created by leo on 2019/12/24. // Copyright © 2019 caiPro. All rights reserved. // #import "YOUPAILPGuardBordeVC.h" #import "YOUPAILPGuardListModel.h" #import "YOUPAILPGuardListCell.h" #import "YOUPAILZUserShowVC.h" #import "YOUPAILPGuardHerVC.h" #import "YOUPAILCGuardModel.h" #import "YOUPAILCUserShowModel.h" #import "UIViewController+TFPresent.h" @interface YOUPAILPGuardBordeVC() @property(nonatomic,assign)NSInteger youpaipcurrentPage; @property(nonatomic,strong)UITableView* youpaiptableView; @property(nonatomic,strong)NSMutableArray* youpaipboardArray; @property(nonatomic,strong)YOUPAILCGuardModel *youpaipguardInfo; @end @implementation YOUPAILPGuardBordeVC - (UITableView *)youpaiptableView{ if (!_youpaiptableView) { _youpaiptableView = [[UITableView alloc]initWithFrame:CGRectMake(0, NavBarHeight,KScreenWidth, KScreenHeight-NavBarHeight) style:UITableViewStylePlain]; _youpaiptableView.showsVerticalScrollIndicator = NO; _youpaiptableView.separatorStyle = UITableViewCellSeparatorStyleNone; _youpaiptableView.backgroundColor = [UIColor whiteColor]; _youpaiptableView.estimatedRowHeight = 70; _youpaiptableView.estimatedSectionHeaderHeight = 0; _youpaiptableView.estimatedSectionFooterHeight = 0; _youpaiptableView.dataSource = self; _youpaiptableView.delegate = self; if (@available(iOS 15.0, *)) { _youpaiptableView.sectionHeaderTopPadding = 0; } } return _youpaiptableView; } - (void)viewDidLoad{ [super viewDidLoad]; if ([self.youpaipuser_id isEqual:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id]) { self.title = @"我的守护"; }else{ self.title = @"ta的守护"; } self.view.backgroundColor = [UIColor whiteColor]; self.youpaipboardArray = [NSMutableArray array]; [self youpaifinitUI]; [self youpaifRequestUserShowData:NO]; [self youpaifinitData]; } - (void)youpaifinitUI{ [self.view addSubview:self.youpaiptableView]; UIButton *guardBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [guardBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth - ScaleSize(96.0f), 48.0f) FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:GradientLeftToRight] forState:UIControlStateNormal]; [guardBtn setTitle:@"守护Ta" forState:UIControlStateNormal]; [guardBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; guardBtn.titleLabel.font = LCFont(18.0f); [guardBtn addTarget:self action:@selector(guardBtnClick) forControlEvents:UIControlEventTouchUpInside]; guardBtn.layer.cornerRadius = 24.0f; guardBtn.clipsToBounds = YES; [self.view addSubview:guardBtn]; [guardBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(ScaleSize(48.0f)); make.right.offset(ScaleSize(-48.0f)); make.height.offset(48.0f); make.bottom.offset(-SafeHeight - 40.0f); }]; } - (void)guardBtnClick{ if (self.youpaipguardInfo == nil) { [self youpaifRequestUserShowData:YES]; }else{ YOUPAILPGuardHerVC *VC= [[YOUPAILPGuardHerVC alloc]init]; VC.youpaipdelegate = self; VC.youpaipuser_id = self.youpaipuser_id; VC.vWidth = KScreenWidth-54; VC.vHeight = ((KScreenWidth-54)*165)/321.0+261.5; VC.youpaipinfoModel = self.youpaipguardInfo; VC.isTouchDismiss = YES; if(VC.youpaipinfoModel!=nil) [self TFPresentVC:VC completion:^{ }]; } } //守护成功 -(void)youpaifaddGuardSuccess { [self youpaifinitData]; } - (void)youpaifRequestUserShowData:(BOOL)isShowGuard{ @weakify(self); [LCHttpHelper requestWithURLString:UserShowPage parameters:@{@"user_id":self.youpaipuser_id} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { @strongify(self); NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 YOUPAILCUserShowModel *youpaipshowModel = [YOUPAILCUserShowModel mj_objectWithKeyValues:[dict objectForKey:@"data"]]; self.youpaipguardInfo = youpaipshowModel.youpaipguard; if (isShowGuard) { [self guardBtnClick]; } } } failure:^(NSError *error) { }]; } - (void)youpaifinitData{ self.youpaipcurrentPage = 1; [self.youpaiptableView.mj_footer endRefreshingWithNoMoreData]; self.youpaiptableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(youpaifloadMoreData)]; [LCHttpHelper requestWithURLString:GuardUserList parameters:@{@"user_id":self.youpaipuser_id,@"page":@(self.youpaipcurrentPage)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 self.youpaipboardArray = [YOUPAILPGuardListModel mj_objectArrayWithKeyValuesArray:[[dict objectForKey:@"data"]objectForKey:@"list"]]; NSInteger totalPage = [[[dict objectForKey:@"data"] objectForKey:@"total_page"]integerValue]; self.youpaipcurrentPage = [[[dict objectForKey:@"data"] objectForKey:@"page"]integerValue]; [self.youpaiptableView reloadData]; if (self.youpaipcurrentPage>=totalPage) { [self.youpaiptableView.mj_footer endRefreshingWithNoMoreData]; self.youpaiptableView.mj_footer.hidden = YES; } [self.youpaiptableView.mj_header endRefreshing]; } [self.youpaiptableView.mj_footer endRefreshing]; if (self.youpaipboardArray.count != 0) { [self.youpaiptableView lz_hideEmptyView]; }else{ [self.youpaiptableView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_home_data"] content:@"暂无守护记录~"]; } } failure:^(NSError *error) { [self.youpaiptableView.mj_footer endRefreshing]; }]; } - (void)youpaifloadMoreData{ [self.youpaiptableView.mj_header endRefreshing]; [LCHttpHelper requestWithURLString:GuardUserList parameters:@{@"user_id":self.youpaipuser_id,@"page":@(self.youpaipcurrentPage+1)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 NSMutableArray* tempArray = [YOUPAILPGuardListModel mj_objectArrayWithKeyValuesArray:[[dict objectForKey:@"data"]objectForKey:@"list"]]; NSInteger totalPage = [[[dict objectForKey:@"data"] objectForKey:@"total_page"]integerValue]; self.youpaipcurrentPage = [[[dict objectForKey:@"data"] objectForKey:@"page"]integerValue]; [self.youpaipboardArray addObjectsFromArray:tempArray]; [self.youpaiptableView reloadData]; if (self.youpaipcurrentPage>=totalPage) { [self.youpaiptableView.mj_footer endRefreshingWithNoMoreData]; self.youpaiptableView.mj_footer.hidden = YES; } [self.youpaiptableView.mj_header endRefreshing]; } [self.youpaiptableView.mj_footer endRefreshing]; } failure:^(NSError *error) { [self.youpaiptableView.mj_footer endRefreshing]; }]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.youpaipboardArray.count; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 70; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ YOUPAILPGuardListCell * cell = [YOUPAILPGuardListCell youpaifcellWithTableViewCell:tableView]; YOUPAILPGuardListModel* model = self.youpaipboardArray[indexPath.row]; [cell setModel:model]; // [cell bottomLineforViewHeight:68]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ YOUPAILPGuardListModel* model = self.youpaipboardArray[indexPath.row]; YOUPAILZUserShowVC *vc = [[YOUPAILZUserShowVC alloc] init]; vc.youpaipuserId = model.youpaipuser_id; [self.navigationController pushViewController:vc animated:YES]; } /* #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