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

#import "TaskPointViewController.h"
#import "TaskCheckViewController.h"
#import "CMPopTipView.h"
#import "ListPartView.h"
#include "TaskListView.h"
#import "TaskListView.h"

@interface TaskPointViewController ()<CMPopTipViewDelegate,UIGestureRecognizerDelegate>
{
    CMPopTipView *popTipView;
    NSString *statustype;
}
@property (nonatomic, strong) UIView *descView;
@property (nonatomic, strong) NSArray *statusArr;
@property (nonatomic, strong) NSMutableArray *arrTaskHistoryArr;
@property (nonatomic, strong) NSString *checkPointStatusType;
@property (nonatomic, strong) NSMutableArray *partContentArr;
@property(nonatomic,strong) ListPartView* view1;
@property(nonatomic,strong) TaskListView* view2;
@property (nonatomic, strong) NSMutableArray *arrHistoryTaskArr;
@end

@interface TaskPointCell : 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 TaskPointViewController

- (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";
    self.CommitFlag=0;
    _statusArr = @[@"全部",@"未上报",@"已上报",@"未评分",@"已评分"];
    if ([[DataMgr getInstance].roleId isEqualToString:@"2"]) {
        if (self.pointType == TaskPointTypeChecked) {
            self.navigationItem.title = @"已上报";
        }else if (self.pointType == TaskPointTypeUnchecked) {
            self.navigationItem.title = @"未上报";
        }
    }else {
        if (self.pointType == TaskPointTypeChecked) {
            self.navigationItem.title = @"已检查";
        }else if (self.pointType == TaskPointTypeUnchecked) {
            self.navigationItem.title = @"已上报";
        }
    }
    
    _descView = [[UIView alloc] init];
    [self.view addSubview:_descView];
    [_descView autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(0, 0, 0, 0) excludingEdge:ALEdgeBottom];
    [_descView autoSetDimension:ALDimensionHeight toSize:115];
    
    UIImageView* descBgImage = [[UIImageView alloc] init];
    descBgImage.image = [UIImage imageNamed:@"Task/bg_fork_on_blue.png"];
    [_descView addSubview:descBgImage];
    [descBgImage autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
    
   
    self.lblTaskName=[[UILabel alloc] init];
    
    self.lblTaskName.font = [UIFont boldSystemFontOfSize:17];
    self.lblTaskName.textColor = [UIColor whiteColor];
    
    [_descView addSubview:self.lblTaskName];
    [self.lblTaskName autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:13];
    [self.lblTaskName autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:15];
    
   
    self.lblTaskTime=[[UILabel alloc]init];
    self.lblTaskTime.font = [UIFont boldSystemFontOfSize:14];
    self.lblTaskTime.textColor = [UIColor whiteColor];
   
    [_descView addSubview:self.lblTaskTime];
    [self.lblTaskTime autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:13];
    [self.lblTaskTime autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.lblTaskName withOffset:10];
    
    
    self.lblTaskStatus=[[UILabel alloc] init];
    
    self.lblTaskStatus.font = [UIFont boldSystemFontOfSize:14];
    self.lblTaskStatus.textColor = [UIColor whiteColor];
    self.lblTaskStatus.text = @"未提交";
    self.lblTaskStatus.backgroundColor = [UIColor colorWithRed:0.3922 green:0.7961 blue:0.7922 alpha:1];
    [_descView addSubview:self.lblTaskStatus];
    [self.lblTaskStatus autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:1];
    [self.lblTaskStatus autoAlignAxis:ALAxisHorizontal toSameAxisOfView:self.lblTaskTime];
    [self.lblTaskTime autoSetDimensionsToSize:CGSizeMake(230, 20)];

    
 
    self.btnSupport=[[UIButton alloc]init];
    self.btnSupport.titleLabel.font = [UIFont systemFontOfSize:15];
    self.btnSupport.layer.cornerRadius = 5;
    [self.btnSupport setTitle:@"提交审核" forState:UIControlStateNormal];
    [self.btnSupport setBackgroundColor:[UIColor colorWithRed:0.2431 green:0.7137 blue:0.9373 alpha:1]];
    [self.view addSubview:self.btnSupport];
    
    self.btnHistory=[[UIButton alloc]init];
    self.btnHistory.hidden = YES;
    self.btnHistory.titleLabel.font = [UIFont systemFontOfSize:15];
    self.btnHistory.layer.cornerRadius=5;
    [self.btnHistory setTitle:@"查看审核历史" forState:UIControlStateNormal];
    [self.btnHistory setBackgroundColor:[UIColor colorWithRed:0.2431 green:0.7137 blue:0.9373 alpha:1]];
   [self.view addSubview:self.btnHistory];

    
    [self.btnSupport addTarget:self action:@selector(CommitorNot) forControlEvents:UIControlEventTouchUpInside];
    [self.btnHistory addTarget:self action:@selector(requestHistoryDatas) forControlEvents:UIControlEventTouchUpInside];
    [self.btnSupport autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.tableVContent withOffset:15];
    [self.btnSupport autoAlignAxis:ALAxisVertical toSameAxisOfView:self.view];
    [self.btnSupport autoSetDimensionsToSize:CGSizeMake(240, 35)];
//    [self.btnHistory autoAlignAxis:ALAxisHorizontal toSameAxisOfView:self.btnSupport];
//    [self.btnHistory autoMatchDimension:ALDimensionHeight toDimension:ALDimensionHeight ofView:self.btnSupport];
//    [self.btnHistory autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self.btnSupport];
//    [self.btnHistory autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:20];
//    [self.btnSupport autoPinEdge:ALEdgeLeft toEdge:ALEdgeRight ofView:self.btnHistory withOffset:20];
    self.tableVContent.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [self setViewLayoutConstraint];
    
    
    [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, 60, 0) excludingEdge:ALEdgeTop];
    [self.tableVContent autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:_descView withOffset:-30];
}

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







