//
//  ProductDetailController.m
//  Open
//
//  Created by 雷俊博 on 2020/7/27.
//  Copyright © 2020 黄江涛 . All rights reserved.
//

#import "ProductDetailController.h"
#import "UIView+frameAdjust.h"
#import "ProductDetailTopView.h"
#import "ProductPerfectInfoView.h"
#import "ProductPerfectCellView.h"
#import "ProductRuleView.h"
#import "ProductDrawRuleView.h"
#import "ProductBankFileView.h"
#import "ProductBuyProgressView.h"
#import "ProductCommonQuestionView.h"
#import "ProductDetailBottomView.h"
#import "PerferctInfoCell.h"

//银行弹框
#import "BankPresentView.h"

#import "OPenAccountController.h"
#import "ProductPurchaseController.h"

#import "SaveBankModel.h"
#import "SaveAccountInfoModel.h"

#import "BCAccountInfoModel.h"

#import "UIImageView+WebCache.h"

#import "ElectronicAccountController.h"


@interface ProductDetailController ()<UIScrollViewDelegate>

@property (nonatomic, strong)UIScrollView* scrollView;

@property (nonatomic, strong)ProductDetailTopView* topView;

@property (nonatomic, strong)ProductBankFileView* fileView;

@property (nonatomic, strong)UIButton* nextBtn;

@end

@implementation ProductDetailController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    UIBarButtonItem *bar = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:0 target:nil action:nil];
    [self.navigationItem setBackBarButtonItem:bar];
    [GTCountSDK trackCountEvent:@"save_wuDangProductDetailCount" withArgs:@{}];//个推统计
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor colorWithHex:0xf4f4f4];
    [self.view addSubview:self.scrollView];
    [self.view addSubview:self.nextBtn];
    [self.nextBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.scrollView.mas_bottom);
        make.left.right.offset(0);
        make.height.offset(45);
    }];
    
    if (self.type == SaveFromTypeYinShu) {
        self.topView.lb_bankName.text =  [NSString stringWithFormat:@"乌当农商银行|%@",self.model.NOTE];
        self.topView.lb_rate.text =  [NSString stringWithFormat:@"%.4lf%%",self.model.RATE.doubleValue];
        self.topView.lb_month.text = [NSString stringWithFormat:@"%d月",self.model.STERM.intValue];
        self.topView.lb_note.text = [NSString stringWithFormat:@"%@元起购|最高%@月",self.model.MIN_AMT,self.model.STERM];
        
        if ([self.model.RET_PRD_CODE isEqualToString:@"35"]) {
            self.topView.lb_mark2.hidden = NO;
            self.topView.lb_mark2.text = @"按月派息";
        }else if ([self.model.RET_PRD_CODE isEqualToString:@"36"]){
            self.topView.lb_mark2.hidden = NO;
            self.topView.lb_mark2.text = @"按年派息";
        }else{
            self.topView.lb_mark2.hidden = YES;
        }
        
        self.fileView.bankIcon.image = [UIImage imageNamed:@"bank_wudang"];
        self.fileView.lb_bankName.text = @"贵州乌当农商银行";
        self.fileView.lb_bankMessage.text = @"隶属于贵州乌当农商银行";
        
        NSString*message = @"银行客服: 400-686-8707";
        NSMutableAttributedString* str = [[NSMutableAttributedString alloc] initWithString:message];
        
        [str yy_setTextHighlightRange:NSMakeRange(6, 12) color:[UIColor colorWithHex:0x137ef6] backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
            NSLog(@"打电话");
        }];
        self.fileView.lb_bankPhone.attributedText = str;
       
    }else if(self.type == SaveFromTypeBiCai) {
        self.topView.lb_bankName.text =  [NSString stringWithFormat:@"%@|%@",self.bcInfoModel.orgName,self.bcInfoModel.productName];
        self.topView.lb_rate.text =  [NSString stringWithFormat:@"%.4lf%%",self.bcInfoModel.interestRate.doubleValue];
        self.topView.lb_month.text = [NSString stringWithFormat:@"%@",self.bcInfoModel.deadlineLabel];
        self.topView.lb_note.text = [NSString stringWithFormat:@"%@元起购|最高%@期",self.bcInfoModel.minPurchaseAmount,self.bcInfoModel.deadlineLabel];
        
        self.topView.lb_mark2.hidden = YES;
        
        [self.fileView.bankIcon sd_setImageWithURL:[NSURL URLWithString:self.bcModel.logoUrl] placeholderImage:nil];
        self.fileView.lb_bankName.text = self.bcInfoModel.orgName;
        self.fileView.lb_bankMessage.text = [NSString stringWithFormat:@"隶属于%@",self.bcInfoModel.orgName];
        
        NSString*message = [NSString stringWithFormat:@"银行客服: %@",[Tools isBlankString:self.bcInfoModel.orgServicePhone] ?@"暂无" : self.bcInfoModel.orgServicePhone];
        NSMutableAttributedString* str = [[NSMutableAttributedString alloc] initWithString:message];
        
        [str addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHex:0x137ef6] range:NSMakeRange(6, message.length - 6)];

