CNLiveContactUsViewController.m 7.89 KB
//
//  CNLiveContactUsViewController.m
//  CNLiveScioLive
//
//  Created by CNLive-zxw on 2018/9/21.
//  Copyright © 2018年 CNLive. All rights reserved.
//

#import "CNLiveContactUsViewController.h"
#import "GCPlaceholderTextView.h"

@interface CNLiveContactUsViewController ()
@property (nonatomic, strong) GCPlaceholderTextView *textView;
@property (nonatomic, strong) GCPlaceholderTextView *contactView;

@end

@implementation CNLiveContactUsViewController
static const NSInteger margin = 10;

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUpNavigationBar];
    [self setUpSubControllers];

    // Do any additional setup after loading the view.
}
#pragma mark - UI
- (void)setUpNavigationBar{
    
    self.navigationController.navigationBar.barTintColor = Color_Blue;
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];

    //左
    UIButton *headerButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 20, 44)];
    headerButton.layer.cornerRadius = 2.0;
    headerButton.layer.masksToBounds = true;
    [headerButton setImage:[UIImage imageNamed:@"cnlive_white_back"] forState:UIControlStateNormal];
    [headerButton addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:headerButton];
    
    self.navigationItem.title = self.navTitle;

}
- (void)setUpSubControllers{
    self.view.backgroundColor = [UIColor whiteColor];
    
    _textView = [[GCPlaceholderTextView alloc] initWithFrame:CGRectMake(margin, margin, MainScreenWidth - 2*margin, 150)];
    _textView.font = [UIFont systemFontOfSize:15];
    _textView.textColor = HEXCOLOR(0x333333);
    _textView.placeholder = CustomStr(@"WeWillReplyToYouSoon");
    [self.view addSubview:_textView];
    UIImageView *lineImage1 = [[UIImageView alloc] initWithFrame:CGRectMake(margin, 160, MainScreenWidth - 2*(margin+2), Line_Height)];
    lineImage1.backgroundColor = Color_Line;
    [self.view addSubview:lineImage1];
    
    _contactView = [[GCPlaceholderTextView alloc] initWithFrame:CGRectMake(margin+2, 161, MainScreenWidth - 2*margin, 68)];
    _contactView.font = [UIFont systemFontOfSize:15];
    _contactView.textColor = HEXCOLOR(0x333333);
    _contactView.placeholder = CustomStr(@"ForUsToReplyToYourInquiries");
    [self.view addSubview:_contactView];
    UIImageView *lineImage2 = [[UIImageView alloc] initWithFrame:CGRectMake(margin+2, 230, MainScreenWidth - 2*(margin+2), Line_Height)];
    lineImage1.backgroundColor = Color_Line;
    [self.view addSubview:lineImage2];
    
    UIButton *doConfirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [doConfirmBtn setFrame:CGRectMake(margin+2, 258, MainScreenWidth - 2*(margin+2), 44)];
    [doConfirmBtn addTarget:self action:@selector(doConfirm:) forControlEvents:UIControlEventTouchUpInside];
    [doConfirmBtn setBackgroundColor:Color_Blue];
    [doConfirmBtn.titleLabel setFont:[UIFont systemFontOfSize:19]];
    [doConfirmBtn setTitle:CustomStr(@"Sure") forState:UIControlStateNormal];
    [doConfirmBtn setTitleColor:HEXCOLOR(0xffffff) forState:UIControlStateNormal];
    doConfirmBtn.layer.masksToBounds = YES;
    doConfirmBtn.layer.cornerRadius = 6.0;
    [self.view addSubview:doConfirmBtn];

    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(margin+2, 320, MainScreenWidth - 2*(margin+2), 180)];
    titleLabel.numberOfLines = 0;
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.textColor = HEXCOLOR(0x333333);
//    titleLabel.text = @" 其他联系方式\n\n 电话:010-65592311\n\n 地址:中国北京东城区朝阳门内大街225号\n\n 邮编:100010";
//    titleLabel.text = [NSString stringWithFormat:@" %@\n\n %@:010-65592311\n\n %@\n\n %@:100010",CustomStr(@"OthercContacts"), CustomStr(@"Tel"), CustomStr(@"Address"), CustomStr(@"Postcode")];

    titleLabel.text = [NSString stringWithFormat:@" %@\n\n %@:010-88824268\n\n %@:guoxinfabu_taolm@scio.gov.cn \n\n QQ:110016699\n\n",CustomStr(@"OthercContacts"), CustomStr(@"Tel"), CustomStr(@"Email")];

    titleLabel.font = [UIFont systemFontOfSize:14];
    [self.view addSubview:titleLabel];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark - Action
- (void)doConfirm:(UIButton *)sender{
    sender.userInteractionEnabled = NO;
    if (_textView.text.length == 0) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:CustomStr(@"Notice")
                                                        message:CustomStr(@"PleaseEnterYourFeedback")
                                                       delegate:nil
                                              cancelButtonTitle:CustomStr(@"Sure")
                                              otherButtonTitles:nil];
        [alert show];
        sender.userInteractionEnabled = YES;
        return;
    }
    if (_contactView.text.length == 0) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:CustomStr(@"Notice")
                                                        message:CustomStr(@"PleaseLeaveYourEmailAccountorPhoneNumber")
                                                       delegate:nil
                                              cancelButtonTitle:CustomStr(@"Sure")
                                              otherButtonTitles:nil];
        [alert show];
        sender.userInteractionEnabled = YES;
        return;
    }
    
    
    NSStringEncoding encoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
    NSString *message = [[NSString stringWithFormat:@"%@%@",_textView.text,_contactView.text] stringByAddingPercentEscapesUsingEncoding:encoding];
    NSDictionary *dic = @{@"id":SP_ID, @"sp_id":SP_ID, @"msg":message};

//    NSMutableDictionary *mudic = [[NSMutableDictionary alloc] init];
//    NSString *message = [NSString stringWithFormat:@"%@%@",_textView.text,_contactView.text];
//    NSStringEncoding enc = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
//    message = [message stringByAddingPercentEscapesUsingEncoding:enc];
//    [mudic setObject:SP_ID forKey:@"sp_id"];
//    [mudic setObject:message forKey:@"msg"];
//    [mudic setObject:SP_ID forKey:@"id"];
    if (![[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) {
        [AlertViewTool showHUDViewText:CustomStr(@"NetworkiInterruption")];
        return;
    }
    
    [AlertViewTool showHUDView];
    [XWHTTPTool POST:@"http://api.cnlive.com/open/api/CnliveMobile/json/report" params:dic success:^(id json) {    
        [AlertViewTool hideHUDView];

        sender.userInteractionEnabled = YES;

        NSLog(@"%@", json);
        NSDictionary *dic = [NSDictionary dictionaryWithDictionary:json];
        NSLog(@"%@", dic);
        if ([dic[@"errorCode"] isEqualToString:@"0"]) {
            [AlertViewTool showHUDViewText:CustomStr(@"ThanksForYourFeedback")];
            [self.navigationController popViewControllerAnimated:YES];
            NSLog(@"成功~");
        } else {
            [AlertViewTool showHUDViewText:dic[@"errorMessage"]];

        }
    } failure:^(NSError *error) {
        // 请求失败
        NSLog(@"%@", [error localizedDescription]);
        [AlertViewTool hideHUDView];
        [AlertViewTool showHUDViewText:CustomStr(@"ServerBusy")];
        sender.userInteractionEnabled = YES;
    }];
}
/*
#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.
}
*/
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [super touchesBegan:touches withEvent:event];
    [self.view endEditing:YES];
}
@end