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

#import "JoinPartnerResultViewController.h"
#import "UIView+frameAdjust.h"

@interface JoinPartnerResultViewController ()

@property (nonatomic, strong)UIScrollView* scrollview;

@end

@implementation JoinPartnerResultViewController
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    //禁止手势返回
    id traget = self.navigationController.interactivePopGestureRecognizer.delegate;
    UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc]initWithTarget:traget action:nil];
    [self.view addGestureRecognizer:pan];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    [self configNav];
    [self configUI];
    
}
- (void)configNav
{
    UIButton * button_2 = [UIButton buttonWithType:UIButtonTypeCustom];
      button_2.frame = CGRectMake(-30, 0, 40, 25);
    //    [button_2 setTitle:@"asdasd按时打发第三方" forState:UIControlStateNormal];
    [button_2 setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    [button_2 setTitle:@"返回" forState:UIControlStateNormal];
    
    //    [button_2 setBackgroundColor:[UIColor redColor]];
    //    [button_2 setTitleColor:[UIColor colorWithRed:12.0 green:12.0 blue:12.0 alpha:1] forState:UIControlStateNormal];
    [button_2 addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * backButtonItem_2 = [[UIBarButtonItem alloc] initWithCustomView:button_2];
    
    self.navigationItem.leftBarButtonItem = backButtonItem_2;
}
- (void)configUI
{
    [self.view addSubview:self.scrollview];
    NSString*imageName;
    NSString*title;
    NSString* message;
    if ([self.type isEqualToString:@"success"]) {
        imageName = @"hehuoren_success";
        title = @"提交成功";
        message = @"为保障入驻用户的合法性和真实性，审核需要1~7个工作日，审核结果会短信通知，还请耐心等待";
    }else if ([self.type isEqualToString:@"fail"]){
        imageName = @"hehuoren_fail";
        title = @"审核失败";
        message = @"感谢您对看看生活的支持，非常遗憾您的申请没有通过审核，期待与您的下次合作！\n如有疑问请联系客服";
    }else if ([self.type isEqualToString:@"loading"]){
        imageName = @"hehuoren_loading";
        title = @"审核中...";
        message = @"为保障入驻用户的合法性和真实性，审核需要1~7个工作日，审核结果会短信通知，还请耐心等待";
    }
    self.title = @"加入合伙人";
    //状态图
    UIImage*image = [UIImage imageNamed:imageName];
    UIImageView*imgState = [[UIImageView alloc]init];
    imgState.image = image;
    [self.scrollview addSubview:imgState];
    //状态标题
    UILabel *lb_title = [[UILabel alloc]init];
    lb_title.text = title;
    lb_title.textColor = [UIColor colorWithHex:0x4d4d4d];
    lb_title.font = [UIFont boldSystemFontOfSize:17 * WIDTHRADIU];
    lb_title.textAlignment = NSTextAlignmentCenter;
    [self.scrollview addSubview:lb_title];
    
    [imgState mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(60 * WIDTHRADIU);
        make.centerX.equalTo(self->_scrollview);
        make.width.offset(image.size.width * WIDTHRADIU);
        make.height.offset(image.size.height * WIDTHRADIU);
    }];
    
    [lb_title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imgState.mas_bottom).offset(10 * WIDTHRADIU);
        make.centerX.equalTo(imgState);
    }];
    
    //message
    UILabel* lb_message = [[UILabel alloc]init];
    lb_message.textColor = [UIColor colorWithHex:0xc0c0c0];
    lb_message.font = [UIFont systemFontOfSize:14 * WIDTHRADIU];
    lb_message.textAlignment= NSTextAlignmentCenter;
    lb_message.text = message;
    lb_message.numberOfLines = 0;
    [self.scrollview addSubview:lb_message];
   
     //富文本设置文字行间距
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
    paragraphStyle.lineSpacing = 4;
    paragraphStyle.alignment = NSTextAlignmentCenter;
       
    NSDictionary *attributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:14 * WIDTHRADIU],NSForegroundColorAttributeName: [UIColor colorWithHex:0xc0c0c0], NSParagraphStyleAttributeName:paragraphStyle};
    lb_message.attributedText = [[NSAttributedString alloc]initWithString:lb_message.text attributes:attributes];
    
    [lb_message mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lb_title.mas_bottom).offset(20 * WIDTHRADIU);
        make.centerX.equalTo(imgState);
        make.left.offset(15 * WIDTHRADIU);
        make.right.offset(-15 * WIDTHRADIU);
    }];
    
    
    //UIbutton
    UIButton* backHomeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [backHomeBtn setTitle:@"返回首页" forState:UIControlStateNormal];
    [backHomeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    backHomeBtn.titleLabel.font =[UIFont systemFontOfSize:15 * WIDTHRADIU];
    backHomeBtn.backgroundColor = RGBCOLOR(22, 107, 224);
    backHomeBtn.layer.cornerRadius = 5;
    [backHomeBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    [self.scrollview addSubview:backHomeBtn];
    
    [backHomeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self->_scrollview);
        make.top.equalTo(lb_message.mas_bottom).offset(50 * WIDTHRADIU);
        make.width.offset(355 * WIDTHRADIU);
        make.height.offset(45 * WIDTHRADIU);
    }];
    
    CGSize size = self.scrollview.contentSize;
    
    size.height = backHomeBtn.maxY + 40;;
    
    self.scrollview.contentSize = size;
    
    
}

#pragma mark - event response
- (void)backClick
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}

#pragma mark - getters and setters
- (UIScrollView *)scrollview
{
    if (!_scrollview) {
        _scrollview = [[UIScrollView alloc]initWithFrame:CGRectMake(0, cl_kNavigationBarHeight, SCREEN_WIDTH, ScreenHeight - cl_kNavigationBarHeight)];
        _scrollview.contentSize = CGSizeMake(ScreenWidth, 0);
        _scrollview.showsHorizontalScrollIndicator = NO;
        _scrollview.showsVerticalScrollIndicator = NO;
    }
    return _scrollview;
}
/*
#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