//           [str addAttribute:NSForegroundColorAttributeName value:kCoffeeColor range:NSMakeRange(onelenght+1, 2)];
//
//        if (![Tools isBlankString:self.bcInfoModel.orgServicePhone]) {
//            [str yy_setTextHighlightRange:NSMakeRange(6, self.bcInfoModel.orgServicePhone.length + 6) color:[UIColor colorWithHex:0x137ef6] backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
//                NSLog(@"打电话");
//            }];
//        }
        
        self.fileView.lb_bankPhone.attributedText = str;
        
    }
    
    
    [self.fileView.phoneBtn addTarget:self action:@selector(phoneBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.fileView.moreBtn addTarget:self action:@selector(moreBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    
   
    
}

#pragma mark - 根据id查询是否开通账户
//乌当
- (void)queryAccountStateRequest
{
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],YSQueryAccountStateRequest];
    
    NSDictionary*params = @{
        @"bankName":@"乌当银行",
        @"id":@([getPeopleID PeopleID]),
        @"tel":[getPeopleID PeopleIphoneNmber]
    };
    
    NSLog(@"银数查询是否开通账户url:%@",url);
    NSLog(@"params:%@",params);
    
    [KKLoadingAnimationView show];
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSString *strHeader = [NSString stringWithFormat:@"IOS#%@",[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]];
    NSLog(@"strHeader:%@",strHeader);
    [manager.requestSerializer setValue:strHeader forHTTPHeaderField:@"User-Agent"];
       
    [manager POST:url parameters:params headers:nil progress:^(NSProgress * _Nonnull uploadProgress) {
       
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
       [KKLoadingAnimationView dismiss];
       NSLog(@"responseObject:%@",responseObject);
        NSString*state = [NSString stringWithFormat:@"%@",responseObject[@"state"]];
        NSString* result = [NSString stringWithFormat:@"%@",responseObject[@"result"]];
        NSString* describe = [NSString stringWithFormat:@"%@",responseObject[@"describe"]];
        if ([state isEqualToString:@"200"]) {
            NSDictionary*dic = [Tools dencode:result];
            NSLog(@"result:%@",[Tools dencode:result]);
            SaveAccountInfoModel*infoModel = [SaveAccountInfoModel mj_objectWithKeyValues:dic];
            if (infoModel.SUBPACKS.count > 0) {
                
                ProductPurchaseController*purchaseVC = [ProductPurchaseController new];
                purchaseVC.title = @"产品购买";
                purchaseVC.model = self.model;
                purchaseVC.infoModel = infoModel;
                purchaseVC.type = SaveFromTypeYinShu;
                purchaseVC.showFuli = self.showFuli;
                [self.navigationController pushViewController:purchaseVC animated:YES];
                return;
            }else{
                [SVProgressHUD showErrorWithStatus:@"开通账户异常"];
            }
               
            
        }else if ([state isEqualToString:@"201"]){
            OPenAccountController*vc = [OPenAccountController new];
            vc.title = @"存钱罐开户";
            vc.productModel = self.model;
            [self.navigationController pushViewController:vc animated:YES];
        }else{
                NSDictionary*dic = [Tools dictionaryWithJsonString:describe];
                NSLog(@"describe:%@",dic);
                NSString*code = nil;
                NSString*message = nil;
                if (![Tools isBlankString:[NSString stringWithFormat:@"%@",dic[@"code"]]]) {
                    code = [NSString stringWithFormat:@"%@",dic[@"code"]];
                }else if (![Tools isBlankString:[NSString stringWithFormat:@"%@",dic[@"RETCODE"]]]){
                    code = [NSString stringWithFormat:@"%@",dic[@"RETCODE"]];
                }
                
                if (code) {
                    message = [KBankErrorCode showErrorMessageWithErrorCode:code];
                    
                    if (message) {
                        [SVProgressHUD showErrorWithStatus:message];
                    }else{
                        [SVProgressHUD showErrorWithStatus:@"系统错误"];
                    }
                }else{
                    [SVProgressHUD showErrorWithStatus:@"系统错误"];
                }
                
                
        
            }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
       [KKLoadingAnimationView dismiss];
       NSLog(@"error:%@",error);
        [SVProgressHUD showInfoWithStatus:@"网络异常"];
    }];
}


