美文网首页
分步请求数据

分步请求数据

作者: iOS攻城狮_Runloop | 来源:发表于2018-10-13 10:58 被阅读0次
//
//  DetailViewController.m
//  HappyOldFamily
//
//  Created by  on 2018/5/17.
//  Copyright © 2018年 Shea. All rights reserved.
//

#import "DetailViewController.h"
#import "TopTableViewCell.h"
#import "CourseDetailCell.h"
#import "introduceViewCell.h"
#import "CourseSignMsgCell.h"
#import "SchoolMsgCell.h"
#import "CommentViewCell.h"
#import "CheckMoreSignController.h"
#import "DetailBottomVIew.h"
#import "SignViewController.h"
#import "SchoolDetailViewController.h"
#import "NoCommentTableViewCell.h"
#import "SDAutoLayout.h"

@interface DetailViewController ()<UITableViewDelegate,UITableViewDataSource,CourseDetailCellDelegate,CourseSignMsgDelegate,CGQInputTextViewDelegate,CommentViewCellDelegate,DetailBottonViewDelegate>{
    NSString * courseDesc;
}
@property(nonatomic,strong)UITableView * tableView;
@property(nonatomic,strong)NSMutableArray * responseArray;
@property(nonatomic,strong)NSMutableArray * msgArray;
@property(nonatomic,strong)NSMutableArray * schoolMsgArray;

@property(nonatomic,assign)NSInteger index;

//第一次遍历的model
@property(nonatomic,strong)NSMutableArray * mainCommentArray;
@property(nonatomic,strong)NSMutableArray * assistCommentArray;
//第二次遍历的model
@property(nonatomic,strong)NSMutableArray * getMainModelArray;
//评论区的区头区尾
@property(nonatomic,strong)CommentHeaderView * headerView;
@property(nonatomic,strong)CommentFooterView * footerView;

@property(nonatomic,strong)CGQInputTextView * inputView;

@property(nonatomic,strong)NSMutableArray * commentCountArray;

@property(nonatomic,strong)NSMutableArray * commentCellHeightArray;


@property(nonatomic,assign)NSInteger row;
@property(nonatomic,assign)NSInteger btnTag;
@property(nonatomic,strong)DetailBottomVIew * bottomView;
@end

@implementation DetailViewController
-(void)dealloc{
    NSLog(@"详情页是放了");
}

-(UITableView*)tableView{
    if (_tableView==nil) {
        _tableView=[[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStyleGrouped];
        [self.view addSubview:_tableView];
        [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.mas_equalTo(0);
            make.bottom.mas_equalTo(-(MatchW(40)+SafeAreaBottomHeight));
        }];
        _tableView.delegate=self;
        _tableView.dataSource=self;
        [_tableView registerClass:[TopTableViewCell class] forCellReuseIdentifier:@"cell1"];
        [_tableView registerClass:[CourseDetailCell class] forCellReuseIdentifier:@"cell2"];
        [_tableView registerClass:[introduceViewCell class] forCellReuseIdentifier:@"cell3"];
         [_tableView registerClass:[CourseSignMsgCell class] forCellReuseIdentifier:@"cell4"];
        [_tableView registerClass:[SchoolMsgCell class] forCellReuseIdentifier:@"cell5"];
        [_tableView registerClass:[CommentViewCell class] forCellReuseIdentifier:@"cell6"];
        [_tableView registerNib:[UINib nibWithNibName:@"NoCommentTableViewCell" bundle:nil] forCellReuseIdentifier:@"NoCommentTableViewCell"];
    }
    return _tableView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.index=0;
    self.tableView.backgroundColor = [UIColor colorWithHexString:@"#E0E0E0"];
    self.responseArray = [NSMutableArray array];
    self.msgArray = [NSMutableArray array];
    self.mainCommentArray=[NSMutableArray array];
    self.assistCommentArray=[NSMutableArray array];
    self.getMainModelArray=[NSMutableArray array];
    self.commentCountArray = [NSMutableArray array];
    self.commentCellHeightArray = [NSMutableArray array];
    
    [self requestState];
    
    DetailBottomVIew * bottomView = [[DetailBottomVIew alloc]init];
    [self.view addSubview:bottomView];
    bottomView.delegate=self;
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(MatchW(45));
        make.bottom.mas_equalTo(-SafeAreaBottomHeight);
    }];
    bottomView.backgroundColor=[UIColor whiteColor];
    self.bottomView=bottomView;
    NSLog(@"%@",self.courseId);
}