- (void)requestDatas
{
    NSDictionary *dicParam = nil;
    if (self.pointType == TaskPointTypeUnchecked) {
        dicParam = @{@"taskId":self.taskId?:@"",@"status":@"-1"};
    }else if (self.pointType == TaskPointTypeChecked) {
        dicParam = @{@"taskId":self.taskId?:@"",@"status":@"-1"};
    }else if (self.pointType == TaskPointTypeArea) {
        dicParam = @{@"taskId":self.taskId?:@"621",@"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 -----------------   CommitorNot  --------------------
-(void)CommitorNot
{
    [self requestDatas];
    int tempflag=0;
    
    if ([statustype isEqualToString:kWeitijiaocode]||[statustype isEqualToString:kDaizhenggaicode]) {
        
        for(id check_status in self.arrContents)
        {
            if([check_status[@"reviewStatus"] isEqual:kWeitijiaocode])
            {
                
                if([check_status[@"isRequire"] isEqual:@"1"])
                {
                    tempflag=1;
                    break;
                }
                
            }
            else if([check_status[@"reviewStatus"] isEqual:kDaizhenggaicode])
            {
                tempflag=1;
                break;
            }
            
        }

        if(tempflag==1)
        {
            [UIApplication showToastViewMessage:@"有必选检查点未提交或未整改，无法提交审核！"];
        }
        else
        {
            NSString *interface = @"updateReviewStatusToUnReviewEX";
            NSDictionary *dicParam = nil;
            dicParam = @{@"taskId":self.taskId?:@""};
            NSOperation *operation = [self.networkMgr operationWithURL:kBaseEXURL(interface)
                                                             interface:interface
                                                                params:dicParam
                                                              dataType:BRNetMgrDataTypeJSON
                                                                method:BRNetMgrMethodPost];
            
            [self.networkMgr startOperation:operation];
            
            [UIApplication showToastViewMessage:@"提交审核成功！"];
            [UIApplication saveObject:@YES type:Number key:kShouldRequestDataWhenBack];
            
            //BOOL b = [[UIApplication getObjectType:Number key:kShouldRequestDataWhenBack] boolValue];
            
            [self.navigationController popViewControllerAnimated:YES];
        }
    }
    else
    {
        [UIApplication showToastViewMessage:@"此任务已在审核过程中，无法再次提交！"];
    }
}


#pragma -----------------   requestHistoryDatas  --------------------
-(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"])
    {
        self.arrContents = [result[@"checkPointList"] validDataOfClass:[NSArray class]];
        
        NSDateFormatter *inputFormatter=[[NSDateFormatter alloc]init];
        [inputFormatter setDateFormat:@"yyyy-MM-dd"];
        NSDate *endDate=[inputFormatter dateFromString:self.reportEndDateStr];
        
        NSString* todayDateStr = [inputFormatter stringFromDate:[NSDate date]];
        NSDate*todayDate = [inputFormatter dateFromString:todayDateStr];
        
        NSTimeInterval cha=[endDate timeIntervalSinceDate:todayDate];
        if(cha<0)
        {
            
        }
        [self.tableVContent reloadData];
        self.lblTaskName.text = result[@"activityName"];
        self.lblTaskTime.text=[[NSString alloc] initWithFormat:@"%@上报截止",self.reportEndDateStr];
        
        statustype=result[@"taskReviewStatus"];
        
        NSArray *status1=[NSArray arrayWithObjects:kWeitijiaocode,kWeishenhecode,kShenhetongguocode,kDaizhenggaicode,kYizhenggaicode,kZhenggaishenhetongguocode, nil];
        int flag=-1;
        
        for (int i=0; i<6;i++ ) {
            if([statustype isEqualToString:status1[i]] )
            {
                flag=i;
                break;
            }
        }
        self.lblTaskStatus.text=result[@"taskReviewStatusDesc"];
        if ([statustype isEqualToString:kWeitijiaocode]||[statustype isEqualToString:kDaizhenggaicode])
        {
            
            [self.btnSupport setEnabled:YES];
            
        }
        else
        {
            [self.btnSupport setEnabled:NO];
            [self.btnSupport setAlpha:0.5f];
            
        }
        for(id check_status in result[@"checkPointList"])
        {//isRequire
            if([check_status[@"status"] isEqual:@"1"])
            {
                
                if([check_status[@"isRequire"] isEqual:@"1"])
                {
                    self.CommitFlag=TRUE;
                    break;
                }
                
            }
            
        }
        
        if (self.arrContents.count == 0)
        {
            self.imageVNoResult.hidden = NO;
            [self.imageVNoResult autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:10];
            self.btnSupport.hidden=YES;
            self.btnHistory.hidden=YES;
        }
    }
    if ([operation.userInfo[@"interface"] isEqualToString:@"updateReviewStatusToUnReviewEX"])
    {
        for (UIViewController *controller in self.navigationController.viewControllers) {
            if ([controller isKindOfClass:NSClassFromString(@"TaskListViewController")]) {
                [self.navigationController popToViewController:controller animated:YES];
            }
        }
    }
    
    if ([operation.userInfo[@"interface"] isEqualToString:@"queryReviewHistoryEX"])
    {
        self.arrHistoryTaskArr = [result[@"historyList"] validDataOfClass:[NSArray class]];
        if (self.arrHistoryTaskArr.count == 0) {
            [UIApplication showToastViewMessage:@"该任务没有审核记录"];
        }
        else
        {
            [self addTaskHistoryListView];
        }
        
    }
}



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

- (void)configureCell:(TaskPointCell *)cell forIndexPath:(NSIndexPath *)indexPath
{

    if ([_checkPointStatusType isEqualToString:@"0"]) {
        cell.lblPoint.text = self.arrContents[indexPath.row][@"name"];
        int typeId=(int)[self.arrContents[indexPath.row][@"type"] integerValue];
        
        //[cell.lblPoint sizeToFit];
        cell.lblPoint.numberOfLines = 0;
        
        
        cell.lblPoint.lineBreakMode = NSLineBreakByCharWrapping;
        
        cell.lblQy.numberOfLines = 0;
        
        
        cell.lblQy.lineBreakMode = NSLineBreakByCharWrapping;
        
        NSArray *requires=[NSArray arrayWithObjects:@"可选",@"必选", nil];
        int requireId=(int)[self.arrContents[indexPath.row][@"isRequire"] integerValue];
        
        cell.lblQy.text = self.arrContents[indexPath.row][@"typeDesc"];
        NSString*status = self.arrContents[indexPath.row][@"reviewStatus"];
        
        cell.lblStatus.text=self.arrContents[indexPath.row][@"reviewStatusDesc"];
        
        if(requireId>=0 && requireId<=1)
        {
            cell.lblCanSelecte.text = requires[requireId];
        }
              NSString *isEnough = self.arrContents[indexPath.row][@"isNumEnough"];
       
        if ([isEnough isEqualToString:@"0"]) {
            cell.lblStatus.textColor = RGBColor(253, 177, 84, 1);
        }
        else
        {
            if ([status isEqualToString:kDaizhenggaicode]) {
                cell.lblStatus.textColor = RGBColor(253, 177, 84, 1);
            }
            else
            {
                cell.lblStatus.textColor = [UIColor lightGrayColor];
            }
        }

        if ([[DataMgr getInstance].roleId isEqualToString:@"2"]) {
            cell.imageVUser.image = [UIImage imageNamed:@"icon_jiancha.png"];
        }else {
            cell.imageVUser.image = [UIImage imageNamed:@"icon_hecha.png"];
        }
    }
    else
    {
        cell.lblPoint.text = self.partContentArr[indexPath.row][@"name"];
        int typeId=(int)[self.partContentArr[indexPath.row][@"type"] integerValue];
        cell.lblPoint.numberOfLines = 0;
        cell.lblPoint.lineBreakMode = NSLineBreakByCharWrapping;
        
        cell.lblQy.numberOfLines = 0;
        
        cell.lblQy.lineBreakMode = NSLineBreakByCharWrapping;
        NSArray *types = [NSArray arrayWithObjects:@"外广场", @"商场大堂", @"商场中庭", @"商场过道",@"其他",nil];
        
        NSArray *requires=[NSArray arrayWithObjects:@"可选",@"必选", nil];
        int requireId=(int)[self.partContentArr[indexPath.row][@"isRequire"] integerValue];
    
        NSString *isEnough = self.partContentArr[indexPath.row][@"isNumEnough"];
        NSString*status = self.partContentArr[indexPath.row][@"reviewStatus"];
                if ([isEnough isEqualToString:@"0"]) {
            cell.lblStatus.textColor = RGBColor(253, 177, 84, 1);
        }
        else
        {
            if ([status isEqualToString:kDaizhenggaicode]) {
                cell.lblStatus.textColor = RGBColor(253, 177, 84, 1);
            }
            else
            {
                cell.lblStatus.textColor = [UIColor lightGrayColor];
            }

        }
        if(typeId>=1 && typeId<=5)
        {
            cell.lblQy.text = types[typeId-1];
        }
        
        
        cell.lblStatus.text=self.partContentArr[indexPath.row][@"reviewStatusDesc"];
        
        if(requireId>=0 && requireId<=1)
        {
            cell.lblCanSelecte.text = requires[requireId];
        }

        if ([[DataMgr getInstance].roleId isEqualToString:@"2"]) {
            cell.imageVUser.image = [UIImage imageNamed:@"icon_jiancha.png"];
        }else {
            cell.imageVUser.image = [UIImage imageNamed:@"icon_hecha.png"];
        }
    }
    
}

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *cellIdentifier = @"TaskListCell";
    TaskPointCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
        cell = [[TaskPointCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleGray;
        
    }
    [self configureCell:cell forIndexPath:indexPath];
    
    return cell;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 35;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *viewHeader = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 35)];

    viewHeader.backgroundColor = [UIColor colorWithRed:0.7333 green:0.7333 blue:0.7333 alpha:1];
    
    UILabel *lblPoint = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 35)];
    lblPoint.textColor = [UIColor whiteColor];
    lblPoint.backgroundColor = [UIColor clearColor];
    lblPoint.font = [UIFont boldSystemFontOfSize:15];
    lblPoint.textAlignment = NSTextAlignmentCenter;
    lblPoint.text = @"检查点";

    [viewHeader addSubview:lblPoint];
    
    UILabel *lblArea = [[UILabel alloc] initWithFrame:CGRectMake(100, 0, 65, 35)];
    lblArea.textColor = [UIColor whiteColor];
    lblArea.backgroundColor = [UIColor clearColor];
    lblArea.font = [UIFont boldSystemFontOfSize:15];
    lblArea.textAlignment = NSTextAlignmentCenter;
    lblArea.text = @"区域";
    [viewHeader addSubview:lblArea];
    
    UILabel *lblStatus = [[UILabel alloc] initWithFrame:CGRectMake(165, 0, 70, 35)];
    lblStatus.textColor = [UIColor whiteColor];
    lblStatus.backgroundColor = [UIColor clearColor];
    lblStatus.font = [UIFont boldSystemFontOfSize:15];
    lblStatus.textAlignment = NSTextAlignmentCenter;
    lblStatus.text = @"可选/必选";
    [viewHeader addSubview:lblStatus];
    
    
    UIButton* btn = [[UIButton alloc] initWithFrame:CGRectMake(235, 0, self.view.bounds.size.width-205, 35)];
    [btn setBackgroundColor:[UIColor colorWithRed:0.2431 green:0.7137 blue:0.9373 alpha:1]];
    [btn addTarget:self action:@selector(searchClick:) forControlEvents:UIControlEventTouchUpInside];
    [viewHeader addSubview:btn];
    UIImageView* img = [[UIImageView alloc] initWithFrame:CGRectMake(3.5, 8.5, 18, 18)];
    img.image = [UIImage imageNamed:@"Task/icon_loudou.png"];
    [btn addSubview:img];
    UILabel *lblSearch = [[UILabel alloc] initWithFrame:CGRectMake(22, 0, 60, 35)];
    lblSearch.textColor = [UIColor whiteColor];
    lblSearch.backgroundColor = [UIColor clearColor];
    lblSearch.font = [UIFont boldSystemFontOfSize:15];
    lblSearch.textAlignment = NSTextAlignmentLeft;
    if ([_checkPointStatusType isEqualToString:@"0"]) {
        lblSearch.text = @"状态筛选";
        img.image = [UIImage imageNamed:@"Task/icon_filter.png"];
    }
    else
    {
        lblSearch.text = @"状态筛选";
        img.image = [UIImage imageNamed:@"Task/icon_loudou_unfull.png"];
    }
    [btn addSubview:lblSearch];
    return viewHeader;
}

