// // ReserveCell.m // jiaPei // // Created by apple on 16/6/29. // Copyright © 2016年 JCZ. All rights reserved. // #import "ReserveCell.h" @implementation ReserveCell - (void)awakeFromNib { [super awakeFromNib]; // Initialization code } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { self.backgroundColor = [UIColor whiteColor]; UILabel *label; CGFloat x,y,w,h; x = 20; y = 0; w = kSize.width - 40; h = 30; label = [[UILabel alloc] KSetxywh]; [self.contentView addSubview:label]; RDatelabel = label; [label addViewWithRect:CGRectMake(10, h, kSize.width - 20, 1)]; y += h + 5; w = kSize.width/2.0 - 20; h = 25; NSMutableArray *labels = [NSMutableArray arrayWithCapacity:6]; for (int i = 0; i < 3; i ++) { label = [[UILabel alloc] initWithFrame:CGRectMake(x, y + h*i, w, h)]; [self.contentView addSubview:label]; [labels addObject:label]; label = [[UILabel alloc] initWithFrame:CGRectMake(x + w, y + h*i, w, h)]; [self.contentView addSubview:label]; [labels addObject:label]; } nameLabel = labels[0]; kmLabel = labels[1]; dateLabel = labels[2]; priceLabel = labels[3]; timeLabel = labels[4]; countLabel = labels[5]; y += 3*h + 4; [countLabel addViewWithRect:CGRectMake(10, y, kSize.width - 20, 1)]; y += 5; w = kSize.width - 40; h = 20; label = [[UILabel alloc] KSetxywh]; [self.contentView addSubview:label]; stateLabel = label; y += h; h = 40; label = [[UILabel alloc] KSetxywh]; label.numberOfLines = 0; [self.contentView addSubview:label]; reasonLabel = label; x = kSize.width - 100; w = 80; h = 30; cancelBtn = [[UIButton alloc] KSetxywh]; [cancelBtn borderColor:defGreen width:1.3 cornorRadios:5]; [cancelBtn setTitle:@"取消预约" textColor:defGreen font:Font16 fotState:UIControlStateNormal]; [cancelBtn target:self]; [self.contentView addSubview:cancelBtn]; // nameLabel = label; // // x += w; // label = [[UILabel alloc] KSetxywh]; // [self.contentView addSubview:label]; // kmLabel = label; } return self; } -(void)setDataDic:(NSDictionary *)dataDic { _dataDic = dataDic; //NSLog(@"----><>%@",dataDic); NSString *dateS = dataDic[@"RI_CRDATE"]; if (dateS.length > 16) { dateS = [NSString stringWithFormat:@"%@(预约时间)",[dateS substringToIndex:16]]; } [RDatelabel setText:dateS Font:Font16 TextColor:KTitleColor Alignment:NSTextAlignmentRight]; NSString *stateString = @""; switch ([dataDic[@"RI_STATUS"] integerValue]) { case 0: //拒绝 stateString = @"教练已拒绝了您的预约申请,可以试下其他的计划哦"; cancelBtn.hidden = YES; break; case 1: //同意 { stateString = @"教练已同意了您的预约申请,祝您练车愉快!"; cancelBtn.hidden = NO; //判断时间是否已经过期 过期就不能再取消了 这里用的是计划的结束时间 服务器好像是开始时间 改lastObject这个就好了 NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; NSDate *taskDate = [formatter dateFromString:[NSString stringWithFormat:@"%@ %@:00",_dataDic[@"PI_TASK_TIME"],[[_dataDic[@"PI_TIMES"] componentsSeparatedByString:@"-"] lastObject]]]; NSComparisonResult result = [taskDate compare:[NSDate date]]; if (result == NSOrderedAscending){ //ShowMsg(@"教练计划已过期,不能取消"); cancelBtn.backgroundColor = kLineColor; [cancelBtn setTitleColor:KContentTextColor forState:UIControlStateNormal]; [cancelBtn borderColor:kLineColor width:1.3 cornorRadios:5]; cancelBtn.userInteractionEnabled = NO; }else{ cancelBtn.backgroundColor = [UIColor clearColor]; [cancelBtn setTitleColor:defGreen forState:UIControlStateNormal]; [cancelBtn borderColor:defGreen width:1.3 cornorRadios:5]; cancelBtn.userInteractionEnabled = YES; } } break; case 2: //预约中 { stateString = @"教练还未审核您的预约申请,请耐心等待哦"; cancelBtn.hidden = NO; //判断时间是否已经过期 过期就不能再取消了 这里用的是计划的结束时间 服务器好像是开始时间 改lastObject这个就好了 NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; NSDate *taskDate = [formatter dateFromString:[NSString stringWithFormat:@"%@ %@:00",_dataDic[@"PI_TASK_TIME"],[[_dataDic[@"PI_TIMES"] componentsSeparatedByString:@"-"] firstObject]]]; NSComparisonResult result = [taskDate compare:[NSDate date]]; if (result == NSOrderedAscending){ //ShowMsg(@"教练计划已过期,不能取消"); cancelBtn.backgroundColor = kLineColor; [cancelBtn setTitleColor:KContentTextColor forState:UIControlStateNormal]; cancelBtn.userInteractionEnabled = NO; }else{ cancelBtn.backgroundColor = [UIColor clearColor]; [cancelBtn setTitleColor:defGreen forState:UIControlStateNormal]; cancelBtn.userInteractionEnabled = YES; } } break; case 3: //已取消 stateString = @"您已取消了本次预约,可在教练计划中重新申请哦"; cancelBtn.hidden = YES; break; default: break; } [stateLabel setText:stateString Font:Font16 TextColor:KTitleColor Alignment:NSTextAlignmentLeft]; [reasonLabel setText:dataDic[@"RI_REASON"] Font:Font16 TextColor:KTitleColor Alignment:NSTextAlignmentLeft]; [nameLabel setText:[NSString stringWithFormat:@"教练:%@",dataDic[@"PI_USER_NAME"]] Font:Font16 TextColor:KTitleColor Alignment:NSTextAlignmentLeft]; [dateLabel setText:[NSString stringWithFormat:@"日期:%@",dataDic[@"PI_TASK_TIME"]] Font:Font16 TextColor:KTitleColor Alignment:NSTextAlignmentLeft]; [timeLabel setText:[NSString stringWithFormat:@"时间:%@",dataDic[@"PI_TIMES"]] Font:Font16 TextColor:KTitleColor Alignment:NSTextAlignmentLeft]; NSString *kmString = @"科目二"; if ([dataDic[@"PI_KM"] isEqualToString:@"3"]) { kmString = @"科目三"; } [kmLabel setText:kmString Font:Font16 TextColor:[UIColor orangeColor] Alignment:NSTextAlignmentCenter]; [priceLabel setText:[NSString stringWithFormat:@"%@元/小时",dataDic[@"PI_MONEY"]] Font:Font16 TextColor:[UIColor orangeColor] Alignment:NSTextAlignmentCenter]; NSString *countString = [NSString stringWithFormat:@"已约%@人,可约%@人",dataDic[@"PI_HAV_NUM"],dataDic[@"PI_NUM"]]; [countLabel setText:countString Font:Font16 TextColor:KTitleColor Alignment:NSTextAlignmentCenter]; NSMutableAttributedString *abs = [[NSMutableAttributedString alloc]initWithString:countString]; NSRange range1 = [countString rangeOfString:dataDic[@"PI_HAV_NUM"]]; NSRange range2 = [countString rangeOfString:dataDic[@"PI_NUM"]]; if ([dataDic[@"PI_HAV_NUM"] isEqualToString:dataDic[@"PI_NUM"]]) { //防止两个值相等的时候 range1 == range2 if ([dataDic[@"PI_HAV_NUM"] length] == 1) { range2 = NSMakeRange(7, 1); } if ([dataDic[@"PI_HAV_NUM"] length] == 2) { range2 = NSMakeRange(8, 2); } } [abs beginEditing]; //字体大小 [abs addAttribute:NSFontAttributeName value:[UIFont scaleSize:20.0] range:range1]; [abs addAttribute:NSFontAttributeName value:[UIFont scaleSize:20.0] range:range2]; //字体颜色 [abs addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:range1]; [abs addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:range2]; //下划线 [abs addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:range1]; [abs addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:range2]; countLabel.attributedText = abs; } -(void)click:(BlockTypeVo)block { clkBlock = block; } -(void)btnClick:(UIButton*)sender { //NSLog(@"当前要取消的预约%@",_dataDic) //这个地方要写取消预约的操作 [self cancelReserve]; } -(void)cancelReserve { //NSLog(@"取消预约---->%@---->%@",arr,root); // if (!root) // { // [LoadingView showMsg:@"操作失败"]; // return; // } // if ([root[@"code"] isEqualToString:@"1"]) { // // [LoadingView showMsg:root[@"body"]]; // return; // } // // ShowMsgSuc(); // // if (clkBlock) { // clkBlock(); // } } @end