-(void)requestState{
    [MBProgressHUD showLoadHUD];
    __weak typeof(self) weakSelf = self;
    //信号量
//    dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
    //创建全局并行
    dispatch_group_t group = dispatch_group_create();
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    //任务一
    dispatch_group_async(group, queue, ^{
        dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
        
        // 处理耗时操作的代码块...
        [BaseHttpRequest requestWithMethod:RequestMethodTypeGet url:[NSString stringWithFormat:@"api/Course/?id=%@",self.courseId] params:nil withSessionKey:@"" WithSignID:@"" success:^(NSString * str) {
            NSLog(@"%@",str);
            DetailViewModel * model = [DetailViewModel mj_objectWithKeyValues:str];
            weakSelf.responseArray = (NSMutableArray*)model.data;
             dispatch_semaphore_signal(semaphore);
            //通知主线程刷新
            dispatch_async(dispatch_get_main_queue(), ^{
                //回调或者说是通知主线程刷新,
                [weakSelf.tableView reloadData];
            });
        } failure:^(NSError *error) {
             [MBProgressHUD hideHUD];
            dispatch_semaphore_signal(semaphore);
        }];
         dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
    });
    
    
    //任务二
    dispatch_group_async(group, queue, ^{
        dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
        [BaseHttpRequest requestWithMethod:RequestMethodTypeGet url:[NSString stringWithFormat:@"api/Course/GetSignEnrolls?id=%@",self.courseId] params:nil withSessionKey:@"" WithSignID:@"" success:^(NSString * str) {
            CourseSignMsgModel * model = [CourseSignMsgModel mj_objectWithKeyValues:str];
            weakSelf.msgArray = (NSMutableArray*)model.data;
            dispatch_semaphore_signal(semaphore);

            //通知主线程刷新
            dispatch_async(dispatch_get_main_queue(), ^{
                //回调或者说是通知主线程刷新,
                [weakSelf.tableView reloadData];
            });
        } failure:^(NSError *error) {
             [MBProgressHUD hideHUD];
            dispatch_semaphore_signal(semaphore);
        }];
        
         dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
        
    });
    
    //任务三
    dispatch_group_async(group, queue, ^{
        dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
        [Request getSchoolMessageWithSchoolId:self.scrhoolAre success:^(linkageRightModel *model) {
            weakSelf.schoolMsgArray = (NSMutableArray*)model.data;
            dispatch_semaphore_signal(semaphore);
//            通知主线程刷新
            dispatch_async(dispatch_get_main_queue(), ^{
                //回调或者说是通知主线程刷新,
                [weakSelf.tableView reloadData];
            });
        } failure:^(NSError *error) {
             [MBProgressHUD hideHUD];
            dispatch_semaphore_signal(semaphore);
        }];
        
         dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
    });
    
    
    //任务四
    dispatch_group_async(group, queue, ^{
        dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
       
        dispatch_semaphore_signal(semaphore);

         dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
        
    });
    
    
    dispatch_group_notify(group, queue, ^{
        //6个任务,6个信号等待.
//        dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
//        dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
//        dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
//        dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
     
        //这里就是所有异步任务请求结束后执行的代码
        dispatch_async(dispatch_get_main_queue(), ^{

            //回调或者说是通知主线程刷新,
          
            [weakSelf.tableView reloadData];
            
            [MBProgressHUD hideHUD];
            
    
            DetailModel * model = weakSelf.responseArray[0];
            
            if (model.CourseState==1) {
                if (model.IsEnroll) {
                    [self.bottomView.enrolBtn setTitle:@"您已报名" forState:UIControlStateNormal];
                }else{
                    [self.bottomView.enrolBtn setTitle:@"我要报名" forState:UIControlStateNormal];
                }
            }else if(model.CourseState==2){
                  [self.bottomView.enrolBtn setTitle:model.CourseStateInfo forState:UIControlStateNormal];
            }else if (model.CourseState==3){
                  [self.bottomView.enrolBtn setTitle:model.CourseStateInfo forState:UIControlStateNormal];
            }else if (model.CourseState==4){
                 [self.bottomView.enrolBtn setTitle:model.CourseStateInfo forState:UIControlStateNormal];
            }else{
                 [self.bottomView.enrolBtn setTitle:model.CourseStateInfo forState:UIControlStateNormal];
            }
          
        });
        
    });
    
 
    
    [self commentReplay];

    
}
#pragma mark 评论回复接口
-(void)commentReplay{
    __weak typeof(self) weakSelf = self;
    [self.mainCommentArray removeAllObjects];
    [self.assistCommentArray removeAllObjects];
    [self.getMainModelArray removeAllObjects];
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
        [Request getCourseCommentwithCourseId:self.courseId success:^(CourseCommentArrayModel *model) {

            NSMutableArray * commentArray = (NSMutableArray*)model.data;
            NSLog(@"%ld",commentArray.count);
            self.commentCountArray=(NSMutableArray*)model.data;
            
            
            for (int i =0; i<self.commentCountArray.count; i++) {
                CourseCommentModel * model = self.commentCountArray[i];
                if ([Tool isBlankString:model.ReplyCommentId]) {
                    [weakSelf.mainCommentArray addObject:model];
                }else{
                    [weakSelf.assistCommentArray addObject:model];
                }
            }
            
            for (int i =0; i<self.mainCommentArray.count; i++) {
                NSMutableArray * selfModelArray = [NSMutableArray array];
                CourseCommentModel * mainModel = self.mainCommentArray[i];
                for (int j =0; j<self.assistCommentArray.count; j++) {
                    CourseCommentModel * assistModel = self.assistCommentArray[j];
                    if ([assistModel.ReplyCommentId isEqualToString:mainModel.CommentId]) {
                        [selfModelArray addObject:assistModel];
                        
                    }
                }
                mainModel.selfModelArray=selfModelArray;
                [weakSelf.getMainModelArray addObject:mainModel];
                
            }

                        //通知主线程刷新
            dispatch_async(dispatch_get_main_queue(), ^{
                           
               [weakSelf.tableView reloadData];
               weakSelf.headerView.replayLeftLable .text=[NSString stringWithFormat:@"讨论区(%ld)",weakSelf.getMainModelArray.count];
            });
            
            
          
            
        } failure:^(NSError *error) {
            
        }];
        
        
    });

}



