//
//  CoinCenterHeaderView.m
//  Open
//
//  Created by 雷俊博 on 2021/3/1.
//  Copyright © 2021 黄江涛 . All rights reserved.
//

#import "CoinCenterHeaderView.h"
#import "LineCollectionReusableView.h"
#import "SignRemindAlertView.h"
#import "CoinsRankViewController.h"
@interface CoinCenterHeaderView ()<UICollectionViewDelegate,UICollectionViewDataSource>

@property (nonatomic, strong)UIImageView* circleImg;

@property (nonatomic, strong)UILabel* lb_coinsNumTitle;

@property (nonatomic, strong)UIButton* btn1;

@property (nonatomic, strong)UIButton* btn2;

@property (nonatomic, strong)UIButton* btn3;

@property (nonatomic, strong)UIButton* btn4;

@property (nonatomic, strong) UIView *RemindView;

@property (nonatomic, strong)UICollectionView *collectionView;

@property (nonatomic, strong)UIButton *btn_signIn;

@property (nonatomic, strong) UIView *shareView;

@property (nonatomic, strong)NSArray *dateArray;

@property (nonatomic, assign)NSInteger currentIndex;

@property (nonatomic, strong)JDFTooltipView *tipView;

@property (nonatomic, strong)UIView *supView;

@property (nonatomic, assign) BOOL SignRemindstatus;

@property (nonatomic, strong) UIButton *SignSwitch;

@property (nonatomic, strong) UIButton *SignDay;

@property (nonatomic, strong) UIImageView *friendBtn1;

@property (nonatomic, strong) UIImageView *friendBtn2;

@property (nonatomic, strong) UIImageView *friendBtn3;
@end

@implementation CoinCenterHeaderView
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        self.userInteractionEnabled = YES;
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    //顶部白色
    //UIView* bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, cl_kNavigationBarHeight + 151 * WIDTHRADIU)];
    UIView *bgView=[UIView new];
    bgView.backgroundColor = [UIColor colorWithHex:0xFB8F6B];
    //设置所需的圆角位置以及大小
    bgView.frame = CGRectMake(0, 0, ScreenWidth, cl_kNavigationBarHeight + 100 * WIDTHRADIU);
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:bgView.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(30*WIDTHRADIU, 30*WIDTHRADIU)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = bgView.bounds;
    maskLayer.path = maskPath.CGPath;
    bgView.layer.mask = maskLayer;
    
    [self addSubview:bgView];
    
    //[bgView addSubview:self.circleImg];
    [bgView addSubview:self.lb_coinsNum];
    [bgView addSubview:self.lb_coinsNumTitle];
    
    UIButton *btn_tx = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn_tx setTitle:@"金币排行榜" forState:UIControlStateNormal];
    btn_tx.backgroundColor = [UIColor whiteColor];
    [btn_tx setTitleColor:[UIColor colorWithHex:0xF8583E] forState:UIControlStateNormal];
    btn_tx.titleLabel.font = [UIFont systemFontOfSize:15 * WIDTHRADIU];
    btn_tx.frame = CGRectMake(ScreenWidth - 90 * WIDTHRADIU, 20 * WIDTHRADIU+cl_kNavigationBarHeight, 90 * WIDTHRADIU, 32 * WIDTHRADIU);
    [btn_tx addTarget:self action:@selector(txBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [bgView addSubview:btn_tx];
    UIBezierPath *bgViewPath = [UIBezierPath bezierPathWithRoundedRect:btn_tx.bounds byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerBottomLeft) cornerRadii:CGSizeMake(16 * WIDTHRADIU,16 * WIDTHRADIU)];
    //圆角大小
    CAShapeLayer *bgViewLayer = [[CAShapeLayer alloc] init];
    bgViewLayer.frame = btn_tx.bounds;
    bgViewLayer.path = bgViewPath.CGPath;
    btn_tx.layer.mask = bgViewLayer;
//    [self.circleImg addSubview:self.lb_coinsNum];
//    [self.circleImg addSubview:self.lb_coinsNumTitle];
//    [bgView addSubview:self.btn1];
//    [bgView addSubview:self.btn2];
//    [bgView addSubview:self.btn3];
//    [bgView addSubview:self.btn4];
    //签到提醒视图
    [self addSubview:self.RemindView];
    //签到视图
    [self  addSubview:self.collectionView];
    //打卡按钮
    [self addSubview:self.btn_signIn];
    //分享好友
    [self addSubview:self.shareView];
    
    [self navConfig];
    
    
//    [self.circleImg mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerX.equalTo(bgView);
//        make.bottom.offset(0);
//        make.width.offset(175 * WIDTHRADIU);
//        make.height.offset(115 * WIDTHRADIU);
//    }];
    
    [self.lb_coinsNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(15*WIDTHRADIU);
        make.top.offset(10 * WIDTHRADIU+cl_kNavigationBarHeight);
    }];
    
    [self.lb_coinsNumTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lb_coinsNum.mas_bottom).offset(8 * WIDTHRADIU);
        make.left.offset(15*WIDTHRADIU);
    }];
    
