//
//  JobUtil.m
//  Open
//
//  Created by 看看智能 on 2018/1/12.
//  Copyright © 2018年 黄江涛 . All rights reserved.
//

#import "JobUtil.h"
#import "UIImage+GIF.h"
static JobUtil *job = nil;
@implementation JobUtil
+(UIImage*)changeImageToGit:(NSString*)str{
   
    NSString  *name = str;
    NSString  *filePath = [[NSBundle bundleWithPath:[[NSBundle mainBundle] bundlePath]] pathForResource:name ofType:nil];
    NSData  *imageData = [NSData dataWithContentsOfFile:filePath];
   UIImage * newGitImage = [UIImage sd_animatedGIFWithData:imageData];
    return newGitImage;
    
}


+(JobUtil *)userShareInstance
{
    if (job == nil) {
        job = [[JobUtil alloc]init];
    }
    return job;
    
}

-(NSString *)netStrNull:(UITextField *)textfied
{
    NSString * str  = textfied.text;
    if ([str isEqualToString:@""]){
        str = [NSNull null];
    }else{
        str =textfied.text;
    }
    return str;
}
+(NSString *)netStrNull_2:(NSString *)textfied
{
    NSString * str_2  = textfied;
    if ([str_2 isEqualToString:@""]){
        str_2 = [NSNull null];
        
    }else{
        str_2 =textfied;
    }
    return str_2;
}

-(NSString *)netStrssssNull:(NSString *)str
{

    if ([str isEqualToString:@""]){
        str = [NSNull null];
    }
    return str;
}

+(BOOL)isNumberBackYes:(NSString *)str{
    if (!str) {
        return FALSE;
    }
    NSScanner *scan = [NSScanner scannerWithString:str];
    int val;
    BOOL PureInt = [scan scanInt:&val]&&[scan isAtEnd];
    return PureInt;
    
}

-(BOOL)isNumberYes:(NSString *)str{
    if (!str) {
        return FALSE;
    }
    NSScanner *scan = [NSScanner scannerWithString:str];
    int val;
    BOOL PureInt = [scan scanInt:&val]&&[scan isAtEnd];
    return PureInt;

}