#pragma mark tableView 代理
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 6;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section==0||section==1||section==2||section==3||section==4) {
        return self.responseArray.count;

    }else if(section==5){//评论区域默认两条数据,多的数据跳转查看
        if (self.getMainModelArray.count) {
            if (self.getMainModelArray.count>2) {
                return 2;
            }else{
                return self.getMainModelArray.count;
            }
        }else{
            return 1;
        }
       
    }else{
        return 1;
    }
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==0) {
        return MatchW(328);
    }else if(indexPath.section==1){
        if (self.responseArray.count) {
            DetailModel * model = self.responseArray[indexPath.row];
            if (self.index==0) {
                
                CGSize sizes = [model.CourseAttenInfo sizeWithfont:[UIFont systemFontOfSize:MatchW(15)] maxWidth:MatchW(272)];
                 CGSize addressSize = [model.CourseAdress sizeWithfont:[UIFont systemFontOfSize:MatchW(15)] maxWidth:MatchW(272)];
                return MatchW(42)+MatchW(110)+sizes.height+2+addressSize.height+2;
            }else{
                CGSize sizes = [model.CourseInfo sizeWithfont:[UIFont systemFontOfSize:MatchW(15)] maxWidth:SCREENWIDTH-MatchW(40)];
                return MatchW(42)+MatchW(40)+sizes.height+5;
            }
        }else{
            return 100;
        }
       
        
    }else if (indexPath.section==2){
       DetailModel * model = self.responseArray[indexPath.row];
        courseDesc = model.CourseDesc;
        if (![Tool isBlankString:model.CourseDesc]) {
            return MatchW(135);
        }else{
            return 0;
        }
        
   
    } else if (indexPath.section==3){
        //校区介绍cell的高度
        if (!self.schoolMsgArray.count) {
            return 0;
        }
       return MatchW(112);
       
    }else if (indexPath.section==4){
        if (self.msgArray.count==0) {
            return MatchW(48)*2;
        }else{
            CGFloat width = (SCREENWIDTH-MatchW(20)*2-(6-1)*MatchW(10))/6;
            if (self.msgArray.count <= 6) {
                return MatchW(48)+(MatchW(10)+width)+MatchW(20);
            }else if (self.msgArray.count>6){
                return MatchW(48)+(MatchW(10)+width)*2+MatchW(20);
            }
        }
 
    }else{
        if (self.getMainModelArray.count) {
            CourseCommentModel * model = self.getMainModelArray[indexPath.row];
            return [model commentCellHeight];
            
        }else{
            return MatchW(48);
        }
    }
    return 100;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell * detailCell;
    if (indexPath.section==0) {
        TopTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell1"];
        detailCell=cell;
        tableView.separatorStyle= NO;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.courseModel = self.responseArray[indexPath.row];
        
    }else if (indexPath.section==1){
        CourseDetailCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell2"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.courseModel = self.responseArray[indexPath.row];
        cell.delegate=self;
        
        if (self.index==0) {
            cell.leftView.hidden=NO;
            cell.rightView.hidden=YES;
        }else {
            cell.leftView.hidden=YES;
            cell.rightView.hidden=NO;
        }
        detailCell=cell;
        
    }else if(indexPath.section==2){
        introduceViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell3"];
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
        DetailModel * model = self.responseArray[indexPath.row];
        
        if (![Tool isBlankString:model.CourseDesc]) {
            cell.introduceLable.text=model.CourseDesc;
        }else{
            cell.hidden=YES;
        }
        detailCell=cell;
        
    }else if (indexPath.section==3){
       
        NSLog(@"%lu",(unsigned long)self.schoolMsgArray.count);
        SchoolMsgCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell5"];
        if (!self.schoolMsgArray.count) {
            detailCell = cell;
            
        }else{
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.model = self.schoolMsgArray[indexPath.row];
            detailCell=cell;
        }
        
    }else if (indexPath.section==4){
   
        CourseSignMsgCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell4"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.responArray = self.msgArray;
        cell.delegate=self;
        detailCell=cell;
    }else{
        
        if (self.getMainModelArray.count) {
            CommentViewCell * cell = [CommentViewCell cellWithTableView:tableView];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.commentModel = self.getMainModelArray[indexPath.row];
            cell.delegate=self;
            cell.replayButton.tag=indexPath.row;
            cell.count=indexPath.row;
            detailCell=cell;
        }else {
            NoCommentTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"NoCommentTableViewCell"];
            
            detailCell = cell;
        }
    }
    return detailCell;
   
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section==3) {
        linkageRightViewModel * model = self.schoolMsgArray[indexPath.row];
        SchoolDetailViewController * detailController = [[SchoolDetailViewController alloc]init];
        detailController.schoolId=model.SchoolId;
        [self.navigationController pushViewController:detailController animated:YES];
    }
   
    
}
#pragma mark 根据情况给cell做头部尾部试图
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section==5) {
        return MatchW(48);
    }
    return 0.01;
}
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    if (section==5) {
        return self.headerView;
    }
    
    return [[UIView alloc]init];
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (self.getMainModelArray.count) {
        if (section==5) {
            return MatchW(48);
        }
    }else{
        if (section==5) {
            return 0.1;
        }
    }
    
    if (self.responseArray.count) {
         DetailModel * model = self.responseArray[0];
        if (![Tool isBlankString:model.CourseDesc]) {
            if (section==2) {
                return MatchW(10);
            }
            
        }else{
            if (section==2) {
                return 0.1;
            }
            
        }
    }
    
    if (self.schoolMsgArray.count) {
        if (section==3) {
            return MatchW(10);
        }else{
            return 0.01;
        }
    }

    return MatchW(10);
}
-(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    if (self.getMainModelArray.count) {
        if (section==5) {
            return self.footerView;
        }
    }

    UIView * view = [[UIView alloc]init];
    view.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
    return view;
}