//    [self.btn1 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerY.equalTo(self.circleImg);
//        make.right.equalTo(self.circleImg.mas_left).offset(- 20 * WIDTHRADIU);
//        make.width.height.offset(60 * WIDTHRADIU);
//    }];
//
//    [self.btn2 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.bottom.equalTo(self.btn1.mas_top).offset(-5 * WIDTHRADIU);
//        make.left.equalTo(self.btn1.mas_right).offset(- 20 * WIDTHRADIU);
//        make.width.height.offset(60 * WIDTHRADIU);
//    }];
//
//    [self.btn4 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerY.equalTo(self.circleImg);
//        make.left.equalTo(self.circleImg.mas_right).offset(20 * WIDTHRADIU);
//        make.width.height.offset(60 * WIDTHRADIU);
//    }];
//
//    [self.btn3 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.bottom.equalTo(self.btn4.mas_top).offset(-5 * WIDTHRADIU);
//        make.right.equalTo(self.btn4.mas_left).offset(20 * WIDTHRADIU);
//        make.width.height.offset(60 * WIDTHRADIU);
//    }];
    
    [self layoutIfNeeded];
    
    
    [self refreshAnimation];
    
}

#pragma mark - event response
- (void)txBtnClick:(UIButton *)sender{//金币排行榜
    CoinsRankViewController *coinVC = [CoinsRankViewController new];
    coinVC.title = @"我的金币";
    coinVC.hidesBottomBarWhenPushed = YES;
    [self.rootVC.navigationController pushViewController:coinVC animated:YES];
}

- (void)navConfig{
    UIView*navView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, cl_kNavigationBarHeight)];
    navView.backgroundColor = [UIColor whiteColor];
    //返回按钮
    UIButton* backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [backBtn setTitle:@"返回" forState:UIControlStateNormal];
    [backBtn setImage:[UIImage imageNamed:@"backItemImage"] forState:UIControlStateNormal];
    [backBtn setTitleColor:[UIColor colorWithHex:0x4c4c4c] forState:UIControlStateNormal];
    backBtn.frame = CGRectMake(10, cl_kStatusBarHeight, 60, 44);
    [backBtn layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleLeft imageTitleSpace:4];
    [backBtn addTarget:self action:@selector(backClick:) forControlEvents:UIControlEventTouchUpInside];
    
    
    UILabel* lb_title = [UILabel new];
    lb_title.text = @"金币中心";
    lb_title.font = [UIFont boldSystemFontOfSize:17];
    lb_title.textAlignment = NSTextAlignmentCenter;
    lb_title.textColor = [UIColor colorWithHex:0x4c4c4c];
    [navView addSubview:backBtn];
    [navView addSubview:lb_title];
    [lb_title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(cl_kStatusBarHeight);
        make.centerX.equalTo(navView);
        make.height.offset(44);
    }];
    [self addSubview:navView];
    
    UIButton *rightBtn = [[UIButton alloc]init];
    [navView addSubview:rightBtn];
    [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(cl_kStatusBarHeight);
        make.right.offset(-10);
        make.width.offset(50);
        make.height.offset(44);
    }];
    [rightBtn setTitle:@"规则" forState:UIControlStateNormal];
    [rightBtn setTitleColor:[UIColor colorWithHex:0x4c4c4c] forState:UIControlStateNormal];
    rightBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [rightBtn addTarget:self action:@selector(signRules:) forControlEvents:UIControlEventTouchUpInside];
}