#pragma mark - 比财 开户校验
//比财
- (void)queryBCAccountStateRequestWithOrgId:(NSString *)orgId
{
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],BCQueryAccountStateRequest];
    NSLog(@"比财账户是否开通url:%@",url);
    NSMutableDictionary *params = [NetworkPublicParams getBCPublicParams];
    
    [params setObject:[getPeopleID PeopleIphoneNmber] forKey:@"loginPhoneNum"];
    [params setObject:self.bcInfoModel.orgId forKey:@"orgId"];
    
    
    NSLog(@"params:%@",params);
    
    [KKLoadingAnimationView show];
    [NetworkRequest Post6:url Params:params Success:^(id _Nonnull objc) {
      
        NSLog(@"objc:%@",objc);
        NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
        NSString *describe = [NSString stringWithFormat:@"%@",objc[@"describe"]];
        if ([state isEqualToString:@"200"]) {
           
            NSString* hasOpenBank = [NSString stringWithFormat:@"%@",objc[@"result"][@"hasOpenBank"]];
            if ([hasOpenBank isEqualToString:@"1"]) {
                [self bcGetEleAccountInfoRequest];
                return;
            }else if ([hasOpenBank isEqualToString:@"2"]) {
                [self bcRegistInfoShowBackRequest];
                return;;
            }else if ([hasOpenBank isEqualToString:@"3"]){
                [self alertShow:@"开户处理中"];
            }
            
            
            
        }else if([state isEqualToString:@"204"]){
            
            NSString* code = [NSString stringWithFormat:@"%@",objc[@"result"][@"code"]];
            
            //Y10004 您未实名，请先实名后再进行其他操作
            //Y10008 去做实名、活体
            //Y10009 您的实名身份证已过期，请更新身份证--去做身份更新操作，无须做活体
            if ([code isEqualToString:@"Y10004"] || [code isEqualToString:@"Y10008"]) {
                OPenAccountController*vc = [OPenAccountController new];
                vc.title = @"存钱罐实名";
                vc.type = self.type;
                vc.bcInfoModel = self.bcInfoModel;
                [self.navigationController pushViewController:vc animated:YES];
            }else if ([code isEqualToString:@"Y10009"]) {
                OPenAccountController* vc = [OPenAccountController new];
                vc.title = @"更新身份证";
                vc.type = SaveFromTypeBiCai;
                vc.functionType = BiCaiOFunctionTypeUpdateIdInfo;
                [self.navigationController pushViewController:vc animated:YES];
                
            }else {
                [self alertShow:describe];
            }
            
            
        } else{
            [self alertShow:describe];
        }
        [KKLoadingAnimationView dismiss];
    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
        [self alertShow:@"网络出小差了,请稍后重试"];
    }];
}


