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

#import "BATaskDetailViewController.h"
#import "BATaskCheckViewController.h"
#import "CMPopTipView.h"
#import "TaskListView.h"
#import "ListPartView.h"

@interface BATaskDetailViewController ()< CMPopTipViewDelegate ,UIGestureRecognizerDelegate>
{
    CMPopTipView *popTipView;
    UIButton* btnSheng;
    UIButton* btnShi;
    
    UILabel* lblTaskName;
    UILabel* lblAreaName;
    UILabel* lblendTime;
    UILabel* lblStatus;
    UILabel* lblSupportPeople;
    UILabel* lblSupportTime;
    UILabel* lblReviewTime;
    UILabel* lblReviewPeople;
        
}
@property (nonatomic, strong) UIView *descView;

@property (nonatomic, strong) NSString *checkPointStatusType;
@property (nonatomic, strong) NSMutableArray *partContentArr;

@property (nonatomic, strong) NSMutableArray *arrTaskArr;
@property (nonatomic, strong) NSMutableArray *arrHistoryTaskArr;
@property(nonatomic,strong) TaskListView* view1;
@property(nonatomic,strong) ListPartView* view2;
@property(nonatomic,strong) NSDictionary* resultDic;

@property (nonatomic,strong) UIButton* btnCheckList;
@end

@interface BATaskPointDetailCell : UITableViewCell

@property (nonatomic, strong) UILabel *lblPoint;
@property (nonatomic, strong) UILabel *lblQy;
@property (nonatomic, strong) UILabel *lblCanSelecte;
@property (nonatomic, strong) UILabel *lblStatus;
@property (nonatomic, strong) UIImageView *imageVArrow;
@property (nonatomic, strong) UIImageView *imageVUser;

@end

