// // DetailTJVC.m // jiaPeiC // // Created by apple on 16/3/18. // Copyright © 2016年 JCZ. All rights reserved. // #import "DetailTJVC.h" #import "PickTimeV.h" #import "DateView.h" #import "TJCell.h" @interface DetailTJVC () { UITableView *mainTableView; HolderView *holderV; UIButton *styleBtn,*beginTBtn,*endTBtn; UILabel *numLabel; NSArray *dataArray; NSString *exerciseStyle; NSString *beginDate; NSString *endDate; } @end @implementation DetailTJVC - (void)viewDidLoad { [super viewDidLoad]; self.title = @"日志统计"; float bd,x,y,w,h; x = bd = 10; y = kNavOffSet + 10; w = kSize.width - 20; h = 50; UIView *bgView; UILabel *label; UIButton *button; bgView = [[UIView alloc] initWithFrame:CGRectMake(x, y , w, h)]; [bgView boardWid:2 Color:lineColor]; [bgView corner:5]; [self addV:bgView]; label = [[UILabel alloc] initWithFrame:CGRectMake(x + bd, y , w - bd, h)]; [label setText:[NSString stringWithFormat:@"统计类型:"] Font:18 TextColor:kTitleColor Alignment:NSTextAlignmentLeft]; [self addV:label]; float widt = [label.text sizeForFont:18].width; button = [[UIButton alloc] initWithFrame:CGRectMake(x + widt - 10, y , w - widt + 10, h)]; [button setTitle:@"请选择日志类型" textColor:defGreen font:17 fotState:UIControlStateNormal]; [button target:self Tag:1]; [self addV:button]; styleBtn = button; y += h + bd; bgView = [[UIView alloc] initWithFrame:CGRectMake(x, y , w, h)]; [bgView boardWid:2 Color:lineColor]; [bgView corner:5]; [self addV:bgView]; NSString *titString = @"统计时间:"; float wid = [titString sizeForFont:18].width; label = [[UILabel alloc] initWithFrame:CGRectMake(x + bd, y , wid, h)]; [label setText:titString Font:18 TextColor:kTitleColor Alignment:NSTextAlignmentLeft]; [self addV:label]; x += 4 + wid; w = (w - 10 - wid)/2.0; label = [[UILabel alloc] initWithFrame:CGRectMake(x + w - 2, y + h/2.0, 10, 2)]; label.backgroundColor = contentTextColor; [self addV:label]; button = [[UIButton alloc] initWithFrame:CGRectMake(x, y , w, h)]; [button setTitle:@"请选择开始时间" textColor:defGreen font:17 fotState:UIControlStateNormal]; [button target:self Tag:2]; [self addV:button]; beginTBtn = button; x += w + 6; button = [[UIButton alloc] initWithFrame:CGRectMake(x , y , w, h)]; [button setTitle:@"请选择结束时间" textColor:defGreen font:17 fotState:UIControlStateNormal]; [button target:self Tag:3]; [self addV:button]; endTBtn = button; x = bd; y += h + 5; w = 200; label = [[UILabel alloc] initWithFrame:CGRectMake(x, y , w, h)]; label.backgroundColor = backGroundColor; [label setText:titString Font:18 TextColor:kTitleColor Alignment:NSTextAlignmentLeft]; label.text = @"当前条件下共有0人"; [self addV:label]; numLabel = label; x = kSize.width - 100; h = 40; w = 80; button = [[UIButton alloc] initWithFrame:CGRectMake(x , y , w, h)]; [button setTitle:@"查询" textColor:[UIColor whiteColor] font:18 fotState:UIControlStateNormal]; button.backgroundColor = defGreen; [button corner:10]; [button target:self Tag:4]; [self addV:button]; label = [[UILabel alloc] initWithFrame:CGRectMake(bd, y + 48, kSize.width - 2*bd, 2)]; label.backgroundColor = lineColor; [self addV:label]; mainTableView = [[UITableView alloc] initWithFrame:kFrame style:UITableViewStylePlain]; mainTableView.delegate = self; mainTableView.backgroundColor = backGroundColor; mainTableView.dataSource = self; mainTableView.y = y + 50; mainTableView.height = kSize.height - y - 50; mainTableView.tableFooterView = [UIView new]; [self addV:mainTableView]; holderV = [[HolderView alloc] initWithFrame:mainTableView.frame]; holderV.backgroundColor = backGroundColor; [holderV freshBlock:^{ [self getMyTeachStatistics]; }]; [self addV:holderV]; } -(void)btnClick:(UIButton *)sender { if (sender.tag == 1) { //选择日记类型 PickTimeV *pickV = [[PickTimeV alloc] init]; //23 无实意 只是为了让picktimeV 与之对应 pickV.KM = @"23"; [pickV setWhichVC:@"AddRecordVC"]; [pickV complete:^(NSDictionary* obj) { [styleBtn setTitle:obj[@"TC_TEACH_TYPE"] forState:UIControlStateNormal]; exerciseStyle = obj[@"TC_ID"]; }]; [pickV show]; } if (sender.tag == 2) { //选择日志开始时间 DateView *dateV = [[DateView alloc] init]; [dateV setStyle:0]; [dateV showWithComplete:^(NSString * result) { //NSLog(@"kaishi-->%@",result); //eg:2016-03-11 beginDate = result; [beginTBtn setTitle:beginDate forState:UIControlStateNormal]; }]; } if (sender.tag == 3) { //选择日志结束时间 DateView *dateV = [[DateView alloc] init]; [dateV setStyle:0]; [dateV showWithComplete:^(NSString * result) { //NSLog(@"jieshu-->%@",result); //eg:2016-03-11 endDate = result; [endTBtn setTitle:endDate forState:UIControlStateNormal]; }]; } if (sender.tag == 4) { [self getMyTeachStatistics]; } } //tableview delegate -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return dataArray.count; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { TJCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; if (cell == nil) { cell = [[TJCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]; } NSDictionary *dic = dataArray[indexPath.row]; NSString *dateString = dic[@"TL_CRDATE"]; if (dateString.length > 10) { dateString = [dateString substringWithRange:NSMakeRange(5, 5)]; } NSString *dString = [NSString stringWithFormat:@"%@ [%@]",dic[@"TELPHONE"],dateString]; if (dString.length > 8) { NSMutableAttributedString * aString = [[NSMutableAttributedString alloc] initWithString:dString]; [aString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(dString.length - 7, 1)]; [aString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(dString.length - 1, 1)]; cell.dateLabel.attributedText = aString; }else{ //防止没电话号码导致意外 cell.dateLabel.text = dString; } cell.textLabel.text = [NSString stringWithFormat:@"%d、%@",(int)indexPath.row + 1,dic[@"TL_NAME"]]; return cell; } //数据请求 - (void)getMyTeachStatistics { [LoadingView showHUD]; if (![Util connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableArray *arr=[NSMutableArray array]; [arr addPro:@"coaSfzhm" Value:defUser.userDict[@"idcard"]]; if (exerciseStyle) { [arr addPro:@"teachId" Value:exerciseStyle]; } [arr addPro:@"startDate" Value:beginDate]; [arr addPro:@"endDate" Value:endDate]; NSString* method = @"getMyTeachStatistics"; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) { RemoveHUD(); //NSLog(@"日志统计---->%@----->%@",arr,root); [holderV setHidden:NO]; if (!root) { ShowMsgFailed(); return ; } if ([root[@"code"] isEqualToString:@"1"]) { ShowMsg(root[@"body"]); return; } if ([[root[@"body"] allKeys] containsObject:@"COUNT"]) { NSString *num = [root[@"body"] objectForKey:@"COUNT"]; numLabel.text = [NSString stringWithFormat:@"当前条件下共有%@人",num]; } if ([[root[@"body"] allKeys] containsObject:@"LIST"]) { dataArray = [root[@"body"] objectForKey:@"LIST"]; if ([dataArray count] == 0) { ShowMsg(@"暂无数据"); }else{ [holderV setHidden:YES]; [mainTableView reloadData]; } } }]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end