- (void)refreshAnimation {
    [self popJumpAnimationView:self.btn1];
    
    [self popJumpAnimationView:self.btn2];
    
    [self popJumpAnimationView:self.btn3];
    
    [self popJumpAnimationView:self.btn4];
}

#pragma mark - 刷新数据
- (void)reloadDataWithData:(NSArray *)dataArray currentIndex:(NSInteger)currentIndex view:(nonnull UIView *)supView {
    
    self.dateArray = dataArray;
    int count = 0;
    if (self.dateArray.count > 0) {
        for (int i = 0; i <= currentIndex; i++) {
            NSDictionary *dic = self.dateArray[i];
            NSString *status = [NSString stringWithFormat:@"%@",dic[@"status"]];
            if ([status isEqualToString:@"302"]) {
                count ++;
            }else{
                if (i == currentIndex) {
                    break;
                }else{
                    count = 0;
                }
                
            }
        }
    }
    [self.SignDay setTitle:[NSString stringWithFormat:@"已连续签到%d天",count] forState:UIControlStateNormal];

    self.supView = supView;
    
    self.currentIndex = currentIndex;
    
    [self.collectionView reloadData];
    
    if (self.tipView == nil) {
        
        if ((currentIndex - 1) >= 0) {
            NSDictionary *dic = dataArray[currentIndex - 1];
            
            NSString *status = [NSString stringWithFormat:@"%@",dic[@"status"]];
            if ([status isEqualToString:@"301"]) {
                
                CGFloat width = (ScreenWidth - (self.dateArray.count * 33 * WIDTHRADIU) - 40 * WIDTHRADIU)/(self.dateArray.count - 1);
                
                CGFloat x  = 20 * WIDTHRADIU + (33* WIDTHRADIU + width) * (self.currentIndex - 1) + 33* WIDTHRADIU/2.0;
                CGPoint targetPoint = CGPointMake(x, cl_kNavigationBarHeight + 161 * WIDTHRADIU);
                JDFTooltipView *tooltip = [[JDFTooltipView alloc] initWithTargetPoint:targetPoint hostView:self tooltipText:@"戳我补签" arrowDirection:JDFTooltipViewArrowDirectionDown width:100.0f];
                
                tooltip.dismissOnTouch = NO;
                
        //        JDFTooltipView *tooltip = [[JDFTooltipView alloc] initWithTargetView:self.collectionView.sub hostView:supView tooltipText:@"戳我补签" arrowDirection:JDFTooltipViewArrowDirectionDown width:100.0f];
        //
        //
                [tooltip show];

                self.tipView = tooltip;
                
            }
        }
        
        
       
    }
    
    
}

#pragma mark - 刷新按钮状态

- (void)refreshBtnStateWithArray:(NSArray *)dataArray {
    
    KKBubbleTaskModel* taskModel0 = dataArray[0];
    KKBubbleTaskModel* taskModel1 = dataArray[1];
    KKBubbleTaskModel* taskModel2 = dataArray[2];
    KKBubbleTaskModel* taskModel3 = dataArray[3];
    
    [self btnStateWithModel:taskModel0 btn:self.btn1];
    [self btnStateWithModel:taskModel1 btn:self.btn2];
    [self btnStateWithModel:taskModel2 btn:self.btn3];
    [self btnStateWithModel:taskModel3 btn:self.btn4];
    
}

