//
//  uoloadFileRecordViewController.m
//  隐私保护
//
//  Created by xd h on 2023/11/13.
//

#import "uploadFileRecordViewController.h"
#import "uploadFileManager.h"
#import "uploadFileDataModel.h"
#import "uploadFileRecordheadView.h"
//#import "uploadFileRecordBodyView.h"
#import "uploadFileRecordEditBottomView.h"
#import "uploadFileRecordBgScorllView.h"
#import "uploadFileRecordTableView.h"
#import "uploadFileRecordTableViewHeadView.h"
#import "ComontAlretViewController.h"

@interface uploadFileRecordViewController ()<UIScrollViewDelegate>

//选中的项
@property (nonatomic, strong) NSMutableArray *indexPathsForSelectedItems;
@property (nonatomic, strong) uploadFileRecordheadView *uploadFileRecordheadV;
//@property (nonatomic, strong) uploadFileRecordBodyView *uploadFileRecordBodyV;

@property (nonatomic, strong) uploadFileRecordBgScorllView *uploadFileRecordBgScorllV;
@property (nonatomic, strong) uploadFileRecordTableView *leftTableView;
@property (nonatomic, strong) uploadFileRecordTableView *midTableView;
@property (nonatomic, strong) uploadFileRecordTableView *rightTableView;

@property (nonatomic,strong) uploadFileRecordTableViewHeadView *leftHeadView;
@property (nonatomic,strong) uploadFileRecordTableViewHeadView *midHeadView;
@property (nonatomic,strong) uploadFileRecordTableViewHeadView *rightHeadView;


//@property (nonatomic, strong) NSMutableArray *allDataArr;

@property (nonatomic, strong) UIButton *leftButton;
@property (nonatomic, strong) UIButton *rightButton;
@property (nonatomic, strong) uploadFileRecordEditBottomView *uploadFileRecordEditBottomV;
@property (nonatomic,assign) BOOL isEditType;
@property(nonatomic,assign) NSInteger selectIndex;// 从1开始
@end

@implementation uploadFileRecordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //[self.view setBackgroundColor:HWF5F7FAColor];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(uploadFileRefreshFun:)  name:uploadFileRefreshNotification  object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(uploadFileDeteleFun:)  name:uploadFileDeteleNotification  object:nil];
    
    [self.view setBackgroundColor:[UIColor whiteColor]];
    
    self.titleLabel.text = NSLocalizedString(@"my_set_no_File_upload_record",nil) ;
    
    [self.toolBar setHidden:YES];
    [self.navigationBar setHidden:YES];
    [self.navBarBGView setHidden:NO];
    self.navBarBGView.backgroundColor = [UIColor whiteColor];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self initbaseUIFun];
        [self getDataInDatabaseFun];
    });
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
}


#pragma mark UI
- (void)initbaseUIFun
{
    _uploadFileRecordheadV = [[uploadFileRecordheadView alloc] init];
    [self.view addSubview:_uploadFileRecordheadV];
    
    [_uploadFileRecordheadV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.top.mas_equalTo(self.navBarBGView.mas_bottom).offset(15.0);
        make.height.mas_equalTo(50);
    }];
    _selectIndex = 1;
    KWeakSelf
#pragma mark 头部点击事件
    _uploadFileRecordheadV.didClickButFun = ^(NSInteger index) {
        [weakSelf didClickHeadFun: index];
    };
    
