猎豆优选

LDTopRuleView.m 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. //
  2. // LDTopRuleView.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/11/16.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "LDTopRuleView.h"
  9. #import "LDPrivilegeReferralTableViewCell.h"
  10. #import "LDPrivilegeReferralModel.h"
  11. #import "LDUserInfo.h"
  12. @interface LDTopRuleView ()<UITableViewDelegate,UITableViewDataSource>
  13. {
  14. NSArray *_dataArr;
  15. NSInteger _index;
  16. }
  17. @property (nonatomic, strong) UITableView *tableView;
  18. @end
  19. @implementation LDTopRuleView
  20. - (instancetype)initWithFrame:(CGRect)frame
  21. {
  22. self = [super initWithFrame:frame];
  23. if (self) {
  24. [self initUI];
  25. }
  26. return self;
  27. }
  28. - (void)initUI {
  29. [self addSubview:self.tableView];
  30. self.tableView.backgroundColor = [UIColor clearColor];
  31. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  32. make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
  33. }];
  34. }
  35. - (void)requestDataWithIndex:(NSInteger)index {
  36. _index = index;
  37. NSDictionary *para = @{@"type":@(index)};
  38. NSString *url = [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/getPrivilegeTop",BaseURL];
  39. [LDHttp post:url params:para success:^(id json) {
  40. _dataArr = [NSArray yy_modelArrayWithClass:[LDPrivilegeReferralModel class] json:json[@"data"]];
  41. [self.tableView reloadData];
  42. } failure:^(NSError *error) {
  43. }];
  44. }
  45. #pragma mark -------- UITableView Delegate -----
  46. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  47. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  48. [cell setSeparatorInset:UIEdgeInsetsMake(0, 15, 0, 15)];
  49. }
  50. }
  51. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  52. return _dataArr.count;
  53. }
  54. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  55. return 90;
  56. }
  57. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  58. return self.width*49/340;
  59. }
  60. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  61. return 0;
  62. }
  63. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  64. LDPrivilegeReferralTableViewCell *cell= [LDPrivilegeReferralTableViewCell cellWithTableView:tableView];
  65. LDPrivilegeReferralModel *model = _dataArr[indexPath.row];
  66. cell.model = model;
  67. return cell;
  68. }
  69. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  70. UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.width, self.width*49/340)];
  71. UIImageView *imgView = [[UIImageView alloc] initWithFrame:header.bounds];
  72. UIButton *curBtn = [[UIButton alloc] initWithFrame:CGRectMake(imgView.width-100, 0, 80, imgView.height)];
  73. [curBtn setImage:[UIImage imageNamed:@"dangqiandengji"] forState:UIControlStateNormal];
  74. [curBtn setTitle:@"当前等级" forState:UIControlStateNormal];
  75. [curBtn setTitleColor:[UIColor YHColorWithHex:0x977341] forState:UIControlStateNormal];
  76. curBtn.titleLabel.font = [UIFont systemFontOfSize:11];
  77. [curBtn setButtonImageTitleStyle:ButtonImageTitleStyleLeft padding:5];
  78. curBtn.enabled = NO;
  79. curBtn.hidden = YES;
  80. NSDictionary *userDic = [LDUserInfoManager shareManager].userInfoDic;
  81. LDUserInfo *userInfo = [LDUserInfo yy_modelWithJSON:userDic];
  82. NSInteger index = [userInfo.user_level integerValue];
  83. if (index == _index) {
  84. curBtn.hidden = NO;
  85. }else {
  86. curBtn.hidden = YES;
  87. }
  88. [imgView addSubview:curBtn];
  89. switch (_index) {
  90. case 1:
  91. imgView.image = [UIImage imageNamed:@"vip_top"];
  92. break;
  93. case 2:
  94. imgView.image = [UIImage imageNamed:@"Svip_top"];
  95. break;
  96. case 3:
  97. imgView.image = [UIImage imageNamed:@"yun_top"];
  98. break;
  99. default:
  100. break;
  101. }
  102. [header addSubview:imgView];
  103. return header;
  104. }
  105. - (UITableView *)tableView {
  106. if (!_tableView) {
  107. _tableView = [[UITableView alloc] initWithFrame:self.bounds style:UITableViewStylePlain];
  108. _tableView.estimatedSectionHeaderHeight = 0;
  109. _tableView.estimatedSectionFooterHeight = 0;
  110. _tableView.sectionFooterHeight = 0;
  111. _tableView.sectionHeaderHeight = 0;
  112. _tableView.estimatedRowHeight = 0;
  113. _tableView.delegate = self;
  114. _tableView.dataSource = self;
  115. _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  116. _tableView.bounces = NO;
  117. _tableView.showsVerticalScrollIndicator = NO;
  118. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  119. }
  120. return _tableView;
  121. }
  122. @end