//
//  OnFootEarnCoinsViewController.m
//  Open
//
//  Created by 雷俊博 on 2019/8/29.
//  Copyright © 2019 黄江涛 . All rights reserved.
//

#import "OnFootEarnCoinsViewController.h"
#import "Constants.h"


#import <Masonry.h>

#import "CQCountDownButton.h"



#import <UICountingLabel.h>
#import "MQGradientProgressView.h"
#import "OnFootAlertView.h"

//获取步数
#import <CoreMotion/CoreMotion.h>
#import "CTAPIBaseManager.h"


#import "kankanshebaoxieyi.h"

#import "WXApi.h"


@interface OnFootEarnCoinsViewController ()<CQCountDownButtonDataSource, CQCountDownButtonDelegate,UIScrollViewDelegate>
{
    BOOL open;
    
    NSString*recordid;
    NSInteger stepNum;
    
}


@property (nonatomic, strong)UIView *backView;

@property (nonatomic, strong)UIScrollView *scrollView;

@property (nonatomic, strong)UIImageView *backImg;

@property (nonatomic, strong)UIImageView *img_ring;

@property (nonatomic, strong)UILabel *lb_stepNumberTitle;

@property (nonatomic, strong)UICountingLabel *lb_stepNumber;

@property (nonatomic, strong)CQCountDownButton *btn_refreshStepNumber;

@property (nonatomic, strong)UIView *whiteCardView;

@property (nonatomic, strong)UILabel *lb_startStep;
@property (nonatomic, strong)UILabel *lb_endStep;
@property (nonatomic, strong)UIImageView *img_person;
@property (nonatomic, strong)MQGradientProgressView *progressView;
@property (nonatomic, strong)UIImageView *img_coins;

@property (nonatomic, strong)UILabel *lb_message;

@property (nonatomic, strong)UIButton *btn_GetCoins;

@property (nonatomic, strong)UIButton *btn_Invite;

@property (nonatomic, strong)UILabel *lb_rule;

@property (nonatomic, assign)NSInteger currentStepCount;

@property(nonatomic,strong)CMPedometer *pedometer;





@end

@implementation OnFootEarnCoinsViewController
#pragma mark - life cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self navConfig];
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.scrollView];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setTitle:@"允许获取用户步数即表示同意隐私政策" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor colorWithHex:0x808080] forState:UIControlStateNormal];
    
    NSMutableAttributedString *fontAttributeNameStr = [[NSMutableAttributedString alloc]initWithString:btn.titleLabel.text];
     btn.titleLabel.font = [UIFont systemFontOfSize:12];
    
    [fontAttributeNameStr addAttribute:NSForegroundColorAttributeName value:K_MainColor range:NSMakeRange(13, 4)];
    btn.titleLabel.attributedText = fontAttributeNameStr;
    
    [btn addTarget:self action:@selector(checkAgreementClick:) forControlEvents:UIControlEventTouchUpInside];
    
    
   
    [self.view addSubview:btn];
    
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.scrollView.mas_bottom).mas_offset(5);
        make.centerX.equalTo(self.view);
    }];
    
    [self setupUI];
    
    
    
    [self getStepCount];
    
    
    NSMutableArray *vcArr = [[NSMutableArray alloc]initWithArray:self.navigationController.viewControllers];
       
       for (UIViewController* vc in vcArr) {
           if ([vc isKindOfClass:[WebVC class]]) {
               [vcArr removeObject:vc];
               break;
           }
       }
       self.navigationController.viewControllers = vcArr;
    
    
    
    
    
   
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    

    //self.navigationController.navigationBar.translucent = NO;
    
    [self.navigationController.navigationBar navBarBackGroundColor:[UIColor colorWithHex:0x18aa6f] image:nil isOpaque:YES];//颜色
            
       [self.navigationController.navigationBar navBarBottomLineHidden:YES];
//    self.navigationController.navigationBar.barTintColor = [UIColor colorWithHex:0x18aa6f];
//    
//    [self.transitionCoordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext>  _Nonnull context) {
//        self.navigationController.navigationBar.barTintColor = [UIColor colorWithHex:0x18aa6f];
//        [self.navigationController.navigationBar setBackgroundImage:[UIImage  imageNamed:@""] forBarMetrics:UIBarMetricsDefault];
//    } completion:^(id<UIViewControllerTransitionCoordinatorContext>  _Nonnull context) {
//    }];
    
    [self.navigationController setNavigationBarHidden:YES animated:animated];

}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBar.translucent = YES;
    
}


- (void)navConfig
{
    
    
    UIView*navView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, cl_kNavigationBarHeight)];
    navView.backgroundColor = [UIColor colorWithHex:0x18aa6f];
    [self.view addSubview:navView];
    
    
    UIButton * backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake( 10 * WIDTHRADIU, cl_kStatusBarHeight , 50, 44);
    backBtn.titleLabel.textAlignment =NSTextAlignmentLeft;
    [backBtn setTitle:@"返回" forState:UIControlStateNormal];
    [backBtn setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    //    [button_2 setBackgroundColor:[UIColor redColor]];
    //    [button_2 setTitleColor:[UIColor colorWithRed:12.0 green:12.0 blue:12.0 alpha:1] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    [navView addSubview:backBtn];
    [backBtn layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleLeft imageTitleSpace:3];
    
    
    
    
    //title
    UILabel* lb_title = [[UILabel alloc]init];
    lb_title.textColor = [UIColor whiteColor];
    lb_title.font = [UIFont boldSystemFontOfSize:17 * WIDTHRADIU];
    lb_title.textAlignment = NSTextAlignmentCenter;
    [navView addSubview:lb_title];
    
    lb_title.text = self.title;
    
    [lb_title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(navView);
        make.height.offset(25);
        make.top.offset(cl_kStatusBarHeight + 9.5);
    }];
}


