// // LogAllViewController.m // IBOSSmini // // Created by guan hong hou on 2017/5/5. // Copyright © 2017年 elongtian. All rights reserved. // #import "LogAllViewController.h" @interface LogAllViewController () @end @implementation LogAllViewController @synthesize dataList; @synthesize vCustomTableView; NSInteger pageNum=1; BOOL reload; #pragma mark - 公共函数 /** viewDidLoad函数 */ - (void)viewDidLoad { [super viewDidLoad]; dataList=[[NSMutableArray alloc]init]; _logModel=[[LogModel alloc]init]; self.view.backgroundColor=[UIColor whiteColor]; UIImageView *separatorsView=[[UIImageView alloc]init]; separatorsView.frame=CGRectMake(0, 0, Screen_Width,10); separatorsView.backgroundColor=LineBackgroundColor; [self.view addSubview:separatorsView]; vCustomTableView = [[RefreshTableView alloc] initWithFrame:CGRectMake(0,CGRectGetMaxY(separatorsView.frame), self.view.frame.size.width,self.view.frame.size.height-10)]; vCustomTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight; vCustomTableView.backgroundColor = [UIColor whiteColor]; vCustomTableView.separatorStyle=UITableViewCellSeparatorStyleNone; vCustomTableView.delegate = self; [self.view addSubview:vCustomTableView]; pageNum=1; UITapGestureRecognizer* singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)]; [self.view addGestureRecognizer:singleTap]; singleTap.delegate = self; singleTap.cancelsTouchesInView = NO; } /** 安全区视图发生变化 */ -(void)viewSafeAreaInsetsDidChange{ self.view.backgroundColor = [UIColor whiteColor]; vCustomTableView.frame = CGRectMake(0,10,SCREENWIDTH, self.view.superview.frame.size.height-10); //将当前view的高度设置到屏幕底部 self.view.frame = CGRectMake(0,0,SCREENWIDTH, self.view.superview.frame.size.height + [Util obtainHomeAreaHeight]); [super viewSafeAreaInsetsDidChange]; } #pragma mark - 委托回调函数 /** 支持手势函数 */ - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { return YES; } /** 手势点击函数 */ -(void)handleSingleTap:(UITapGestureRecognizer *)sender { CGPoint point = [sender locationInView:self.view]; CGFloat y= point.y; if(_commentView !=nil){ if(y<_commentView.frame.origin.y){ [_commentView removeFromSuperview]; [_commentView finishSendMessage]; } } } /** 数据加载完成回调函数 */ - (void)onLoadFinish:(ASIDownManager *)sender { NSDictionary *dic = [sender.mWebStr JSONValue]; [self stopLoading]; NSInteger iNewCount = 0; if (dic && [dic isKindOfClass:[NSDictionary class]]) { int iStatus = [[dic objectForKey:@"Status"] intValue]; NSString *message=[dic objectForKey:@"Message"]; if (iStatus == 0) { NSArray *approvArr=[dic objectForKey:@"Result"]; if(approvArr!=nil&&approvArr.count>0) { iNewCount=[approvArr count]; vCustomTableView.mbMoreHidden = (iNewCount == 0); [dataList addObjectsFromArray:approvArr]; if(dataList.count>0){ [_logModel ParseWorkFlowArr:dataList]; } [vCustomTableView reloadData]; } else{ vCustomTableView.mbMoreHidden=1; vCustomTableView.separatorStyle = UITableViewCellSeparatorStyleNone; if(dataList.count==0){ UIView *noDataView=[[UIView alloc]init]; noDataView.frame=vCustomTableView.bounds; UIImageView *nodataImgView=[[UIImageView alloc] initWithFrame:CGRectMake(noDataView.frame.size.width/2-16,noDataView.frame.size.height/2-16,32,32)]; [nodataImgView setImage:[UIImage imageNamed:@"icon_no_data"]]; [noDataView addSubview:nodataImgView]; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(noDataView.frame.size.width/2-16-12,CGRectGetMaxY(nodataImgView.frame)+3,70, 25)]; label.font=[UIFont systemFontOfSize:NoDataFontOfSize]; label.text = @"无数据"; label.numberOfLines = 2; label.textColor = [UIColor lightGrayColor]; [noDataView addSubview:label]; vCustomTableView.mTableView.backgroundView =noDataView; } [vCustomTableView reloadData]; } [vCustomTableView FinishLoading]; } else if(iStatus==ActionResultStatusAuthError ||iStatus==ActionResultStatusNoLogin ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid){ [self showReLoginDialog:message]; return; } else{ [self showAlertViewText:message]; [vCustomTableView reloadData]; return; } } } /** 数据加载失败回调函数 */ - (void)onLoadFail:(ASIDownManager *)sender { [self stopLoading]; [self.vCustomTableView reloadData]; [self showAlertViewText:@"加载失败"]; } /** 下拉刷新回调函数 */ - (void)scrollViewDidScroll:(UIScrollView *)scrollView{ if (scrollView.isDragging) {//显示下拉更新 if(_commentView !=nil){ [_commentView removeFromSuperview]; [_commentView finishSendMessage]; } if (vCustomTableView.mRefreshHeader.state == PullRefreshPulling && scrollView.contentOffset.y > -65.0f && scrollView.contentOffset.y < 0.0f && [vCustomTableView CanRefresh]) { [vCustomTableView.mRefreshHeader setState:PullRefreshNormal]; } else if (vCustomTableView.mRefreshHeader.state == PullRefreshNormal && scrollView.contentOffset.y < -65.0f && [vCustomTableView CanRefresh]) {//显示松开更新 [vCustomTableView.mRefreshHeader setState:PullRefreshPulling]; } } } /** tableview的分区数 */ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } /** tableview的列表项 */ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [dataList count]; } /** tableview的cell */ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CustomCellIdentifier = @"CellId"; LogCell *cell1 = [tableView dequeueReusableCellWithIdentifier:CustomCellIdentifier]; cell1=[[LogCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CustomCellIdentifier]; cell1.selectionStyle=UITableViewCellSelectionStyleNone; cell1.delegate=self; cell1.indexPath=indexPath; NSUInteger row = [indexPath row]; LogFrame *logFrame= [_logModel.logArr objectAtIndex:row]; cell1.currentLog=logFrame; return cell1; } //tableviewcell的高度 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { LogFrame *logFrame= [_logModel.logArr objectAtIndex:indexPath.row]; return [logFrame cellHeight]; } /** 加载更多回调函数 */ - (void)LoadMoreList:(RefreshTableView *)sender { pageNum++; [self reloadData]; } /** 下拉刷新回调函数 */ - (void)ReloadList:(RefreshTableView *)sender{ pageNum = 1; [dataList removeAllObjects]; vCustomTableView.mbMoreHidden=YES; [vCustomTableView reloadData]; [self reloadData]; } /** 支持下拉刷新回调函数 */ - (BOOL)CanRefreshTableView:(RefreshTableView *)sender { return YES; } /** 回复信息窗口弹出回调函数 */ - (void)didShowOperationView:(UIButton *)sender indexPath:(NSIndexPath *)indexPath logFrame:(LogFrame *)logFrame tag:(NSInteger)tag replyInfo:(ReplyInfo *)replyInfo { _replyInfo=replyInfo; _logFrame=logFrame; _tag=tag; if(_commentView!=nil){ [_commentView removeFromSuperview]; } //高度设置成150是为了遮挡语音输入时的空白 _commentView=[[SendMessageView alloc] initWithFrame:CGRectMake(0,Screen_Height, Screen_Width,150)]; if(tag==1||tag==2){ [_commentView setHintMessage:@"说点什么吧..." view:self.view]; } else if(tag==3){ NSString *AtInfo=[NSString stringWithFormat:@"@%@",[replyInfo userName]]; [_commentView setHintMessage:AtInfo view:self.view]; } _commentView.backgroundColor = [UIColor colorWithWhite:0.910 alpha:1.000]; [self.view addSubview:_commentView]; self.selectedIndexPath=indexPath; _commentView.sendMessageDelegate = self; } /** 发送消息接口回调 */ - (void)didSendMessage:(NSString *)message albumInputView:(SendMessageView *)sendMessageView { if(_tag==1){ if (self.selectedIndexPath && self.selectedIndexPath.row < self.dataList.count) { if(message==nil||message.length==0){ [self showAlertViewText:@"评论信息不能为空"]; return; } if(message.length>255){ [self showAlertViewText:@"评论信息不能超过 255个字符"]; return; } NSString *urlStr = ServerURL; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:@"UpdateDailyRecordCheckManager" forKey:@"Action"]; [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"]; [dict setObject:kkUserCode forKey:@"UserCode"]; [dict setObject:kkUserPwd forKey:@"UserPassword"]; [dict setObject:kkSessionKey forKey:@"SessionKey"]; NSString * recordid = [NSString stringWithFormat:@"%ld",(long)_logFrame.log.recordId]; [dict setObject:recordid forKey:@"RecordID"]; [dict setObject:message forKey:@"Remarks"]; NSString * commentUserId = [NSString stringWithFormat:@"%ld",(long)_logFrame.log.commentUserId]; [dict setObject:commentUserId forKey:@"CommentUserID"]; _mDownManager = [[ASIDownManager alloc] init]; NSString* json= [_mDownManager syncPostHttpRequestUrl:urlStr dic:dict path:nil filename:nil fileType:nil]; if(json!=nil&&json.length>0){ NSDictionary *dic = [json JSONValue]; if (dic && [dic isKindOfClass:[NSDictionary class]]) { int iStatus = [[dic objectForKey:@"Status"] intValue]; NSString *message1=[dic objectForKey:@"Message"]; if(iStatus==0){ NSString *commentTime=[dic objectForKey:@"Result"]; for(int i=0;i<_logModel.logArr.count;i++){ if(i==self.selectedIndexPath.row){ LogFrame *logFrame=[_logModel.logArr objectAtIndex:self.selectedIndexPath.row]; Log *log= logFrame.log; [log setRecordStatus:@"(已点评)"]; [log setRemarks:message]; [log setChecker:kkUserName]; [log setCommentUpdateTime:commentTime]; [logFrame setLogModel:log]; break; } } [vCustomTableView.mTableView reloadRowsAtIndexPaths:@[self.selectedIndexPath] withRowAnimation:UITableViewRowAnimationNone]; [sendMessageView finishSendMessage]; if(_commentView!=nil){ [_commentView removeFromSuperview]; } } else if(iStatus==ActionResultStatusAuthError ||iStatus==ActionResultStatusNoLogin ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid){ [self showReLoginDialog:message1]; } else{ [self showAlertViewText:message1]; return; } } } } } else if(_tag==2){ if (self.selectedIndexPath && self.selectedIndexPath.row < self.dataList.count) { if(message==nil||message.length==0){ [self showAlertViewText:@"回复信息不能为空"]; return; } if(message.length>255){ [self showAlertViewText:@"回复信息不能超过 255个字符"]; return; } NSString *urlStr = ServerURL; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:@"SaveDailyRecordReplyManager" forKey:@"Action"]; [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"]; [dict setObject:kkUserCode forKey:@"UserCode"]; [dict setObject:kkUserPwd forKey:@"UserPassword"]; [dict setObject:kkSessionKey forKey:@"SessionKey"]; NSString * recordid = [NSString stringWithFormat:@"%ld",(long)_logFrame.log.recordId]; [dict setObject:recordid forKey:@"RecordID"]; [dict setObject:@"" forKey:@"RepliedUserID"]; [dict setObject:message forKey:@"ReplyContent"]; self.mDownManager = [[ASIDownManager alloc] init]; NSString* json = [_mDownManager syncPostHttpRequestUrl:urlStr dic:dict path:nil filename:nil fileType:nil]; if(json!=nil&&json.length>0){ NSDictionary *dic = [json JSONValue]; if (dic && [dic isKindOfClass:[NSDictionary class]]) { int iStatus = [[dic objectForKey:@"Status"] intValue]; NSString *message1=[dic objectForKey:@"Message"]; if(iStatus==0){ ReplyInfo *info=[ReplyInfo new]; [info setRecordId:[recordid intValue]]; [info setRepliedUserName:@""]; [info setReplyId:@""]; [info setUserName:kkUserName]; [info setCreateUserId:[kkUserID intValue]]; [info setReplyContent:message]; ReplyFrame *replyFrame=[[ReplyFrame alloc]init]; [replyFrame setReplyInfoFrame:info]; LogFrame *logFrame=[_logModel.logArr objectAtIndex:self.selectedIndexPath.row]; Log *log= logFrame.log; NSMutableArray *replyInfoArray=[log replyArray]; NSMutableArray *replyTempArray = [[NSMutableArray alloc] initWithArray:replyInfoArray]; [replyTempArray addObject:replyFrame]; log.replyArray=replyTempArray; [logFrame setLogModel:log]; [vCustomTableView.mTableView reloadRowsAtIndexPaths:@[self.selectedIndexPath] withRowAnimation:UITableViewRowAnimationNone]; [sendMessageView finishSendMessage]; if(_commentView!=nil){ [_commentView removeFromSuperview]; } } else if(iStatus==ActionResultStatusAuthError ||iStatus==ActionResultStatusNoLogin ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid){ [self showReLoginDialog:message1]; return; } else{ [self showAlertViewText:message1]; return; } } } } } else if(_tag==3){ if (self.selectedIndexPath && self.selectedIndexPath.row < self.dataList.count) { if(message==nil||message.length==0){ [self showAlertViewText:@"回复信息不能为空"]; return; } if(message.length>255){ [self showAlertViewText:@"回复信息不能超过 255个字符"]; return; } NSInteger recordId = 0; NSInteger replierId=0; NSString *userName=nil; ReplyInfo *info=nil; ReplyFrame *replyFrame; if(_replyInfo!=nil){ recordId=[_replyInfo recordId]; replierId=[_replyInfo createUserId]; userName=[_replyInfo userName]; info =[ReplyInfo new]; [info setRecordId:recordId]; [info setRepliedUserName:userName]; [info setReplyUserId:replierId]; [info setUserName:kkUserName]; [info setReplyContent:message]; replyFrame=[[ReplyFrame alloc]init]; [replyFrame setReplyInfoFrame:info]; } NSString *urlStr = ServerURL; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:@"SaveDailyRecordReplyManager" forKey:@"Action"]; [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"]; [dict setObject:kkUserCode forKey:@"UserCode"]; [dict setObject:kkUserPwd forKey:@"UserPassword"]; [dict setObject:kkSessionKey forKey:@"SessionKey"]; NSString * replierUserId; if(replierId==0){ replierUserId= nil; } else{ replierUserId = [NSString stringWithFormat:@"%ld",(long)replierId]; } NSString *recordid = [NSString stringWithFormat:@"%ld",(long)recordId]; [dict setObject:recordid forKey:@"RecordID"]; [dict setObject:replierUserId forKeyedSubscript:@"RepliedUserID"]; [dict setObject:message forKey:@"ReplyContent"]; self.mDownManager = [[ASIDownManager alloc] init]; NSString* json= [self.mDownManager syncPostHttpRequestUrl:urlStr dic:dict path:nil filename:nil fileType:nil]; if(json!=nil&&json.length>0){ NSDictionary *dic = [json JSONValue]; if (dic && [dic isKindOfClass:[NSDictionary class]]) { int iStatus = [[dic objectForKey:@"Status"] intValue]; NSString *message1=[dic objectForKey:@"Message"]; if(iStatus==0){ LogFrame *logFrame=[_logModel.logArr objectAtIndex:self.selectedIndexPath.row]; Log *log= logFrame.log; NSMutableArray *replyInfoArray=[log replyArray]; NSMutableArray *replyTempArray = [[NSMutableArray alloc] initWithArray:replyInfoArray]; [replyTempArray addObject:replyFrame]; log.replyArray=replyTempArray; [logFrame setLogModel:log]; [vCustomTableView.mTableView reloadRowsAtIndexPaths:@[self.selectedIndexPath] withRowAnimation:UITableViewRowAnimationNone]; [sendMessageView finishSendMessage]; if(_commentView!=nil){ [_commentView removeFromSuperview]; } } else if(iStatus==ActionResultStatusAuthError ||iStatus==ActionResultStatusNoLogin ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid){ [self showReLoginDialog:message1]; return; } else{ [self showAlertViewText:message1]; return; } } } } } } #pragma mark - 私有函数 -(void)refresh{ pageNum=1; [dataList removeAllObjects]; vCustomTableView.mbMoreHidden=YES; [vCustomTableView reloadData]; [self reloadData]; } /** 加载数据 */ -(void)reloadData { [self startLoading]; NSString *urlStr = ServerURL; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:@"GetAllDailyRecordManager" forKey:@"Action"]; [dict setObject:kkAccountCode forKey:@"AccountCode"]; [dict setObject:kkUserCode forKey:@"UserCode"]; [dict setObject:kkUserPwd forKey:@"UserPassword"]; [dict setObject:kkSessionKey forKey:@"SessionKey"]; if(_startDate==nil){ [dict setObject:@"" forKey:@"CreateTimeFrom"]; } else{ [dict setObject:_startDate forKey:@"CreateTimeFrom"]; } if(_endDate==nil){ [dict setObject:@"" forKey:@"CreateTimeTo"]; } else{ [dict setObject:_endDate forKey:@"CreateTimeTo"]; } if(_createUserIds==nil){ [dict setObject:@"" forKey:@"CreateUserIDs"]; } else{ [dict setObject:_createUserIds forKey:@"CreateUserIDs"]; } [dict setObject:_recordStatus forKey:@"RecordStatus"]; [dict setObject:[NSString stringWithFormat:@"%d",(int)pageNum] forKey:@"PageNum"]; [dict setObject:[NSString stringWithFormat:@"%d",logPageSize] forKey:@"PageSize"]; self.mDownManager = [[ASIDownManager alloc] init]; _mDownManager.delegate = self; _mDownManager.OnImageDown = @selector(onLoadFinish:); _mDownManager.OnImageFail = @selector(onLoadFail:); [_mDownManager postHttpRequest:urlStr dic:dict path:nil fileName:nil]; } /** 关闭键盘 */ -(void) closeKeyboard{ [_commentView finishSendMessage]; if(_commentView!=nil){ [_commentView removeFromSuperview]; } } @end