//    CGRect rrr2= self.navBarBGView.frame;
//    CGRect rrr= _uploadFileRecordheadV.frame;
    CGFloat curHeight = SCREEN_H - CGRectGetMaxY(self.navBarBGView.frame) - 50 - 15;
    
    
    _uploadFileRecordBgScorllV= [[uploadFileRecordBgScorllView alloc] init];
    _uploadFileRecordBgScorllV.delegate = self;
    [self.view addSubview:_uploadFileRecordBgScorllV];
    [_uploadFileRecordBgScorllV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.top.mas_equalTo(_uploadFileRecordheadV.mas_bottom).offset(0.0);
        make.bottom.mas_equalTo(0);
    }];
    
    
    _leftTableView = [[uploadFileRecordTableView alloc] init];
    _leftTableView.tag =100;
    [_uploadFileRecordBgScorllV addSubview:_leftTableView];

    [_leftTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(SCREEN_W*0.0);
        make.width.mas_equalTo(SCREEN_W);
        make.top.mas_equalTo(0);
        make.height.mas_equalTo(curHeight);
    }];

    _leftTableView.didLongPressClick = ^{
        weakSelf.isEditType = YES;
    };

    _midTableView = [[uploadFileRecordTableView alloc] init];
    _midTableView.tag = 101;
    [_uploadFileRecordBgScorllV addSubview:_midTableView];

    [_midTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(SCREEN_W*1.0);
        make.width.mas_equalTo(SCREEN_W);
        make.top.mas_equalTo(0);
        make.height.mas_equalTo(curHeight);
    }];

    _midTableView.didLongPressClick = ^{
        weakSelf.isEditType = YES;
    };
    
    _rightTableView = [[uploadFileRecordTableView alloc] init];
    _rightTableView.tag = 102;
    [_uploadFileRecordBgScorllV addSubview:_rightTableView];

    [_rightTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(SCREEN_W*2.0);
        make.width.mas_equalTo(SCREEN_W);
        make.top.mas_equalTo(0);
        make.height.mas_equalTo(curHeight);
    }];

    _rightTableView.didLongPressClick = ^{
        weakSelf.isEditType = YES;
    };
    
    _rightTableView.didClickReUploadBlock = ^(uploadFileDataModel * _Nonnull model) {
        [weakSelf didClickReUploadFun:model];
    };
    
    _uploadFileRecordBgScorllV.contentSize = CGSizeMake(SCREEN_W*3.0, curHeight);
    
    _leftHeadView =  [[uploadFileRecordTableViewHeadView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 40)];
    _leftTableView.tableHeaderView = _leftHeadView;
    _leftHeadView.didClickButFun = ^{
        [weakSelf didClickAllSuspendInLoadingFun];
    };
    
    _midHeadView =  [[uploadFileRecordTableViewHeadView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 40)];
    _midTableView.tableHeaderView = _midHeadView;
    _midHeadView.didClickButFun = ^{
        [weakSelf didClickClearRecordInDoneFun];
    };
    
    _rightHeadView =  [[uploadFileRecordTableViewHeadView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 40)];
    _rightTableView.tableHeaderView = _rightHeadView;
    _rightHeadView.didClickButFun = ^{
        [weakSelf didClickClearRecordInFailFun];
    };
    
    
    
    
//    _uploadFileRecordBodyV = [[uploadFileRecordBodyView alloc] init];
//
//    [self.view addSubview:_uploadFileRecordBodyV];
//
//    [_uploadFileRecordBodyV mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(0);
//        make.right.mas_equalTo(0);
//        make.top.mas_equalTo(_uploadFileRecordheadV.mas_bottom).offset(0.0);
//        make.bottom.mas_equalTo(0);
//    }];
//
    
//    _uploadFileRecordBodyV.didScrollFun = ^(NSInteger index) {
//        [weakSelf didScorllBodyFun:index];
//    };
//
//    _uploadFileRecordBodyV.didLongPressClick = ^{
//        weakSelf.isEditType = YES;
//    };
  
    _leftButton = [[UIButton alloc] init];
    [_leftButton setTitleColor:[UIColor hwColor:@"#01B7EA" alpha:1.0] forState:UIControlStateNormal];
    _leftButton.titleLabel.font = [UIFont systemFontOfSize:18.0];
    _leftButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [_leftButton addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside];
    _leftButton.tag = 1;
    [_leftButton setTitle:NSLocalizedString(@"other_cancel",nil) forState:UIControlStateNormal];
    _leftButton.hidden = YES;
    [self.navBarBGView addSubview:_leftButton];
    
    [_leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(80);
        make.left.mas_equalTo(15);
        make.height.mas_equalTo(self.backBtn.mas_height);
        make.centerY.mas_equalTo(self.backBtn.mas_centerY);
    }];
    
    _rightButton = [[UIButton alloc] init];
    [_rightButton setTitleColor:[UIColor hwColor:@"#01B7EA" alpha:1.0] forState:UIControlStateNormal];
    _rightButton.titleLabel.font = [UIFont systemFontOfSize:18.0];
    _rightButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [_rightButton addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside];
    _rightButton.tag = 2;
    [_rightButton setTitle:NSLocalizedString(@"File_upload_Record_select_all",nil) forState:UIControlStateNormal];
    _rightButton.hidden = YES;
    [self.navBarBGView addSubview:_rightButton];
    
    [_rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(80);
        make.right.mas_equalTo(-15);
        make.height.mas_equalTo(self.backBtn.mas_height);
        make.centerY.mas_equalTo(self.backBtn.mas_centerY);
    }];
    
    _uploadFileRecordEditBottomV = [[uploadFileRecordEditBottomView alloc] init];
    _uploadFileRecordEditBottomV.hidden = YES;
    [self.view addSubview:_uploadFileRecordEditBottomV];
    
    [_uploadFileRecordEditBottomV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.height.mas_equalTo(60 + safeArea);
        make.bottom.mas_equalTo(0);
    }];
    
    _uploadFileRecordEditBottomV.didClickButFun = ^{
        //[weakSelf.uploadFileRecordBodyV deleteModelOneByOneFun];
        
        [weakSelf didClickBottomDeleteFun];
    };
}

