ReplyCell.m 11 KB

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