-(void)searchClick:(UIButton*)sender
{
    [self addTaskPartView];
}


-(void)addTaskHistoryListView
{
   // _view2 = [[TaskListView alloc] initWithFrame:self.navigationController.view.bounds andHistoryArray:self.arrHistoryTaskArr];

    _view2=[[TaskListView alloc] initWithFrame:self.navigationController.view.bounds andHistoryArray1:self.arrHistoryTaskArr];
    
    UITapGestureRecognizer* tapGesture1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(Actiondo:)];
    
    tapGesture1.delegate = self;
    [_view2 addGestureRecognizer:tapGesture1];
    [self.navigationController.view addSubview:_view2];
}


#pragma --------------addTaskPartView-----------------
-(void)addTaskPartView
{
    NSArray* arr = @[@"未提交",@"未审核",@"审核通过",@"待整改",@"已整改",@"已整改审核通过"];
    _view1 = [[ListPartView alloc] initWithFrame:self.navigationController.view.bounds andArray:arr andType:@""];
    __weak typeof(TaskPointViewController) *weakSelf = self;
    _view1.BtnClickBlock = ^(int 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)listBtnClick:(int)rowNum
{
//    14001	未提交
//    14002	未审核
//    14003	审核通过
//    14004	待整改
//    14005	已整改
//    14006	已整改审核通过
    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 = @"4";
        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 = @"4";
        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]];
            }
        }
    }
    [_view1 removeFromSuperview];
    [self.tableVContent reloadData];
}
-(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;
}
#pragma mark =============  UITableView Delegate  =============

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    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"]) {
        self.selectedIndexPath = indexPath;
        DLog(@"You Click At Section: %d Row: %d", (int)indexPath.section, (int)indexPath.row);
        TaskCheckViewController *detailVC = [[TaskCheckViewController alloc] initWithNibName:nil bundle:nil];
        
        detailVC.checkPointRecordId = self.arrContents[indexPath.row][@"id"];
        detailVC.taskStatus = statustype;
        detailVC.picEnough=self.arrContents[indexPath.row][@"isNumEnough"];
        
        detailVC.checkPointIdArr = idArr;
        detailVC.checkPointIsEnoughArr = isEnuoghArr;
        [self.navigationController pushViewController:detailVC animated:YES];
        