#pragma mark 底部删除点击
-(void)didClickBottomDeleteFun
{
    NSString *delTipTip = nil;
    if(_selectIndex == 1){
        delTipTip = NSLocalizedString(@"File_upload_Record_clear_uploading_Tip_msg",nil);;
    }
    else if(_selectIndex == 2){
        delTipTip = NSLocalizedString(@"File_upload_Record_clear_done_Tip_msg",nil);
    }
    else if(_selectIndex == 3){
        delTipTip = NSLocalizedString(@"File_upload_Record_clear_fail_Tip_msg",nil);
    }
    
    /*弹窗提示二次确认*/
    KWeakSelf
    ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"File_upload_Record_clear_Tip_title",nil)
                                                                                     msg:delTipTip
                                                                                imageStr:nil
                                                                             cancelTitle:NSLocalizedString(@"other_cancel",nil)
                                                                                 okTitle:NSLocalizedString(@"other_comment_ok",nil) isOkBtnHighlight:YES
                                                                              didClickOk:^{
        [weakSelf didClickBottomDeleteFunAfterAleartFun];
    } didClickCancel:^{
        
    }];
    nextVC.modalPresentationStyle = UIModalPresentationCustom;
  
    [self presentViewController:nextVC animated:YES completion:^{
        nextVC.view.superview.backgroundColor = [UIColor clearColor];
    }];
}


-(void)didClickBottomDeleteFunAfterAleartFun
{
    if(_selectIndex == 1){
        [_leftTableView deleteModelOneByOneFun];
    }
    else if(_selectIndex == 2){
        [_midTableView deleteModelOneByOneFun];
    }
    else if(_selectIndex == 3){
        [_rightTableView deleteModelOneByOneFun];
    }
}

#pragma mark 头部点击 背景滚动
- (void)didClickHeadFun:(NSInteger)index
{
    //_uploadFileRecordBodyV.selectIndex = index;
    
    _selectIndex = index;
    _uploadFileRecordBgScorllV.contentOffset = CGPointMake(SCREEN_W *(index -1), 0);
}

- (void)didScorllBodyFun:(NSInteger)index
{
    _uploadFileRecordheadV.selectIndex = index;
    
    _selectIndex = index;
}

#pragma mark  背景滚动代理
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    if(scrollView != _uploadFileRecordBgScorllV) return;
    
    CGFloat x = scrollView.contentOffset.x;
    NSInteger index = (x+1)/SCREEN_W;
    
    index += 1;//因为头部是从1开始的
    
     //HLog(@"index:%ld",index);
    [self didScorllBodyFun:index];
}