#pragma mark - loadApi
- (NSDictionary *)getstepRequestPara:(NSInteger)step
{
    NSDictionary *dic = @{      @"userid":[NSNumber numberWithInteger:[getPeopleID PeopleID]],
                                @"telephone":[EnercryTool encryptUseDES:[getPeopleID PeopleIphoneNmber] key:DESKEY],
                                @"stepNum":@(step),
                                @"reqStamp":[NSNumber numberWithInteger:[self getNowTimeTimestamp3]],
                                };
    NSArray *result = [dic.allKeys sortedArrayUsingComparator:^NSComparisonResult(id  _Nonnull obj1, id  _Nonnull obj2) {
              
              NSLog(@"%@~%@",obj1,obj2); //3~4 2~1 3~1 3~2
              
              return [obj1 compare:obj2]; //升序
              
          }];
          NSString *sign = nil;
          for (int i = 0; i < result.count; i++) {
              NSString *key = result[i];
              if (i==0) {
                  sign = [NSString stringWithFormat:@"%@=%@",key,dic[key]];
              }else{
                  
                  sign = [NSString stringWithFormat:@"%@&%@=%@",sign,key,dic[key]];
              }
          }
          
          sign = [NSString stringWithFormat:@"%@&Kanwf574",sign];
          
          NSMutableDictionary *params = [[NSMutableDictionary alloc]initWithDictionary:dic];
          
          NSString *signString = [[MyMD5 md5:sign] lowercaseString];
          [params setObject:signString forKey:@"sign"];
    return params;
}


- (void)getstepRequest:(NSInteger)step
{
    NSString *url = [NSString stringWithFormat:@"%@walkservice/getstep",CoinsBaseUrl];
    NSLog(@"获取指定用户的走路步数url:%@",url);
    NSLog(@"params:%@",[self getstepRequestPara:step]);
    WeakSelf
    [KKLoadingAnimationView show];
    [CTAPIBaseManager POST:url params:[self getstepRequestPara:step] completionHandler:^(id  _Nonnull responseObject, NSError * _Nonnull error) {
        [KKLoadingAnimationView dismiss];
        if (error) {
            NSLog(@"error:%@",error);
            [SVProgressHUD showErrorWithStatus:@"无网络"];
        }
        
        if (responseObject) {
            NSLog(@"responseObject:%@",responseObject);
            
            if ([responseObject isKindOfClass:[NSDictionary class]]) {
                NSString *code = [NSString stringWithFormat:@"%@",responseObject[@"code"]];
                NSString *des = [NSString stringWithFormat:@"%@",responseObject[@"des"]];
                if ([code isEqualToString:@"0"]) {
                    NSDictionary*result = responseObject[@"result"];
                    self->recordid = [NSString stringWithFormat:@"%@",result[@"id"]];
                    self->stepNum = [NSString stringWithFormat:@"%@",result[@"stepNum"]].integerValue + [NSString stringWithFormat:@"%@",result[@"shareNum"]].integerValue;
                    
                    weakSelf.currentStepCount = self->stepNum ;
   
                }else if ([code isEqualToString:@"2006"]){
                    NSDictionary*result = responseObject[@"result"];
                    self->recordid = [NSString stringWithFormat:@"%@",result[@"id"]];
                    self->stepNum = [NSString stringWithFormat:@"%@",result[@"stepNum"]].integerValue + [NSString stringWithFormat:@"%@",result[@"shareNum"]].integerValue;
                    
                    weakSelf.currentStepCount = self->stepNum ;
                    [self.btn_GetCoins setTitle:@"恭喜已达标,金币领取成功" forState:UIControlStateNormal];
                    _btn_GetCoins.backgroundColor = [UIColor colorWithHex:0xcccccc];
                    [_btn_GetCoins setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                    [self.btn_GetCoins setBackgroundImage:nil forState:UIControlStateNormal];
                    self.btn_GetCoins.userInteractionEnabled = NO;
                    self.lb_message.text = @"提示：恭喜您今日任务已完成，明天再接再厉！";
                }else if ([code isEqualToString:@"2002"]){
                    [SVProgressHUD showErrorWithStatus:@"当前时间与网络时间不一致!!!"];
                }else if ([code isEqualToString:@"1001"] || [code isEqualToString:@"9999"]){
                    [SVProgressHUD showErrorWithStatus:@"服务器繁忙,请稍等!!!"];
                }else if ([code isEqualToString:@"1009"]){
                    [SVProgressHUD showErrorWithStatus:@"系统错误,请退出重试!!"];
                } else{
                    [SVProgressHUD showErrorWithStatus:des];
                }
            }else{
               [SVProgressHUD showErrorWithStatus:@"服务器异常"];
            }
        }
        
        [weakSelf.lb_stepNumber countFrom:weakSelf.lb_stepNumber.text.integerValue to:weakSelf.currentStepCount];
        
    }];
}

- (NSDictionary *)getincreateScoreRequestPara
{
    NSDictionary *dic = @{      @"userId":[NSNumber numberWithInteger:[getPeopleID PeopleID]],
                                @"telephone":[EnercryTool encryptUseDES:[getPeopleID PeopleIphoneNmber] key:DESKEY],
                                @"scoreType":@"1013",
                                @"reqTimesTamp":[NSNumber numberWithInteger:[self getNowTimeTimestamp3]],
                                @"fromModel":@"2"
                                };
    NSArray *result = [dic.allKeys sortedArrayUsingComparator:^NSComparisonResult(id  _Nonnull obj1, id  _Nonnull obj2) {
              
              NSLog(@"%@~%@",obj1,obj2); //3~4 2~1 3~1 3~2
              
              return [obj1 compare:obj2]; //升序
              
          }];
          NSString *sign = nil;
          for (int i = 0; i < result.count; i++) {
              NSString *key = result[i];
              if (i==0) {
                  sign = [NSString stringWithFormat:@"%@=%@",key,dic[key]];
              }else{
                  
                  sign = [NSString stringWithFormat:@"%@&%@=%@",sign,key,dic[key]];
              }
          }
          
          sign = [NSString stringWithFormat:@"%@&Kanwf574",sign];
          
          NSMutableDictionary *params = [[NSMutableDictionary alloc]initWithDictionary:dic];
          
          NSString *signString = [[MyMD5 md5:sign] lowercaseString];
          [params setObject:signString forKey:@"sign"];
    return params;
}


- (void)getincreateScoreRequest:(UIButton *)sender
{
    NSString *url = [NSString stringWithFormat:@"%@/score/increateScore",CoinsBaseUrl];
    NSLog(@"走路赚金币url:%@",url);
    NSLog(@"params:%@",[self getincreateScoreRequestPara]);
       WeakSelf
    [KKLoadingAnimationView show];
       [CTAPIBaseManager POST:url params:[self getincreateScoreRequestPara] completionHandler:^(id  _Nonnull responseObject, NSError * _Nonnull error) {
           [KKLoadingAnimationView dismiss];
           sender.userInteractionEnabled = YES;
           if (error) {
               NSLog(@"error:%@",error);
           }
           
           if (responseObject) {
               NSLog(@"responseObject:%@",responseObject);
           }
           
           if (responseObject) {
               NSNumber *code = responseObject[@"code"];
               NSString *des = responseObject[@"des"];
               if (code.integerValue == 1006) {
                   
                   [getPeopleID setOnFootCoinsDate:[NSDate date]];
                   [weakSelf getStepCount];
                   [OnFootAlertView alertWithButtonClickedBlock:^{
                       sender.userInteractionEnabled = NO;
                       [self refreshCoins:sender];
                      }];
                    
                  
                   
               }else{
                   [self alertShow:des];
               }
           }
           
           
       }];
}


#pragma mark - call api
- (void)refreshCoins:(UIButton *)sender
{
    
    if ([getPeopleID PeopleID] && [getPeopleID PeopleIphoneNmber])
    {
        NSDictionary *params = @{
                                 @"userId":[NSNumber numberWithInteger:[getPeopleID PeopleID]],
                                 @"telephone": [EnercryTool encryptUseDES:[getPeopleID PeopleIphoneNmber] key:DESKEY]
                                 };
        NSString *url =[NSString stringWithFormat:@"%@score/getpersonintegrals",CoinsBaseUrl];
        [BaseNetManager POST2:url parameters:params completionHandler:^(id responseObj, NSError *error) {
            sender.userInteractionEnabled = YES;
            if (error) {
                [SVProgressHUD showInfoWithStatus:@"无网络"];
                return ;
            }
            if (responseObj) {
                NSString *code = [responseObj[@"code"] stringValue];
                if ([code isEqualToString:@"0"]) {
                    [getPeopleID getTotalCoins:responseObj[@"result"]];
                   
                    WebVC *webVC = [[WebVC alloc]init];
                     webVC.title = @"金币抽奖";
                     //外网http://nginx.weface.com.cn/lesson/award/src/award.html
                     //内网@"http://172.16.10.121/projects/html-nginx/html-nginx/lesson/award/src/award.html"
                    webVC.url = CoinsRewardedUrl;
                      //webVC.url = @"http://172.16.10.144/projects/html-nginx/html-nginx/lesson/award/src/award.html";
                     [self.navigationController pushViewController:webVC animated:YES];
                    
                    return ;
                }
            }
            
        
        }];
    }
}


//判断当前是否可以领取
- (BOOL)canRequestOnFootApi
{
       NSDate *oldTime = [getPeopleID getOnFootCoinsDate];

       if (oldTime && [self isSameDay:[NSDate date] date2:oldTime]) {
           return NO;
       }
    
    return YES;
    
}


#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    NSLog(@"y:%lf",scrollView.contentOffset.y);
    if (scrollView.contentOffset.y <= 0) {
        scrollView.contentOffset = CGPointMake(scrollView.contentOffset.x, 0);
    }
}

