//
//  TaskPointReview.m
//  Macalline
//
//  Created by bestRun on 15-9-1.
//  Copyright (c) 2015年 JianjiYuan. All rights reserved.
//

#import "TaskPointReview.h"

@interface TaskPointReview ()<UITextFieldDelegate,UITextViewDelegate>
@property (strong,nonatomic)UILabel *lblTitle;
@property (strong,nonatomic)UITextView *textRemark;
@property (strong,nonatomic)UILabel *lblTextholder;

@property (strong,nonatomic)UIButton *btnPass;
@property (strong,nonatomic)UIButton *btnNo;
@end
@implementation TaskPointReview
-(id)initWithFrame:(CGRect)frame
{
    self=[super initWithFrame:frame];
    if(self)
    {
        self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
        UIView * view = [[UIView alloc] init];
        view.backgroundColor = [UIColor whiteColor];
        [self addSubview:view];
   
        view.layer.cornerRadius=5;
        
        [view autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:20];
        [view autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:20];
        [view autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:self.frame.size.height/3];
        [view autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:self.frame.size.height/3];
        [view autoSetDimension:ALDimensionHeight toSize:self.frame.size.height/3];
        
        self.lblTitle=[[UILabel alloc] init];
        self.lblTitle.backgroundColor=RGBColor(0, 171, 202, 1);
        self.lblTitle.text=@"审核";
        self.lblTitle.textColor=[UIColor whiteColor];
        self.lblTitle.font=[UIFont boldSystemFontOfSize:16];
        self.lblTitle.textAlignment=NSTextAlignmentCenter;
   
        
        [view addSubview:self.lblTitle];
        [self.lblTitle autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(0, 0, 0, 0) excludingEdge:ALEdgeBottom];
        [self.lblTitle autoSetDimension:ALDimensionHeight toSize:35];
        
        
      
        
        
   
        self.textRemark = [[UITextView alloc] init];
        self.textRemark.delegate = self;
        self.textRemark.layer.cornerRadius = 5;
        self.textRemark.layer.borderWidth = 1;
        self.textRemark.layer.borderColor = [UIColor colorWithRed:0.9333 green:0.9333 blue:0.9333 alpha:1].CGColor;
        [view addSubview:_textRemark];
        [self.textRemark autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.lblTitle withOffset:10];
        [self.textRemark autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:20];
        [self.textRemark autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:20];
        [self.textRemark autoSetDimension:ALDimensionHeight toSize:80];
     
        self.lblTextholder=[[UILabel alloc] init];
        self.lblTextholder.textAlignment=NSTextAlignmentLeft;
        self.lblTextholder.text=@"请输入备注";
        self.lblTextholder.font=[UIFont systemFontOfSize:15];
        self.lblTextholder.textColor=[UIColor darkGrayColor];
        [self.textRemark addSubview:self.lblTextholder];
        [self.lblTextholder autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:3];
        [self.lblTextholder autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:3];
     //   [self registObserverOfTextInputView];
        
        
        
        self.btnPass=[[UIButton alloc] init];
        [self.btnPass setTitle:@"审核通过" forState:UIControlStateNormal];
        [self.btnPass setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.btnPass addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        self.btnPass.titleLabel.font=[UIFont systemFontOfSize:16];
        self.btnPass.backgroundColor=RGBColor(0, 171, 202, 1);
        self.btnPass.layer.cornerRadius=5;
        self.btnPass.layer.masksToBounds=YES;
        self.btnPass.tag = 999;
        [view addSubview:self.btnPass];
        self.btnPass.titleLabel.textAlignment=NSTextAlignmentCenter;
        [self.btnPass autoSetDimension:ALDimensionHeight toSize:35];
        [self.btnPass autoSetDimension:ALDimensionWidth toSize:100];
        [self.btnPass autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:20];
        [self.btnPass autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:20];
        
        
        
        
        
        
        
        self.btnNo=[[UIButton alloc] init];
        [self.btnNo setTitle:@"审核不通过" forState:UIControlStateNormal];
        [self.btnNo setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.btnNo addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        self.btnNo.titleLabel.font=[UIFont systemFontOfSize:15];
        self.btnNo.backgroundColor=RGBColor(244, 160, 0, 1);
        self.btnNo.layer.cornerRadius=5;
        self.btnNo.layer.masksToBounds=YES;
        [view addSubview:self.btnNo];
        self.btnNo.titleLabel.textAlignment=NSTextAlignmentCenter;
        [self.btnNo autoSetDimension:ALDimensionHeight toSize:35];
        [self.btnNo autoSetDimension:ALDimensionWidth toSize:100];
        [self.btnNo autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:20];
        [self.btnNo autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:20];
        
        
        
    }
    return self;
    
}


-(void)btnClick:(UIButton*)sender
{
    if (self.CheckClickAtIndex) {//回调
        if (sender.tag == 999) {
            self.CheckClickAtIndex(@"1",self.textRemark.text);
        }
        else
        {
            if (self.textRemark.text.length > 0) {
                self.CheckClickAtIndex(@"0",self.textRemark.text);
            }
            else
            {
                [UIApplication showToastViewMessage:@"请输入审核备注!"];
            }
            
        }
    }
}


- (void)textViewDidChange:(UITextView *)textView
{
    if ([textView.text isEqualToString:@""]) {
        self.lblTextholder.hidden = NO;
    }else {
        self.lblTextholder.hidden = YES;
    }
}

- (void)textViewDidEndEditing:(UITextView *)textView
{
    if ([textView.text isEqualToString:@""]) {
        self.lblTextholder.hidden = NO;
    }else {
        self.lblTextholder.hidden = YES;
    }
    
    _hasDataChanged = YES;
}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    if ([text isEqualToString:@"\n"]) {
        [textView resignFirstResponder];
        return NO;
    }
    if (text.length > 0) {
        self.lblTextholder.hidden = YES;
    }
    else
    {
        self.lblTextholder.hidden = NO;
    }
    return YES;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}


@end