-(void)gotoUploadFile:(NSMutableArray*)indexPathsForSelectedItems
{
    
    KWeakSelf
    [[uploadFileManager shareInstance] handlTZAssetModelToUploadFileDataFunBy:indexPathsForSelectedItems complete:^(NSMutableArray * _Nonnull Arr) {
        NSMutableArray *arr1 = Arr;
        
        //[weakSelf setRecordBodyDataFunBy:arr1];
        
        weakSelf.leftTableView.curDataArr = Arr[0];
        [weakSelf.leftTableView reloadDataFun];
        
        weakSelf.midTableView.curDataArr = Arr[1];
        [weakSelf.midTableView reloadDataFun];
        
        weakSelf.rightTableView.curDataArr = Arr[2];
        [weakSelf.rightTableView reloadDataFun];
    }];
    
    
}

#pragma mark 读取数据库数据
- (void)getDataInDatabaseFun
{
    
    KWeakSelf
    [[uploadFileManager shareInstance] getDataInDatabaseFun:_isNotUploadingType complete:^(NSMutableArray * _Nonnull Arr) {
        //[weakSelf setRecordBodyDataFunBy:Arr];
        
        if(!Arr ||Arr.count != 3){
            HLog(@"数据库出错\n\n\n");
            return;
        }
        
        NSMutableArray *curLoadIngArr = Arr[0];
        //不是上传视频和进来的  所以上传状态（上传中和等待）改为暂停
        if(self->_isNotUploadingType && ![uploadFileManager shareInstance].isUploadIngType){
            for (uploadFileDataModel * curModel in curLoadIngArr) {
                curModel.curUploadStateType = uploadStateSuspend;
            }
        }
        
        weakSelf.leftTableView.curDataArr = curLoadIngArr;
        [weakSelf.leftTableView reloadDataFun];
        
        weakSelf.midTableView.curDataArr = Arr[1];
        [weakSelf.midTableView reloadDataFun];
        
        weakSelf.rightTableView.curDataArr = Arr[2];
        [weakSelf.rightTableView reloadDataFun];
    }];
    
    
    
//    _allDataArr = [NSMutableArray new];
//
//    KWeakSelf
//    [uploadFileDataModel bg_findAllAsync:upLoadFile_image_tableName complete:^(NSArray * _Nullable array) {
//        NSMutableArray *failArr = [NSMutableArray new];
//        NSMutableArray *doneArr = [NSMutableArray new];
//        NSMutableArray *otherArr = [NSMutableArray new];
//
//            for (uploadFileDataModel * curModel in array) {
//
//                //图片 和视频 还原
//                if(curModel.curUploadFileType == uploadFileTypeImage){
//                    NSString*pathStr = [cachesFileManager getFilePathWithName:curModel.filename type:uploadFileTypeImage];
//                    curModel.imageData = [NSData dataWithContentsOfFile:pathStr];
//                }
//                else if(curModel.curUploadFileType == uploadFileTypeVideo){
//                    NSString*pathStr = [cachesFileManager getFilePathWithName:curModel.videoFirstImageName type:uploadFileTypeImage];
//                    curModel.imageData = [NSData dataWithContentsOfFile:pathStr];
//
//                    if(curModel.curUploadStateType != uploadStateDone){
//                        NSString*videoPathStr = [cachesFileManager getFilePathWithName:curModel.filename type:uploadFileTypeVideo];
//                        curModel.videoData = [NSData dataWithContentsOfFile:videoPathStr];
//                    }
//                }
//
//                if(curModel.curUploadStateType == uploadStateFail){
//                    [failArr addObject:curModel];
//                }
//                else if(curModel.curUploadStateType == uploadStateDone){
//                    [doneArr addObject:curModel];
//                }
//                else{
//                    //不是上传视频和进来的  所以上传状态（上传中和等待）改为暂停
//                    if(self->_isNotUploadingType && ![uploadFileManager shareInstance].isUploadIngType){
//                        curModel.curUploadStateType = uploadStateSuspend;
//                    }
//
//                    [otherArr addObject:curModel];
//                }
//            }
//
//        [self->_allDataArr addObject:otherArr];
//        [self->_allDataArr addObject:doneArr];
//        [self->_allDataArr addObject:failArr];
//
//        self->_uploadFileRecordBodyV.allDataArr = self->_allDataArr;
//    }];

}