#pragma mark - CQCountDownButton DataSource

// 设置起始倒计时秒数
- (NSUInteger)startCountDownNumOfCountDownButton:(CQCountDownButton *)countDownButton {
    return 60;
}

#pragma mark - CQCountDownButton Delegate

// 倒计时按钮点击回调
- (void)countDownButtonDidClick:(CQCountDownButton *)countDownButton {
    [self.btn_refreshStepNumber startCountDown];
    
    [self getStepCount];
}

// 倒计时开始时的回调
- (void)countDownButtonDidStartCountDown:(CQCountDownButton *)countDownButton {
    NSLog(@"倒计时开始");
}

// 倒计时进行中的回调
- (void)countDownButtonDidInCountDown:(CQCountDownButton *)countDownButton withRestCountDownNum:(NSInteger)restCountDownNum {
    NSString *title = [NSString stringWithFormat:@"(%ld)秒", (long)restCountDownNum];
    [_btn_refreshStepNumber setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [self.btn_refreshStepNumber setTitle:title forState:UIControlStateNormal];
}

// 倒计时结束时的回调
- (void)countDownButtonDidEndCountDown:(CQCountDownButton *)countDownButton {
    [self.btn_refreshStepNumber setTitle:@"刷新" forState:UIControlStateNormal];
    [_btn_refreshStepNumber setImage:[UIImage imageNamed:@"btn_exercise_refresh"] forState:UIControlStateNormal];
    NSLog(@"倒计时结束");
}


#pragma mark - event response
- (void)backClick
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)refreshBtnClick:(UIButton *)sender
{
    if (open) {
        [self getStepCount];
    }else{
        NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
        if([[UIApplication sharedApplication] canOpenURL:url]) {
            [[UIApplication sharedApplication] openURL:url];
        }else{
            NSLog(@"不能打开设置界面");
        }
      
    }
    
}