- (void)btnStateWithModel:(KKBubbleTaskModel *)model btn:(UIButton *)btn{
    
    if (model.status.boolValue) {
        btn.hidden = YES;
    }else{
        btn.hidden = NO;
    }
    
    switch (model.taskType.intValue) {
        case 60:
        {
            [btn setImage:[UIImage imageNamed:@"coinCenter_lingxianjin"] forState:UIControlStateNormal];
            [btn setTitle:@"幸运金币" forState:UIControlStateNormal];
        }
            break;
        case 61:
        {
            [btn setImage:[UIImage imageNamed:@"coincenter_package"] forState:UIControlStateNormal];
            [btn setTitle:@"每日红包" forState:UIControlStateNormal];
        }
            break;
        case 62:
        {
            [btn setImage:[UIImage imageNamed:@"coincenter_box"] forState:UIControlStateNormal];
            [btn setTitle:@"随机红包" forState:UIControlStateNormal];
        }
            break;
            
        default:
            break;
    }
    
}


#pragma mark - UICollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return self.dateArray.count;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 1;
}
//这是正确的方法
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    SignInCollectionViewCell * cell  = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    [cell refreshUIWithData:self.dateArray[indexPath.section] index:indexPath.section currentIndex:self.currentIndex view:self.supView];
    
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(33 * WIDTHRADIU, 49 * WIDTHRADIU);
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    
    return UIEdgeInsetsMake(0, 0, 0, 0);
}

/**
 分区内cell之间的最小行间距
 */
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    
    return 0.0;
}
/**
 分区内cell之间的最小列间距
 */
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    
    return 0.0;
}


- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.item != (self.dateArray.count - 1) ) {
        LineCollectionReusableView *lineView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"lineCell" forIndexPath:indexPath];
        lineView.backgroundColor = [UIColor whiteColor];
        return lineView;
    }
   
    return nil;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section {
    if (section == (self.dateArray.count - 1)) {
        return CGSizeZero;
    }
    
    CGFloat width = (ScreenWidth - (self.dateArray.count * 33 * WIDTHRADIU) - 40 * WIDTHRADIU)/(self.dateArray.count - 1);
    return CGSizeMake( width > 0 ? width : 17.5 * WIDTHRADIU , 49 * WIDTHRADIU);
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    SignInCollectionViewCell * cell  = (SignInCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(clickWithCell:model:tipView:)] && cell.state == ListCoinsPackageStateBuQian) {
        [self.delegate clickWithCell:cell model:self.dateArray[indexPath.section] tipView:self.tipView];
    }
    
}

#pragma mark - 设置签到按钮状态