#pragma mark 给RecordBody 设置数据
//- (void)setRecordBodyDataFunBy:(NSMutableArray*)arr
//{
//    if(!arr || ![arr isKindOfClass:[NSMutableArray class]] || arr.count !=3){
//        return;
//    }
//    //不是上传视频和进来的  所以上传状态（上传中和等待）改为暂停
//    if(self->_isNotUploadingType && ![uploadFileManager shareInstance].isUploadIngType){
//        NSMutableArray *otherArr = arr[0];
//        for (uploadFileDataModel * curModel in otherArr) {
//            curModel.curUploadStateType = uploadStateSuspend;
//        }
//
//    }
//
//    //_uploadFileRecordBodyV.allDataArr = arr;
//}

- (void)uploadFileRefreshFun:(NSNotification*)not
{
    uploadFileDataModel *uploadFileDataMod = [not object];
    //HLog(@"%@",uploadFileDataMod);
    
    uploadFileDataMod.curTimeInterval = [[NSDate date] timeIntervalSince1970];
    
    //UI和数据还没准备好
    if(!_leftTableView
       && (uploadFileDataMod.curUploadStateType == uploadStateFail
           ||uploadFileDataMod.curUploadStateType == uploadStateDone)){
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [[NSNotificationCenter defaultCenter] postNotificationName:uploadFileRefreshNotification object:uploadFileDataMod];
        });
        
        return;
    }
    
    if(_leftTableView && [uploadFileDataMod isKindOfClass:[uploadFileDataModel class]] ){
        
        NSMutableArray *curArr = _leftTableView.curDataArr;
        
        NSInteger index = 0;
        for (uploadFileDataModel*mod in curArr) {
            HLog(@"%@ bg_id:%@ ?=? %@",mod.filename,mod.bg_id,uploadFileDataMod.bg_id);
            
            if(mod.bg_id.integerValue == uploadFileDataMod.bg_id.integerValue){
                
                if(uploadFileDataMod.curUploadStateType == uploadStateDone){
                    [curArr removeObject:mod];
                    
                    NSMutableArray *doneArr = _midTableView.curDataArr;
                    [doneArr insertObject:uploadFileDataMod atIndex:0];
                    
                    //全部上传了
                    if(curArr.count == 0){
                        
                    }
                }
                else if(uploadFileDataMod.curUploadStateType == uploadStateFail){
                    [curArr removeObject:mod];
                    
                    NSMutableArray *failArr = _rightTableView.curDataArr;
                    [failArr insertObject:uploadFileDataMod atIndex:0];
                }
                else{
                    [curArr replaceObjectAtIndex:index withObject:uploadFileDataMod];
                }
                
                break;
            }
            
            index++;
        }
        
        //精准刷新
        if(uploadFileDataMod.curUploadStateType == uploadStateDone){
            //[self.uploadFileRecordBodyV RefreshDataWithUploadingArr:_allDataArr[0] withDoneArr:_allDataArr[1] withfailArr:nil];
            
            [self.leftTableView reloadDataFun];
            
            [self.midTableView reloadDataFun];
        }
        else if(uploadFileDataMod.curUploadStateType == uploadStateFail){
            //[self.uploadFileRecordBodyV RefreshDataWithUploadingArr:_allDataArr[0] withDoneArr:nil withfailArr:_allDataArr[2]];
            
            [self.leftTableView reloadDataFun];
            
            [self.rightTableView reloadDataFun];
        }
        else{
            //[self.uploadFileRecordBodyV RefreshDataWithUploadingArr:_allDataArr[0] withDoneArr:nil withfailArr:nil];
            
            [self.leftTableView reloadDataFun];
            
        }
    }
    
}

- (void)uploadFileDeteleFun:(NSNotification*)not
{
    uploadFileDataModel *uploadFileDataMod = [not object];
    //HLog(@"%@",uploadFileDataMod);
    
    //UI和数据还没准备好
    if(!_leftTableView){
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [[NSNotificationCenter defaultCenter] postNotificationName:uploadFileDeteleNotification object:uploadFileDataMod];
        });
        
        return;
    }
    
    if([uploadFileDataMod isKindOfClass:[uploadFileDataModel class]] ){
        
        NSMutableArray *curArr = _leftTableView.curDataArr;
        
        NSInteger index = 0;
        for (uploadFileDataModel*mod in curArr) {
            HLog(@"bg_id:%@ ?=? %@",mod.bg_id,uploadFileDataMod.bg_id);
            
            if(mod.bg_id.integerValue == uploadFileDataMod.bg_id.integerValue){
                [curArr removeObject:mod];
                break;
            }
            
            index++;
        }
        
        //精准刷新
        //[self.uploadFileRecordBodyV RefreshDataWithUploadingArr:_allDataArr[0] withDoneArr:nil withfailArr:nil];
        [self.leftTableView reloadDataFun];
    }
    
}