- (void)getCoinsClick:(UIButton *)sender
{
    [self getincreateScoreRequest:sender];
}

- (void)invitePeopleClick:(UIButton *)sender
{
    
    if (!recordid) {
        [self getstepRequest:self.currentStepCount];
        return;
    }
    [self shareWebPageToPlatformType:UMSocialPlatformType_WechatSession];
    
   
}

- (void)checkAgreementClick:(UIButton *)sender
{
//   UIStoryboard *sb  =[UIStoryboard storyboardWithName:@"Main" bundle:nil];
    
    
    
     Web2ViewController*tc = [Web2ViewController new];
     tc.skipUrl =[NSURL URLWithString:@"http://kefu.weface.com.cn/ys/index1.html"];
    
     tc.title = @"隐私协议";
     [self.navigationController pushViewController:tc animated:YES];
    
    
    
}


- (void)alertShow:(NSString *)msg
{
    if (@available(iOS 9.0,*)) {
        
        UIAlertController * alertV = [UIAlertController alertControllerWithTitle:@"提示" message:msg preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction *confirm = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        
        [alertV addAction:confirm];
        
        [self presentViewController:alertV animated:YES completion:nil];
        
    }else{
        UIAlertView *alertV = [[UIAlertView alloc]initWithTitle:@"提示" message:msg delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
        [alertV show];
    }
}


#pragma mark - setupUI
- (void)setupUI
{
    //UIScrollView
    
    UIImage *image = [UIImage imageNamed:@"img_exercise_ring"];
    CGFloat imageWidth = image.size.width;
    CGFloat imageHeight = image.size.height;
    
    [self.btn_refreshStepNumber mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.backView).offset(20 * WIDTHRADIU + imageHeight * WIDTHRADIU - 20 * WIDTHRADIU);
        make.centerX.equalTo(self.backView);
        make.width.offset(80 * WIDTHRADIU);
        make.height.offset(30 * WIDTHRADIU);
    }];
    
    [self.lb_rule mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.whiteCardView.mas_bottom);
        make.left.offset(10 * WIDTHRADIU);
        make.right.offset(-10 * WIDTHRADIU);
    }];
    
    
   
    
    [self.img_ring mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(20 * WIDTHRADIU);
        make.centerX.equalTo(self.backImg);
        make.width.offset(imageWidth * WIDTHRADIU);
        make.height.offset(imageHeight * WIDTHRADIU);
    }];
    
    
    //backImg
    [self.lb_stepNumberTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(47 * WIDTHRADIU);
        make.centerX.equalTo(self.img_ring);
        make.height.offset(14 * WIDTHRADIU);
    }];
    
    [self.lb_stepNumber mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lb_stepNumberTitle.mas_bottom).offset(10 * WIDTHRADIU);
        make.centerX.equalTo(self.lb_stepNumberTitle);
        make.height.offset(40 * WIDTHRADIU);
    }];
    
    
    
    [self.progressView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(35 * WIDTHRADIU);
        make.left.offset(15 * WIDTHRADIU);
        make.right.offset(-15 * WIDTHRADIU);
    }];
    
   
    
    [self.img_coins mas_makeConstraints:^(MASConstraintMaker *make) {
       make.top.equalTo(self.progressView.mas_bottom).offset(13 * WIDTHRADIU);
        make.right.equalTo(self.progressView);
    }];
    
    [self.lb_endStep mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.img_coins);
        make.right.equalTo(self.img_coins.mas_left).offset(-4);
        make.height.offset(12 * WIDTHRADIU);
    }];
    
    [self.lb_startStep mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.img_coins);
        make.left.equalTo(self.progressView);
        make.height.offset(12 * WIDTHRADIU);
    }];
    
    [self.lb_message mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lb_startStep.mas_bottom).offset(10 * WIDTHRADIU);
        make.left.equalTo(self.lb_startStep);
        make.height.offset(14 * WIDTHRADIU);
    }];
    
    [self.btn_GetCoins mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.progressView);
        make.top.equalTo(self.lb_message.mas_bottom).offset(30 * WIDTHRADIU);
        make.height.offset(45 * WIDTHRADIU);
    }];
    
    [self.btn_Invite mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.progressView);
        make.top.equalTo(self.btn_GetCoins.mas_bottom).offset(20 * WIDTHRADIU);
        make.height.offset(45 * WIDTHRADIU);
    }];
    
    
    

}

#pragma mark - prvate methods
//网页分享
- (void)shareWebPageToPlatformType:(UMSocialPlatformType)platformType
{
    if (![WXApi isWXAppInstalled]) {
        [Tools showMessage:@"请先安装微信!!!"];
        return;
    }
    
//     WeakSelf
          //创建分享消息对象
          UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
          
          
          //创建网页内容对象
//          NSString* thumbURL =  UMS_THUMB_IMAGE;
          UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:@"你知道吗？走路也能抽大奖哦~" descr:@"我离大奖就差几步了，赶快来帮我助力吧" thumImage:[UIImage imageNamed:@"login_icon"]];
          //设置网页地址
    NSString *url = [NSString stringWithFormat:@"http://nginx.weface.com.cn/lesson/award/step/step.html?userid=%ld&telephone=%@&recordid=%ld&reqStamp=%ld",(long)[getPeopleID PeopleID],[EnercryTool encryptUseDES:[getPeopleID PeopleIphoneNmber] key:DESKEY],recordid.integerValue,[self getNowTimeTimestamp3]];//外网