#pragma mark 动态改变cell高度,感觉现在做的不太好,以后改进
-(void)leftClickWith:(NSInteger)index{
    self.index=0;
    NSDictionary * dic = [NSDictionary dictionaryWithObject:@"0" forKey:@"click"];
    [[NSNotificationCenter defaultCenter]postNotificationName:@"click" object:nil userInfo:dic];

    [self.tableView reloadData];
}

-(void)rightClickWith:(NSInteger)index{
    self.index=1;
    NSDictionary * dic = [NSDictionary dictionaryWithObject:@"1" forKey:@"click"];
    [[NSNotificationCenter defaultCenter]postNotificationName:@"click" object:nil userInfo:dic];
 
    [self.tableView reloadData];
}


#pragma mark 查看更多报名人员
-(void)checkMoreMessage{
    CheckMoreSignController * more =[[CheckMoreSignController alloc]init];
    more.responArray=self.msgArray;
    more.index=0;
    [self.navigationController pushViewController:more animated:YES];
}



-(void)replayHaveCommentWithrow:(NSInteger)row andWithTag:(NSInteger)tag{
    
    NSDictionary * dic = [[NSUserDefaults standardUserDefaults]objectForKey:USERINFOMATION];
    UserInfomation * infomation = [UserInfomation mj_objectWithKeyValues:dic];
    if ([Tool isBlankString:infomation.SessionKey] || [Tool isBlankString:infomation.SignId]) {
        [Tool showMaskMessage:@"尚未登录,请先登录" WithDuration:2 WithY: MatchW(300)];
        
        LoginViewController * loginView = [[LoginViewController alloc]init];
        [self.navigationController pushViewController:loginView animated:YES];
    }else{
        CGQInputTextView *inptuView = [[CGQInputTextView alloc] init];
        self.inputView=inptuView;
        inptuView.delegate = self;
        inptuView.index=1001;
        [inptuView show];
        self.row = row;
        self.btnTag=tag;
        
        CourseCommentModel * mainModel = self.getMainModelArray[self.row];
        CourseCommentModel * assitModel = mainModel.selfModelArray[self.btnTag];
        inptuView.placeholder.text=[NSString stringWithFormat:@"回复:%@",assitModel.SignUserName];
    }
    
}