#pragma mark 按钮点击
- (void)didClickButFun:(UIButton*)but
{
    NSInteger tag = but.tag;
    if(tag == 1){
        self.isEditType = NO;
        //self.uploadFileRecordBodyV.isEditType = NO;
        
        if(_selectIndex == 1){
            self.leftTableView.isEditType = NO;
        }
        else if(_selectIndex == 2){
            self.midTableView.isEditType = NO;
        }
        else if(_selectIndex == 3){
            self.rightTableView.isEditType = NO;
        }
        
    }
    else{
        //self.uploadFileRecordBodyV.isSelectAllType = YES;
        
        if(_selectIndex == 1){
            self.leftTableView.isSelectAllType = YES;
        }
        else if(_selectIndex == 2){
            self.midTableView.isSelectAllType = YES;
        }
        else if(_selectIndex == 3){
            self.rightTableView.isSelectAllType = YES;
        }
    }
}

-(void)setIsEditType:(BOOL)isEditType
{
    _isEditType = isEditType;
    
    _leftButton.hidden = !isEditType;
    _rightButton.hidden = !isEditType;
    self.backBtn.hidden = isEditType;
    
    _uploadFileRecordEditBottomV.hidden = !isEditType;
    _uploadFileRecordheadV.userInteractionEnabled = !isEditType;
    _uploadFileRecordBgScorllV.scrollEnabled = !isEditType;
    
    _leftHeadView.rightButton.userInteractionEnabled = !isEditType;
    
    if(_isEditType){
       
        CGFloat curHeight = SCREEN_H - CGRectGetMaxY(self.navBarBGView.frame) - 50 - 15 - (60 + safeArea);
        [_uploadFileRecordBgScorllV mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(0);
            make.right.mas_equalTo(0);
            make.top.mas_equalTo(_uploadFileRecordheadV.mas_bottom).offset(0.0);
            make.bottom.mas_equalTo(_uploadFileRecordEditBottomV.mas_top);
        }];
        
        [_leftTableView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(SCREEN_W*0.0);
            make.width.mas_equalTo(SCREEN_W);
            make.top.mas_equalTo(0);
            make.height.mas_equalTo(curHeight);
        }];
        
        [_midTableView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(SCREEN_W*1.0);
            make.width.mas_equalTo(SCREEN_W);
            make.top.mas_equalTo(0);
            make.height.mas_equalTo(curHeight);
        }];
        
        
        [_rightTableView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(SCREEN_W*2.0);
            make.width.mas_equalTo(SCREEN_W);
            make.top.mas_equalTo(0);
            make.height.mas_equalTo(curHeight);
        }];
        
    }
    else{

        CGFloat curHeight = SCREEN_H - CGRectGetMaxY(self.navBarBGView.frame) - 50 - 15;
        [_uploadFileRecordBgScorllV mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(0);
            make.right.mas_equalTo(0);
            make.top.mas_equalTo(_uploadFileRecordheadV.mas_bottom).offset(0.0);
            make.bottom.mas_equalTo(0);
        }];
        
        [_leftTableView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(SCREEN_W*0.0);
            make.width.mas_equalTo(SCREEN_W);
            make.top.mas_equalTo(0);
            make.height.mas_equalTo(curHeight);
        }];
        
        [_midTableView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(SCREEN_W*1.0);
            make.width.mas_equalTo(SCREEN_W);
            make.top.mas_equalTo(0);
            make.height.mas_equalTo(curHeight);
        }];
        
        
        [_rightTableView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(SCREEN_W*2.0);
            make.width.mas_equalTo(SCREEN_W);
            make.top.mas_equalTo(0);
            make.height.mas_equalTo(curHeight);
        }];
    }
}