//          NSString *url = [NSString stringWithFormat:@"http://172.16.10.133/projects/html-nginx/html-nginx/lesson/award/step/step.html?userid=%ld&telephone=%@&recordid=%ld&reqStamp=%ld",(long)[getPeopleID PeopleID],[EnercryTool encryptUseDES:[getPeopleID PeopleIphoneNmber] key:DESKEY],recordid.integerValue,[self getNowTimeTimestamp3]];//内网
        
          shareObject.webpageUrl = url;
          
          //分享消息对象设置分享内容对象
          messageObject.shareObject = shareObject;
          
          //调用分享接口
          [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
              if (error) {
                  UMSocialLogInfo(@"************Share fail with error %@*********",error);
              }else{
                  if ([data isKindOfClass:[UMSocialShareResponse class]]) {
                      UMSocialShareResponse *resp = data;
                      //分享结果消息
                      UMSocialLogInfo(@"response message is %@",resp.message);
                      //第三方原始返回的数据
                      UMSocialLogInfo(@"response originalResponse data is %@",resp.originalResponse);
                      
                  }else{
                      UMSocialLogInfo(@"response data is %@",data);
                  }
                  
                 // [weakSelf loadData2];
              }
              
          }];
}
- (void)alertWithError:(NSError *)error
{
    NSString *result = nil;
    if (!error) {
        result = [NSString stringWithFormat:@"分享成功"];
    }
    else{
        NSMutableString *str = [NSMutableString string];
        if (error.userInfo) {
            for (NSString *key in error.userInfo) {
                [str appendFormat:@"%@ = %@\n", key, error.userInfo[key]];
            }
        }
        if (error) {
            result = [NSString stringWithFormat:@"Share fail with error code: %d\n%@",(int)error.code, str];
            result = [NSString stringWithFormat:@"分享失败"];
        }
        else{
            result = [NSString stringWithFormat:@"Share fail"];
        }
    }
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil
                                                    message:result
                                                   delegate:nil
                                          cancelButtonTitle:NSLocalizedString(@"确定", @"确定")
                                          otherButtonTitles:nil];
    [alert show];
}
- (void)popJumpAnimationView:(UIView *)sender {
    
    CGFloat duration = 0.4f;
    CGFloat height = 5.f;
    CAKeyframeAnimation * animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.translation.y"];
    CGFloat currentTy = sender.transform.ty;
    animation.duration = duration;
    animation.values = @[@(currentTy), @(currentTy - height/4), @(currentTy-height/4*2), @(currentTy-height/4*3), @(currentTy - height), @(currentTy-height/4*3), @(currentTy -height/4*2), @(currentTy - height/4), @(currentTy)];
    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 = MAXFLOAT;
    animation.removedOnCompletion = NO;
    [sender.layer addAnimation:animation forKey:@"kViewShakerAnimationKey"];
}



#pragma mark - private methods
-(NSInteger )getNowTimeTimestamp3{
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init] ;
    
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss SSS"]; // ----------设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制
    
    //设置时区,这个对于时间的处理有时很重要
    
    NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Beijing"];
    
    [formatter setTimeZone:timeZone];
    
    NSDate *datenow = [NSDate date];//现在时间,你可以输出来看下是什么格式
    
    NSInteger timeSp = [datenow timeIntervalSince1970]*1000;
    
    return timeSp;
}

- (BOOL)isSameDay:(NSDate*)date1 date2:(NSDate*)date2
{
    NSCalendar* calendar = [NSCalendar currentCalendar];
    unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
    NSDateComponents* comp1 = [calendar components:unitFlags fromDate:date1];
    NSDateComponents* comp2 = [calendar components:unitFlags fromDate:date2];
    return [comp1 day] == [comp2 day] &&
    [comp1 month] == [comp2 month] &&
    [comp1 year] == [comp2 year];
}

#pragma mark - 富文本部分字体飘灰
- (NSMutableAttributedString *)setupAttributeString:(NSString *)text highlightText:(NSString *)highlightText {
    NSRange hightlightTextRange = [text rangeOfString:highlightText];
    NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:text];
    if (hightlightTextRange.length > 0) {
        [attributeStr addAttribute:NSForegroundColorAttributeName
                             value:[UIColor colorWithHex:0xee551a]
                             range:hightlightTextRange];
        [attributeStr addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:13.0f * WIDTHRADIU] range:hightlightTextRange];
       
        return attributeStr;
    }else {
        return [highlightText copy];
    }
}


/**
 *  获取矩形的渐变色的UIImage(此函数还不够完善)
 *
 *  @param bounds       UIImage的bounds
 *  @param colors       渐变色数组，可以设置两种颜色
 *  @param gradientType 渐变的方式：0--->从上到下   1--->从左到右
 *
 *  @return 渐变色的UIImage
 */
- (UIImage*)gradientImageWithBounds:(CGRect)bounds andColors:(NSArray*)colors andGradientType:(int)gradientType{
    NSMutableArray *ar = [NSMutableArray array];
    
    for(UIColor *c in colors) {
        [ar addObject:(id)c.CGColor];
    }
    //UIGraphicsBeginImageContextWithOptions(bounds.size, YES, 1);
    UIGraphicsImageRendererFormat *format = [[UIGraphicsImageRendererFormat alloc] init];
    format.opaque = NO;
    format.scale = 1;
    UIGraphicsImageRenderer*re=[[UIGraphicsImageRenderer alloc] initWithSize:bounds.size format:format];
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSaveGState(context);
    CGColorSpaceRef colorSpace = CGColorGetColorSpace([[colors lastObject] CGColor]);
    CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (CFArrayRef)ar, NULL);
    CGPoint start;
    CGPoint end;
    
    switch (gradientType) {
        case 0:
            start = CGPointMake(0.0, 0.0);
            end = CGPointMake(0.0, bounds.size.height);
            break;
        case 1:
            start = CGPointMake(0.0, 0.0);
            end = CGPointMake(bounds.size.width, 0.0);
            break;
    }
    CGContextDrawLinearGradient(context, gradient, start, end, kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation);
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    CGGradientRelease(gradient);
    CGContextRestoreGState(context);
    CGColorSpaceRelease(colorSpace);
    UIGraphicsEndImageContext();
    return image;
}