#pragma mark 我要评论按钮点击
-(void)addMyComment{
    
    NSDictionary * dic = [[NSUserDefaults standardUserDefaults]objectForKey:USERINFOMATION];
    UserInfomation * infomation = [UserInfomation mj_objectWithKeyValues:dic];
    if ([Tool isBlankString:infomation.SessionKey] || [Tool isBlankString:infomation.SignId]) {
        [Tool showMaskMessage:@"尚未登录,请先登录" WithDuration:2 WithY: MatchW(300)];
        
        LoginViewController * loginView = [[LoginViewController alloc]init];
        [self.navigationController pushViewController:loginView animated:YES];
    }else{
        CGQInputTextView *inptuView = [[CGQInputTextView alloc] init];
        inptuView.placeholder.text=@"讨论您的看法";
        self.inputView=inptuView;
        inptuView.index = 1000;
        inptuView.delegate = self;
        [inptuView show];
    }
  
}

//回复按钮点击
-(void)replayBtnClickWith:(UIButton *)btn{
    
    
    NSDictionary * dic = [[NSUserDefaults standardUserDefaults]objectForKey:USERINFOMATION];
    UserInfomation * infomation = [UserInfomation mj_objectWithKeyValues:dic];
    if ([Tool isBlankString:infomation.SessionKey] || [Tool isBlankString:infomation.SignId]) {
        [Tool showMaskMessage:@"尚未登录,请先登录" WithDuration:2 WithY: MatchW(300)];
        
        LoginViewController * loginView = [[LoginViewController alloc]init];
        [self.navigationController pushViewController:loginView animated:YES];
    }else{
        CourseCommentModel * model = self.getMainModelArray[btn.tag];
        CGQInputTextView *inptuView = [[CGQInputTextView alloc] init];
        inptuView.placeholder.text=[NSString stringWithFormat:@"回复:%@",model.SignUserName];
        inptuView.delegate = self;
        [inptuView show];
        inptuView.index=btn.tag+1;
        self.inputView=inptuView;
    }
    
}