@implementation BATaskDetailViewController

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

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    NSString *areaName = nil;
    switch ([self.areaId intValue]) {
        case 1: areaName = @"外广场"; break;
        case 2: areaName = @"商场大堂"; break;
        case 3: areaName = @"中庭"; break;
        case 4: areaName = @"过道"; break;
        case 5: areaName = @"其他"; break;
        default:
            break;
    }
    self.navigationItem.title = @"任务详情";
    
    _checkPointStatusType = @"0";
    
    _descView = [[UIView alloc] init];
    _descView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_descView];
    [_descView autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(0, 0, 0, 0) excludingEdge:ALEdgeBottom];
    [_descView autoSetDimension:ALDimensionHeight toSize:125];
    
    
    
    
    UIView* areaNameView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 75)];
    areaNameView.backgroundColor = RGBColor(0, 99, 159, 1);
    [_descView addSubview:areaNameView];
    
    lblTaskName = [[UILabel alloc] initWithFrame:CGRectMake(10, 4, 300, 20)];
    lblTaskName.font = [UIFont systemFontOfSize:14];
    lblTaskName.textColor = [UIColor whiteColor];
    lblTaskName.text = @"2015年6月第二季会员季";
    [areaNameView addSubview:lblTaskName];
    
    UIImageView* locationImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 26, 12, 18)];
    locationImage.image = [UIImage imageNamed:@"Task/icon_site_white.png"];
    [areaNameView addSubview:locationImage];
    
    lblAreaName = [[UILabel alloc] initWithFrame:CGRectMake(26, 25, 300, 20)];
    lblAreaName.font = [UIFont systemFontOfSize:13];
    lblAreaName.textColor = [UIColor whiteColor];
    lblAreaName.text = @"无锡锡山商场";
    [areaNameView addSubview:lblAreaName];
    
    lblendTime = [[UILabel alloc] initWithFrame:CGRectMake(26, 47, self.view.bounds.size.width/2, 20)];
    lblendTime.font = [UIFont systemFontOfSize:13];
    lblendTime.textColor = [UIColor whiteColor];
    lblendTime.text = @"2015-06-05 到期 ";
    [areaNameView addSubview:lblendTime];
    
    lblStatus = [[UILabel alloc] initWithFrame:CGRectMake(self.view.bounds.size.width-(self.view.bounds.size.width/3.5), 55, self.view.bounds.size.width/3.5, 20)];
    lblStatus.backgroundColor = RGBColor(92, 202, 201, 1);
    lblStatus.font = [UIFont systemFontOfSize:13];
    lblStatus.textColor = [UIColor whiteColor];
    lblStatus.textAlignment = NSTextAlignmentCenter;
    lblStatus.text = @"审核通过";
    [areaNameView addSubview:lblStatus];
    
    UIView* supportView = [[UIView alloc] initWithFrame:CGRectMake(0, 75, self.view.bounds.size.width, 50)];
    supportView.backgroundColor =RGBColor(0, 90, 147, 1);
    [_descView addSubview:supportView];
    
    lblSupportPeople = [[UILabel alloc] initWithFrame:CGRectMake(186, 5, 150, 20)];
    lblSupportPeople.font = [UIFont systemFontOfSize:12];
    lblSupportPeople.textColor = [UIColor whiteColor];
    lblSupportPeople.text = @"上 报 人:王林";
    [supportView addSubview:lblSupportPeople];
    
    lblSupportTime = [[UILabel alloc] initWithFrame:CGRectMake(26, 5, 150, 20)];
    lblSupportTime.font = [UIFont systemFontOfSize:12];
    lblSupportTime.textColor = [UIColor whiteColor];
    lblSupportTime.text = @"上报日期:2015-05-29";
    [supportView addSubview:lblSupportTime];
    
    lblReviewTime = [[UILabel alloc] initWithFrame:CGRectMake(26, 25, 300, 20)];
    lblReviewTime.font = [UIFont systemFontOfSize:12];
    lblReviewTime.textColor = [UIColor whiteColor];
    lblReviewTime.text = @"审核日期:2015-05-29";
    [supportView addSubview:lblReviewTime];
    
    lblReviewPeople = [[UILabel alloc] initWithFrame:CGRectMake(186, 25, 150, 20)];
    lblReviewPeople.font = [UIFont systemFontOfSize:12];
    lblReviewPeople.textColor = [UIColor whiteColor];
    lblReviewPeople.text = @"审 核 人:王林";
    [supportView addSubview:lblReviewPeople];
    
    self.tableVContent.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [self setViewLayoutConstraint];
    
    UIButton *btnHome = [UIButton buttonWithType:UIButtonTypeCustom];
    [btnHome setBackgroundImage:[UIImage imageNamed:@"Task/icon_filter1.png"] forState:UIControlStateNormal];
    [btnHome setFrame:CGRectMake(0, 0, 25, 25)];
    [btnHome addTarget:self action:@selector(btnHomeClick) forControlEvents:UIControlEventTouchUpInside];
    
    [self.navigationController navbarRightItemCustomized:@[btnHome] onwer:self.navigationItem];
    
    _btnCheckList = [[UIButton alloc] init];
    _btnCheckList.hidden = YES;
    [_btnCheckList setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_btnCheckList setTitle:@"审核记录" forState:UIControlStateNormal];
    [_btnCheckList setBackgroundColor:RGBColor(0, 90, 147, 1)];
    [_btnCheckList addTarget:self action:@selector(requestHistoryDatas) forControlEvents:UIControlEventTouchUpInside];
    _btnCheckList.layer.cornerRadius = 3;
    //_btnCheckList.titleLabel.font = [UIFont systemFontOfSize:15];
    [self.view addSubview:_btnCheckList];
    [_btnCheckList autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(0, 10, 10, 10) excludingEdge:ALEdgeTop];
    [_btnCheckList autoSetDimension:ALDimensionHeight toSize:35];
    
    [self requestDatas];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    if ([[UIApplication getObjectType:Number key:kShouldRequestDataWhenBack] boolValue]) {
        [self requestDatas];
    }
}

- (void)setViewLayoutConstraint
{

    [self.tableVContent autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(0, 0, 10, 0) excludingEdge:ALEdgeTop];
    [self.tableVContent autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:_descView];

}

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

- (void)btnHomeClick
{
//    for (UIViewController *controller in self.navigationController.viewControllers) {
//        if ([controller isKindOfClass:NSClassFromString(@"TabBarViewController")]) {
//            [self.navigationController popToViewController:controller animated:YES];
//        }
//    }
    [self selectTaskListData];
}

