// // ReplyCell.m // jiaPeiC // // Created by apple on 15/12/25. // Copyright © 2015年 JCZ. All rights reserved. // #import "ReplyCell.h" #import "UIImageView+WebCache.h" @interface ReplyCell() { UITextView *tfReason; UIView *backView; UIView *alertV; UILabel *remindLabel; NSString *reasonString; BOOL isCanEdit; } @end @implementation ReplyCell +(id)cellForTabelView:(UITableView*)tableView; { ReplyCell* cell = [tableView dequeueReusableCellWithIdentifier:@"ReplyCell"]; if (!cell) { cell = [[ReplyCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"ReplyCell"]; } return cell; } -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { UIButton* btn ;UIImageView *iv; iv = [UIImageView new]; [iv imageName:@"imgRefuse.png"]; [iv setHidden:YES]; [self addSubview:iv]; ivReady = iv; UILabel *label = [UILabel new]; [self addSubview:label]; _dateLabel = label; btn = [UIButton new]; [self addSubview:btn]; _btnYes = btn; btn = [UIButton new]; [self addSubview:btn]; _btnNO = btn; btn = [UIButton new]; btn.hidden = YES; [self addSubview:btn]; _selectBtn = btn; [_btnYes setImage:[UIImage imageNamed:@"reserveYES.png"] forState:UIControlStateNormal]; [_btnNO setImage:[UIImage imageNamed:@"reserveNO.png"] forState:UIControlStateNormal]; [_selectBtn setImage:[UIImage imageNamed:@"selectAll.png"] forState:UIControlStateNormal]; [_selectBtn setImage:[UIImage imageNamed:@"selectedAll.png"] forState:UIControlStateSelected]; [self.imageView borderColor:defGreen width:1 cornorRadios:5]; [self.textLabel setFont:[UIFont scaleSize:Font16]]; [self.detailTextLabel setFont:[UIFont scaleSize:Font16]]; [_dateLabel setFont:[UIFont scaleSize:Font16]]; [self.textLabel setTextColor:contentTextColor]; [self.detailTextLabel setTextColor:contentTextColor]; [_dateLabel setTextColor:contentTextColor]; //[self.detailTextLabel setNumberOfLines:0]; [_btnYes target:self Tag:0]; [_btnNO target:self Tag:1]; [_selectBtn target:self Tag:2]; } return self; } - (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 } -(void)setModel:(NSDictionary *)model { _model = model; /** RI_TIME = 08:00-11:00, RO_STATUS = , RI_STATUS = 2, RO_ID = , RI_ID = 2075, CRDATE = 2016-07-13 09:07, RI_USER_TEL = 15255112618, PHOTO = http://fj.jppt.com.cn//upload/student/201606/7419620160624.jpg, RI_TASK_ID = 1492, RI_REASON = , RI_USER_NAME = 何玲玉, RI_USER = 340824199203124227, HEADIMG = */ //NSLog(@"是否同意------->%@",_model); NSString *headString = model[@"PHOTO"]; if (!headString || headString.length == 0) { headString = model[@"HEADIMG"]; } if (!headString) { headString = @""; } [self.imageView sd_setImageWithURL:[NSURL URLWithString:headString] placeholderImage:[UIImage imageNamed:@"noHeadImg.png"]]; [self.textLabel setText:[NSString stringWithFormat:@"学员姓名:%@",model[@"RI_USER_NAME"]]]; [self.detailTextLabel setText:[NSString stringWithFormat:@"联系电话:%@", model[@"RI_USER_TEL"]]]; if ([model[@"CRDATE"] length] > 5) { _dateLabel.text = [NSString stringWithFormat:@"申请日期:%@",[model[@"CRDATE"] substringFromIndex:5]]; }else{ _dateLabel.text = [NSString stringWithFormat:@"申请日期:%@",model[@"CRDATE"]]; } } -(void)setStyle:(int)style { if (1 == style) { _btnYes.hidden = YES; _btnNO.hidden = YES; ivReady.hidden = NO; }else{ _btnYes.hidden = NO; _btnNO.hidden = NO; ivReady.hidden = YES; } } -(void)setClickBlock:(BlockTypeVo)block { comp = block; } -(void)click:(MyBlockType)block { clkBlock = block; } -(void)layoutSubviews { [super layoutSubviews]; //CGFloat hei = self.height; CGFloat x,y,w,h,bd; if (!isCanEdit) { x = 20; w = h = 25; y = 40; _selectBtn.frame = CGRectMake(x, y, w, h); //图片规格:102*126 x = bd =20; y = 15; w = 51; h = 63; [self.imageView setFrame:CGRectMake(x, y, w, h)]; x += w + 10; w = 220; y = 10; h = 25; [self.textLabel setFrame:CGRectMake(x, y, w, h)]; y += h; [self.detailTextLabel setFrame:CGRectMake(x, y, w, h)]; y += h; w = kSize.width - x - 10; [_dateLabel setFrame:CGRectMake(x, y, w, h)]; y = 90; h = 30; w = 90; x = self.width - 50 - w; [_btnYes setFrame:CGRectMake(x, y, w, h)]; x -= w + bd; [_btnNO setFrame:CGRectMake(x, y, w, h)]; ivReady.frame = _btnNO.frame; }else{ x = 20; w = h = 25; y = 40; _selectBtn.frame = CGRectMake(x, y, w, h); w = 51; h = 63; // x = bd = 20; y = 15; [self.imageView setFrame:CGRectMake(60, y, w, h)]; // x += w + 10; w = 220; y = 10; h = 25; [self.textLabel setFrame:CGRectMake(120, y, w, h)]; y += h; [self.detailTextLabel setFrame:CGRectMake(120, y, w, h)]; y += h; [_dateLabel setFrame:CGRectMake(120, y, w, h)]; y = 90; h = 30; w = 90; x = self.width - 30 - w; [_btnYes setFrame:CGRectMake(x, y, w, h)]; x -= w; [_btnNO setFrame:CGRectMake(x, y, w, h)]; ivReady.frame = _btnNO.frame; } } -(void)setCanEdit { _selectBtn.hidden = NO; isCanEdit = YES; [self layoutSubviews]; } -(void)setCanNotEdit { _selectBtn.hidden = YES; isCanEdit = NO; [self layoutSubviews]; } #pragma mark 处理预约 -(void)btnClick:(UIButton*)sender { int tag = (int)sender.tag; if (tag == 0) { [self updateReserveState:1]; } if (tag == 1) { //拒绝的时候 要写原因的 [self getRefuseReason]; } if (tag == 2) { _selectBtn.selected = !_selectBtn.selected; clkBlock([NSString stringWithFormat:@"%d",_selectBtn.selected]); } } -(void)getRefuseReason { backView = [[UIView alloc] initWithFrame:kFrame]; backView.backgroundColor = [UIColor blackColor]; backView.alpha = .3; UITapGestureRecognizer *tapGR=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGR:)]; [backView addGestureRecognizer:tapGR]; [[UIApplication sharedApplication].delegate.window addSubview:backView]; alertV = [[UIView alloc] init]; alertV.bounds = CGRectMake(0, 0, 280, 250); alertV.alpha = 1; alertV.center = CGPointMake(kSize.width/2.0, kSize.height/2.0); alertV.y -= 20; alertV.backgroundColor = backGroundColor; [alertV corner:15]; [[UIApplication sharedApplication].delegate.window addSubview:alertV]; tfReason = [[UITextView alloc] initWithFrame:CGRectMake(10, 20, 260, 140)]; tfReason.delegate = self; [tfReason setFont:[UIFont scaleSize:Font18]]; [alertV addSubview:tfReason]; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 20, 260, 30)]; label.text = @"请输入拒绝原因(100字以内)"; label.textColor = contentTextColor; [alertV addSubview:label]; remindLabel = label; UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(190, 190, 70, 40)]; btn.backgroundColor = defGreen; [btn setTitle:@"确定" textColor:[UIColor whiteColor] font:Font18 fotState:UIControlStateNormal]; [btn corner:5]; [btn addTarget:self action:@selector(clickToAddReason:) forControlEvents:UIControlEventTouchUpInside]; btn.tag = 4; [alertV addSubview:btn]; btn = [[UIButton alloc] initWithFrame:CGRectMake(20, 190, 70, 40)]; btn.backgroundColor = defGreen; [btn setTitle:@"取消" textColor:[UIColor whiteColor] font:Font18 fotState:UIControlStateNormal]; [btn corner:5]; [btn addTarget:self action:@selector(clickToAddReason:) forControlEvents:UIControlEventTouchUpInside]; btn.tag = 5; [alertV addSubview:btn]; } -(void)tapGR:(UITapGestureRecognizer *)tapGR { [alertV endEditing:YES]; } -(void)clickToAddReason:(UIButton *)sender { if (sender.tag == 4) { if (tfReason.text.length > 52) { ShowMsg(@"字数不能超过50字"); return; } [[UIApplication sharedApplication].delegate.window endEditing:YES]; reasonString = tfReason.text; if (!reasonString) { reasonString = @""; } [alertV removeFromSuperview]; [backView removeFromSuperview]; [self updateReserveState:0]; } if (sender.tag == 5) { [[UIApplication sharedApplication].delegate.window endEditing:YES]; [alertV removeFromSuperview]; [backView removeFromSuperview]; return; } } -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [[UIApplication sharedApplication].delegate.window endEditing:YES]; } -(void)textViewDidBeginEditing:(UITextView *)textView { [remindLabel setTextColor:lineColor]; } -(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { NSMutableString * changedString=[[NSMutableString alloc]initWithString:textView.text]; [changedString replaceCharactersInRange:range withString:text]; if (changedString.length > 0) { [remindLabel setHidden:YES]; }else{ [remindLabel setHidden:NO]; } return YES; } -(void)updateReserveState:(BOOL)staus { NSMutableArray *arr=[NSMutableArray array]; [arr addPro:@"ids" Value:_model[@"RI_ID"]]; [arr addPro:@"status" Value:[NSString stringWithFormat:@"%d",staus]]; [arr addPro:@"reason" Value:reasonString]; NSString* method = @"betchUpdateReserveState"; // TICK; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * dict) { // TOCK; // return; //NSLog(@"同意或者拒绝预约请求-->%@->%@",arr,dict); if (!dict) { ShowMsg(@"操作失败"); return ; } if ( [dict[@"code"] isEqualToString:@"1"]) { ShowMsg(dict[@"body"]); return ; } if (comp) { comp(); } }]; } @end