- (void)clickedSureBtnWithText:(NSString *)text{
    NSDictionary * dic = [[NSUserDefaults standardUserDefaults]objectForKey:USERINFOMATION];
    UserInfomation * infomation = [UserInfomation mj_objectWithKeyValues:dic];
    if (self.inputView.index==1000) {
        NSLog(@"评论");
            if (![Tool isBlankString:text]) {
               [Request commentMyMindWith:self.courseId andWithCommentInfo:text andWithSignId:infomation.SignId andWithReplayId:@"" andWithCommentType:0  success:^(AFMessage *model) {
                    if (model.success) {
                       [Tool showMaskMessage:@"评论成功" WithDuration:1.0 WithY:MatchW(200)];
                       [self commentReplay];
                    }else{
                        [Tool showMaskMessage:model.msg WithDuration:1.0 WithY:MatchW(200)];
                    }
                } failure:^(NSError *error) {
                     [Tool showMaskMessage:@"评论失败" WithDuration:1.0 WithY:MatchW(200)];
                }];
            }
    }else if (self.inputView.index==1001){
        NSLog(@"%ld---%ld",self.row,self.btnTag);
        CourseCommentModel * mainModel = self.getMainModelArray[self.row];
        CourseCommentModel * assitModel = mainModel.selfModelArray[self.btnTag];
        NSString * str =[NSString stringWithFormat:@"%@ 回复 %@: %@",infomation.SignUserName, assitModel.SignUserName,text];
        NSLog(@"%@",assitModel.CommentId);
        if (![Tool isBlankString:text]) {
            [Request commentMyMindWith:self.courseId andWithCommentInfo:str andWithSignId:infomation.SignId andWithReplayId:mainModel.CommentId  andWithCommentType:1 success:^(AFMessage *model) {
                if (model.success) {
                    [Tool showMaskMessage:@"评论成功" WithDuration:1.0 WithY:MatchW(200)];
                    [self commentReplay];
                }else{
                    [Tool showMaskMessage:model.msg WithDuration:1.0 WithY:MatchW(200)];
                }
            } failure:^(NSError *error) {
                [Tool showMaskMessage:@"评论失败" WithDuration:1.0 WithY:MatchW(200)];
            }];
        }
        
    }else{
        NSLog(@"回复");
        CourseCommentModel * model = self.getMainModelArray[self.inputView.index-1];
        NSString * str =[NSString stringWithFormat:@"%@ 回复 %@: %@",infomation.SignUserName, model.SignUserName,text];
       
        if (![Tool isBlankString:text]) {
            [Request commentMyMindWith:self.courseId andWithCommentInfo:str andWithSignId:infomation.SignId andWithReplayId:model.CommentId  andWithCommentType:1 success:^(AFMessage *model) {
                if (model.success) {
                    [Tool showMaskMessage:@"评论成功" WithDuration:1.0 WithY:MatchW(200)];
                    [self commentReplay];
                }else{
                    [Tool showMaskMessage:model.msg WithDuration:1.0 WithY:MatchW(200)];
                }
            } failure:^(NSError *error) {
                [Tool showMaskMessage:@"评论失败" WithDuration:1.0 WithY:MatchW(200)];
            }];
        }
    }
    
}




#pragma mark 查看更多评论
-(void)checkMore{
    CheckCommentController * commentControl=[[CheckCommentController alloc]init];
    commentControl.courseId=self.courseId;
    [self.navigationController pushViewController:commentControl animated:YES];
}