#pragma ---------------------   请求数据   -----------------------
-(void)selectTaskListData
{
    NSDictionary *dicParam = nil;
    
    dicParam = @{@"type":@"-1",@"status":@"-1",@"shopId":self.shopId};
    
    [UIApplication showLoadingView:kTextShowInProgress];
    NSString *interface = @"queryTaskListEX";
    NSOperation *operation = [self.networkMgr operationWithURL:kBaseEXURL(interface)
                                                     interface:interface
                                                        params:dicParam
                                                      dataType:BRNetMgrDataTypeJSON
                                                        method:BRNetMgrMethodPost];
    [self.networkMgr startOperation:operation];
    
}

#pragma ---------------------   请求数据   -----------------------
- (void)requestDatas
{
    NSDictionary *dicParam = nil;
    
    dicParam = @{@"taskId":self.taskId,@"status":@"-1"};
    
    [UIApplication showLoadingView:kTextShowInProgress];
    NSString *interface = @"queryCheckPointListEX";
    NSOperation *operation = [self.networkMgr operationWithURL:kBaseEXURL(interface)
                                                     interface:interface
                                                        params:dicParam
                                                      dataType:BRNetMgrDataTypeJSON
                                                        method:BRNetMgrMethodPost];
    [self.networkMgr startOperation:operation];
}


#pragma ---------------------   请求数据   -----------------------

-(void)requestHistoryDatas
{
    NSDictionary *dicParam = @{@"taskId":self.taskId};
    
    [UIApplication showLoadingView:kTextShowInProgress];
    NSString *interface = @"queryReviewHistoryEX";
    NSOperation *operation = [self.networkMgr operationWithURL:kBaseEXURL(interface)
                                                     interface:interface
                                                        params:dicParam
                                                      dataType:BRNetMgrDataTypeJSON
                                                        method:BRNetMgrMethodPost];
    [self.networkMgr startOperation:operation];
}
#pragma mark =============  BRNetworkMgr Delegate  =============
- (void)httpOperationSuccess:(AFHTTPRequestOperation *)operation
                      result:(NSDictionary *)result
{
    if ([operation.userInfo[@"interface"] isEqualToString:@"queryCheckPointListEX"])
    {
        _resultDic = result;
        lblTaskName.text = result[@"activityName"];
        lblAreaName.text = result[@"shopName"];
        lblendTime.text = [NSString stringWithFormat:@"%@ 活动结束",result[@"activityEndDate"]];
        
        lblSupportPeople.text = [NSString stringWithFormat:@"上 报 人:%@",result[@"reportUser"]];
        lblSupportTime.text = [NSString stringWithFormat:@"上报日期:%@",result[@"reportDate"]];
        lblReviewTime.text = [NSString stringWithFormat:@"审核日期:%@",result[@"reviewTime"]];
        lblReviewPeople.text = [NSString stringWithFormat:@"审 核 人:%@",result[@"reviewUser"]];
        
        NSString* status = result[@"taskReviewStatus"];
        if ([status isEqualToString:kWeitijiaocode]) {
            lblStatus.text = [NSString stringWithFormat:@"未提交"];
        }
        if ([status isEqualToString:kWeishenhecode]) {
            lblStatus.text = [NSString stringWithFormat:@"未审核"];
        }
        if ([status isEqualToString:kShenhetongguocode]) {
            lblStatus.text = [NSString stringWithFormat:@"审核通过"];
        }
        if ([status isEqualToString:kDaizhenggaicode]) {
            lblStatus.text = [NSString stringWithFormat:@"待整改"];
        }
        if ([status isEqualToString:kYizhenggaicode]) {
            lblStatus.text = [NSString stringWithFormat:@"已整改"];
        }
        if ([status isEqualToString:kZhenggaishenhetongguocode]) {
            lblStatus.text = [NSString stringWithFormat:@"整改审核通过"];
        }
        
        self.arrContents = [result[@"checkPointList"] validDataOfClass:[NSArray class]];
        [self.tableVContent reloadData];
        
       
        
        if (self.arrContents.count == 0) {
            self.imageVNoResult.hidden = NO;
        }
    }
    if ([operation.userInfo[@"interface"] isEqualToString:@"queryTaskListEX"])
    {
        self.arrTaskArr = [result[@"taskList"] validDataOfClass:[NSArray class]];
        [self addTaskListView];
    }
    if ([operation.userInfo[@"interface"] isEqualToString:@"queryReviewHistoryEX"])
    {
        self.arrHistoryTaskArr = [result[@"historyList"] validDataOfClass:[NSArray class]];
        if (self.arrHistoryTaskArr.count == 0) {
            [UIApplication showToastViewMessage:@"该任务没有审核记录"];
        }
        else
        {
            [self addTaskHistoryListView];
        }
        
    }
}

