//
//  SettingViewController.m
//  Macalline
//
//  Created by JianjiYuan on 14-12-1.
//  Copyright (c) 2014年 JianjiYuan. All rights reserved.
//

#import "SettingViewController.h"
#import "RDVTabBarController.h"
#import "ModifyPWDViewController.h"
#import "AboutUsViewController.h"
#import "GexinPushMgr.h"
#import "DBDaoMgr.h"
#import "UserInfoViewController.h"
#import "SetSearchDaysViewController.h"
#import "setSearchDays.h"
@interface SettingViewController () < UITableViewDataSource, UITableViewDelegate, UIAlertViewDelegate ,UIGestureRecognizerDelegate>
{
    NSDictionary *dictUpdateInfo;
}

@property (nonatomic, strong) UITableView *tableVContent;
@property (nonatomic, strong) UIButton *btnLogout;
@property (nonatomic,strong)setSearchDays *setSearchDays;

@end

@implementation SettingViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
//        self.title = @"我";
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor=RGBColor(153, 153, 153, 0.3 );
    [self setViewLayoutConstraint];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    self.navigationItem.leftBarButtonItems = nil;
    self.navigationController.navigationBarHidden = NO;
    self.rdv_tabBarController.navigationController.navigationBarHidden = YES;
}

- (void)setViewLayoutConstraint
{
    [self.tableVContent autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
    
   // [self.btnLogout autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(0, 0, 5, 0) excludingEdge:ALEdgeTop];
//    [self.btnLogout autoSetDimension:ALDimensionHeight toSize:35];
  //  [self.btnLogout autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.tableVContent withOffset:8];
}

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

- (void)checkAppUpdate
{
    [UIApplication showLoadingView:@"正在检测新版本，请稍后"];
    //NSString *interface = @"checkAppUpdate";
    NSString *interface=@"checkAppUpdateEX";
    NSString *curVersion = [[NSBundle mainBundle] infoDictionary][@"CFBundleVersion"];
    NSDictionary *dicParam = @{@"versionCode":curVersion, @"platform":@"2"};
//    NSOperation *operation = [self.networkMgr operationWithURL:kBaseURL(interface)
//                                                                interface:interface
//                                                                   params:dicParam
//                                                                 dataType:BRNetMgrDataTypeJSON
//                                                                   method:BRNetMgrMethodPost];
    NSOperation *operation = [self.networkMgr operationWithURL:kBaseEXURL(interface)
                                                     interface:interface
                                                        params:dicParam
                                                      dataType:BRNetMgrDataTypeJSON
                                                        method:BRNetMgrMethodPost];
    [self.networkMgr startOperation:operation];
}

- (void)uploadUnUploadedDatas
{
    NSString *type = nil;
    if ([[DataMgr getInstance].roleId isEqualToString:@"2"]) {
        type = @"2";
    }else {
        type = @"3";
    }
    
    NSArray *checkPointImageIds = [DBDaoMgr fetchUnUploadedImageIdsByType:type];
    NSArray *checkPointInfoIds = [DBDaoMgr fetchUnUploadedCheckPointIdsByType:type];
    if (checkPointImageIds.count == 0 && checkPointInfoIds.count == 0) {
        [UIApplication showToastViewMessage:@"暂无未上传数据"];
        return;
    }else {
        [UIApplication showLoadingView:kTextShowInProgress];
    }
    
    [self.networkMgr.operationQueue setSuspended:YES];
    
    for (NSDictionary *dictCheckInfoId in checkPointInfoIds) {
        
        NSArray *arrCheckInfos = [DBDaoMgr fetchCheckPointInfoByType:type checkPointId:dictCheckInfoId[@"checkPointId"]];
        if (arrCheckInfos.count > 0) {
            NSDictionary *dictCheckInfo = arrCheckInfos[0];
            AFHTTPRequestOperation *operation = [self handleCheckPoint:dictCheckInfoId[@"checkPointId"]
                                                                remark:dictCheckInfo[@"remark"]
                                                                amount:dictCheckInfo[@"amount"]];
            [operation setUserInfo:@{@"interface":@"handleCheckPoint",
                                     @"checkPointId":dictCheckInfoId[@"checkPointId"],
                                     @"type":type}];
            
        }
    }
    
    for (NSDictionary *dictPointId in checkPointImageIds) {
        
        NSArray *arrImages = [DBDaoMgr fetchImagesByType:type checkPointId:dictPointId[@"checkPointId"]];
        if (arrImages.count > 0) {
            [self uploadCheckPointPicture:dictPointId[@"checkPointId"] type:type images:arrImages];
        }
        
    }
    
    self.networkMgr.operationQueue.maxConcurrentOperationCount = 2;
    [self.networkMgr addObserverForQueueProgress];
    DLog(@"self.operationQueue %@", self.networkMgr.operationQueue);
    
    [self.networkMgr.operationQueue setSuspended:NO];

}

- (AFHTTPRequestOperation *)handleCheckPoint:(NSString *)checkPointId remark:(NSString *)remark amount:(NSString *)amount
{
    NSString *interface = @"handleCheckPoint";
    NSDictionary *dicParam = @{@"checkPointId":checkPointId?:@"",
                               @"remark":remark?:@"",@"amount":amount?:@"", @"location":[DataMgr getInstance].locationName?:@""};
    AFHTTPRequestOperation *operation = [self.networkMgr operationWithURL:kBaseURL(interface)
                                                interface:interface
                                                   params:dicParam
                                                 dataType:BRNetMgrDataTypeJSON
                                                   method:BRNetMgrMethodPost];
    
    return operation;
}

- (AFHTTPRequestOperation *)uploadCheckPointPicture:(NSString *)checkPointId type:(NSString *)type images:(NSArray *)images
{
    NSMutableArray *arrFiles = [NSMutableArray array];
    for (NSDictionary *imageObj in images) {
        NSDictionary *dictImage = @{kFileKeyName:[NSString stringWithFormat:@"%@.jpg", imageObj[@"id"]], kFilePath:imageObj[@"imagePath"]};
        [arrFiles addObject:dictImage];
    }
    
    NSString *interface = @"uploadCheckPointPicture";
    AFHTTPRequestOperation *operation = [self.networkMgr
                                         operationUploadWithURL:kBaseURL(interface)
                                         interface:interface
                                         params:@{@"type":type, @"checkPointId":checkPointId?:@""}
                                         dataType:BRNetMgrDataTypeJSON
                                         fileType:BRNetMgrFileTypeJpeg
                                         files:arrFiles];
    [operation setUserInfo:@{@"interface":interface, @"checkPointId":checkPointId, @"files":arrFiles}];
        
    return operation;

}

#pragma mark =============  BRNetworkMgr Delegate  =============
- (void)httpOperationSuccess:(AFHTTPRequestOperation *)operation
                      result:(NSDictionary *)result
{
    DLog(@"operation.userInfo %@", operation.userInfo);
    
    //if ([operation.userInfo[@"interface"] isEqualToString:@"checkAppUpdate"])
    
    if ([operation.userInfo[@"interface"] isEqualToString:@"checkAppUpdateEX"])

    {
        
        dictUpdateInfo = result[@"versionDetails"];
        if (dictUpdateInfo) {
            if ([dictUpdateInfo[@"type"] isEqualToString:@"1"]) {//强制更新
                
                [UIApplication showAlertViewWithTitle:@"提示"
                                              message:dictUpdateInfo[@"updateLog"]
                                             delegate:self
                                                  tag:101
                                    cancelButtonTitle:@"确认更新" otherButtonTitles:nil, nil];
            }else {
                
                [UIApplication showAlertViewWithTitle:@"提示"
                                              message:dictUpdateInfo[@"updateLog"]
                                             delegate:self
                                                  tag:100
                                    cancelButtonTitle:@"下次再说" otherButtonTitles:@"立即更新", nil];
            }
        }else {
            [UIApplication showToastViewMessage:@"当前已是最新版本"];
        }
        
    }else if ([operation.userInfo[@"interface"] isEqualToString:@"handleCheckPoint"]){
        
        NSString *checkPointId = operation.userInfo[@"checkPointId"];
        NSString *type = operation.userInfo[@"type"];
        [DBDaoMgr updateCheckPointInfosTagUploaded:@[@{@"id":[NSString stringWithFormat:@"%@%@", checkPointId, type]}]];
        
        
    }else if ([operation.userInfo[@"interface"] isEqualToString:@"uploadCheckPointPicture"]){
        NSArray *arrImages = operation.userInfo[@"files"];
        NSMutableArray *arrImageIds = [NSMutableArray array];
        for (NSDictionary *dictImage in arrImages) {
            NSString *imageId = [[dictImage[kFileKeyName] componentsSeparatedByString:@"."] firstObject];
            [arrImageIds addObject:@{@"id":imageId?:@""}];
        }
        [DBDaoMgr updateImagesTagUploaded:arrImageIds];
        
    }
    
}

- (void)httpOperationFailed:(AFHTTPRequestOperation *)operation
                      error:(NSError *)error
{
    
}

//队列异步请求
- (void)networkQueueComplete:(NSOperationQueue *)queue
{
    [self.networkMgr removeObserverForQueueProgress];
    [[NSNotificationCenter defaultCenter] postNotificationName:kShouldReQueryCountInit object:nil];
    [UIApplication showToastViewMessage:@"上传成功！"];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (alertView.tag == 2046) {
        if (buttonIndex == 0) {
            
        }else {
            NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init];
            [inputFormatter setDateFormat:@"yyyy-MM-dd"];
            NSTimeInterval timeInterval = 24*60*60;
            
            NSArray* infoArr = [DBDaoMgr fetchAllInstructionBookInfo];
            int i = [[DataMgr getInstance].dayCount integerValue];
            NSDate* sDate = [NSDate dateWithTimeInterval:timeInterval*-i sinceDate:[NSDate date]];
            
            NSMutableArray* nameArr = [[NSMutableArray alloc] init];
            for (int m = 0; m < infoArr.count; m++) {
                NSString* str = infoArr[m][@"taskEndTime"];
                NSDate* endDate = [inputFormatter dateFromString:str];
                if ([[sDate earlierDate:endDate] isEqualToDate:endDate]) {
                    [nameArr addObject:infoArr[m][@"fileName"]];
                }
            }
            
            if (nameArr.count > 0) {
                for (int k = 0; k < nameArr.count; k++) {
                    if ([UIApplication deleteFileByFileName:nameArr[k]]) {
                        [DBDaoMgr deleteInstructionBookInfoByName:nameArr[k]];
                    }else
                    {
                        [UIApplication showToastViewMessage:@"删除文件失败!"];
                    }
                    
                }
            }
            
            NSArray* noticeArr = [DBDaoMgr fetchNoticeByUserId:[DataMgr getInstance].userID];
            NSMutableArray* noticeNameArr = [[NSMutableArray alloc] init];
            for (int t = 0; t < noticeArr.count; t++) {
                NSString* str = noticeArr[t][@"time"];
                NSDate* endDate = [inputFormatter dateFromString:str];
                if ([[sDate earlierDate:endDate] isEqualToDate:endDate]) {
                    [noticeNameArr addObject:noticeArr[t][@"noticeId"]];
                }
            }
            
            if (noticeNameArr.count > 0) {
                for (int j = 0; j < noticeNameArr.count; j++) {
                    if ([DBDaoMgr deleteNoticeByUserID:[DataMgr getInstance].userID andNoticeID:noticeNameArr[j]]) {
                        
                    }else
                    {
                        [UIApplication showToastViewMessage:@"删除消息失败!"];
                    }
                    
                }
            }
            
            [UIApplication showToastViewMessage:@"清除缓存成功!"];
        }
        
    } else if (alertView.tag == 100) {
        if (buttonIndex == 0) {
            if ([dictUpdateInfo[@"type"] isEqualToString:@"1"]) {
                [UIApplication showToastViewMessage:@"本次更新为强制更新，应用程序即将退出，请及时更新"];
                [self performSelector:@selector(exitApplication) withObject:nil afterDelay:1.5];
            }
        }else {
            [self performSelector:@selector(exitApplication) withObject:nil afterDelay:1.5];
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[dictUpdateInfo[@"appURL"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
        }
        
    }else if (alertView.tag == 101) {
        [self performSelector:@selector(exitApplication) withObject:nil afterDelay:1.5];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[dictUpdateInfo[@"appURL"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
    }else {
        if (alertView.tag == 200) {
            if (buttonIndex == 1) {
                //让SDK第一时间断线，让个推先用APN推送, offline消息则收不到
//                [[GexinPushMgr getInstance] applicationDidEnterBackground];
//                [[GexinPushMgr getInstance] unRegisterRemoteNotification];//目前一直推送
                
                //标识自动登录:NO
                NSDictionary *dict = [UIApplication getObjectType:Dictionary key:kDictAutoLoginInfo];
                NSMutableDictionary *dictLoginInfo = [NSMutableDictionary dictionaryWithDictionary:dict];
                [dictLoginInfo setValue:@NO forKey:kAutoLogin];
                [UIApplication saveObject:dictLoginInfo type:Dictionary key:kDictAutoLoginInfo];
                
                [self.rdv_tabBarController.navigationController popViewControllerAnimated:YES];
                
            }
        }
    }
}

- (void)exitApplication
{
    exit(0);
}

- (void)btnLogoutClick:(id)sender
{
    [UIApplication showAlertViewWithTitle:@"提示"
                                  message:@"确认要退出系统吗？"
                                 delegate:self
                                      tag:200
                        cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    
    
}

- (void)switchButtonClick:(UISwitch *)switchBtn
{
    if (switchBtn.tag == 105) {
        [UIApplication saveObject:[NSString stringWithFormat:@"%d", switchBtn.on] type:String key:kLocalNotifySoundEnable];
    }else {
        [UIApplication saveObject:[NSString stringWithFormat:@"%d", switchBtn.on] type:String key:kLocalNotifyShakeEnable];
    }
}

- (void)configureCell:(UITableViewCell *)cell forIndexPath:(NSIndexPath *)indexPath
{
    if ([[DataMgr getInstance].roleId isEqualToString:@"daqufuzeren"]) {
        cell.textLabel.textColor= RGBColor(3, 119, 193, 1);
    }
    else if ([[DataMgr getInstance].roleId isEqualToString:@"xiaoqufuzeren"]) {
        cell.textLabel.textColor= RGBColor(26, 171, 200, 1);
    }
    else
    {
        cell.textLabel.textColor= [UIColor colorWithRed:0.2314 green:0.7098 blue:0.9373 alpha:1];
        
    }
    
    switch (indexPath.row) {
        case 0:
        {
            cell.textLabel.text = @"个人信息";
            cell.textLabel.font = [UIFont boldSystemFontOfSize:18];
         //   cell.textLabel.textColor = RGBColor(153, 153, 153, 1);
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            UIImageView *imageVArrow = [[UIImageView alloc] initWithFrame:CGRectMake(297, 15.5,12, 21)];
            imageVArrow.image = [UIImage imageNamed:@"Task_Point/image_point_arrow.png"];
            [cell.contentView addSubview:imageVArrow];
        }
            break;
//        case 1:
//        {
////            cell.textLabel.text = @"上传本地记录";
////            UIImageView *imageVArrow = [[UIImageView alloc] initWithFrame:CGRectMake(297, 15.5, 13, 13)];
////            imageVArrow.image = [UIImage imageNamed:@"Task_Point/image_point_arrow.png"];
////            [cell.contentView addSubview:imageVArrow];
//        }
//            break;
        case 1:
        {
            cell.textLabel.text = @"修改密码";
            cell.textLabel.font = [UIFont boldSystemFontOfSize:17];
            UIImageView *imageVArrow = [[UIImageView alloc] initWithFrame:CGRectMake(297, 15.5, 12, 21)];
            imageVArrow.image = [UIImage imageNamed:@"Task_Point/image_point_arrow.png"];
            [cell.contentView addSubview:imageVArrow];
        }
            break;

        case 2:
        {
            cell.textLabel.text = @"设置获取任务时间段";
            cell.textLabel.font = [UIFont boldSystemFontOfSize:17];
            UIImageView *imageVArrow = [[UIImageView alloc] initWithFrame:CGRectMake(297, 15.5,12, 21)];
            imageVArrow.image = [UIImage imageNamed:@"Task_Point/image_point_arrow.png"];
            [cell.contentView addSubview:imageVArrow];
        }
            break;
        case 3:
        {
            cell.textLabel.text = @"设置从服务器获取任务的时间间隔。";
            cell.textLabel.font = [UIFont boldSystemFontOfSize:13];
            cell.textLabel.textColor = RGBColor(153, 153, 153, 1);
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            cell.backgroundColor=[UIColor clearColor];
        }
            break;
        case 4:
        {
            cell.textLabel.text = @"通知提示音";
            cell.textLabel.font = [UIFont boldSystemFontOfSize:17];
            UISwitch *swithBtn = [[UISwitch alloc] init];
            swithBtn.frame = CGRectMake(310-CGRectGetWidth(swithBtn.frame), 7, CGRectGetWidth(swithBtn.frame), CGRectGetHeight(swithBtn.frame));
            swithBtn.tag = 105;
            [swithBtn addTarget:self action:@selector(switchButtonClick:) forControlEvents:UIControlEventValueChanged];
            [cell.contentView addSubview:swithBtn];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            swithBtn.on = [[UIApplication getObjectType:String key:kLocalNotifySoundEnable] boolValue];
            
        }
            break;
        case 5:
        {
            cell.textLabel.text = @"通知震动";
            cell.textLabel.font = [UIFont boldSystemFontOfSize:17];
            UISwitch *swithBtn = [[UISwitch alloc] init];
            swithBtn.frame = CGRectMake(310-CGRectGetWidth(swithBtn.frame), 7, CGRectGetWidth(swithBtn.frame), CGRectGetHeight(swithBtn.frame));
            swithBtn.tag = 106;
            [cell.contentView addSubview:swithBtn];
            [swithBtn addTarget:self action:@selector(switchButtonClick:) forControlEvents:UIControlEventValueChanged];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            swithBtn.on = [[UIApplication getObjectType:String key:kLocalNotifyShakeEnable] boolValue];
        }
            break;
        case 6:
        {
            cell.textLabel.text = @"当APP运行时，你可以设置是否需要声音或震动。";
            cell.textLabel.textColor = RGBColor(153, 153, 153, 1);
             cell.textLabel.font = [UIFont boldSystemFontOfSize:13];
            
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            

            cell.backgroundColor=[UIColor clearColor];
//            if ([[DataMgr getInstance].hasNewVersion isEqualToString:@"YES"]) {
//                UIButton* lblUndoneNum = [[UIButton alloc] init];
//                [lblUndoneNum setBackgroundColor:[UIColor redColor]];
//                lblUndoneNum.titleLabel.font = [UIFont systemFontOfSize:11];
//                lblUndoneNum.layer.cornerRadius = 4;
//                [cell.contentView addSubview:lblUndoneNum];
//                [lblUndoneNum autoAlignAxis:ALAxisHorizontal toSameAxisOfView:cell.contentView];
//                [lblUndoneNum autoSetDimensionsToSize:CGSizeMake(8, 8)];
//                [lblUndoneNum autoPinEdge:ALEdgeRight toEdge:ALEdgeRight ofView:cell.contentView withOffset:10];
//            }
        }
            break;
        case 7:
        {
            cell.textLabel.text = @"清除缓存数据";
            cell.textLabel.font = [UIFont boldSystemFontOfSize:17];
            UIImageView *imageVArrow = [[UIImageView alloc] initWithFrame:CGRectMake(297, 15.5,12, 21)];
            imageVArrow.image = [UIImage imageNamed:@"Task_Point/image_point_arrow.png"];
            [cell.contentView addSubview:imageVArrow];
        }
            break;
        case 8:
        {
            cell.textLabel.text = @"版本升级";
            cell.textLabel.font = [UIFont boldSystemFontOfSize:17];
            UIImageView *imageVArrow = [[UIImageView alloc] initWithFrame:CGRectMake(297, 15.5,12, 21)];
            imageVArrow.image = [UIImage imageNamed:@"Task_Point/image_point_arrow.png"];
            [cell.contentView addSubview:imageVArrow];
            
            if ([[DataMgr getInstance].hasNewVersion isEqualToString:@"YES"]) {
                UIButton* lblUndoneNum = [[UIButton alloc] init];
                [lblUndoneNum setBackgroundColor:[UIColor redColor]];
                lblUndoneNum.titleLabel.font = [UIFont systemFontOfSize:11];
                lblUndoneNum.layer.cornerRadius = 4;
                [cell.contentView addSubview:lblUndoneNum];
                [lblUndoneNum autoAlignAxis:ALAxisHorizontal toSameAxisOfView:cell.contentView];
                [lblUndoneNum autoSetDimensionsToSize:CGSizeMake(8, 8)];
                [lblUndoneNum autoPinEdge:ALEdgeRight toEdge:ALEdgeRight ofView:cell.contentView withOffset:10];
            }
            
        }
            break;
        case 9:
        {
            cell.textLabel.text = @"关于我们";
            cell.textLabel.font = [UIFont boldSystemFontOfSize:17];
            UIImageView *imageVArrow = [[UIImageView alloc] initWithFrame:CGRectMake(297, 15.5,12, 21)];
            imageVArrow.image = [UIImage imageNamed:@"Task_Point/image_point_arrow.png"];
            [cell.contentView addSubview:imageVArrow];
        }
            break;
        case 10:
        {
            //cell.textLabel.textColor = RGBColor(153, 153, 153, 1);
            //cell.textLabel.font = [UIFont boldSystemFontOfSize:13];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.backgroundColor=[UIColor clearColor];
        }
            break;
        case 11:
        {
            // [self.btnLogout autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(0, 0, 5, 0) excludingEdge:ALEdgeTop];
            //    [self.btnLogout autoSetDimension:ALDimensionHeight toSize:35];
            //  [self.btnLogout autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.tableVContent withOffset:8];
            
            [cell.contentView addSubview:self.btnLogout];
            [self.btnLogout autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
            
            
         }
            break;
            
        default:
            break;
    }
 
    if(indexPath.row==1 ||indexPath.row==0 ||indexPath.row== 4 ||indexPath.row==7||indexPath.row==8)
    {
    UIView *viewLine = [[UIView alloc] initWithFrame:CGRectMake(10, 43, 300, 1.1)];
    
    //viewLine.backgroundColor = RGBColor(0, 120, 193, 1);
    viewLine.backgroundColor=RGBColor(153, 153, 153,0.5 );
    
    [cell.contentView addSubview:viewLine];
    }
}

#pragma mark =============  UITableView DataSource  =============

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    
    [self configureCell:cell forIndexPath:indexPath];
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row==3 || indexPath.row==6 || indexPath.row==10)

        return 30;
    else
        
    return 44;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 12;
}

#pragma mark =============  UITableView Delegate  =============

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    DLog(@"You Click At Section: %d Row: %d", (int)indexPath.section, (int)indexPath.row);
    
    switch (indexPath.row) {
        case 0:
        {
//            UserInfoViewController *detailVC = [[UserInfoViewController alloc] initWithNibName:@"UserInfoViewController"   bundle:nil];
        //    UserInfoViewController *detailVC=[[UserInfoViewController alloc] initWithNibName:nil bundle:nil];
            UserInfoViewController *detailVC=[[UserInfoViewController alloc]init];
            
            [self.rdv_tabBarController.navigationController pushViewController:detailVC animated:YES];
        }
        case 3:
            break;
//        case 1:
//        {
////            cell.textLabel.text = @"上传本地记录";
//            [self uploadUnUploadedDatas];
//
//        }
       //     break;
        case 1:
        {
//            cell.textLabel.text = @"个人信息";
//            UIImageView *imageVArrow = [[UIImageView alloc] initWithFrame:CGRectMake(297, 15.5, 13, 13)];
//            imageVArrow.image = [UIImage imageNamed:@"Task_Point/image_point_arrow.png"];
//            [cell.contentView addSubview:imageVArrow];
//            UserInfoViewController *detailVC = [[UserInfoViewController alloc] initWithNibName:@"UserInfoViewController"
//                                                                                        bundle:nil];
//            [self.rdv_tabBarController.navigationController pushViewController:detailVC animated:YES];
            ModifyPWDViewController *detailVC = [[ModifyPWDViewController alloc] initWithNibName:nil bundle:nil];
        
            [self.rdv_tabBarController.navigationController pushViewController:detailVC animated:YES];
            
        }
            break;
            
        case 2:
        {
//            cell.textLabel.text = @"修改密码";
//            ModifyPWDViewController *detailVC = [[ModifyPWDViewController alloc] initWithNibName:nil bundle:nil];
//            BaseNavigationController *navModifyPwd = [[BaseNavigationController alloc] initWithRootViewController:detailVC];
//            [self.rdv_tabBarController.navigationController presentViewController:navModifyPwd animated:YES completion:nil];
            
//            SetSearchDaysViewController *detailVC = [[SetSearchDaysViewController alloc] initWithNibName:nil bundle:nil];
//            [self.rdv_tabBarController.navigationController pushViewController:detailVC animated:YES];
            
            /*
             -(void)addTaskPartView
             {
             _view1 = [[SATaskPartView alloc] initWithFrame:self.navigationController.view.bounds];
             __weak typeof(TaskListViewController) *weakSelf = self;
             _view1.BtnClickBlock = ^(NSString* tag) {
             [weakSelf listBtnClick:tag];
             };
             //    _view1.closeClickBlock = ^(NSString* tag) {
             //        [weakSelf listBtnClick:@"close"];
             //    };
             UITapGestureRecognizer* tapGesture1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(Actiondo:)];
             tapGesture1.delegate = self;
             [_view1 addGestureRecognizer:tapGesture1];
             [self.navigationController.view addSubview:_view1];
             }
             */
            
            [self addSetSearchDaysView];
            

        }
            break;
            
        case 4:
        {
//            cell.textLabel.text = @"通知提示音";
        }
            break;
        case 5:
        {
//            cell.textLabel.text = @"通知震动";
        }
            break;
        case 6:
        {
//            cell.textLabel.text = @"版本升级";
//            [self checkAppUpdate];
        }
            break;
        case 7:
        {
            //清除缓存
            UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提示" message:@"是否清除缓存数据!" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
            alert.delegate = self;
            alert.tag=2046;
            [alert show];
        }
            break;
        case 8:
        {
//            cell.textLabel.text = @"关于我们";
            
            [self checkAppUpdate];
        }
            break;
        case 9:
        {
            //            cell.textLabel.text = @"关于我们";
            AboutUsViewController *detailVC = [[AboutUsViewController alloc] initWithNibName:nil bundle:nil];
            [self.rdv_tabBarController.navigationController pushViewController:detailVC animated:YES];
        }
            break;
            
        case 10:
            break;
        case 11:
            break;
            
        default:
            break;
    }
 
}



-(void)addSetSearchDaysView
{

    _setSearchDays=[[setSearchDays alloc] initWithFrame:self.rdv_tabBarController.navigationController.view.bounds];

    UITapGestureRecognizer *tapGuesture1=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(Actiondo:)];
    tapGuesture1.delegate=self;
    [_setSearchDays addGestureRecognizer:tapGuesture1];
    
    [self.rdv_tabBarController.navigationController.view addSubview:_setSearchDays];
    
//    self.navigationController.navigationBarHidden = YES;
//    self.rdv_tabBarController.navigationController.navigationBarHidden = YES;
}
-(void)Actiondo:(UITapGestureRecognizer*)sender
{
    CGPoint point = [sender locationInView:self.view];
    
    NSLog(@"handleSingleTap!pointx:%f,y:%f",point.x,point.y);
    
    [_setSearchDays removeFromSuperview];
}


-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    if(touch.view!=_setSearchDays)
    {
        return NO;
    }
    return YES;
}

#pragma mark =============  Properties Lazy Load  =============

- (UITableView *)tableVContent
{
    if (_tableVContent) {
        return _tableVContent;
    }
    self.tableVContent = [UITableView newAutoLayoutView];
    _tableVContent.backgroundColor = [UIColor clearColor];
    
    _tableVContent.delegate = self;
    
    _tableVContent.dataSource = self;
    _tableVContent.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableVContent.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  //  _tableVContent.separatorColor=RGBColor(153, 153, 153, 0.8 );
    
    
   // _tableVContent.separatorInset=UIEdgeInsetsMake(0, 10, 0, 10);
    
    
    
    [self.view addSubview:_tableVContent];
    return _tableVContent;
}

- (UIButton *)btnLogout
{
    if (!_btnLogout) {
        self.btnLogout = [UIButton buttonWithType:UIButtonTypeCustom];
        _btnLogout.translatesAutoresizingMaskIntoConstraints = NO;
        _btnLogout.backgroundColor = [UIColor clearColor];
        [_btnLogout setTitle:@"退出登录" forState:UIControlStateNormal];
        _btnLogout.titleLabel.font= [UIFont boldSystemFontOfSize:18];
        
        if ([[DataMgr getInstance].roleId isEqualToString:@"daqufuzeren"]) {
            [_btnLogout setTitleColor:RGBColor(3, 119, 193, 1) forState:UIControlStateNormal];
        }
        else if ([[DataMgr getInstance].roleId isEqualToString:@"xiaoqufuzeren"]) {
            [_btnLogout setTitleColor:RGBColor(26, 171, 200, 1) forState:UIControlStateNormal];
        }
        else
        {
            [_btnLogout setTitleColor:[UIColor colorWithRed:0.2314 green:0.7098 blue:0.9373 alpha:1] forState:UIControlStateNormal];
        }

        //[_btnLogout setBackgroundImage:[UIImage imageNamed:@"Login/btn_login.png"] forState:UIControlStateNormal];
        [_btnLogout setBackgroundColor:[UIColor whiteColor] ];
        [_btnLogout addTarget:self action:@selector(btnLogoutClick:) forControlEvents:UIControlEventTouchUpInside];
        //[self.view addSubview:_btnLogout];
    }
    return _btnLogout;
}


@end