#pragma mark 评论区的区头区尾
-(CommentHeaderView*)headerView{
    if (_headerView==nil) {
        _headerView=[[CommentHeaderView alloc]init];
        _headerView.backgroundColor=[UIColor whiteColor];
        __weak typeof(self) weakSelf = self;
        _headerView.addCommentBtnClick = ^{
            [weakSelf addMyComment];
        };
    }
    return _headerView;
}


-(CommentFooterView*)footerView{
    if (_footerView==nil) {
        _footerView=[[CommentFooterView alloc]init];
        __weak typeof(self) weakSelf = self;
        _footerView.CheckMoreComment = ^{
            [weakSelf checkMore];
        };
    }
    return _footerView;
}


#pragma mark 点击电话按钮
-(void)PhoneNumClick{
    DetailModel * model = self.responseArray[0];

    NSMutableString *str=[[NSMutableString alloc]initWithFormat:@"tel:%@",model.CourseTel];
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"呼叫" message:model.CourseTel preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
    }];
    UIAlertAction *otherAction = [UIAlertAction actionWithTitle:@"呼叫" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
    }];
   // Add the actions.
  [alertController addAction:cancelAction];
  [alertController addAction:otherAction];
  [self presentViewController:alertController animated:YES completion:nil];
    
}
#pragma mark 点击我的课程 按钮
-(void)myCourse{
    
    NSDictionary * dic = [[NSUserDefaults standardUserDefaults]objectForKey:USERINFOMATION];
    UserInfomation * infomation = [UserInfomation mj_objectWithKeyValues:dic];
    if (![Tool isBlankString:infomation.SessionKey] && ![Tool isBlankString:infomation.SignId]) {
        MyCourseController * controller = [[MyCourseController alloc]init];
        [self.navigationController pushViewController:controller animated:YES];
        
    }else{
        [Tool showMaskMessage:@"您还没登录,请先登录" WithDuration:2 WithY:MatchW(300)];
        LoginViewController * loginView = [[LoginViewController alloc]init];
        [self.navigationController pushViewController:loginView animated:YES];
        
    }
    
  
}

#pragma mark 点击报名时候的状态 分析,已报名,报名已结束,跳转报名界面
-(void)enrollClickWithBtn:(UIButton *)btn{
    
    
    DetailModel * model = self.responseArray[0];   
    
    if (model.CourseState==1) {
        if (model.IsEnroll) {
            [Tool showMaskMessage:@"您已报名" WithDuration:2 WithY: MatchW(350)];
            
        }else{
             [self userEnrol];
        }
    }else if(model.CourseState==2){
        [Tool showMaskMessage:model.CourseStateInfo WithDuration:2 WithY: MatchW(350)];
    }else if (model.CourseState==3){
        [Tool showMaskMessage:model.CourseStateInfo WithDuration:2 WithY: MatchW(350)];
    }else if (model.CourseState==4){
        [Tool showMaskMessage:model.CourseStateInfo WithDuration:2 WithY: MatchW(350)];
    }else{
        [Tool showMaskMessage:model.CourseStateInfo WithDuration:2 WithY: MatchW(350)];
    }
    
  
}

-(void)userEnrol{
    NSDictionary * dic = [[NSUserDefaults standardUserDefaults]objectForKey:USERINFOMATION];
    UserInfomation * infomation = [UserInfomation mj_objectWithKeyValues:dic];
    if (![Tool isBlankString:infomation.SessionKey] && ![Tool isBlankString:infomation.SignId]) {
        SignViewController * controller = [[SignViewController alloc]init];
        DetailModel * model = self.responseArray[0];
        controller.courseId=model.CourseId;
        [self.navigationController pushViewController:controller animated:YES];
        
    }else{
        [Tool showMaskMessage:@"您还没登录,请先登录" WithDuration:2 WithY:MatchW(300)];
        LoginViewController * loginView = [[LoginViewController alloc]init];
        [self.navigationController pushViewController:loginView animated:YES];
        
    }
}

@end

相关文章

网友评论

      本文标题:分步请求数据

      本文链接:https://www.haomeiwen.com/subject/fxcoaftx.html