#pragma mark -  比财 用户信息回显
- (void)bcRegistInfoShowBackRequest
{
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],BCRegistInfoShowBackRequest];
    NSLog(@"比财账户用户信息回显url:%@",url);
    
    NSMutableDictionary *params = [NetworkPublicParams getBCPublicParams];
    [params setObject:[getPeopleID PeopleIphoneNmber] forKey:@"loginPhoneNum"];
    [params setObject:self.bcInfoModel.orgId forKey:@"orgId"];
   // [params setObject:@"340" forKey:@"orgId"];
    NSLog(@"params:%@",params);
    
    [NetworkRequest Post6:url Params:params Success:^(id _Nonnull objc) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"objc:%@",objc);
        NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
        NSString *describe = [NSString stringWithFormat:@"%@",objc[@"describe"]];
        if ([state isEqualToString:@"200"]) {
            
            BCRegistInfoModel* infoModel = [BCRegistInfoModel mj_objectWithKeyValues:objc[@"result"]];
            
            ElectronicAccountController* vc = [ElectronicAccountController new];
            vc.title = @"电子账户";
            vc.type = SaveFromTypeBiCai;
            vc.registerModel = infoModel;
            vc.bcInfoModel = self.bcInfoModel;
           
            [self.navigationController pushViewController:vc animated:YES];
            
        }else{
            [Tools showMessage:describe];
        }

    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
        
        [Tools showMessage:@"网络出小差了,请稍后重试"];
        
    }];
}


#pragma mark - 比财 电子账户信息详情
- (void)bcGetEleAccountInfoRequest {
    
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],BCGETAccountInfoRequest];
    NSLog(@"比财电子账户详情url:%@",url);
    NSMutableDictionary *params = [NetworkPublicParams getBCPublicParams];
    
    [params setObject:[getPeopleID PeopleIphoneNmber] forKey:@"loginPhoneNum"];
    [params setObject:self.bcInfoModel.orgId forKey:@"orgId"];
    
    
    NSLog(@"params:%@",params);
    
    [NetworkRequest Post6:url Params:params Success:^(id _Nonnull objc) {
      
        NSLog(@"objc:%@",objc);
        NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
        NSString *describe = [NSString stringWithFormat:@"%@",objc[@"describe"]];
        if ([state isEqualToString:@"200"]) {
           
            BCAccountInfoModel* model = [BCAccountInfoModel mj_objectWithKeyValues:objc[@"result"]];
            
            ProductPurchaseController*purchaseVC = [ProductPurchaseController new];
            purchaseVC.title = @"产品购买";
            purchaseVC.type = SaveFromTypeBiCai;
            purchaseVC.bcInfoModel = model;
            purchaseVC.bcProInfoModel = self.bcInfoModel;
            purchaseVC.showFuli = self.showFuli;
            [self.navigationController pushViewController:purchaseVC animated:YES];
            
        } else{
            [self alertShow:describe];
        }
        [KKLoadingAnimationView dismiss];
    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
        
        [self alertShow:@"网络出小差了,请稍后重试"];
        
    }];
    
}




#pragma mark - 根据机构id查询支持银行的列表
- (void)querySupportBankListWithOrgId:(NSString *)orgId
{
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],BCGetOrgSupportCardsRequest];
    NSLog(@"比财机构支持的银行卡列表url:%@",url);
    NSMutableDictionary *params = [NetworkPublicParams getBCPublicParams];
    
    [params setObject:[getPeopleID PeopleIphoneNmber] forKey:@"loginPhoneNum"];
    [params setObject:self.bcInfoModel.orgId forKey:@"orgId"];
    
    
    NSLog(@"params:%@",params);
    
    [KKLoadingAnimationView show];
    [NetworkRequest Post6:url Params:params Success:^(id _Nonnull objc) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"objc:%@",objc);
        NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
        NSString *describe = [NSString stringWithFormat:@"%@",objc[@"describe"]];
        if ([state isEqualToString:@"200"]) {
            
            NSArray* bankListArray = [SaveBCBankModel mj_objectArrayWithKeyValuesArray:objc[@"result"][@"supportBankList"]];
            [BankPresentView showBankListWithVC:self type:BankPresentViewTypeBiCai bankArray:bankListArray block:nil];
            
        }else{
            [self alertShow:describe];
        }

    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
        
        [self alertShow:@"网络出小差了,请稍后重试"];
        
    }];
}


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

#pragma mark - public methods
-(id)getXiblWithClassName:(NSString *)className
{
    return [[NSBundle mainBundle]loadNibNamed:className owner:self options:nil].lastObject;
}