-(void)addTaskPartView
{
    NSArray* arr = @[@"未提交",@"未审核",@"审核通过",@"待整改",@"已整改",@"已整改审核通过"];
    _view2 = [[ListPartView alloc] initWithFrame:self.navigationController.view.bounds andArray:arr andType:@""];
    __weak typeof(BATaskDetailViewController) *weakSelf = self;
    _view2.BtnClickBlock = ^(int tag) {
        [weakSelf listBtnClickAtRow:tag];
    };
    UITapGestureRecognizer* tapGesture1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(Actiondo:)];
    tapGesture1.delegate = self;
    [_view2 addGestureRecognizer:tapGesture1];
    [self.navigationController.view addSubview:_view2];
}
-(void)listBtnClickAtRow:(int)rowNum
{
    self.partContentArr = [[NSMutableArray alloc] init];
    if (rowNum == 0) {
        _checkPointStatusType = @"0";
    }
    
    if (rowNum == 1) {
        _checkPointStatusType = @"1";
        for (int i = 0; i < self.arrContents.count; i++) {
            NSString* str = self.arrContents[i][@"reviewStatus"];
            if ([str isEqualToString:@"14001"]) {
                [self.partContentArr addObject:self.arrContents[i]];
            }
        }
    }
    if (rowNum == 2) {
        _checkPointStatusType = @"2";
        for (int i = 0; i < self.arrContents.count; i++) {
            NSString* str = self.arrContents[i][@"reviewStatus"];
            if ([str isEqualToString:@"14002"]) {
                [self.partContentArr addObject:self.arrContents[i]];
            }
        }
    }
    if (rowNum == 3) {
        _checkPointStatusType = @"3";
        for (int i = 0; i < self.arrContents.count; i++) {
            NSString* str = self.arrContents[i][@"reviewStatus"];
            if ([str isEqualToString:@"14003"]) {
                [self.partContentArr addObject:self.arrContents[i]];
            }
        }
    }
    if (rowNum == 4) {
        _checkPointStatusType = @"4";
        for (int i = 0; i < self.arrContents.count; i++) {
            NSString* str = self.arrContents[i][@"reviewStatus"];
            if ([str isEqualToString:@"14004"]) {
                [self.partContentArr addObject:self.arrContents[i]];
            }
        }
    }
    if (rowNum == 5) {
        _checkPointStatusType = @"5";
        for (int i = 0; i < self.arrContents.count; i++) {
            NSString* str = self.arrContents[i][@"reviewStatus"];
            if ([str isEqualToString:@"14005"]) {
                [self.partContentArr addObject:self.arrContents[i]];
            }
        }
    }
    if (rowNum == 6) {
        _checkPointStatusType = @"5";
        for (int i = 0; i < self.arrContents.count; i++) {
            NSString* str = self.arrContents[i][@"reviewStatus"];
            if ([str isEqualToString:@"14006"]) {
                [self.partContentArr addObject:self.arrContents[i]];
            }
        }
    }
    [_view2 removeFromSuperview];
    [self.tableVContent reloadData];
}
-(void)addTaskHistoryListView
{
    _view1 = [[TaskListView alloc] initWithFrame:self.navigationController.view.bounds andHistoryArray1:self.arrHistoryTaskArr];
    
    UITapGestureRecognizer* tapGesture1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(Actiondo:)];
    
    tapGesture1.delegate = self;
    [_view1 addGestureRecognizer:tapGesture1];
    [self.navigationController.view addSubview:_view1];
}
-(void)addTaskListView
{
    _view1 = [[TaskListView alloc] initWithFrame:self.navigationController.view.bounds andArray:self.arrTaskArr];
    __weak typeof(BATaskDetailViewController) *weakSelf = self;
    _view1.BtnClickBlock = ^(NSString* tag) {
        [weakSelf listBtnClick:tag];
    };
    UITapGestureRecognizer* tapGesture1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(Actiondo:)];
    tapGesture1.delegate = self;
    [_view1 addGestureRecognizer:tapGesture1];
    [self.navigationController.view addSubview:_view1];
}
-(void)Actiondo:(UITapGestureRecognizer*)sender
{
    CGPoint point = [sender locationInView:self.view];
    
    NSLog(@"handleSingleTap!pointx:%f,y:%f",point.x,point.y);
    [_view2 removeFromSuperview];
    [_view1 removeFromSuperview];
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    if (touch.view == _view1||touch.view == _view2) {
        return YES;
        
    }
    return NO;
}

