YOUPAILPGuardBordeVC.m 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. //
  2. // YOUPAILPGuardBordeVC.m
  3. // livePro
  4. //
  5. // Created by leo on 2019/12/24.
  6. // Copyright © 2019 caiPro. All rights reserved.
  7. //
  8. #import "YOUPAILPGuardBordeVC.h"
  9. #import "YOUPAILPGuardListModel.h"
  10. #import "YOUPAILPGuardListCell.h"
  11. #import "YOUPAILZUserShowVC.h"
  12. #import "YOUPAILPGuardHerVC.h"
  13. #import "YOUPAILCGuardModel.h"
  14. #import "YOUPAILCUserShowModel.h"
  15. #import "UIViewController+TFPresent.h"
  16. @interface YOUPAILPGuardBordeVC()<UITableViewDataSource,UITableViewDelegate,LPGuardHerDelegate>
  17. @property(nonatomic,assign)NSInteger youpaipcurrentPage;
  18. @property(nonatomic,strong)UITableView* youpaiptableView;
  19. @property(nonatomic,strong)NSMutableArray* youpaipboardArray;
  20. @property(nonatomic,strong)YOUPAILCGuardModel *youpaipguardInfo;
  21. @end
  22. @implementation YOUPAILPGuardBordeVC
  23. - (UITableView *)youpaiptableView{
  24. if (!_youpaiptableView) {
  25. _youpaiptableView = [[UITableView alloc]initWithFrame:CGRectMake(0, NavBarHeight,KScreenWidth, KScreenHeight-NavBarHeight) style:UITableViewStylePlain];
  26. _youpaiptableView.showsVerticalScrollIndicator = NO;
  27. _youpaiptableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  28. _youpaiptableView.backgroundColor = [UIColor whiteColor];
  29. _youpaiptableView.estimatedRowHeight = 70;
  30. _youpaiptableView.estimatedSectionHeaderHeight = 0;
  31. _youpaiptableView.estimatedSectionFooterHeight = 0;
  32. _youpaiptableView.dataSource = self;
  33. _youpaiptableView.delegate = self;
  34. if (@available(iOS 15.0, *)) {
  35. _youpaiptableView.sectionHeaderTopPadding = 0;
  36. }
  37. }
  38. return _youpaiptableView;
  39. }
  40. - (void)viewDidLoad{
  41. [super viewDidLoad];
  42. if ([self.youpaipuser_id isEqual:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id]) {
  43. self.title = @"我的守护";
  44. }else{
  45. self.title = @"ta的守护";
  46. }
  47. self.view.backgroundColor = [UIColor whiteColor];
  48. self.youpaipboardArray = [NSMutableArray array];
  49. [self youpaifinitUI];
  50. [self youpaifRequestUserShowData:NO];
  51. [self youpaifinitData];
  52. }
  53. - (void)youpaifinitUI{
  54. [self.view addSubview:self.youpaiptableView];
  55. UIButton *guardBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  56. [guardBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth - ScaleSize(96.0f), 48.0f) FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:GradientLeftToRight] forState:UIControlStateNormal];
  57. [guardBtn setTitle:@"守护Ta" forState:UIControlStateNormal];
  58. [guardBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  59. guardBtn.titleLabel.font = LCFont(18.0f);
  60. [guardBtn addTarget:self action:@selector(guardBtnClick) forControlEvents:UIControlEventTouchUpInside];
  61. guardBtn.layer.cornerRadius = 24.0f;
  62. guardBtn.clipsToBounds = YES;
  63. [self.view addSubview:guardBtn];
  64. [guardBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.left.offset(ScaleSize(48.0f));
  66. make.right.offset(ScaleSize(-48.0f));
  67. make.height.offset(48.0f);
  68. make.bottom.offset(-SafeHeight - 40.0f);
  69. }];
  70. }
  71. - (void)guardBtnClick{
  72. if (self.youpaipguardInfo == nil) {
  73. [self youpaifRequestUserShowData:YES];
  74. }else{
  75. YOUPAILPGuardHerVC *VC= [[YOUPAILPGuardHerVC alloc]init];
  76. VC.youpaipdelegate = self;
  77. VC.youpaipuser_id = self.youpaipuser_id;
  78. VC.vWidth = KScreenWidth-54;
  79. VC.vHeight = ((KScreenWidth-54)*165)/321.0+261.5;
  80. VC.youpaipinfoModel = self.youpaipguardInfo;
  81. VC.isTouchDismiss = YES;
  82. if(VC.youpaipinfoModel!=nil)
  83. [self TFPresentVC:VC completion:^{
  84. }];
  85. }
  86. }
  87. //守护成功
  88. -(void)youpaifaddGuardSuccess
  89. {
  90. [self youpaifinitData];
  91. }
  92. - (void)youpaifRequestUserShowData:(BOOL)isShowGuard{
  93. @weakify(self);
  94. [LCHttpHelper requestWithURLString:UserShowPage parameters:@{@"user_id":self.youpaipuser_id} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  95. @strongify(self);
  96. NSDictionary* dict = (NSDictionary*)responseObject;
  97. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  98. if (code==0) {//成功
  99. YOUPAILCUserShowModel *youpaipshowModel = [YOUPAILCUserShowModel mj_objectWithKeyValues:[dict objectForKey:@"data"]];
  100. self.youpaipguardInfo = youpaipshowModel.youpaipguard;
  101. if (isShowGuard) {
  102. [self guardBtnClick];
  103. }
  104. }
  105. } failure:^(NSError *error) {
  106. }];
  107. }
  108. - (void)youpaifinitData{
  109. self.youpaipcurrentPage = 1;
  110. [self.youpaiptableView.mj_footer endRefreshingWithNoMoreData];
  111. self.youpaiptableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(youpaifloadMoreData)];
  112. [LCHttpHelper requestWithURLString:GuardUserList parameters:@{@"user_id":self.youpaipuser_id,@"page":@(self.youpaipcurrentPage)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  113. NSDictionary* dict = (NSDictionary*)responseObject;
  114. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  115. if (code==0) {//成功
  116. self.youpaipboardArray = [YOUPAILPGuardListModel mj_objectArrayWithKeyValuesArray:[[dict objectForKey:@"data"]objectForKey:@"list"]];
  117. NSInteger totalPage = [[[dict objectForKey:@"data"] objectForKey:@"total_page"]integerValue];
  118. self.youpaipcurrentPage = [[[dict objectForKey:@"data"] objectForKey:@"page"]integerValue];
  119. [self.youpaiptableView reloadData];
  120. if (self.youpaipcurrentPage>=totalPage) {
  121. [self.youpaiptableView.mj_footer endRefreshingWithNoMoreData];
  122. self.youpaiptableView.mj_footer.hidden = YES;
  123. }
  124. [self.youpaiptableView.mj_header endRefreshing];
  125. }
  126. [self.youpaiptableView.mj_footer endRefreshing];
  127. if (self.youpaipboardArray.count != 0) {
  128. [self.youpaiptableView lz_hideEmptyView];
  129. }else{
  130. [self.youpaiptableView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_home_data"] content:@"暂无守护记录~"];
  131. }
  132. } failure:^(NSError *error) {
  133. [self.youpaiptableView.mj_footer endRefreshing];
  134. }];
  135. }
  136. - (void)youpaifloadMoreData{
  137. [self.youpaiptableView.mj_header endRefreshing];
  138. [LCHttpHelper requestWithURLString:GuardUserList parameters:@{@"user_id":self.youpaipuser_id,@"page":@(self.youpaipcurrentPage+1)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  139. NSDictionary* dict = (NSDictionary*)responseObject;
  140. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  141. if (code==0) {//成功
  142. NSMutableArray* tempArray = [YOUPAILPGuardListModel mj_objectArrayWithKeyValuesArray:[[dict objectForKey:@"data"]objectForKey:@"list"]];
  143. NSInteger totalPage = [[[dict objectForKey:@"data"] objectForKey:@"total_page"]integerValue];
  144. self.youpaipcurrentPage = [[[dict objectForKey:@"data"] objectForKey:@"page"]integerValue];
  145. [self.youpaipboardArray addObjectsFromArray:tempArray];
  146. [self.youpaiptableView reloadData];
  147. if (self.youpaipcurrentPage>=totalPage) {
  148. [self.youpaiptableView.mj_footer endRefreshingWithNoMoreData];
  149. self.youpaiptableView.mj_footer.hidden = YES;
  150. }
  151. [self.youpaiptableView.mj_header endRefreshing];
  152. }
  153. [self.youpaiptableView.mj_footer endRefreshing];
  154. } failure:^(NSError *error) {
  155. [self.youpaiptableView.mj_footer endRefreshing];
  156. }];
  157. }
  158. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  159. return self.youpaipboardArray.count;
  160. }
  161. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  162. return 70;
  163. }
  164. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  165. YOUPAILPGuardListCell * cell = [YOUPAILPGuardListCell youpaifcellWithTableViewCell:tableView];
  166. YOUPAILPGuardListModel* model = self.youpaipboardArray[indexPath.row];
  167. [cell setModel:model];
  168. // [cell bottomLineforViewHeight:68];
  169. return cell;
  170. }
  171. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  172. YOUPAILPGuardListModel* model = self.youpaipboardArray[indexPath.row];
  173. YOUPAILZUserShowVC *vc = [[YOUPAILZUserShowVC alloc] init];
  174. vc.youpaipuserId = model.youpaipuser_id;
  175. [self.navigationController pushViewController:vc animated:YES];
  176. }
  177. /*
  178. #pragma mark - Navigation
  179. // In a storyboard-based application, you will often want to do a little preparation before navigation
  180. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  181. // Get the new view controller using [segue destinationViewController].
  182. // Pass the selected object to the new view controller.
  183. }
  184. */
  185. @end