//        NewTaskUploadViewController *detailVC = [[NewTaskUploadViewController alloc] initWithNibName:nil bundle:nil];
//        detailVC.checkPointRecordId = self.arrContents[indexPath.row][@"id"];
//        [self.navigationController pushViewController:detailVC animated:YES];
    }
    else
    {
        self.selectedIndexPath = indexPath;
        DLog(@"You Click At Section: %d Row: %d", (int)indexPath.section, (int)indexPath.row);
        TaskCheckViewController *detailVC = [[TaskCheckViewController alloc] initWithNibName:nil bundle:nil];
        detailVC.checkPointRecordId = self.partContentArr[indexPath.row][@"id"];
        detailVC.taskStatus = statustype;
        detailVC.picEnough=self.arrContents[indexPath.row][@"isNumEnough"];
       
        detailVC.checkPointIdArr = idArr;
        detailVC.checkPointIsEnoughArr = isEnuoghArr;
        [self.navigationController pushViewController:detailVC animated:YES];
//        NewTaskUploadViewController *detailVC = [[NewTaskUploadViewController alloc] initWithNibName:nil bundle:nil];
//        [self.navigationController pushViewController:detailVC animated:YES];
    }

    
}








#pragma mark =============  CMPopTipView Delegate  =============
- (void)popTipViewWasDismissedByUser:(CMPopTipView *)popTipView
{
    
}
@end

