You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

227 lines
7.7 KiB

//
// SingViewController.m
// tongxin
//
// Created by ecell on 2023/3/30.
// Copyright © 2023 xTT. All rights reserved.
//
#import "SingViewController.h"
#import "EBCalendarView.h"
#import "SignListModel.h"
#import "SignRuleViewController.h"
@interface SingViewController ()<EBCalendarViewDelegate>
@property (nonatomic ,strong) UIView *headerView;
@property (nonatomic,strong) EBCalendarView *calendarView;
@property (nonatomic ,weak) UILabel *leftLabel;
@property (nonatomic ,weak) UILabel *rightLabel;
@end
@implementation SingViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.title = @"签到领积分";
[self zx_setRightBtnWithText:@"签到规则" clickedBlock:^(ZXNavItemBtn * _Nonnull btn) {
SignRuleViewController *vc = [[SignRuleViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
}];
self.view.backgroundColor = tabViewBG;
[self.view addSubview:self.headerView];
[self.headerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.view).inset(14);
make.top.equalTo(self.view).offset(iPhoneX_NavHeight+20);
make.height.mas_equalTo(Adapted(100));
}];
[self.view addSubview:self.calendarView];
[self querySign];
}
#pragma mark - EBCalendarViewDelegate
- (void)calendarView:(EBCalendarView*)calendarView didSelectedDate:(NSDate*)date
{
[self SetSign];
}
- (void)querySign
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM"];
NSString *currentDateStr = [dateFormatter stringFromDate:[NSDate date]];
[self GetSignInfo:currentDateStr];
}
- (EBCalendarView *)calendarView
{
if (!_calendarView)
{
_calendarView = [[EBCalendarView alloc] initWithFrame:CGRectMake(15, iPhoneX_NavHeight+20+Adapted(100)+20, ScreenWidth-30, 363)];
_calendarView.delegate = self;
_calendarView.layer.cornerRadius = 5;
_calendarView.layer.masksToBounds = YES;
_calendarView.layer.shadowColor = [UIColor blackColor].CGColor;
_calendarView.layer.shadowOpacity = 0.2f;
_calendarView.layer.shadowRadius = 4.f;
_calendarView.layer.shadowOffset = CGSizeMake(1,1);
}
return _calendarView;
}
#pragma mark 查询签到信息
/// 查询签到信息
- (void)GetSignInfo:(NSString *)time
{
WEAKSELF
[cUser.cDevice GetAccountsSignWithMonth:time Success:^(id responseObject) {
NSDictionary *data = responseObject[@"data"];
if (data)
{
SignListModel *model = [SignListModel yy_modelWithJSON:data];
self.leftLabel.attributedText = [self labelFontSize:[NSString stringWithFormat:@"连续签到数\n%ld",model.keepSignDays]];
self.rightLabel.attributedText = [self labelFontSize:[NSString stringWithFormat:@"当前积分\n%ld",model.total]];
NSMutableArray *timeArr = [NSMutableArray new];
[model.signList enumerateObjectsUsingBlock:^(NSDictionary *obj, NSUInteger idx, BOOL * _Nonnull stop) {
// NSDate *timeStampToDate = [NSDate dateWithTimeIntervalSince1970:[obj[@"t"] integerValue]];
// [timeArr addObject:timeStampToDate];
[timeArr addObject:obj[@"date"]];
}];
weakSelf.calendarView.signDate = timeArr;
[weakSelf.calendarView signViewUpdate];
}
} failure:^(NSError *error) {
}];
}
#pragma mark 签到
/// 签到
- (void)SetSign
{
[cUser.cDevice SetAccountsSign:^{
} failure:^(NSError *error) {
}];
}
- (UIView *)headerView
{
if (!_headerView)
{
_headerView = [[UIView alloc] init];
_headerView.backgroundColor = UIColor.whiteColor;
_headerView.layer.cornerRadius = 5;
_headerView.layer.masksToBounds = YES;
UIImageView *rightImg = [[UIImageView alloc] init];
rightImg.image = [UIImage imageNamed:@"sign_duty_calendar_book_img"];
[_headerView addSubview:rightImg];
[rightImg mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(_headerView);
make.right.equalTo(_headerView.mas_right).inset(10);
make.height.width.mas_equalTo(AdaptedHeight(rightImg.image.size.width));
}];
UIView *bgView = [[UIView alloc] init];
bgView.backgroundColor = UIColor.whiteColor;
bgView.layer.cornerRadius = 5;
bgView.layer.shadowColor = [UIColor blackColor].CGColor;
bgView.layer.shadowOpacity = 0.2f;
bgView.layer.shadowRadius = 4.f;
bgView.layer.shadowOffset = CGSizeMake(1,1);
[_headerView addSubview:bgView];
[bgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_headerView);
make.right.equalTo(rightImg.mas_left).inset(10);
make.top.equalTo(_headerView.mas_top);
make.bottom.equalTo(_headerView.mas_bottom);
}];
UIImageView *line = [UIImageView new];
line.backgroundColor = RGB(235, 235, 235);
[bgView addSubview:line];
[line mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(bgView.mas_centerX);
make.top.equalTo(bgView.mas_top).offset(5);
make.bottom.equalTo(bgView.mas_bottom).inset(5);
make.width.mas_equalTo(1);
}];
UILabel *leftLabel = [UILabel new];
leftLabel.textColor = mainColor;
leftLabel.font = FontBold_(40);
leftLabel.numberOfLines = 0;
self.leftLabel = leftLabel;
[bgView addSubview:leftLabel];
[leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(bgView);
make.left.equalTo(bgView);
make.right.equalTo(line.mas_left);
}];
UILabel *rightLabel = [UILabel new];
rightLabel.textColor = mainColor;
rightLabel.numberOfLines = 0;
rightLabel.font = FontBold_(40);
self.rightLabel = rightLabel;
[bgView addSubview:rightLabel];
[rightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(bgView);
make.right.equalTo(bgView.mas_right);
make.left.equalTo(line.mas_right);
}];
}
return _headerView;
}
/// 指定字符大小
/// @param text 内容
- (NSAttributedString *)labelFontSize:(NSString *)text
{
NSRange symbolRange = [text rangeOfString:@"连续签到数"];
NSRange symbolRange1 = [text rangeOfString:@"当前积分"];
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:text];
if (symbolRange.location != NSNotFound) {
[string addAttribute:NSFontAttributeName value:Font_(15) range:NSMakeRange(symbolRange.location, symbolRange.length)];
}
if (symbolRange1.location != NSNotFound) {
[string addAttribute:NSFontAttributeName value:Font_(15) range:NSMakeRange(symbolRange1.location, symbolRange1.length)];
}
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineSpacing = 5;
paragraphStyle.alignment = NSTextAlignmentCenter;
[string addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, string.length)];
return string;
}
/*
#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