- (NSMutableArray *)showReceivedData:(id)result className:(NSString*)className valuePath:(NSString *)path titleNeedShow:(NSString*)title
{
    NSMutableArray *models = [NSMutableArray array];
    Class dataClass = NSClassFromString(className);
    if([result isKindOfClass:[NSArray class]]){
        for (NSDictionary *dic in result) {
            id model = [[dataClass alloc] initWithDictionary:dic];
            [models addObject:model];
        }
    }
    else if([result isKindOfClass:[NSDictionary class]]){
        if(path.length == 0)
        {
            id model = [[dataClass alloc] initWithDictionary:result];
            [models addObject:model];
        }
        else
        {
            NSArray *paths = [path componentsSeparatedByString:@"."];
            
//            NSLog(@"paths have %lu objects inside", (unsigned long)[paths count]);
//            NSLog(@"paths last object is %@", paths.lastObject);
            
            NSDictionary *dic = result;
            for (int i=0;i<paths.count-1;i++)
            {
                NSString *subPath = paths[i];
                dic = dic[subPath];
            }
            for (NSDictionary *dict in dic[paths.lastObject])
            {
                id model = [[dataClass alloc] initWithDictionary:dict];
                [models addObject:model];
                
            }
        }
    }
    
    return models;
}

#pragma mark - event response
- (void)progressBtnClick:(UIButton *)sender
{
    
    if (self.type == SaveFromTypeYinShu) {
        NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"BankList"ofType:@"plist"];
        NSArray*array = [NSArray arrayWithContentsOfFile:plistPath];
        NSMutableArray*bankArray = [NSMutableArray array];
        for (NSDictionary*dic in array) {
            SaveBankModel*model = [SaveBankModel new];
            model.bankName = dic[@"bankName"];
            model.bankImage = dic[@"bankImage"];
            model.orderMin = dic[@"orderMin"];
            model.dMin = dic[@"dMin"];
            [bankArray addObject:model];
        }

        [BankPresentView showBankListWithVC:self type:BankPresentViewTypeWuDang bankArray:bankArray block:nil];
    }else if(self.type == SaveFromTypeBiCai) {
        [self querySupportBankListWithOrgId:self.bcInfoModel.orgId];
    }
    
}
- (void)nextBtnClick:(UIButton *)sender
{
    if (self.type == SaveFromTypeYinShu) {
        [self queryAccountStateRequest];
    }else if (self.type == SaveFromTypeBiCai){
        [self queryBCAccountStateRequestWithOrgId:self.bcInfoModel.orgId];
    }
    
    
}

- (void)phoneBtnClick:(UIButton *)sender
{
    NSLog(@"打电话");
    if (self.type == SaveFromTypeYinShu) {
        NSString *callPhone = @"telprompt:400-686-8707";
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone]];
    }else if (self.type == SaveFromTypeBiCai) {
        if (![Tools isBlankString:self.bcInfoModel.orgServicePhone]) {
            NSString *callPhone = [NSString stringWithFormat:@"telprompt:%@",self.bcInfoModel.orgServicePhone];
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone]];
        }else{
            [Tools showMessage:@"暂无客服电话"];
        }
    }
   
}

- (void)moreBtnClick:(UIButton *)sender
{
    
    if (self.type == SaveFromTypeYinShu) {
        [self jumpToHTML5:@"http://nginx.weface.com.cn/agreement/gzwdjj.html" andJAnalytics:@"产品档案"];
    }else if (self.type == SaveFromTypeBiCai) {
        
        [self alertShow:self.bcInfoModel.synopsis];
        
    }
    
    
}

-(void)jumpToHTML5:(NSString*)url andJAnalytics:(NSString*)janalytics
{
    WebViewController *tc=[WebViewController new];
    tc.URL =[NSURL URLWithString:url];
    tc.hidesBottomBarWhenPushed =YES;
    tc.janalytics = janalytics;
    [self.navigationController pushViewController:tc animated:YES];

}