@implementation TaskPointCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.lblPoint = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
        _lblPoint.textColor = [UIColor colorWithRed:0.2431 green:0.7137 blue:0.9373 alpha:1];
        _lblPoint.backgroundColor = [UIColor clearColor];
        _lblPoint.font = [UIFont systemFontOfSize:14];
        _lblPoint.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:_lblPoint];
        
        self.lblQy = [[UILabel alloc] initWithFrame:CGRectMake(100, 0, 65, 44)];
        _lblQy.textColor = [UIColor lightGrayColor];
        _lblQy.backgroundColor = [UIColor clearColor];
        _lblQy.font = [UIFont systemFontOfSize:14];
        _lblQy.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:_lblQy];
        
        self.lblCanSelecte = [[UILabel alloc] initWithFrame:CGRectMake(165, 0, 70, 44)];
        _lblCanSelecte.textColor = [UIColor lightGrayColor];
        _lblCanSelecte.backgroundColor = [UIColor clearColor];
        _lblCanSelecte.font = [UIFont systemFontOfSize:14];
        _lblCanSelecte.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:_lblCanSelecte];
        
        self.lblStatus = [[UILabel alloc] initWithFrame:CGRectMake(237, 0, 65, 44)];
        _lblStatus.font = [UIFont systemFontOfSize:14];
        _lblStatus.textColor =[UIColor lightGrayColor];
        _lblStatus.backgroundColor = [UIColor clearColor];
        _lblStatus.textAlignment = NSTextAlignmentLeft;
        _lblStatus.numberOfLines = 2;
        [self.contentView addSubview:_lblStatus];
        
        self.imageVArrow = [[UIImageView alloc] initWithFrame:CGRectMake(297, 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