- (void)setSignBtnInterace:(BOOL)Interace
{
    if (Interace) {
        [_btn_signIn setTitle:@"打卡领金币" forState:UIControlStateNormal];
        [_btn_signIn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _btn_signIn.titleLabel.font = [UIFont systemFontOfSize:17 * WIDTHRADIU];
        _btn_signIn.backgroundColor = [UIColor colorWithHex:0xed8b0b];
        _btn_signIn.layer.cornerRadius = 22 * WIDTHRADIU;
        _btn_signIn.userInteractionEnabled = YES;
    }else{
        [_btn_signIn setTitle:@"已打卡" forState:UIControlStateNormal];
        [_btn_signIn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _btn_signIn.titleLabel.font = [UIFont systemFontOfSize:17 * WIDTHRADIU];
        _btn_signIn.backgroundColor = [UIColor colorWithHex:0xffd28e];
        _btn_signIn.layer.cornerRadius = 22 * WIDTHRADIU;
        _btn_signIn.userInteractionEnabled = NO;
    }
}
#pragma mark - 设置签到提醒按钮状态
- (void)setSignRemindBtnInterace:(BOOL)Interace{
    self.SignRemindstatus = Interace;
    self.SignSwitch.selected = Interace;
}
#pragma mark - 更新分享用户
- (void)setshareUser:(NSArray *)shareArr{
    if (shareArr.count > 0) {
        for (int i = 0; i < shareArr.count; i++) {
            NSDictionary *dic = shareArr[i];
            if (i == 0) {
                [self.friendBtn1 sd_setImageWithURL:[NSURL URLWithString:dic[@"photoUrl"]] placeholderImage:[UIImage imageNamed:@"shareAdd"]];
            }else if(i == 1){
                [self.friendBtn2 sd_setImageWithURL:[NSURL URLWithString:dic[@"photoUrl"]] placeholderImage:[UIImage imageNamed:@"shareAdd"]];
            }else if(i == 2){
                [self.friendBtn3 sd_setImageWithURL:[NSURL URLWithString:dic[@"photoUrl"]] placeholderImage:[UIImage imageNamed:@"shareAdd"]];
            }
        }
    }
}
#pragma mark - event response
- (void)backClick:(UIButton *)sender{
    if (self.delegate && [self.delegate respondsToSelector:@selector(clickWithBtn:type:)]) {
        [self.delegate clickWithBtn:sender type:BtnTypeBack];
    }
}
//签到
- (void)signBtnClick:(UIButton *)sender {
    if (self.delegate && [self.delegate respondsToSelector:@selector(clickWithBtn:type:)]) {
        [self.delegate clickWithBtn:sender type:BtnTypeSign];
    }
    
}

- (void)btnClick:(UIButton *)sender{
    BtnType type = BtnTypePackage1;
    switch (sender.tag) {
        case 100:
            type = BtnTypePackage1;
            break;
        case 101:
            type = BtnTypeLuckyCoins;
            break;
        case 102:
            type = BtnTypePackage2;
            break;
        case 103:
            type = BtnTypeGiftBox;
            break;
            
        default:
            break;
    }
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(clickWithBtn:type:)]) {
        [self.delegate clickWithBtn:sender type:type];
    }
}



#pragma mark - 上下抖动动画

- (void)popJumpAnimationView:(UIView *)sender {
    
    CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.translation.y"];
    CGFloat duration = 1.f;
    CGFloat height = 7.f;
    CGFloat currentY = sender.transform.ty;
    animation.duration = duration;
    animation.values = @[@(currentY),@(currentY - height/4),@(currentY - height/4*2),@(currentY - height/4*3),@(currentY - height),@(currentY - height/ 4*3),@(currentY - height/4*2),@(currentY - height/4),@(currentY)];
    animation.keyTimes = @[ @(0), @(0.025), @(0.085), @(0.2), @(0.5), @(0.8), @(0.915), @(0.975), @(1) ];
    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    animation.repeatCount = HUGE_VALF;
    animation.removedOnCompletion = NO;
    [sender.layer addAnimation:animation forKey:nil];
   
}

#pragma mark - getters and setters
- (UIImageView *)circleImg {
    if (!_circleImg) {
        _circleImg = [[UIImageView alloc]init];
        _circleImg.image = [UIImage imageNamed:@"coincenter_circle"];
        _circleImg.layer.masksToBounds = YES;
    }
    return _circleImg;
}

- (UICountingLabel *)lb_coinsNum
{
    if (!_lb_coinsNum) {
        _lb_coinsNum = [[UICountingLabel alloc]init];
        _lb_coinsNum.text = @"0";
        _lb_coinsNum.method = UILabelCountingMethodEaseOut;
        _lb_coinsNum.format = @"%d";
        _lb_coinsNum.textColor = [UIColor whiteColor];
        _lb_coinsNum.font = [UIFont boldSystemFontOfSize:35 * WIDTHRADIU];
        _lb_coinsNum.textAlignment = NSTextAlignmentCenter;
    }
    return _lb_coinsNum;
}

