ReplyCell.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. //
  2. // ReplyCell.m
  3. // jiaPeiC
  4. //
  5. // Created by apple on 15/12/25.
  6. // Copyright © 2015年 JCZ. All rights reserved.
  7. //
  8. #import "ReplyCell.h"
  9. @interface ReplyCell()<UITextViewDelegate>
  10. {
  11. UITextView *tfReason;
  12. UIView *backView;
  13. UIView *alertV;
  14. UILabel *remindLabel;
  15. NSString *reasonString;
  16. BOOL isCanEdit;
  17. }
  18. @end
  19. @implementation ReplyCell
  20. +(id)cellForTabelView:(UITableView*)tableView;
  21. {
  22. ReplyCell* cell = [tableView dequeueReusableCellWithIdentifier:@"ReplyCell"];
  23. if (!cell) {
  24. cell = [[ReplyCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"ReplyCell"];
  25. }
  26. return cell;
  27. }
  28. -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  29. {
  30. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  31. if (self) {
  32. UIButton* btn ;UIImageView *iv;
  33. iv = [UIImageView new];
  34. [iv imageName:@"imgRefuse.png"];
  35. [iv setHidden:YES];
  36. [self addSubview:iv];
  37. ivReady = iv;
  38. UILabel *label = [UILabel new];
  39. [self addSubview:label];
  40. _dateLabel = label;
  41. btn = [UIButton new];
  42. [self addSubview:btn];
  43. _btnYes = btn;
  44. btn = [UIButton new];
  45. [self addSubview:btn];
  46. _btnNO = btn;
  47. btn = [UIButton new];
  48. btn.hidden = YES;
  49. [self addSubview:btn];
  50. _selectBtn = btn;
  51. [_btnYes setImage:[UIImage imageNamed:@"reserveYES.png"] forState:UIControlStateNormal];
  52. [_btnNO setImage:[UIImage imageNamed:@"reserveNO.png"] forState:UIControlStateNormal];
  53. [_selectBtn setImage:[UIImage imageNamed:@"selectAll.png"] forState:UIControlStateNormal];
  54. [_selectBtn setImage:[UIImage imageNamed:@"selectedAll.png"] forState:UIControlStateSelected];
  55. [self.imageView borderColor:defGreen width:1 cornorRadios:5];
  56. [self.textLabel setFont:[UIFont scaleSize:Font16]];
  57. [self.detailTextLabel setFont:[UIFont scaleSize:Font16]];
  58. [_dateLabel setFont:[UIFont scaleSize:Font16]];
  59. [self.textLabel setTextColor:contentTextColor];
  60. [self.detailTextLabel setTextColor:contentTextColor];
  61. [_dateLabel setTextColor:contentTextColor];
  62. //[self.detailTextLabel setNumberOfLines:0];
  63. [_btnYes target:self Tag:0];
  64. [_btnNO target:self Tag:1];
  65. [_selectBtn target:self Tag:2];
  66. }
  67. return self;
  68. }
  69. - (void)awakeFromNib {
  70. [super awakeFromNib];
  71. // Initialization code
  72. }
  73. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  74. [super setSelected:selected animated:animated];
  75. // Configure the view for the selected state
  76. }
  77. -(void)setModel:(NSDictionary *)model
  78. {
  79. _model = model;
  80. /**
  81. RI_TIME = 08:00-11:00,
  82. RO_STATUS = ,
  83. RI_STATUS = 2,
  84. RO_ID = ,
  85. RI_ID = 2075,
  86. CRDATE = 2016-07-13 09:07,
  87. RI_USER_TEL = 15255112618,
  88. PHOTO = http://fj.jppt.com.cn//upload/student/201606/7419620160624.jpg,
  89. RI_TASK_ID = 1492,
  90. RI_REASON = ,
  91. RI_USER_NAME = 何玲玉,
  92. RI_USER = 340824199203124227,
  93. HEADIMG =
  94. */
  95. //NSLog(@"是否同意------->%@",_model);
  96. NSString *headString = model[@"PHOTO"];
  97. if (!headString || headString.length == 0) {
  98. headString = model[@"HEADIMG"];
  99. if (headString && ![headString hasPrefix:@"http"]){
  100. headString = [imgPreFix stringByAppendingString:headString];
  101. }
  102. }else{
  103. NSString *photoString = @"http://fj.jppt.com.cn";
  104. if (headString && ![headString hasPrefix:@"http"]){
  105. headString = [photoString stringByAppendingString:headString];
  106. }
  107. }
  108. if (!headString) {
  109. headString = @"";
  110. }
  111. [self.imageView sd_setImageWithURL:[NSURL URLWithString:headString] placeholderImage:[UIImage imageNamed:@"noHeadImg.png"]];
  112. [self.textLabel setText:[NSString stringWithFormat:@"学员姓名:%@",model[@"RI_USER_NAME"]]];
  113. [self.detailTextLabel setText:[NSString stringWithFormat:@"联系电话:%@",
  114. model[@"RI_USER_TEL"]]];
  115. if ([model[@"CRDATE"] length] > 5) {
  116. _dateLabel.text = [NSString stringWithFormat:@"申请日期:%@",[model[@"CRDATE"] substringFromIndex:5]];
  117. }else{
  118. _dateLabel.text = [NSString stringWithFormat:@"申请日期:%@",model[@"CRDATE"]];
  119. }
  120. }
  121. -(void)setStyle:(int)style
  122. {
  123. if (1 == style) {
  124. _btnYes.hidden = YES;
  125. _btnNO.hidden = YES;
  126. ivReady.hidden = NO;
  127. }else{
  128. _btnYes.hidden = NO;
  129. _btnNO.hidden = NO;
  130. ivReady.hidden = YES;
  131. }
  132. }
  133. -(void)setClickBlock:(BlockTypeVo)block
  134. {
  135. comp = block;
  136. }
  137. -(void)click:(MyBlockType)block
  138. {
  139. clkBlock = block;
  140. }
  141. -(void)layoutSubviews
  142. {
  143. [super layoutSubviews];
  144. //CGFloat hei = self.height;
  145. CGFloat x,y,w,h,bd;
  146. if (!isCanEdit) {
  147. x = 20;
  148. w = h = 25;
  149. y = 40;
  150. _selectBtn.frame = CGRectMake(x, y, w, h);
  151. //图片规格:102*126
  152. x = bd =20;
  153. y = 15;
  154. w = 51;
  155. h = 63;
  156. [self.imageView setFrame:CGRectMake(x, y, w, h)];
  157. x += w + 10;
  158. w = 220;
  159. y = 10;
  160. h = 25;
  161. [self.textLabel setFrame:CGRectMake(x, y, w, h)];
  162. y += h;
  163. [self.detailTextLabel setFrame:CGRectMake(x, y, w, h)];
  164. y += h;
  165. w = kSize.width - x - 10;
  166. [_dateLabel setFrame:CGRectMake(x, y, w, h)];
  167. y = 90;
  168. h = 30;
  169. w = 90;
  170. x = self.width - 50 - w;
  171. [_btnYes setFrame:CGRectMake(x, y, w, h)];
  172. x -= w + bd;
  173. [_btnNO setFrame:CGRectMake(x, y, w, h)];
  174. ivReady.frame = _btnNO.frame;
  175. }else{
  176. x = 20;
  177. w = h = 25;
  178. y = 40;
  179. _selectBtn.frame = CGRectMake(x, y, w, h);
  180. w = 51;
  181. h = 63;
  182. // x = bd = 20;
  183. y = 15;
  184. [self.imageView setFrame:CGRectMake(60, y, w, h)];
  185. // x += w + 10;
  186. w = 220;
  187. y = 10;
  188. h = 25;
  189. [self.textLabel setFrame:CGRectMake(120, y, w, h)];
  190. y += h;
  191. [self.detailTextLabel setFrame:CGRectMake(120, y, w, h)];
  192. y += h;
  193. [_dateLabel setFrame:CGRectMake(120, y, w, h)];
  194. y = 90;
  195. h = 30;
  196. w = 90;
  197. x = self.width - 30 - w;
  198. [_btnYes setFrame:CGRectMake(x, y, w, h)];
  199. x -= w;
  200. [_btnNO setFrame:CGRectMake(x, y, w, h)];
  201. ivReady.frame = _btnNO.frame;
  202. }
  203. }
  204. -(void)setCanEdit
  205. {
  206. _selectBtn.hidden = NO;
  207. isCanEdit = YES;
  208. [self layoutSubviews];
  209. }
  210. -(void)setCanNotEdit
  211. {
  212. _selectBtn.hidden = YES;
  213. isCanEdit = NO;
  214. [self layoutSubviews];
  215. }
  216. #pragma mark 处理预约
  217. -(void)btnClick:(UIButton*)sender
  218. {
  219. int tag = (int)sender.tag;
  220. if (tag == 0) {
  221. [self updateReserveState:1];
  222. }
  223. if (tag == 1) {
  224. //拒绝的时候 要写原因的
  225. [self getRefuseReason];
  226. }
  227. if (tag == 2) {
  228. _selectBtn.selected = !_selectBtn.selected;
  229. clkBlock([NSString stringWithFormat:@"%d",_selectBtn.selected]);
  230. }
  231. }
  232. -(void)getRefuseReason
  233. {
  234. backView = [[UIView alloc] initWithFrame:kFrame];
  235. backView.backgroundColor = [UIColor blackColor];
  236. backView.alpha = .3;
  237. UITapGestureRecognizer *tapGR=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGR:)];
  238. [backView addGestureRecognizer:tapGR];
  239. [[UIApplication sharedApplication].delegate.window addSubview:backView];
  240. alertV = [[UIView alloc] init];
  241. alertV.bounds = CGRectMake(0, 0, 280, 250);
  242. alertV.alpha = 1;
  243. alertV.center = CGPointMake(kSize.width/2.0, kSize.height/2.0);
  244. alertV.y -= 20;
  245. alertV.backgroundColor = backGroundColor;
  246. [alertV corner:15];
  247. [[UIApplication sharedApplication].delegate.window addSubview:alertV];
  248. tfReason = [[UITextView alloc] initWithFrame:CGRectMake(10, 20, 260, 140)];
  249. tfReason.delegate = self;
  250. [tfReason setFont:[UIFont scaleSize:Font18]];
  251. [alertV addSubview:tfReason];
  252. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 20, 260, 30)];
  253. label.text = @"请输入拒绝原因(100字以内)";
  254. label.textColor = contentTextColor;
  255. [alertV addSubview:label];
  256. remindLabel = label;
  257. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(190, 190, 70, 40)];
  258. btn.backgroundColor = defGreen;
  259. [btn setTitle:@"确定" textColor:[UIColor whiteColor] font:Font18 fotState:UIControlStateNormal];
  260. [btn corner:5];
  261. [btn addTarget:self action:@selector(clickToAddReason:) forControlEvents:UIControlEventTouchUpInside];
  262. btn.tag = 4;
  263. [alertV addSubview:btn];
  264. btn = [[UIButton alloc] initWithFrame:CGRectMake(20, 190, 70, 40)];
  265. btn.backgroundColor = defGreen;
  266. [btn setTitle:@"取消" textColor:[UIColor whiteColor] font:Font18 fotState:UIControlStateNormal];
  267. [btn corner:5];
  268. [btn addTarget:self action:@selector(clickToAddReason:) forControlEvents:UIControlEventTouchUpInside];
  269. btn.tag = 5;
  270. [alertV addSubview:btn];
  271. }
  272. -(void)tapGR:(UITapGestureRecognizer *)tapGR
  273. {
  274. [alertV endEditing:YES];
  275. }
  276. -(void)clickToAddReason:(UIButton *)sender
  277. {
  278. if (sender.tag == 4) {
  279. if (tfReason.text.length > 52) {
  280. ShowMsg(@"字数不能超过50字");
  281. return;
  282. }
  283. [[UIApplication sharedApplication].delegate.window endEditing:YES];
  284. reasonString = tfReason.text;
  285. if (!reasonString) {
  286. reasonString = @"";
  287. }
  288. [alertV removeFromSuperview];
  289. [backView removeFromSuperview];
  290. [self updateReserveState:0];
  291. }
  292. if (sender.tag == 5) {
  293. [[UIApplication sharedApplication].delegate.window endEditing:YES];
  294. [alertV removeFromSuperview];
  295. [backView removeFromSuperview];
  296. return;
  297. }
  298. }
  299. -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
  300. {
  301. [[UIApplication sharedApplication].delegate.window endEditing:YES];
  302. }
  303. -(void)textViewDidBeginEditing:(UITextView *)textView
  304. {
  305. [remindLabel setTextColor:lineColor];
  306. }
  307. -(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
  308. {
  309. NSMutableString * changedString=[[NSMutableString alloc]initWithString:textView.text];
  310. [changedString replaceCharactersInRange:range withString:text];
  311. if (changedString.length > 0) {
  312. [remindLabel setHidden:YES];
  313. }else{
  314. [remindLabel setHidden:NO];
  315. }
  316. return YES;
  317. }
  318. -(void)updateReserveState:(BOOL)staus
  319. {
  320. NSMutableArray *arr=[NSMutableArray array];
  321. [arr addPro:@"ids" Value:_model[@"RI_ID"]];
  322. [arr addPro:@"status" Value:[NSString stringWithFormat:@"%d",staus]];
  323. [arr addPro:@"reason" Value:reasonString];
  324. NSString* method = @"betchUpdateReserveState";
  325. // TICK;
  326. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * dict) {
  327. // TOCK;
  328. // return;
  329. //NSLog(@"同意或者拒绝预约请求-->%@->%@",arr,dict);
  330. if (!dict) {
  331. ShowMsg(@"操作失败");
  332. return ;
  333. }
  334. if ( [dict[@"code"] isEqualToString:@"1"]) {
  335. ShowMsg(dict[@"body"]);
  336. return ;
  337. }
  338. if (comp) {
  339. comp();
  340. }
  341. }];
  342. }
  343. @end