123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- //
- // LDTopRuleView.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/11/16.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "LDTopRuleView.h"
- #import "LDPrivilegeReferralTableViewCell.h"
- #import "LDPrivilegeReferralModel.h"
- #import "LDUserInfo.h"
- @interface LDTopRuleView ()<UITableViewDelegate,UITableViewDataSource>
- {
- NSArray *_dataArr;
- NSInteger _index;
- }
- @property (nonatomic, strong) UITableView *tableView;
- @end
- @implementation LDTopRuleView
- - (instancetype)initWithFrame:(CGRect)frame
- {
- self = [super initWithFrame:frame];
- if (self) {
- [self initUI];
- }
- return self;
- }
- - (void)initUI {
- [self addSubview:self.tableView];
- self.tableView.backgroundColor = [UIColor clearColor];
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
- }];
- }
- - (void)requestDataWithIndex:(NSInteger)index {
- _index = index;
- NSDictionary *para = @{@"type":@(index)};
- NSString *url = [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/getPrivilegeTop",BaseURL];
- [LDHttp post:url params:para success:^(id json) {
-
- _dataArr = [NSArray yy_modelArrayWithClass:[LDPrivilegeReferralModel class] json:json[@"data"]];
- [self.tableView reloadData];
-
- } failure:^(NSError *error) {
-
- }];
- }
- #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 _dataArr.count;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- return 90;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- return self.width*49/340;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
- return 0;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- LDPrivilegeReferralTableViewCell *cell= [LDPrivilegeReferralTableViewCell cellWithTableView:tableView];
- LDPrivilegeReferralModel *model = _dataArr[indexPath.row];
- cell.model = model;
- return cell;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
- UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.width, self.width*49/340)];
- UIImageView *imgView = [[UIImageView alloc] initWithFrame:header.bounds];
- UIButton *curBtn = [[UIButton alloc] initWithFrame:CGRectMake(imgView.width-100, 0, 80, imgView.height)];
- [curBtn setImage:[UIImage imageNamed:@"dangqiandengji"] forState:UIControlStateNormal];
- [curBtn setTitle:@"当前等级" forState:UIControlStateNormal];
- [curBtn setTitleColor:[UIColor YHColorWithHex:0x977341] forState:UIControlStateNormal];
- curBtn.titleLabel.font = [UIFont systemFontOfSize:11];
- [curBtn setButtonImageTitleStyle:ButtonImageTitleStyleLeft padding:5];
- curBtn.enabled = NO;
- curBtn.hidden = YES;
- NSDictionary *userDic = [LDUserInfoManager shareManager].userInfoDic;
- LDUserInfo *userInfo = [LDUserInfo yy_modelWithJSON:userDic];
- NSInteger index = [userInfo.user_level integerValue];
- if (index == _index) {
- curBtn.hidden = NO;
- }else {
- curBtn.hidden = YES;
- }
-
- [imgView addSubview:curBtn];
- switch (_index) {
- case 1:
- imgView.image = [UIImage imageNamed:@"vip_top"];
- break;
- case 2:
- imgView.image = [UIImage imageNamed:@"Svip_top"];
- break;
- case 3:
- imgView.image = [UIImage imageNamed:@"yun_top"];
- break;
- default:
- break;
- }
- [header addSubview:imgView];
- return header;
- }
- - (UITableView *)tableView {
- if (!_tableView) {
- _tableView = [[UITableView alloc] initWithFrame:self.bounds style:UITableViewStylePlain];
- _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.bounces = NO;
- _tableView.showsVerticalScrollIndicator = NO;
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
-
-
- }
- return _tableView;
- }
- @end
|