#pragma mark =====横向、纵向移动===========
-(CABasicAnimation *)moveX:(float)time X:(NSNumber *)x
{
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];///.y的话就向下移动。
    animation.toValue = x;
    animation.duration = time;
    animation.removedOnCompletion = NO;//yes的话，又返回原位置了。
    animation.repeatCount = 1;
    animation.fillMode = kCAFillModeForwards;
    return animation;
}




#pragma mark - life cycle


//获取计步数
- (void)getStepCount
{
    
    WeakSelf
    
    
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDate *now = [NSDate date];
    NSDateComponents *components = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay fromDate:now];
    // 开始日期
    NSDate *startDate = [calendar dateFromComponents:components];
    // 结束日期
    NSDate *endDate = [calendar dateByAddingUnit:NSCalendarUnitDay value:1 toDate:startDate options:0];
   
    //判断记步功能
    if ([CMPedometer isStepCountingAvailable]) {
        [self.pedometer queryPedometerDataFromDate:startDate toDate:endDate withHandler:^(CMPedometerData * _Nullable pedometerData, NSError * _Nullable error) {
            if (error) {
                NSLog(@">>>error====%@",error);
                dispatch_async(dispatch_get_main_queue(), ^{
                    [weakSelf.btn_GetCoins setTitle:@"开启权限,领今日金币" forState:UIControlStateNormal];
                    [weakSelf.btn_GetCoins setBackgroundImage:[self gradientImageWithBounds:CGRectMake(0, 0, ScreenWidth - 50 * WIDTHRADIU, 45 * WIDTHRADIU) andColors:@[(id)[UIColor colorWithHex:0xee551a] ,(id)[UIColor colorWithHex:0xf36d39]] andGradientType:1] forState:UIControlStateNormal];
                    weakSelf.btn_GetCoins.userInteractionEnabled = YES;
                });
                self->open = NO;
                return ;
                
            }else {
                
                self->open = YES;
                
                NSLog(@"步数====%@",pedometerData.numberOfSteps);
                NSLog(@"距离====%@",pedometerData.distance);
                NSInteger stepCount = pedometerData.numberOfSteps.integerValue;


                dispatch_async(dispatch_get_main_queue(), ^{
                    
                    self.currentStepCount = stepCount;
                   
                    [self getstepRequest:stepCount];
                });
            }
        }];
    }else{
        NSLog(@"记步功能不可用");
    }
    
    
    
}

- (void)setCurrentStepCount:(NSInteger)currentStepCount
{
    _currentStepCount = currentStepCount;
    
    
    NSString *message = [NSString stringWithFormat:@"提示: 还差%ld步才能领取金币，赶快邀请好友助力吧！",_currentStepCount>=5000 ? 0 : (5000 -  _currentStepCount)];
    
    self.lb_message.attributedText = [self setupAttributeString:message highlightText:[NSString stringWithFormat:@"%ld",_currentStepCount>=5000 ? 0 : (5000 -  _currentStepCount)]];
    
    
    if (_currentStepCount >= 5000) {
        [self.img_coins.layer removeAllAnimations];
        
        if ([self canRequestOnFootApi]) {
            [self.btn_GetCoins setTitle:@"立即领取金币" forState:UIControlStateNormal];
                   
                   [self.btn_GetCoins setBackgroundImage:[self gradientImageWithBounds:CGRectMake(0, 0, ScreenWidth - 50 * WIDTHRADIU, 45 * WIDTHRADIU) andColors:@[(id)[UIColor colorWithHex:0xee551a] ,(id)[UIColor colorWithHex:0xf36d39]] andGradientType:1] forState:UIControlStateNormal];
                   self.btn_GetCoins.userInteractionEnabled = YES;
            self.lb_message.text = @"提示：恭喜您步数已达标，可以领取金币啦！";
        }else{
            [self.btn_GetCoins setTitle:@"已领取" forState:UIControlStateNormal];
            [_btn_GetCoins setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [self.btn_GetCoins setBackgroundImage:nil forState:UIControlStateNormal];
             self.btn_GetCoins.userInteractionEnabled = NO;
            self.lb_message.text = @"提示：恭喜您今日任务已完成，明天再接再厉！";
            
        }
        
       
    }else{
        [self.btn_GetCoins setTitle:[NSString stringWithFormat:@"还差%ld步领取100金币",(5000 -  _currentStepCount)] forState:UIControlStateNormal];
    }
    
    
     [self.lb_stepNumber countFrom:self.lb_stepNumber.text.integerValue to:_currentStepCount];
    
    CGFloat percentage = _currentStepCount/5000.0;
    
    
    
    self.progressView.progress = percentage <= 1 ? percentage : 1.0;

    
    
    
     UIImage *image = [UIImage imageNamed:@"img_exercise_person"];
    double dx = 15 * WIDTHRADIU + self.progressView.progress *self.progressView.bounds.size.width - image.size.width;
    
    NSNumber *x = [NSNumber numberWithDouble:dx];
    
    CABasicAnimation *animation = [self moveX:0.25 X:x];
    
    [self.img_person.layer addAnimation:animation forKey:nil];
    
    
    
}

- (CMPedometer *)pedometer
{
    if (!_pedometer) {
        _pedometer = [[CMPedometer alloc]init];
    }
    return _pedometer;
}

- (UIScrollView *)scrollView
{
    if (!_scrollView) {
        _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, cl_kNavigationBarHeight, ScreenWidth, ScreenHeight-45 - cl_kNavigationBarHeight)];
        _scrollView.backgroundColor = [UIColor whiteColor];
        _scrollView.contentSize = CGSizeMake(ScreenWidth, ScreenHeight);
        _scrollView.delegate = self;
    
       
        _scrollView.showsHorizontalScrollIndicator = NO;
        _scrollView.showsVerticalScrollIndicator = NO;
        
        [_scrollView addSubview:self.backView];
        
    }
    return _scrollView;
}