+(NSInteger)onlyNumber:(NSString *)str
{
    if ([str isEqualToString:@""]) {
        return 0;
    }
    
    NSString *newStr = [[str stringByReplacingOccurrencesOfString:@"-" withString:@""] stringByReplacingOccurrencesOfString:@"年" withString:@""];
    NSString *newStr_2 =[[newStr stringByReplacingOccurrencesOfString:@"月" withString:@""] stringByReplacingOccurrencesOfString:@"日" withString:@""];
   NSString *newStr_3 = [newStr_2 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    NSScanner *scanner = [NSScanner scannerWithString:newStr_3];
    [scanner scanUpToCharactersFromSet:[NSCharacterSet decimalDigitCharacterSet] intoString:nil];
    int number;
    [scanner scanInt:&number];
    return number;

}
+(NSString *)onlyBirthDai:(NSString *)asd
{
    NSString *str4;
    if (!asd) {
        return [NSNull null];
    }
    
    NSString *newStr = [asd stringByReplacingOccurrencesOfString:@"-" withString:@""];
    NSString *newStr_3 = [newStr stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    NSString *st1 =[newStr_3 substringWithRange:NSMakeRange(0, 4)];
    NSString *st2 =[newStr_3 substringWithRange:NSMakeRange(4, 2)];
    NSString *st3 =[newStr_3 substringFromIndex:6];
      str4  =  [NSString stringWithFormat:@"%@年%@月%@日",st1,st2,st3];

    return str4;
    
}




//self..placeholder =@"请选择(单选)  >";
//self.employeeAddress.placeholder =@"请选择(单选)  >";
//self.EmployeePliticsStatusTextField.placeholder =@"请选择(单选)  >";
//self.employeeGroupTextField.placeholder =@"请选择(多选)  >";
//self.employeeGraducationInstitution.placeholder =@"请选择(单选)  >";
//self.employeeTimeOfGraducation.placeholder =@"请选择(单选)  >";
//self.employeeOccupationQualificationDeGrade.placeholder =@"请选择(单选)  >";
//self.employeePorfessionalQualification.placeholder =@"请选择(单选)  >";


//旧版改的东西
//+(NSInteger)chooseEmployeeFamilyRelation:(NSArray *)arr andSelectedString:(NSString *)selectStr
//{
//
//    if (arr.count >0) {
//        for (int i = 0 ; i < arr.count  ; i ++ ) {
//            if ([arr[i] isEqualToString:selectStr]) {
//                                    return i+1 ;
//            }
//        }
//    }
//
//    return 1;
//}
//+(NSString*)chooseEmployeeFamilyRelation_2:(NSArray *)arr andSelectedString:(NSString *)selectStr
//{
//    if (arr.count >0) {
//        for (int i = 0 ; i < arr.count  ; i ++ ) {
//            if ([arr[i] isEqualToString:selectStr]) {
//                return  [NSString stringWithFormat:@"%d",i+1];
//            }
//        }
//    }
//
//    return @"1";
//
//
//
//}

+(NSString*)chooseEmployeeFamilyRelation_2:(NSArray *)arr andSelectedString:(NSString *)selectStr
{

    if (arr.count >0) {
        for (int i = 0 ; i < arr.count  ; i ++ ) {
            if ([arr[i] isEqualToString:selectStr]) {
                AppDelegate *delegate=(AppDelegate*)[[UIApplication sharedApplication]delegate];
                if(delegate.numberXMLArray.count >0){
                    for (PersonJob *model in delegate.numberXMLArray) {
                        if ([model.nameJob isEqualToString:arr[0]]) {
                            //写逻辑
                            NSArray *asdfasf =    model.politicalStatus;
                            if (asdfasf.count == arr.count ) {
                                NSString *sf =       asdfasf[i];
                                if([JobUtil isNumberBackYes:sf] == YES){
                                    return sf;
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    return @"-1";
}

+(NSInteger)chooseEmployeeFamilyRelation:(NSArray *)arr andSelectedString:(NSString *)selectStr
{

    if (arr.count >0) {
        for (int i = 0 ; i < arr.count  ; i ++ ) {
            if ([arr[i] isEqualToString:selectStr]) {
                AppDelegate *delegate=(AppDelegate*)[[UIApplication sharedApplication]delegate];
                if(delegate.numberXMLArray.count >0){
                    for (PersonJob *model in delegate.numberXMLArray) {
                        if ([model.nameJob isEqualToString:arr[0]]) {
                            //写逻辑
                            NSArray *asdfasf =    model.politicalStatus;
                            if (asdfasf.count == arr.count ) {
                                     NSString *sf =       asdfasf[i];
                                if([JobUtil isNumberBackYes:sf] == YES){
                                    return [sf integerValue];
                                }
                            }
                        }
                    }
                }
            }
         }
     }

    return 9999;
}


+(NSString*)chooseMoreEmployee:(NSArray *)arr andSelectedString:(NSString*)selectStr{
    
    NSArray *selectStr_ = [self arrayDOUHAOstring:selectStr];
    NSString *choice =nil;
    if (arr.count >0) {
        for (int i = 0 ; i < arr.count  ; i ++ ) {
            
            for (NSString *str2 in selectStr_) {
                if ([arr[i] isEqualToString:str2]) {
                    if (choice) {
                        choice=[choice stringByAppendingString:[NSString stringWithFormat:@",%d",i+1]];
                      
                    }else
                    {
                        choice=[NSString stringWithFormat:@"%d",i+1];
                   
                    }
                }
            }
        }
    }
    return choice;
}




+(void)logicRun:(UITextField *)textField{

    if ([textField.text isEqualToString:@""]) {
        [SVProgressHUD showErrorWithStatus:@"信息没有填写完整"];
        return ;
      
    }

}
+(NSArray *)arrayDOUHAOstring:(NSString *)str
{
//    反之
//    [image componentsJoinedByString:@","]
   
    return  [str componentsSeparatedByString:@","];
}
//电话号码正则表达式
+ (BOOL)validateCellPhoneNumber:(NSString *)cellNum{
    /**
     * 手机号码
     * 移动：134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
     * 联通：130,131,132,152,155,156,185,186
     * 电信：133,1349,153,180,189
     */
    NSString * MOBILE = @"^1(3[0-9]|5[0-35-9]|8[025-9])\\d{8}$";
    
    /**
     10         * 中国移动：China Mobile
     11         * 134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
     12         */
    NSString * CM = @"^1(34[0-8]|(3[5-9]|5[017-9]|8[278])\\d)\\d{7}$";
    
    /**
     15         * 中国联通：China Unicom
     16         * 130,131,132,152,155,156,185,186
     17         */
    NSString * CU = @"^1(3[0-2]|5[256]|8[56])\\d{8}$";
    
    /**
     20         * 中国电信：China Telecom
     21         * 133,1349,153,177,180,189
     22         */
    NSString * CT = @"^1((33|53|77|8[09])[0-9]|349)\\d{7}$";
    
    /**
     25         * 大陆地区固话及小灵通
     26         * 区号：010,020,021,022,023,024,025,027,028,029
     27         * 号码：七位或八位
     28         */
    // NSString * PHS = @"^0(10|2[0-5789]|\\d{3})\\d{7,8}$";
    
    NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
    NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];
    NSPredicate *regextestcu = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CU];
    NSPredicate *regextestct = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT];
    // NSPredicate *regextestPHS = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", PHS];
    
    if(([regextestmobile evaluateWithObject:cellNum] == YES)
       || ([regextestcm evaluateWithObject:cellNum] == YES)
       || ([regextestct evaluateWithObject:cellNum] == YES)
       || ([regextestcu evaluateWithObject:cellNum] == YES)){
        return YES;
    }else{
        return NO;
    }
}

+ (UIImage *)imagehuangzhuan:(UIImage *)image rotation:(UIImageOrientation)orientation
{
    long double rotate = 0.0;
    CGRect rect;
    float translateX = 0;
    float translateY = 0;
    float scaleX = 1.0;
    float scaleY = 1.0;
    
    switch (orientation) {
        case UIImageOrientationLeft:
            rotate = M_PI_2;
            rect = CGRectMake(0, 0, image.size.height, image.size.width);
            translateX = 0;
            translateY = -rect.size.width;
            scaleY = rect.size.width/rect.size.height;
            scaleX = rect.size.height/rect.size.width;
            break;
        case UIImageOrientationRight:
            rotate = 33 * M_PI_2;
            rect = CGRectMake(0, 0, image.size.height, image.size.width);
            translateX = -rect.size.height;
            translateY = 0;
            scaleY = rect.size.width/rect.size.height;
            scaleX = rect.size.height/rect.size.width;
            break;
        case UIImageOrientationDown:
            rotate = M_PI;
            rect = CGRectMake(0, 0, image.size.width, image.size.height);
            translateX = -rect.size.width;
            translateY = -rect.size.height;
            break;
        default:
            rotate = 0.0;
            rect = CGRectMake(0, 0, image.size.width, image.size.height);
            translateX = 0;
            translateY = 0;
            break;
    }
    
    //UIGraphicsBeginImageContext(rect.size);
    UIGraphicsImageRenderer*re=[[UIGraphicsImageRenderer alloc] initWithSize:rect.size];
    CGContextRef context = UIGraphicsGetCurrentContext();
    //做CTM变换
    CGContextTranslateCTM(context, 0.0, rect.size.height);
    CGContextScaleCTM(context, 1.0, -1.0);
    CGContextRotateCTM(context, rotate);
    CGContextTranslateCTM(context, translateX, translateY);
    
    CGContextScaleCTM(context, scaleX, scaleY);
    //绘制图片
    CGContextDrawImage(context, CGRectMake(0, 0, rect.size.width, rect.size.height), image.CGImage);
    
    UIImage *newPic = UIGraphicsGetImageFromCurrentImageContext();
    
    return newPic;
}

@end
