Files
xj-ios/XinjiangProject/XinjiangProject/Project/BANK/myPointsBankHomeViewController.m
T
2026-03-03 18:12:00 +08:00

440 lines
13 KiB
Objective-C

//
// myPointsBankHomeViewController.m
// XinjiangProject
//
// Created by Apple on 2026/2/6.
//
#import "myPointsBankHomeViewController.h"
#import "PointsBankHModel.h"
#import "PointsBankHomeTopView.h"
@interface myPointsBankHomeViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView * homeTable;
@property (nonatomic, assign) NSInteger pageNo;
@property (nonatomic, strong) NSMutableArray * dataArray;
@property (nonatomic, strong) NSMutableArray * buttonArray;
@property (nonatomic, strong) PointsBankHomeTopView * topView;
@property (nonatomic, strong) UIView * lineView;
@end
@implementation myPointsBankHomeViewController
- (NSMutableArray *)dataArray {
if (!_dataArray ) {
_dataArray = [[NSMutableArray alloc] init];
}
return _dataArray;
}
- (NSMutableArray *)buttonArray {
if (!_buttonArray ) {
_buttonArray = [[NSMutableArray alloc] init];
}
return _buttonArray;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.isHidenNaviBar = false;
self.navigationItem.title = @"我的积分银行";
[self createData];
//默认总榜单
[self creeateRankDataWithTyep:@"0"];
[self createUI];
}
- (void)createUI {
//首页
self.topView = [[PointsBankHomeTopView alloc] init];
[self.view addSubview:self.topView];
[self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.top.mas_offset(0);
// make.height.mas_offset(185);
}];
//功能栏
NSArray * toolsArray = @[@[@"积分兑换",@"img1"],@[@"积分明细",@"img2"],@[@"兑换记录",@"img3"]];
CGFloat itemWidth = 60;
CGFloat itemHeight = 110;
NSInteger count = toolsArray.count;
for (int i = 0; i < count; i++) {
NSArray *item = toolsArray[i];
// 1️⃣ 容器 view
UIView *itemView = [[UIView alloc] init];
itemView.tag = i;
itemView.userInteractionEnabled = YES;
[self.view addSubview:itemView];
// 2️⃣ 点击手势
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(itemTap:)];
[itemView addGestureRecognizer:tap];
// 3️⃣ 布局 container(每个 item 占 1/3 屏幕宽)
CGFloat thirdWidth = UIScreen.mainScreen.bounds.size.width / count;
[itemView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.topView.mas_bottom).offset(20);
make.width.mas_equalTo(itemWidth);
make.height.mas_equalTo(itemHeight);
make.centerX.mas_equalTo(self.view.mas_left).offset(thirdWidth * i + thirdWidth / 2);
}];
// 4️⃣ 图片
UIImageView *icon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:item[1]]];
icon.contentMode = UIViewContentModeScaleAspectFit;
[itemView addSubview:icon];
[icon mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(0);
make.centerX.equalTo(itemView);
make.width.height.mas_equalTo(40);
}];
// 5️⃣ 文字
UILabel *label = [[UILabel alloc] init];
label.text = item[0];
label.font = [UIFont systemFontOfSize:14];
label.textAlignment = NSTextAlignmentCenter;
[itemView addSubview:label];
[label mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(icon.mas_bottom).offset(8);
make.left.right.equalTo(itemView);
make.height.mas_equalTo(20);
}];
}
//排行
UIView * rankView = [[UIView alloc] init];
rankView.backgroundColor = KWhiteColor;
[self.view addSubview:rankView];
UILabel * rankTitleLab = [[UILabel alloc] init];
rankTitleLab.text = @"积分排行(单位)";
rankTitleLab.textColor = CFontColor1;
[rankView addSubview:rankTitleLab];
[rankTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_offset(15);
make.top.mas_offset(15);
}];
UILabel * detailLab = [[UILabel alloc] init];
detailLab.text = @"以员工累计获得积分进行排名";
detailLab.textColor = CFontColor1;
[rankView addSubview:detailLab];
[detailLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_offset(15);
make.top.mas_equalTo(rankTitleLab.mas_bottom).offset(8);
}];
//周排名 月排名 年排名
UIView * lineView = [[UIView alloc] init];
lineView.backgroundColor = UIColor.blueColor;
self.lineView = lineView;
[rankView addSubview:lineView];
[lineView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_offset(80);
make.height.mas_offset(2);
}];
NSArray * array = @[@"周排名",@"月排名",@"年排名"];
UIButton * lastBtn = nil;
for (int i= 0; i < 3; i ++) {
UIButton * btn = [[UIButton alloc] init];
[btn setTitle:array[i] forState:UIControlStateNormal];
[btn setTitleColor:UIColor.blueColor forState:UIControlStateSelected];
[btn setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
btn.titleLabel.font = MEDIUMFONT(13);
btn.tag = i;
[btn addTarget:self action:@selector(chageDataType:) forControlEvents:UIControlEventTouchUpInside];
btn.selected = false;
if (i == 2) {
btn.selected = true;
lastBtn = btn;
}
[rankView addSubview:btn];
[btn mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_offset(80);
make.height.mas_offset(32);
make.top.mas_equalTo(detailLab.mas_bottom).offset(10);
if (i == 0) {
make.left.mas_offset(82);
}
if (i == 1) {
make.centerX.mas_equalTo(rankView);
}
if (i == 2) {
make.right.mas_offset(-82);
}
}];
[self.buttonArray addObject:btn];
}
if (lastBtn) {
[lineView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(lastBtn);
make.top.mas_equalTo(lastBtn.mas_bottom).offset(5);
}];
}
[rankView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_offset(0);
make.top.mas_equalTo(self.topView.mas_bottom).offset(15);
make.bottom.mas_equalTo(lastBtn.mas_bottom).offset(20);
}];
self.homeTable = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
if ([[UIDevice currentDevice].systemVersion floatValue] >= 11) {
self.homeTable.estimatedRowHeight = 60;
if (@available(iOS 15.0, *)) {
self.homeTable.sectionHeaderTopPadding = 0;
} else {
// Fallback on earlier versions
}
self.homeTable.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
self.homeTable.delegate = self;
self.homeTable.dataSource = self;
self.homeTable.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
self.homeTable.showsVerticalScrollIndicator = NO;
self.homeTable.backgroundColor = KClearColor;
self.homeTable.rowHeight = UITableViewAutomaticDimension;
self.homeTable.estimatedRowHeight = 80;
[self.view addSubview:self.homeTable];
[self.homeTable mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(rankView.mas_bottom);
make.left.bottom.right.mas_offset(0);
}];
__weak __typeof(self) weakSelf = self;
self.homeTable.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
weakSelf.pageNo = 1;
[weakSelf.dataArray removeAllObjects];
[weakSelf createData];
}];
self.homeTable.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
weakSelf.pageNo++;
[weakSelf createData];
}];
LYEmptyView *emptyView = [LYEmptyView emptyViewWithImageStr:@"noDataBox" titleStr:@"暂无数据" detailStr:@""];
//元素竖直方向的间距
emptyView.subViewMargin = 20.f;
//标题颜色
emptyView.titleLabTextColor = [UIColor blackColor];
//描述字体
emptyView.detailLabFont = [UIFont systemFontOfSize:17];
//按钮背景色
emptyView.actionBtnBackGroundColor = KWhiteColor;
emptyView.actionBtnWidth = CGFLOAT_MIN;
emptyView.actionBtnHeight = CGFLOAT_MIN;
//设置空内容占位图
self.homeTable.ly_emptyView = emptyView;
}
- (void)createData {
[self showMBProgressHUDWithString:@"加载中,请稍候..." autoHidden:false];
NSMutableDictionary * parmDic = [[NSMutableDictionary alloc] init];
XJPNetAPI * listApi = [[XJPNetAPI alloc] init:self tag:@"HEARD" NeedToken:@""];
[listApi getPointsBankHeard:parmDic];
}
#pragma mark - DataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.dataArray.count;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCell.new;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
- (CGFloat )tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return CGFLOAT_MIN;
}
- (CGFloat )tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return CGFLOAT_MIN;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
return UIView.new;
}
- (void)chageDataType:(UIButton *)typeBtn {
for (UIButton * seleBtn in self.buttonArray) {
if (seleBtn == typeBtn) {
seleBtn.selected = true;
[self.lineView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(typeBtn);
make.bottom.mas_equalTo(typeBtn.mas_bottom).offset(8);
make.height.mas_offset(1);
make.centerX.mas_equalTo(typeBtn);
}];
}else
{
seleBtn.selected = false;
}
}
//请求接口
if (typeBtn.tag == 0) {
[self creeateRankDataWithTyep:@"1"];
}
if (typeBtn.tag == 1) {
[self creeateRankDataWithTyep:@"2"];
}
if (typeBtn.tag == 2) {
[self creeateRankDataWithTyep:@"0"];
}
}
- (void)creeateRankDataWithTyep:(NSString *)type {
//rankType(榜单类型,0总榜,1周榜,2月榜)
[self showMBProgressHUDWithString:@"加载中,请稍候..." autoHidden:false];
NSMutableDictionary * parmDic = [[NSMutableDictionary alloc] init];
[parmDic setObject:@(self.pageNo) forKey:@"pageNo"];
[parmDic setObject:@"10" forKey:@"pageSize"];
[parmDic setObject:type forKey:@"rankType"];
XJPNetAPI * listApi = [[XJPNetAPI alloc] init:self tag:@"RANK" NeedToken:@""];
[listApi postPointsBankRankData:parmDic];
}
- (void)Failed:(NSString*)message tag:(NSString*)tag
{
[self.homeTable.mj_header endRefreshing];
[self.homeTable.mj_footer endRefreshing];
[self hiddenAllMBProgressHUD];
}
- (void)Sucess:(id)response tag:(NSString*)tag
{
[self.homeTable.mj_header endRefreshing];
[self.homeTable.mj_footer endRefreshing];
if ([tag isEqualToString:@"HEARD"]) {
[self hiddenAllMBProgressHUD];
NSDictionary * responseDic = response;
PointsBankHModel * model = [PointsBankHModel modelWithDictionary:responseDic];
//points 可用积分 addPointsSum 累计积分 exchangePointsSum 累计兑换
self.topView.model = model;
}
if ([tag isEqualToString:@"RANK"]) {
NSDictionary * dic = response;
if ([dic.allKeys containsObject:@"page"]) {
NSDictionary * pageDic = [dic objectForKey:@"page"];
//取到排名
if ([pageDic.allKeys containsObject:@"records"]) {
NSArray * array = [pageDic objectForKey:@"records"];
for (NSDictionary * rankDic in array) {
PointsBankHModel * mdoel = [PointsBankHModel modelWithDictionary:rankDic];
[self.dataArray addObject:mdoel];
}
//处理结束 给数据
[self.homeTable reloadData];
}
}
}
//
}
- (void)itemTap:(UITapGestureRecognizer *)tap {
NSInteger index = tap.view.tag;
NSLog(@"点击了第 %ld 个", index);
if(index == 1 || index == 2) {
[EasyTextView showInfoText:@"开发者,敬请期待!"];
return;
}
}
/*
#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