137 lines
4.4 KiB
Objective-C
137 lines
4.4 KiB
Objective-C
//
|
|
// LMSignInAlertView.m
|
|
// SweetParty
|
|
//
|
|
// Created by Xmac on 2024/8/30.
|
|
//
|
|
|
|
#import "LMSignInAlertView.h"
|
|
#import "LMSignInAlertCollectionViewCell.h"
|
|
#import "LMSignInSuccessAlertView.h"
|
|
|
|
@interface LMSignInAlertView ()<UICollectionViewDelegate,UICollectionViewDataSource>
|
|
|
|
@property (weak, nonatomic) IBOutlet UIButton *confirmButton;
|
|
@property (weak, nonatomic) IBOutlet UICollectionView *signItemView;
|
|
@property (nonatomic, assign) NSInteger today_sign; //1-已签到 2-未签到
|
|
@property (nonatomic, assign) NSInteger sign_num; //已签到天数
|
|
@property (nonatomic, strong) NSMutableArray *dataArr;
|
|
@property (weak, nonatomic) IBOutlet UILabel *signnumLabel;
|
|
|
|
@end
|
|
|
|
@implementation LMSignInAlertView
|
|
|
|
- (void)awakeFromNib
|
|
{
|
|
[super awakeFromNib];
|
|
[self setupUI];
|
|
}
|
|
|
|
- (void)setIsHome:(NSInteger)isHome
|
|
{
|
|
_isHome = isHome;
|
|
if (self.isHome){
|
|
[self setupHomeResp];
|
|
}else{
|
|
[self requestSigninInfo];
|
|
}
|
|
}
|
|
|
|
- (void)setupHomeResp
|
|
{
|
|
NSDictionary *data = [self.response safeDictionaryForKey:@"data"];
|
|
self.sign_num = [data safeIntForKey:@"sign_num"];
|
|
self.today_sign = [data safeIntForKey:@"today_sign"];
|
|
self.signnumLabel.text = [NSString stringWithFormat:@"已累计签到%ld天",self.sign_num];
|
|
self.dataArr = [LMSingListModel mj_objectArrayWithKeyValuesArray:[data safeArrayForKey:@"sign_log"]];
|
|
[self.signItemView reloadData];
|
|
if (self.today_sign == 1){
|
|
self.confirmButton.selected = YES;
|
|
}
|
|
}
|
|
|
|
- (void)setupUI
|
|
{
|
|
UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init];
|
|
flow.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
|
|
|
|
self.signItemView.collectionViewLayout = flow;
|
|
self.signItemView.delegate = self;
|
|
self.signItemView.dataSource = self;
|
|
[self.signItemView registerNib:[UINib nibWithNibName:@"LMSignInAlertCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:LMSignInAlertCollectionViewCellID];
|
|
}
|
|
|
|
|
|
- (IBAction)confirmButtonClick:(UIButton *)sender {
|
|
if (self.today_sign == 1){
|
|
return;
|
|
}
|
|
[BJHttpTool BJ_User_day_signParameters:@{} success:^(id response) {
|
|
NSDictionary *data = [response safeDictionaryForKey:@"data"];
|
|
NSString *award = [data safeStringForKey:@"award"];
|
|
|
|
[self requestSigninInfo];
|
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
LMSignInSuccessAlertView *suc = LoadNib(@"LMSignInSuccessAlertView");
|
|
suc.frame = CGRectMake(0, 0, APPW, APPH);
|
|
suc.sucTipLabel.text = [NSString stringWithFormat:@"签到成功 金币+%@",award];
|
|
[MainWindow() addSubview:suc];
|
|
[self removeFromSuperview];
|
|
});
|
|
} failure:^(NSError *error) {
|
|
|
|
}];
|
|
}
|
|
|
|
- (IBAction)closeButtonClick:(UIButton *)sender {
|
|
[self removeFromSuperview];
|
|
}
|
|
|
|
|
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
|
|
{
|
|
return self.dataArr.count;
|
|
}
|
|
|
|
|
|
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
|
|
{
|
|
LMSignInAlertCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:LMSignInAlertCollectionViewCellID forIndexPath:indexPath];
|
|
if (indexPath.row < self.dataArr.count){
|
|
LMSingListModel *model = self.dataArr[indexPath.row];
|
|
cell.model = model;
|
|
cell.index = indexPath.row;
|
|
}
|
|
return cell;
|
|
}
|
|
|
|
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
|
|
{
|
|
if (indexPath.row < 6){
|
|
return CGSizeMake((APPW-60-12*3)/4, 55);
|
|
}else{
|
|
return CGSizeMake((APPW-60-12*3)/2+15, 55);
|
|
}
|
|
}
|
|
|
|
- (void)requestSigninInfo
|
|
{
|
|
[BJHttpTool BJ_User_day_sign_logParameters:@{} success:^(id response) {
|
|
NSDictionary *data = [response safeDictionaryForKey:@"data"];
|
|
self.sign_num = [data safeIntForKey:@"sign_num"];
|
|
self.today_sign = [data safeIntForKey:@"today_sign"];
|
|
self.signnumLabel.text = [NSString stringWithFormat:@"已累计签到%ld天",self.sign_num];
|
|
self.dataArr = [LMSingListModel mj_objectArrayWithKeyValuesArray:[data safeArrayForKey:@"sign_log"]];
|
|
[self.signItemView reloadData];
|
|
if (self.today_sign == 1){
|
|
self.confirmButton.selected = YES;
|
|
}
|
|
} failure:^(NSError *error) {
|
|
|
|
}];
|
|
}
|
|
|
|
|
|
@end
|