#pragma mark 点击上传中的全部暂停
- (void)didClickAllSuspendInLoadingFun
{
    _leftHeadView.rightButton.selected = !_leftHeadView.rightButton.selected;
    
    if(_leftHeadView.rightButton.selected){
        [[uploadFileManager shareInstance] suspendUploadFileFun:YES];
    }
    else{
        NSMutableArray *leftArr = _leftTableView.curDataArr;
        [[uploadFileManager shareInstance] reUploadFileFunBy:leftArr];
    }
}
#pragma mark 点击上传成功的清空记录
- (void)didClickClearRecordInDoneFun
{
    /*弹窗提示二次确认*/
    KWeakSelf
    ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"File_upload_Record_clear_Tip_title",nil)
                                                                                     msg:NSLocalizedString(@"File_upload_Record_clear_done_Tip_msg",nil)
                                                                                imageStr:nil
                                                                             cancelTitle:NSLocalizedString(@"other_cancel",nil)
                                                                                 okTitle:NSLocalizedString(@"other_comment_ok",nil) isOkBtnHighlight:YES
                                                                              didClickOk:^{
        [weakSelf ClearAllRecordInDoneFun];
    } didClickCancel:^{
        
    }];
    nextVC.modalPresentationStyle = UIModalPresentationCustom;
  
    [self presentViewController:nextVC animated:YES completion:^{
        nextVC.view.superview.backgroundColor = [UIColor clearColor];
    }];

}

- (void)ClearAllRecordInDoneFun
{
    [[uploadFileManager shareInstance] deleteUploadFileRecordBy:_midTableView.curDataArr complete:^(BOOL isSuccess) {
        HLog(@"isSuccess:%d",isSuccess);
        
        if(isSuccess){
            [self->_midTableView.curDataArr removeAllObjects];
            [self->_midTableView reloadDataFun];
        }
    }];
}

#pragma mark 点击上传失败的清空记录
- (void)didClickClearRecordInFailFun
{
    /*弹窗提示二次确认*/
    KWeakSelf
    ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"File_upload_Record_clear_Tip_title",nil)
                                                                                     msg:NSLocalizedString(@"File_upload_Record_clear_fail_Tip_msg",nil)
                                                                                imageStr:nil
                                                                             cancelTitle:NSLocalizedString(@"other_cancel",nil)
                                                                                 okTitle:NSLocalizedString(@"other_comment_ok",nil) isOkBtnHighlight:YES
                                                                              didClickOk:^{
        [weakSelf ClearAllRecordInFailFun];
    } didClickCancel:^{
        
    }];
    nextVC.modalPresentationStyle = UIModalPresentationCustom;
  
    [self presentViewController:nextVC animated:YES completion:^{
        nextVC.view.superview.backgroundColor = [UIColor clearColor];
    }];

}

- (void)ClearAllRecordInFailFun
{
    [[uploadFileManager shareInstance] deleteUploadFileRecordBy:_rightTableView.curDataArr complete:^(BOOL isSuccess) {
        HLog(@"isSuccess:%d",isSuccess);
        
        if(isSuccess){
            [self->_rightTableView.curDataArr removeAllObjects];
            [self->_rightTableView reloadDataFun];
        }
    }];
}

#pragma mark 失败重传
- (void)didClickReUploadFun:(uploadFileDataModel*)model{
    
    if(![model isKindOfClass:[uploadFileDataModel class]]){
        return;
    }
    
    NSMutableArray *curArr = _leftTableView.curDataArr;
    
    BOOL isNeedToAdd = YES;
    
    for (uploadFileDataModel*mod in curArr) {
        if(mod.bg_id.integerValue == model.bg_id.integerValue){
            isNeedToAdd = NO;
            break;
        }
    }
    
    if(isNeedToAdd){
        [curArr addObject:model];
    }
    
    [_leftTableView reloadDataFun];
}

//-(void)backBtnPressed{
//    [super backBtnPressed];
//
//    _indexPathsForSelectedItems = nil;
//    _uploadFileRecordheadV = nil;
//    //_uploadFileRecordBodyV = nil;
//    //_allDataArr = nil;
//    _uploadFileRecordEditBottomV = nil;
//
//}
@end