- (UILabel *)lb_coinsNumTitle
{
    if (!_lb_coinsNumTitle) {
        _lb_coinsNumTitle = [[UILabel alloc]init];
        _lb_coinsNumTitle.text = @"本月底到期金币数:0";
        _lb_coinsNumTitle.textColor = [UIColor whiteColor];
        _lb_coinsNumTitle.font = [UIFont systemFontOfSize:13 * WIDTHRADIU];
        _lb_coinsNumTitle.textAlignment = NSTextAlignmentCenter;
    }
    return _lb_coinsNumTitle;
}

- (UIButton *)btn1
{
    if (!_btn1) {
        _btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
        [_btn1 setImage:[UIImage imageNamed:@"coincenter_package"] forState:UIControlStateNormal];
        [_btn1 setTitle:@"每日红包" forState:UIControlStateNormal];
        _btn1.titleLabel.font = [UIFont systemFontOfSize:13 * WIDTHRADIU];
        [_btn1 layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleTop imageTitleSpace:4];
        _btn1.tag = 100;
        [_btn1 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _btn1;
}

- (UIButton *)btn2
{
    if (!_btn2) {
        _btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
        [_btn2 setImage:[UIImage imageNamed:@"coinCenter_lingxianjin"] forState:UIControlStateNormal];
        [_btn2 setTitle:@"幸运金币" forState:UIControlStateNormal];
        _btn2.titleLabel.font = [UIFont systemFontOfSize:13 * WIDTHRADIU];
        [_btn2 layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleTop imageTitleSpace:4];
        _btn2.tag = 101;
        [_btn2 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _btn2;
}

- (UIButton *)btn3
{
    if (!_btn3) {
        _btn3 = [UIButton buttonWithType:UIButtonTypeCustom];
        [_btn3 setImage:[UIImage imageNamed:@"coincenter_package"] forState:UIControlStateNormal];
        [_btn3 setTitle:@"每日红包" forState:UIControlStateNormal];
        _btn3.titleLabel.font = [UIFont systemFontOfSize:13 * WIDTHRADIU];
        [_btn3 layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleTop imageTitleSpace:4];
        _btn3.tag = 102;
        [_btn3 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _btn3;
}

- (UIButton *)btn4
{
    if (!_btn4) {
        _btn4 = [UIButton buttonWithType:UIButtonTypeCustom];
        [_btn4 setImage:[UIImage imageNamed:@"coincenter_box"] forState:UIControlStateNormal];
        [_btn4 setTitle:@"随机红包" forState:UIControlStateNormal];
        _btn4.titleLabel.font = [UIFont systemFontOfSize:13 * WIDTHRADIU];
        [_btn4 layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleTop imageTitleSpace:4];
        _btn4.tag = 103;
        [_btn4 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _btn4;
}
- (UIView *)RemindView{
    if (_RemindView == nil) {
        _RemindView = [[UIView alloc]initWithFrame:CGRectMake(0, cl_kNavigationBarHeight + 100 * WIDTHRADIU, ScreenWidth, 40 * WIDTHRADIU)];
        
        UIButton *SignDay = [[UIButton alloc]initWithFrame:CGRectMake(20 * WIDTHRADIU, 0 , 100 * WIDTHRADIU, 30 * WIDTHRADIU)];
        [SignDay setTitleColor:[UIColor colorWithHex:0x808080] forState:UIControlStateNormal];
        SignDay.titleLabel.font = [UIFont systemFontOfSize:13 * WIDTHRADIU];
        [SignDay setTitle:@"已连续签到0天" forState:UIControlStateNormal];
        [_RemindView addSubview:SignDay];
        
        UIButton *SignSwitch = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth - 100 , 0, 90, 30)];
        [SignSwitch setTitleColor:[UIColor colorWithHex:0x808080] forState:UIControlStateNormal];
        SignSwitch.titleLabel.font = [UIFont systemFontOfSize:13 * WIDTHRADIU];
        [SignSwitch setTitle:@"签到提醒" forState:UIControlStateNormal];
        [SignSwitch setImage:[UIImage imageNamed:@"signSwitchClose"] forState:UIControlStateNormal];
        [SignSwitch setImage:[UIImage imageNamed:@"signSwitchOpen"] forState:UIControlStateSelected];
        [SignSwitch addTarget:self action:@selector(signSwitch:) forControlEvents:UIControlEventTouchUpInside];
        [SignSwitch layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleLeft imageTitleSpace:5];
        _SignSwitch = SignSwitch;
        [_RemindView addSubview:SignSwitch];
    }
    return _RemindView;
}
- (UIView *)shareView{
    if (_shareView == nil) {
        _shareView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.btn_signIn.frame), ScreenWidth, 100 * WIDTHRADIU)];
        _shareView.backgroundColor = [UIColor whiteColor];
        
        UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 10 * WIDTHRADIU, ScreenWidth, 10 * WIDTHRADIU)];
        lineView.backgroundColor = [UIColor colorWithHex:0xf5f5f5];
        [_shareView addSubview:lineView];
        
        UILabel *titleLabe = [[UILabel alloc]initWithFrame:CGRectMake(10 * WIDTHRADIU, 25 * WIDTHRADIU, ScreenWidth - 40 * WIDTHRADIU, 30 * WIDTHRADIU)];
        titleLabe.textColor = [UIColor colorWithHex:0x4d4d4d];
        titleLabe.font = [UIFont systemFontOfSize:15 * WIDTHRADIU];
        titleLabe.text = @"分享群好友  金币翻倍领";
        [_shareView addSubview:titleLabe];

        UIButton *invitationBtn = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth - 135 , 60 * WIDTHRADIU, 120, 40 * WIDTHRADIU)];
        [invitationBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        invitationBtn.titleLabel.font = [UIFont systemFontOfSize:14 * WIDTHRADIU];
        [invitationBtn setTitle:@"立即邀请" forState:UIControlStateNormal];
        invitationBtn.backgroundColor = [UIColor colorWithHex:0xed8b0b];
        invitationBtn.layer.cornerRadius = 20 * WIDTHRADIU;
        [invitationBtn addTarget:self action:@selector(invitationBtn:) forControlEvents:UIControlEventTouchUpInside];
        [_shareView addSubview:invitationBtn];
        
        CGFloat spacing = (ScreenWidth - 46 * WIDTHRADIU * 3 - 135 - 15)/3;
        UIImageView *friendBtn1 = [[UIImageView alloc]initWithFrame:CGRectMake(10, 0, 46 * WIDTHRADIU, 46 * WIDTHRADIU)];
        friendBtn1.centerY = invitationBtn.centerY;
        friendBtn1.image = [UIImage imageNamed:@"shareAdd"];
        friendBtn1.layer.cornerRadius = 23 * WIDTHRADIU;
        friendBtn1.layer.masksToBounds = YES;
        _friendBtn1 = friendBtn1;
        [_shareView addSubview:friendBtn1];
        
        UIImageView *friendBtn2 = [[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(friendBtn1.frame) + spacing, 0, 46 * WIDTHRADIU, 46 * WIDTHRADIU)];
        friendBtn2.centerY = invitationBtn.centerY;
        friendBtn2.image = [UIImage imageNamed:@"shareAdd"];
        friendBtn2.layer.cornerRadius = 23 * WIDTHRADIU;
        friendBtn2.layer.masksToBounds = YES;
        _friendBtn2 = friendBtn2;
        [_shareView addSubview:friendBtn2];
        
        UIImageView *friendBtn3 = [[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(friendBtn2.frame) + spacing, 0, 46 * WIDTHRADIU, 46 * WIDTHRADIU)];
        friendBtn3.centerY = invitationBtn.centerY;
        friendBtn3.image = [UIImage imageNamed:@"shareAdd"];
        friendBtn3.layer.cornerRadius = 23 * WIDTHRADIU;
        friendBtn3.layer.masksToBounds = YES;
        _friendBtn3 = friendBtn3;
        [_shareView addSubview:friendBtn3];
    }
    return _shareView;
}
- (UICollectionView *)collectionView
{
    if (!_collectionView) {
        //创建一个layout布局类
        UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init];
        //设置布局方向为垂直流布局
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        //设置每个item的大小为100*100
        layout.itemSize = CGSizeMake(100, 60);

        _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(20 * WIDTHRADIU, CGRectGetMaxY(self.RemindView.frame), ScreenWidth - 40 * WIDTHRADIU, 49 * WIDTHRADIU) collectionViewLayout:layout];
        _collectionView.backgroundColor = [UIColor whiteColor];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        [_collectionView registerClass:[SignInCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
        [_collectionView registerClass:[LineCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"lineCell"];
    }
    return _collectionView;
}

- (UIButton *)btn_signIn
{
    if (!_btn_signIn) {
        _btn_signIn = [UIButton buttonWithType:UIButtonTypeCustom];
        _btn_signIn.frame = CGRectMake(10 * WIDTHRADIU, CGRectGetMaxY(self.collectionView.frame) + 15 * WIDTHRADIU, ScreenWidth - 20 * WIDTHRADIU, 45 * WIDTHRADIU);
        [_btn_signIn setTitle:@"打卡领金币" forState:UIControlStateNormal];
        [_btn_signIn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _btn_signIn.titleLabel.font = [UIFont systemFontOfSize:17 * WIDTHRADIU];
        _btn_signIn.backgroundColor = [UIColor colorWithHex:0xed8b0b];
        _btn_signIn.layer.cornerRadius = 22 * WIDTHRADIU;
        _btn_signIn.userInteractionEnabled = YES;
        _btn_signIn.tag = 104;
        [_btn_signIn addTarget:self action:@selector(signBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _btn_signIn;
}
#pragma mark - 签到规则
- (void)signRules:(UIButton *)sender{
    BtnType type = BtnTypeSignRuler;
    if (self.delegate && [self.delegate respondsToSelector:@selector(clickWithBtn:type:)]) {
        [self.delegate clickWithBtn:sender type:type];
    }
}
#pragma mark - 开启签到提醒
- (void)signSwitch:(UIButton *)button{
    if (button.selected) {
        WeakSelf
        [SignRemindAlertView showInWindowWithImageName:@"" VC:self.rootVC OpneBlock:^(BOOL success) {
            
        } ShutdownBlock:^(BOOL success) {
            button.selected = NO;
            weakSelf.SignRemindstatus = NO;
            [weakSelf UpdateSignRemind];
        }];
    }else{
        button.selected = YES;
        self.SignRemindstatus = YES;
        [self UpdateSignRemind];
    }
}
#pragma mark - 立即邀请
- (void)invitationBtn:(UIButton *)sender{
    BtnType type = BtnTypeSignShare;
    if (self.delegate && [self.delegate respondsToSelector:@selector(clickWithBtn:type:)]) {
        [self.delegate clickWithBtn:sender type:type];
    }
}
#pragma mark - 更新签到提醒状态
- (void)UpdateSignRemind{
    NSString *clientId = [UserDefault valueForKey:@"clientId"];
    if (clientId && clientId.length == 0) {
        return;
    }
     NSString *url = [NSString stringWithFormat:@"%@save/cid",[NetworkConfig ipYinShuConfig]];
//        NSString *url = [NSString stringWithFormat:@"%@save/cid",@"http://172.16.10.18:8017/"];
    NSString *SignRemindstatus = @"0";
    if (self.SignRemindstatus) {
        SignRemindstatus = @"1";
    }else{
        SignRemindstatus = @"0";
    }
    NSDictionary *params1 = @{
        @"cid":clientId,
        @"uid":@([getPeopleID PeopleID]),
        @"status":SignRemindstatus,
        @"type":@(1001)
    };
    [NetworkRequest PostNo:url Params:params1 Success:^(id _Nonnull objc) {
       
        NSLog(@"===========%@",objc);
    } Failure:^(NSError *error) {
        NSLog(@"error:%@",error);
    }];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