-(void)listBtnClick:(NSString*)Name
{
    self.taskId = Name;
    [self requestDatas];
    [_view1 removeFromSuperview];
}
- (void)httpOperationFailed:(AFHTTPRequestOperation *)operation
                      error:(NSError *)error
{
    
}

- (void)configureCell:(BATaskPointDetailCell *)cell forIndexPath:(NSIndexPath *)indexPath
{
    if ([_checkPointStatusType isEqualToString:@"0"])
    {
        cell.lblPoint.text = self.arrContents[indexPath.row][@"name"];
        
        cell.lblQy.text = self.arrContents[indexPath.row][@"typeDesc"];
        
        
        NSString *isRequire = self.arrContents[indexPath.row][@"isRequire"];
        if ([isRequire isEqualToString:@"0"]) {
            cell.lblCanSelecte.text = @"可选";
        }
        else
        {
            cell.lblCanSelecte.text = @"必选";
        }
        
        
        cell.lblStatus.text=self.arrContents[indexPath.row][@"reviewStatusDesc"];
        
        NSString *isEnough = self.arrContents[indexPath.row][@"isNumEnough"];
        
        if ([isEnough isEqualToString:@"0"]) {
            cell.lblStatus.textColor = RGBColor(253, 177, 84, 1);
        }
        else
        {
            cell.lblStatus.textColor = [UIColor lightGrayColor];
        }

    }
    else
    {
        cell.lblPoint.text = self.partContentArr[indexPath.row][@"name"];
        
        cell.lblQy.text = self.arrContents[indexPath.row][@"typeDesc"];
        
        
        NSString *isRequire = self.partContentArr[indexPath.row][@"isRequire"];
        if ([isRequire isEqualToString:@"0"]) {
            cell.lblCanSelecte.text = @"可选";
        }
        else
        {
            cell.lblCanSelecte.text = @"必选";
        }
        
        
        cell.lblStatus.text =self.partContentArr[indexPath.row][@"reviewStatusDesc"];
        
        NSString *isEnough = self.partContentArr[indexPath.row][@"isNumEnough"];
        
        if ([isEnough isEqualToString:@"0"]) {
            cell.lblStatus.textColor = RGBColor(253, 177, 84, 1);
        }
        else
        {
            cell.lblStatus.textColor = [UIColor lightGrayColor];
        }

    }
    
}

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(tableView.tag == 502)
    {
        static NSString *cellIdentifier = @"hitoryCell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
        if (!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        }
        UILabel *lblPoint = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 64, 20)];
        lblPoint.textColor = [UIColor darkGrayColor];
        lblPoint.backgroundColor = [UIColor clearColor];
        lblPoint.font = [UIFont boldSystemFontOfSize:11];
        lblPoint.textAlignment = NSTextAlignmentCenter;
        NSString* time =self.arrHistoryTaskArr[indexPath.row][@"createTime"];
        lblPoint.text = [time substringToIndex:10];
        [cell.contentView addSubview:lblPoint];
        
        UILabel *lblArea = [[UILabel alloc] initWithFrame:CGRectMake(64, 0, 64, 20)];
        lblArea.textColor = [UIColor darkGrayColor];
        lblArea.backgroundColor = [UIColor clearColor];
        lblArea.font = [UIFont boldSystemFontOfSize:11];
        lblArea.textAlignment = NSTextAlignmentCenter;
        lblArea.text = self.arrHistoryTaskArr[indexPath.row][@"reviewName"];
        [cell.contentView addSubview:lblArea];
        
        UILabel *lblStatus1 = [[UILabel alloc] initWithFrame:CGRectMake(128, 0, 64, 20)];
        lblStatus1.textColor = [UIColor darkGrayColor];
        lblStatus1.backgroundColor = [UIColor clearColor];
        lblStatus1.font = [UIFont boldSystemFontOfSize:11];
        lblStatus1.textAlignment = NSTextAlignmentCenter;
        lblStatus1.text = self.arrHistoryTaskArr[indexPath.row][@"reportDate"];
        [cell.contentView addSubview:lblStatus1];
        
        UILabel *lblsupportPeople = [[UILabel alloc] initWithFrame:CGRectMake(192, 0, 64, 20)];
        lblsupportPeople.textColor = [UIColor darkGrayColor];
        lblsupportPeople.backgroundColor = [UIColor clearColor];
        lblsupportPeople.font = [UIFont boldSystemFontOfSize:11];
        lblsupportPeople.textAlignment = NSTextAlignmentCenter;
        lblsupportPeople.text = self.arrHistoryTaskArr[indexPath.row][@"reportName"];
        [cell.contentView addSubview:lblsupportPeople];
        
        UILabel *lblResult = [[UILabel alloc] initWithFrame:CGRectMake(256, 0, 64, 20)];
        lblResult.backgroundColor = [UIColor clearColor];
        lblResult.font = [UIFont boldSystemFontOfSize:11];
        lblResult.textAlignment = NSTextAlignmentCenter;
        NSString* pass = self.arrHistoryTaskArr[indexPath.row][@"isPass"];
        if ([pass isEqualToString:@"1"]) {
            lblResult.text = @"通过";
            lblResult.textColor = [UIColor greenColor];
        }
        else
        {
            lblResult.text = @"未通过";
            lblResult.textColor = [UIColor redColor];
        }
        [cell.contentView addSubview:lblResult];
        return cell;
    }
    else
    {
        NSString *cellIdentifier = @"TaskListCell";
        BATaskPointDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
        if (!cell) {
            cell = [[BATaskPointDetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
            cell.selectionStyle = UITableViewCellSelectionStyleGray;
            
        }
        [self configureCell:cell forIndexPath:indexPath];
        
        return cell;
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView.tag == 502) {
        return  self.arrHistoryTaskArr.count;
    }
    if ([_checkPointStatusType isEqualToString:@"0"]) {
        return self.arrContents.count;
    }
    else
    {
        return self.partContentArr.count;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView.tag == 502) {
        
        return 20;
    }
    return 44;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (tableView.tag == 502) {
        
        return 20;
    }
    return 35;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (tableView.tag == 502) {
        UIView *viewHeader = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 35)];
        //viewHeader.backgroundColor = [UIColor colorWithRed:0.2431 green:0.7137 blue:0.9373 alpha:1];
        viewHeader.backgroundColor = [UIColor lightGrayColor];
        
        UILabel *lblPoint = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 64, 20)];
        lblPoint.textColor = [UIColor darkGrayColor];
        lblPoint.backgroundColor = [UIColor clearColor];
        lblPoint.font = [UIFont boldSystemFontOfSize:11];
        lblPoint.textAlignment = NSTextAlignmentCenter;
        lblPoint.text = @"审核日期";
        [viewHeader addSubview:lblPoint];
        
        UILabel *lblArea = [[UILabel alloc] initWithFrame:CGRectMake(64, 0, 64, 20)];
        lblArea.textColor = [UIColor darkGrayColor];
        lblArea.backgroundColor = [UIColor clearColor];
        lblArea.font = [UIFont boldSystemFontOfSize:11];
        lblArea.textAlignment = NSTextAlignmentCenter;
        lblArea.text = @"审核人";
        [viewHeader addSubview:lblArea];
        
        UILabel *lblStatus1 = [[UILabel alloc] initWithFrame:CGRectMake(128, 0, 64, 20)];
        lblStatus1.textColor = [UIColor darkGrayColor];
        lblStatus1.backgroundColor = [UIColor clearColor];
        lblStatus1.font = [UIFont boldSystemFontOfSize:11];
        lblStatus1.textAlignment = NSTextAlignmentCenter;
        lblStatus1.text = @"上报日期";
        [viewHeader addSubview:lblStatus1];
        
        UILabel *lblsupportPeople = [[UILabel alloc] initWithFrame:CGRectMake(192, 0, 64, 20)];
        lblsupportPeople.textColor = [UIColor darkGrayColor];
        lblsupportPeople.backgroundColor = [UIColor clearColor];
        lblsupportPeople.font = [UIFont boldSystemFontOfSize:11];
        lblsupportPeople.textAlignment = NSTextAlignmentCenter;
        lblsupportPeople.text = @"上报人";
        [viewHeader addSubview:lblsupportPeople];
        
        UILabel *lblResult = [[UILabel alloc] initWithFrame:CGRectMake(256, 0, 64, 20)];
        lblResult.textColor = [UIColor darkGrayColor];
        lblResult.backgroundColor = [UIColor clearColor];
        lblResult.font = [UIFont boldSystemFontOfSize:11];
        lblResult.textAlignment = NSTextAlignmentCenter;
        lblResult.text = @"审核结果";
        [viewHeader addSubview:lblResult];
        
        return viewHeader;

    }
    UIView *viewHeader = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 35)];
    //viewHeader.backgroundColor = [UIColor colorWithRed:0.2431 green:0.7137 blue:0.9373 alpha:1];
    viewHeader.backgroundColor = [UIColor lightGrayColor];
    
    UILabel *lblPoint = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 115, 35)];
    lblPoint.textColor = [UIColor whiteColor];
    lblPoint.backgroundColor = [UIColor clearColor];
    lblPoint.font = [UIFont boldSystemFontOfSize:13];
    lblPoint.textAlignment = NSTextAlignmentCenter;
    lblPoint.text = @"检查点";
    [viewHeader addSubview:lblPoint];
    
    UILabel *lblArea = [[UILabel alloc] initWithFrame:CGRectMake(115, 0, 50, 35)];
    lblArea.textColor = [UIColor whiteColor];
    lblArea.backgroundColor = [UIColor clearColor];
    lblArea.font = [UIFont boldSystemFontOfSize:13];
    lblArea.textAlignment = NSTextAlignmentCenter;
    lblArea.text = @"区域";
    [viewHeader addSubview:lblArea];
    
    UILabel *lblStatus1 = [[UILabel alloc] initWithFrame:CGRectMake(165, 0, 60, 35)];
    lblStatus1.textColor = [UIColor whiteColor];
    lblStatus1.backgroundColor = [UIColor clearColor];
    lblStatus1.font = [UIFont boldSystemFontOfSize:13];
    lblStatus1.textAlignment = NSTextAlignmentCenter;
    lblStatus1.text = @"可选/必选";
    [viewHeader addSubview:lblStatus1];
    
    UIButton *btnShaiXuan = [[UIButton alloc] initWithFrame:CGRectMake(235, 0, self.view.bounds.size.width-235, 35)];
    [btnShaiXuan addTarget:self action:@selector(shaiXuanClick:) forControlEvents:UIControlEventTouchUpInside];
    [btnShaiXuan setBackgroundColor:[UIColor colorWithRed:0.2431 green:0.7137 blue:0.9373 alpha:1]];
    [viewHeader addSubview:btnShaiXuan];
    
    UIImageView* imageView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 7.5, 20, 20)];
    [btnShaiXuan addSubview:imageView];
    
    UILabel *lblStatusName = [[UILabel alloc] initWithFrame:CGRectMake(28, 7.5, self.view.bounds.size.width-255, 20)];
    lblStatusName.textColor = [UIColor whiteColor];
    lblStatusName.backgroundColor = [UIColor clearColor];
    lblStatusName.font = [UIFont boldSystemFontOfSize:13];
    lblStatusName.textAlignment = NSTextAlignmentLeft;
    if ([_checkPointStatusType isEqualToString:@"0"]) {
        lblStatusName.text = @"状态筛选";
        imageView.image = [UIImage imageNamed:@"Task/icon_filter.png"];
    }
    else
    {
        lblStatusName.text = @"状态筛选";
        imageView.image = [UIImage imageNamed:@"Task/icon_loudou_unfull.png"];
    }
    //lblStatusName.text = @"全部";
    [btnShaiXuan addSubview:lblStatusName];
    
    return viewHeader;
}
-(void)shaiXuanClick:(UIButton*)sender
{
    [self addTaskPartView];
}
#pragma mark =============  UITableView Delegate  =============

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(tableView.tag == 502)
    {
        return;
    }
    else
    {
        NSMutableArray* idArr = [[NSMutableArray alloc] init];
        for (int i = 0; i < self.arrContents.count; i++) {
            [idArr addObject:self.arrContents[i][@"id"]];
        }
        
        NSMutableArray* isEnuoghArr = [[NSMutableArray alloc] init];
        for (int i = 0; i < self.arrContents.count; i++) {
            [isEnuoghArr addObject:self.arrContents[i][@"isNumEnough"]];
        }
        
        if ([_checkPointStatusType isEqualToString:@"0"]) {
//            NSString* status = self.arrContents[indexPath.row][@"status"];
//            if ([status isEqualToString:@"1"]) {
//                [UIApplication showToastViewMessage:@"检查点未上报，无法查看"];
//            }
//            else
//            {
                self.selectedIndexPath = indexPath;
                DLog(@"You Click At Section: %d Row: %d", (int)indexPath.section, (int)indexPath.row);
                BATaskCheckViewController *detailVC = [[BATaskCheckViewController alloc] initWithNibName:nil bundle:nil];
                detailVC.isEnuogh = self.arrContents[indexPath.row][@"isNumEnough"];
                detailVC.checkPointRecordId = self.arrContents[indexPath.row][@"id"];
                detailVC.checkPointIdArr = idArr;
                detailVC.checkPointIsEnoughArr = isEnuoghArr;
                [self.navigationController pushViewController:detailVC animated:YES];
//            }
        }
        else
        {
//            NSString* status = self.partContentArr[indexPath.row][@"status"];
//            if ([status isEqualToString:@"1"]) {
//                [UIApplication showToastViewMessage:@"检查点未上报，无法查看"];
//            }
//            else
//            {
                self.selectedIndexPath = indexPath;
                DLog(@"You Click At Section: %d Row: %d", (int)indexPath.section, (int)indexPath.row);
                BATaskCheckViewController *detailVC = [[BATaskCheckViewController alloc] initWithNibName:nil bundle:nil];
                detailVC.isEnuogh = self.arrContents[indexPath.row][@"isNumEnough"];
                detailVC.checkPointRecordId = self.partContentArr[indexPath.row][@"id"];
                detailVC.checkPointIdArr = idArr;
                detailVC.checkPointIsEnoughArr = isEnuoghArr;
                [self.navigationController pushViewController:detailVC animated:YES];
//            }
        }
    }
    
}
#pragma mark =============  CMPopTipView Delegate  =============
- (void)popTipViewWasDismissedByUser:(CMPopTipView *)popTipView
{
    
}
@end
#pragma ---------------------   自定义cell   -----------------------
@implementation BATaskPointDetailCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.lblPoint = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 115, 44)];
        _lblPoint.textColor = [UIColor colorWithRed:0.2431 green:0.7137 blue:0.9373 alpha:1];
        _lblPoint.backgroundColor = [UIColor clearColor];
        _lblPoint.font = [UIFont systemFontOfSize:13];
        _lblPoint.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:_lblPoint];
        
        self.lblQy = [[UILabel alloc] initWithFrame:CGRectMake(115, 0, 50, 44)];
        _lblQy.textColor = [UIColor lightGrayColor];
        _lblQy.backgroundColor = [UIColor clearColor];
        _lblQy.font = [UIFont systemFontOfSize:11];
        _lblQy.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:_lblQy];
        
        self.lblCanSelecte = [[UILabel alloc] initWithFrame:CGRectMake(165, 0, 60, 44)];
        _lblCanSelecte.textColor = [UIColor lightGrayColor];
        _lblCanSelecte.backgroundColor = [UIColor clearColor];
        _lblCanSelecte.font = [UIFont systemFontOfSize:13];
        _lblCanSelecte.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:_lblCanSelecte];
        
        self.lblStatus = [[UILabel alloc] initWithFrame:CGRectMake(240, 0, 70, 44)];
        _lblStatus.textColor = [UIColor lightGrayColor];
        _lblStatus.backgroundColor = [UIColor clearColor];
        _lblStatus.font = [UIFont systemFontOfSize:13];
        _lblStatus.textAlignment = NSTextAlignmentLeft;
        _lblStatus.numberOfLines = 2;
        [self.contentView addSubview:_lblStatus];
        
        self.imageVArrow = [[UIImageView alloc] initWithFrame:CGRectMake(305, 15.5, 8, 13)];
        _imageVArrow.image = [UIImage imageNamed:@"Task_Point/image_point_arrow.png"];
        [self.contentView addSubview:_imageVArrow];
        
        UIView *viewLine = [[UIView alloc] initWithFrame:CGRectMake(0, 43, 320, 0.5)];
        viewLine.backgroundColor = [UIColor colorWithRed:0.7333 green:0.7333 blue:0.7333 alpha:1];
        [self.contentView addSubview:viewLine];
        
    }
    return self;
}

@end