//
//  GroupVerifyVC.m
//  smartRhino
//
//  Created by niuzhen on 2020/7/16.
//  Copyright © 2020 tederen. All rights reserved.
//

#import "GroupVerifyVC.h"
#import "MailListMoveVC.h"

@interface GroupVerifyVC ()<UITextViewDelegate>
@property (weak, nonatomic) IBOutlet UIButton *sendBtn;
@property (weak, nonatomic) IBOutlet UITextView *textView;
@property (weak, nonatomic) IBOutlet UILabel *countL;
@property (copy, nonatomic) NSString        *Name;
@property (assign, nonatomic) NSInteger      GroupId;
@end

@implementation GroupVerifyVC
+(GroupVerifyVC *)initGroupVerifyVC{
    GroupVerifyVC *controller = [StoryboardManager.shared.Source instantiateViewControllerWithIdentifier:@"GroupVerifyVC"];
    return controller;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.fd_prefersNavigationBarHidden = YES;
    self.view.backgroundColor = UIColorHex(0xF8F8F8);

    WS(weakSelf);
    [self.sendBtn setAction:^{
        NSDictionary * paraDict = @{@"GroupId":@(weakSelf.Id),
                                    @"UserIds":@[@([AppUserModel sharedAppUserModel].Id)],
                                    @"UserId":@([AppUserModel sharedAppUserModel].Id),
                                    @"SourceType":@(1),///申请
                                    @"Remark":weakSelf.textView.text
        };
        [[HttpManager sharedHttpManager] POSTUrl:Host(APP_Group_Insert_User) parameters:paraDict responseStyle:JOSN success:^(id  _Nonnull responseObject) {
            if (weakSelf.SendBlock) {
                weakSelf.SendBlock();
            }
            [weakSelf.navigationController popViewControllerAnimated:YES];
        } failure:^(NSError * _Nonnull error) {
            SHOWERROR([ZYCTool handerResultData:error]);
        }];
    }];
    self.textView.delegate = self;
}

- (void)textViewDidChange:(UITextView *)textView
{
    UITextRange *markRange = textView.markedTextRange;
    NSInteger pos = [textView offsetFromPosition:markRange.start
                              toPosition:markRange.end];
    NSInteger nLength = textView.text.length - pos;
    if (nLength > 100 && pos == 0)
    {
        self.countL.text = [NSString stringWithFormat:@"100/100"];
        self.textView.text = [textView.text substringToIndex:100];
    }else{
        self.countL.text = [NSString stringWithFormat:@"%ld/100",textView.text.length];
    }
}

@end