#pragma mark - 提示
- (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 - getters
- (UIScrollView *)scrollView
{
    if (!_scrollView) {
        _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, cl_kNavigationBarHeight, ScreenWidth, ScreenHeight - cl_kNavigationBarHeight - cl_kTabBarHeight)];
        _scrollView.showsVerticalScrollIndicator = NO;
        _scrollView.delegate = self;
        _scrollView.contentSize = CGSizeMake(ScreenWidth, 0);
        
        //topView
        ProductDetailTopView*topView = [self getXiblWithClassName:@"ProductDetailTopView"];
        topView.frame = CGRectMake(0, 0, ScreenWidth, 132);
        topView.backgroundColor = [UIColor colorWithHex:0x137ef6];
        [_scrollView addSubview:topView];
        self.topView = topView;
        
        //产品亮点
        ProductPerfectInfoView* markView = [self getXiblWithClassName:@"ProductPerfectInfoView"];
        //markView.frame = CGRectMake(0, topView.maxY + 10, ScreenWidth, 280);
        [_scrollView addSubview:markView];
        [markView mas_makeConstraints:^(MASConstraintMaker *make) {
             make.top.equalTo(topView.mas_bottom).offset(10);
             make.left.mas_equalTo(0);
             make.width.mas_equalTo(ScreenWidth);
             make.height.mas_greaterThanOrEqualTo(50);
        }];
        
        ProductPerfectCellView* infoCell = [self getXiblWithClassName:@"ProductPerfectCellView"];
        [_scrollView addSubview:infoCell];
        [infoCell mas_makeConstraints:^(MASConstraintMaker *make) {
             make.top.equalTo(markView.mas_bottom).offset(0);
             make.left.mas_equalTo(0);
             make.width.mas_equalTo(ScreenWidth);
             make.height.mas_greaterThanOrEqualTo(50);
        }];
        //规则
        ProductRuleView* ruleView = [self getXiblWithClassName:@"ProductRuleView"];
       // ruleView.frame = CGRectMake(0, markView.maxY + 10, ScreenWidth, 330);
        [_scrollView addSubview:ruleView];
        [ruleView mas_makeConstraints:^(MASConstraintMaker *make) {
             make.top.equalTo(infoCell.mas_bottom).offset(10);
             make.left.mas_equalTo(0);
             make.width.mas_equalTo(ScreenWidth);
             make.height.mas_greaterThanOrEqualTo(200);
        }];
        
        
        
        
        //支取规则
        ProductDrawRuleView* drawRuleView = [self getXiblWithClassName:@"ProductDrawRuleView"];
        [_scrollView addSubview:drawRuleView];
        [drawRuleView mas_makeConstraints:^(MASConstraintMaker *make) {
             make.top.equalTo(ruleView.mas_bottom).offset(10);
             make.left.mas_equalTo(0);
             make.width.mas_equalTo(ScreenWidth);
             make.height.mas_greaterThanOrEqualTo(70);
        }];
         
        
        //银行说明
        ProductBankFileView*fileView = [self getXiblWithClassName:@"ProductBankFileView"];
        [_scrollView addSubview:fileView];
        [fileView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(drawRuleView.mas_bottom).offset(10);
            make.left.mas_equalTo(0);
            make.width.mas_equalTo(ScreenWidth);
            make.height.mas_greaterThanOrEqualTo(70);
        }];
        self.fileView = fileView;
        
        //购买流程
        ProductBuyProgressView* progressView = [self getXiblWithClassName:@"ProductBuyProgressView"];
        [progressView.btn addTarget:self action:@selector(progressBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [_scrollView addSubview:progressView];
        [progressView mas_makeConstraints:^(MASConstraintMaker *make) {
           make.top.equalTo(fileView.mas_bottom).offset(10);
           make.left.mas_equalTo(0);
           make.width.mas_equalTo(ScreenWidth);
           make.height.mas_greaterThanOrEqualTo(70);
       }];
        //常见问题
        ProductCommonQuestionView* questionView = [self getXiblWithClassName:@"ProductCommonQuestionView"];
        [questionView.phoneBtn addTarget:self action:@selector(phoneBtnClick:) forControlEvents:UIControlEventTouchUpInside];
       [_scrollView addSubview:questionView];
       [questionView mas_makeConstraints:^(MASConstraintMaker *make) {
          make.top.equalTo(progressView.mas_bottom).offset(10);
          make.left.mas_equalTo(0);
          make.width.mas_equalTo(ScreenWidth);
          make.height.mas_greaterThanOrEqualTo(70);
      }];
        //安全保障
        ProductDetailBottomView* bottomView = [self getXiblWithClassName:@"ProductDetailBottomView"];
         [_scrollView addSubview:bottomView];
         [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(questionView.mas_bottom).offset(10);
            make.left.mas_equalTo(0);
            make.width.mas_equalTo(ScreenWidth);
            make.height.mas_greaterThanOrEqualTo(70);
        }];
        
        //底部message
        UILabel* lb_message = [UILabel new];
        lb_message.textColor = [UIColor colorWithHex:0x4d4d4d];
        lb_message.font = [UIFont systemFontOfSize:12];
        lb_message.textAlignment = NSTextAlignmentCenter;
        [_scrollView addSubview:lb_message];
        
        
        [lb_message mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(bottomView.mas_bottom).offset(10);
            make.left.mas_equalTo(0);
            make.width.mas_equalTo(ScreenWidth);
            make.height.mas_greaterThanOrEqualTo(10);
            make.bottom.mas_equalTo( - 10 );
        }];
        
        
        
        if (self.type == SaveFromTypeYinShu) {
            NSString*text = nil;
            
            if ([self.model.RET_PRD_CODE isEqualToString:@"35"]) {
                text = @"存入后按满期利率周期付息，付息周期为一个月。第一个结息日期为起息日顺延一个月（对月对日），以此类推。周期利息=本金*年利率/12。";
            }else if ([self.model.RET_PRD_CODE isEqualToString:@"36"]){
                text = @"存入后按满期利率周期付息，付息周期为一个月。第一个结息日期为起息日顺延一年（对月对日），以此类推。周期利息=本金*年利率。";
            }else{
               text = @"存入后按满期利率周期付息，付息周期为一个月。第一个结息日期为起息日顺延一年（对月对日），以此类推。周期利息=本金*年利率。";
            }
            
            ruleView.lb_rule1.attributedText = [self attributedStrWithFaultCode:@"本产品19点之前购买，次日计息，19点之后购买D+2日起息；"];
            ruleView.lb_rule2.attributedText = [self attributedStrWithFaultCode:text];
            
            
            
            NSString*drawText = @"提前支取应得利息=本金*实际持有天数*挂牌活期利率/360；提前支取时到账金额=本金+提前支取应得利息-已付所有周期利息；挂牌活期利率为0.38%。";
           drawRuleView.lb_rule1.attributedText = [self attributedStrWithFaultCode:@"可全部提前支取,不支持部分提前支取；"];
           drawRuleView.lb_rule2.attributedText = [self attributedStrWithFaultCode:drawText];
            
            lb_message.text = @"本产品服务由贵州乌当农商银行提供";
        }else if(self.type == SaveFromTypeBiCai) {
            NSString*text = @"可全部提前支取，不支持部分提前支取；提前支取时未满付息周期的利息=本金*实际持有天数*挂牌活期利率/360。";
            
            ruleView.lb_rule1.attributedText = [self attributedStrWithFaultCode:self.bcInfoModel.rateRule];
            ruleView.lb_rule2.attributedText = [self attributedStrWithFaultCode:text];
            
            NSString*drawText = @"可随时提前存取，提前支取的本金对应的利息按当前银行当日挂牌活期利率计算，支取金额回到电子账户。";
           drawRuleView.lb_rule1.attributedText = [self attributedStrWithFaultCode:self.bcInfoModel.dealRule];
           drawRuleView.lb_rule2.attributedText = [self attributedStrWithFaultCode:drawText];
            
            lb_message.text = [NSString stringWithFormat:@"本产品服务由%@提供",self.bcInfoModel.orgName];
        }
        
        
        //_scrollView.contentSize = CGSizeMake(ScreenWidth, ruleView.maxY + 10);
    }
    return _scrollView;
}

- (UIButton *)nextBtn
{
    if (!_nextBtn) {
        _nextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_nextBtn setTitle:@"放心购买" forState:UIControlStateNormal];
        _nextBtn.backgroundColor = [UIColor colorWithHex:0x137ef6];
        [_nextBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _nextBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        [_nextBtn addTarget:self action:@selector(nextBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _nextBtn;
}

- (NSAttributedString *) attributedStrWithFaultCode:(NSString *)faultCode {
    NSMutableAttributedString * faultCode_ = [[NSMutableAttributedString alloc] initWithString:faultCode];
    
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
    paraStyle.lineSpacing = 8;
    
    NSDictionary * faultCodeAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:14],NSParagraphStyleAttributeName:paraStyle,NSForegroundColorAttributeName:[UIColor colorWithHex:0x808080]};
    [faultCode_ setAttributes:faultCodeAttributes range:NSMakeRange(0,faultCode_.length)];
    
    
    
    return faultCode_;
}

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