- (UIView *)backView
{
    if (!_backView) {
        _backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight * 1)];
        _backView.backgroundColor = [UIColor whiteColor];
        [_backView addSubview:self.backImg];
        [_backView addSubview:self.btn_refreshStepNumber];
        [_backView addSubview:self.whiteCardView];
        [_backView addSubview:self.lb_rule];
    }
    return _backView;
}

- (UIImageView *)backImg
{
    if (!_backImg) {
        
        UIImage *image = [UIImage imageNamed:@"img_exercise_back"];
        CGFloat imageWidth = image.size.width;
        CGFloat imageHeight = image.size.height;
        CGFloat imageScale = imageHeight/imageWidth;
        
        _backImg = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH *imageScale)];
        _backImg.image = image;
        [_backImg addSubview:self.img_ring];
    }
    return _backImg;
}

- (UIImageView *)img_ring
{
    if (!_img_ring) {
        _img_ring = [[UIImageView alloc]init];
        _img_ring.image = [UIImage imageNamed:@"img_exercise_ring"];
        [_img_ring addSubview:self.lb_stepNumberTitle];
        [_img_ring addSubview:self.lb_stepNumber];
       // [_img_ring addSubview:self.btn_refreshStepNumber];
    }
    return _img_ring;
}

//当前步数
- (UILabel *)lb_stepNumberTitle
{
    if (!_lb_stepNumberTitle) {
        _lb_stepNumberTitle = [[UILabel alloc]init];
        _lb_stepNumberTitle.text = @"当前步数";
        _lb_stepNumberTitle.textAlignment = NSTextAlignmentCenter;
        _lb_stepNumberTitle.textColor = [UIColor whiteColor];
        _lb_stepNumberTitle.font = [UIFont systemFontOfSize:14 * WIDTHRADIU];
    }
    return _lb_stepNumberTitle;
}

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

