//
//  ChangeUserSignatureViewController.m
//  ALand
//
//  Created by Z on 16/5/24.
//  Copyright © 2016年 Z. All rights reserved.
//

#import "ChangeUserSignatureViewController.h"
#import "ICRPlaceholderTextView.h"
@interface ChangeUserSignatureViewController ()<UITextViewDelegate>
@property (weak, nonatomic) IBOutlet ICRPlaceholderTextView *textViewTop;

@end

@implementation ChangeUserSignatureViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.textViewTop.m_placeHolder = @"输入签名…";
    self.textViewTop.text = self.reseller.internalBaseClassDescription;
    self.textViewTop.delegate = self;
    // Do any additional setup after loading the view from its nib.
}

- (IBAction)actionChangeSignature:(id)sender {
    [self changeSignature:self.textViewTop.text];
}


- (void)changeSignature:(NSString *)signature {
    [MBProgressHUD Javen_showMessage:@"修改中" onView:self.view];
    self.reseller.internalBaseClassDescription = signature;
    NSDictionary *params = [self getParamsWithReseller:self.reseller];
    [self changeResellerInfoWithDic:params];
}


- (NSDictionary *)getParamsWithReseller:(JavenResellerBigModel *)resellerModel {
    //    resellerModel.ownerOrg = nil;
    UserInfo *user = [UserInfo shareInstance];
    NSDictionary *reseller = [resellerModel dictionaryRepresentation];
    NSDictionary *params = @{@"operCtx" : @{@"time" : [[NSDate date] timeStampNumber],
                                            @"domain" : kDomain,
                                            @"operator" : @{@"id" : user.reseller.uuid,
                                                            @"fullName" : user.reseller.name}},
                             @"reseller" : reseller};
    return params;
}

/** 把修改的信息上传到服务器 */
- (void)changeResellerInfoWithDic:(NSDictionary *)params
{
    WS(weakSelf)
    [[HTTPCilent shareCilent] POST:@"reseller/save" parameters:params success:^(NSURLSessionDataTask *task, id responseObject) {
        
        [MBProgressHUD hideHUDForView:weakSelf.view];
        
        if ([responseObject[@"code"] isEqualToNumber:@0]) {
            [MBProgressHUD Javen_showSuccess:@"修改成功！" onView:weakSelf.view  delay:0.7 complete:^{
                [weakSelf popAction];
            }];
        }else{
            [MBProgressHUD Javen_showError:responseObject[@"message"] onView:weakSelf.view delay:0.7 complete:nil];
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
    }];
    
}


- (IBAction)actionSaveSignature:(id)sender {
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

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