- (CQCountDownButton *)btn_refreshStepNumber
{
    if (!_btn_refreshStepNumber) {
        _btn_refreshStepNumber = [CQCountDownButton buttonWithType:UIButtonTypeCustom];
        [_btn_refreshStepNumber setTitle:@"刷新" forState:UIControlStateNormal];
        [_btn_refreshStepNumber setImage:[UIImage imageNamed:@"btn_exercise_refresh"] forState:UIControlStateNormal];
        [_btn_refreshStepNumber setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _btn_refreshStepNumber.titleLabel.font = [UIFont systemFontOfSize:14 * WIDTHRADIU];
        [_btn_refreshStepNumber layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleLeft imageTitleSpace:4];
        _btn_refreshStepNumber.backgroundColor = [UIColor colorWithHex:0x0b904b];
        _btn_refreshStepNumber.layer.cornerRadius = 15 * WIDTHRADIU;
       // [_btn_refreshStepNumber addTarget:self action:@selector(refreshBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        _btn_refreshStepNumber.delegate = self;
        _btn_refreshStepNumber.dataSource = self;
    }
    return _btn_refreshStepNumber;
}

- (UIView *)whiteCardView
{
    if (!_whiteCardView) {
        
        UIImage *image = [UIImage imageNamed:@"img_exercise_back"];
        CGFloat imageWidth = image.size.width;
        CGFloat imageHeight = image.size.height;
        CGFloat imageScale = imageHeight/imageWidth;
        
        _whiteCardView = [[UIView alloc]initWithFrame:CGRectMake(10 * WIDTHRADIU, ScreenWidth *imageScale - 60 * WIDTHRADIU, SCREEN_WIDTH - 20 * WIDTHRADIU, 250 * WIDTHRADIU)];//250
        _whiteCardView.backgroundColor = [UIColor whiteColor];
        _whiteCardView.layer.cornerRadius = 10 * WIDTHRADIU;
       
        [_whiteCardView addSubview:self.img_person];
        [_whiteCardView addSubview:self.progressView];
        [_whiteCardView addSubview:self.lb_startStep];
        [_whiteCardView addSubview:self.lb_endStep];
        [_whiteCardView addSubview:self.img_coins];
        [_whiteCardView addSubview:self.lb_message];
        [_whiteCardView addSubview:self.btn_GetCoins];
        [_whiteCardView addSubview:self.btn_Invite];
    }
    return _whiteCardView;
}

- (UILabel *)lb_startStep
{
    if (!_lb_startStep) {
        _lb_startStep = [[UILabel alloc]init];
        _lb_startStep.text = @"0步";
        _lb_startStep.textColor = [UIColor colorWithHex:0x4d4d4d];
        _lb_startStep.font = [UIFont systemFontOfSize:12 * WIDTHRADIU];
    }
    return _lb_startStep;
}

- (UILabel *)lb_endStep
{
    if (!_lb_endStep) {
        _lb_endStep = [[UILabel alloc]init];
        _lb_endStep.text = @"5000步";
        _lb_endStep.textColor = [UIColor colorWithHex:0x4d4d4d];
        _lb_endStep.font = [UIFont systemFontOfSize:12 * WIDTHRADIU];
    }
    return _lb_endStep;
}

- (UIImageView *)img_coins
{
    if (!_img_coins) {
        _img_coins = [[UIImageView alloc]init];
        _img_coins.image = [UIImage imageNamed:@"img_exercise_coins"];
        [self popJumpAnimationView:_img_coins];
    }
    return _img_coins;
}

- (MQGradientProgressView *)progressView
{
    if (!_progressView) {
        _progressView = [[MQGradientProgressView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth - 50 * WIDTHRADIU, 8 * WIDTHRADIU)];
       // _progressView.center = self.view.center;
        //    progressView.colorArr = @[(id)MQRGBColor(59, 221, 255).CGColor,(id)MQRGBColor(34, 126, 239).CGColor];
        _progressView.colorArr = @[(id)[UIColor colorWithHex:0xfda783].CGColor,(id)[UIColor colorWithHex:0xee551a].CGColor];
        _progressView.progress = 0.0;
    }
    return _progressView;
}

- (UIImageView *)img_person
{
    if (!_img_person) {
        UIImage *image = [UIImage imageNamed:@"img_exercise_person"];
        _img_person = [[UIImageView alloc]init];
        _img_person.image = image;
        _img_person.frame = CGRectMake(15 * WIDTHRADIU + self.progressView.progress *self.progressView.bounds.size.width - image.size.width, 35 - image.size.height - 5, 14 * WIDTHRADIU, 21 * WIDTHRADIU);
    }
    return _img_person;
}

- (UILabel *)lb_message
{
    if (!_lb_message) {
        _lb_message = [[UILabel alloc]init];
        _lb_message.text = @"提示: 还差1800步才能领取金币，赶快邀请好友助力吧！";
        _lb_message.textColor = [UIColor colorWithHex:0x808080];
        _lb_message.font = [UIFont systemFontOfSize:13 * WIDTHRADIU];
        
        _lb_message.attributedText = [self setupAttributeString:_lb_message.text highlightText:@"1800"];
        
    }
    return _lb_message;
}

- (UIButton *)btn_GetCoins
{
    if (!_btn_GetCoins) {
        _btn_GetCoins = [UIButton buttonWithType:UIButtonTypeCustom];
        [_btn_GetCoins setTitle:@"还差1800步领100金币" forState:UIControlStateNormal];
        [_btn_GetCoins setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _btn_GetCoins.titleLabel.font = [UIFont systemFontOfSize:15 * WIDTHRADIU];
        _btn_GetCoins.backgroundColor = [UIColor colorWithHex:0xcccccc];
        _btn_GetCoins.layer.cornerRadius = 22.5 * WIDTHRADIU;
        self.btn_GetCoins.layer.masksToBounds = YES;
        [_btn_GetCoins addTarget:self action:@selector(getCoinsClick:) forControlEvents:UIControlEventTouchUpInside];
        _btn_GetCoins.userInteractionEnabled = NO;
        
    }
    return _btn_GetCoins;
}

- (UIButton *)btn_Invite
{
    if (!_btn_Invite) {
        _btn_Invite = [UIButton buttonWithType:UIButtonTypeCustom];
        [_btn_Invite setTitle:@"邀请好友助力，最高可得500步" forState:UIControlStateNormal];
        [_btn_Invite setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _btn_Invite.layer.cornerRadius = 22.5 * WIDTHRADIU;
        _btn_Invite.layer.masksToBounds = YES;
        
        CAGradientLayer *gradientLayer =  [CAGradientLayer layer];
        gradientLayer.frame = CGRectMake(0, 0, ScreenWidth - 50 * WIDTHRADIU, 45 * WIDTHRADIU);
        gradientLayer.startPoint = CGPointMake(0, 0);
        gradientLayer.endPoint = CGPointMake(1, 0);
        gradientLayer.locations = @[@(0.5),@(1.0)];//渐变点
        [gradientLayer setColors:@[(id)[[UIColor colorWithHex:0xee551a] CGColor],(id)[[UIColor colorWithHex:0xf36d39] CGColor]]];//渐变数组
        [_btn_Invite.layer addSublayer:gradientLayer];
        
        _btn_Invite.titleLabel.font = [UIFont systemFontOfSize:15 * WIDTHRADIU];
        [_btn_Invite addTarget:self action:@selector(invitePeopleClick:) forControlEvents:UIControlEventTouchUpInside];
        _btn_Invite.hidden = NO;
    }
    return _btn_Invite;
}


- (UILabel *)lb_rule
{
    if (!_lb_rule) {
        _lb_rule = [[UILabel alloc]init];
        _lb_rule.textColor = [UIColor colorWithHex:0x808080];
        _lb_rule.font = [UIFont systemFontOfSize:12 * WIDTHRADIU];
        
        
        NSString * titlestr=@"活动规则:\n";
        NSMutableParagraphStyle * paragraphstyle0 =[[NSMutableParagraphStyle alloc]init];
        [paragraphstyle0 setLineSpacing:5];
        paragraphstyle0.alignment = NSTextAlignmentLeft;
        
        NSMutableAttributedString * attribustring0 =[[NSMutableAttributedString alloc]initWithString: titlestr attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:14 * WIDTHRADIU],NSForegroundColorAttributeName:[UIColor colorWithHex:0x808080],NSParagraphStyleAttributeName:paragraphstyle0}];
        
        //2、每位好友助力可增加500步，截止时间为22：00；\n
        NSString *text = @"1、每日步数达到5000步，可领取100金币；\n2、每位好友助力可增加500步，截止时间为24：00；\n3、每日步数截止时间为24：00，之后的步数计算在次日；\n4、本活动最终解释权归看看生活APP所有。";
      
        
        //行间距
        NSMutableParagraphStyle * paragraphstyle =[[NSMutableParagraphStyle alloc]init];
        [paragraphstyle setLineSpacing:8];
        paragraphstyle.alignment = NSTextAlignmentLeft;
        
        NSMutableAttributedString * attribustring =[[NSMutableAttributedString alloc]initWithString: text attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14*WIDTHRADIU],NSForegroundColorAttributeName:[UIColor colorWithHex:0x808080],NSParagraphStyleAttributeName:paragraphstyle}];
        
       
    
    //合并
    [attribustring0 appendAttributedString:attribustring];
    
        _lb_rule.attributedText = attribustring0;
        _lb_rule.numberOfLines =0;
    }
    return _lb_rule;
}






/*
#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
