ReserveCell.m 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. //
  2. // ReserveCell.m
  3. // jiaPei
  4. //
  5. // Created by apple on 16/6/29.
  6. // Copyright © 2016年 JCZ. All rights reserved.
  7. //
  8. #import "ReserveCell.h"
  9. @implementation ReserveCell
  10. - (void)awakeFromNib {
  11. [super awakeFromNib];
  12. // Initialization code
  13. }
  14. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  15. [super setSelected:selected animated:animated];
  16. // Configure the view for the selected state
  17. }
  18. -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  19. {
  20. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  21. if (self) {
  22. self.backgroundColor = [UIColor whiteColor];
  23. UILabel *label;
  24. CGFloat x,y,w,h;
  25. x = 20;
  26. y = 0;
  27. w = kSize.width - 40;
  28. h = 30;
  29. label = [[UILabel alloc] KSetxywh];
  30. [self.contentView addSubview:label];
  31. RDatelabel = label;
  32. [label addViewWithRect:CGRectMake(10, h, kSize.width - 20, 1)];
  33. y += h + 5;
  34. w = kSize.width/2.0 - 20;
  35. h = 25;
  36. NSMutableArray *labels = [NSMutableArray arrayWithCapacity:6];
  37. for (int i = 0; i < 3; i ++) {
  38. label = [[UILabel alloc] initWithFrame:CGRectMake(x, y + h*i, w, h)];
  39. [self.contentView addSubview:label];
  40. [labels addObject:label];
  41. label = [[UILabel alloc] initWithFrame:CGRectMake(x + w, y + h*i, w, h)];
  42. [self.contentView addSubview:label];
  43. [labels addObject:label];
  44. }
  45. nameLabel = labels[0];
  46. kmLabel = labels[1];
  47. dateLabel = labels[2];
  48. priceLabel = labels[3];
  49. timeLabel = labels[4];
  50. countLabel = labels[5];
  51. y += 3*h + 4;
  52. [countLabel addViewWithRect:CGRectMake(10, y, kSize.width - 20, 1)];
  53. y += 5;
  54. w = kSize.width - 40;
  55. h = 20;
  56. label = [[UILabel alloc] KSetxywh];
  57. [self.contentView addSubview:label];
  58. stateLabel = label;
  59. y += h;
  60. h = 40;
  61. label = [[UILabel alloc] KSetxywh];
  62. label.numberOfLines = 0;
  63. [self.contentView addSubview:label];
  64. reasonLabel = label;
  65. x = kSize.width - 100;
  66. w = 80;
  67. h = 30;
  68. cancelBtn = [[UIButton alloc] KSetxywh];
  69. [cancelBtn borderColor:defGreen width:1.3 cornorRadios:5];
  70. [cancelBtn setTitle:@"取消预约" textColor:defGreen font:Font16 fotState:UIControlStateNormal];
  71. [cancelBtn target:self];
  72. [self.contentView addSubview:cancelBtn];
  73. // nameLabel = label;
  74. //
  75. // x += w;
  76. // label = [[UILabel alloc] KSetxywh];
  77. // [self.contentView addSubview:label];
  78. // kmLabel = label;
  79. }
  80. return self;
  81. }
  82. -(void)setDataDic:(NSDictionary *)dataDic
  83. {
  84. _dataDic = dataDic;
  85. //NSLog(@"----><>%@",dataDic);
  86. NSString *dateS = dataDic[@"RI_CRDATE"];
  87. if (dateS.length > 16) {
  88. dateS = [NSString stringWithFormat:@"%@(预约时间)",[dateS substringToIndex:16]];
  89. }
  90. [RDatelabel setText:dateS Font:Font16 TextColor:KTitleColor Alignment:NSTextAlignmentRight];
  91. NSString *stateString = @"";
  92. switch ([dataDic[@"RI_STATUS"] integerValue]) {
  93. case 0: //拒绝
  94. stateString = @"教练已拒绝了您的预约申请,可以试下其他的计划哦";
  95. cancelBtn.hidden = YES;
  96. break;
  97. case 1: //同意
  98. {
  99. stateString = @"教练已同意了您的预约申请,祝您练车愉快!";
  100. cancelBtn.hidden = NO;
  101. //判断时间是否已经过期 过期就不能再取消了 这里用的是计划的结束时间 服务器好像是开始时间 改lastObject这个就好了
  102. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  103. [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  104. NSDate *taskDate = [formatter dateFromString:[NSString stringWithFormat:@"%@ %@:00",_dataDic[@"PI_TASK_TIME"],[[_dataDic[@"PI_TIMES"] componentsSeparatedByString:@"-"] lastObject]]];
  105. NSComparisonResult result = [taskDate compare:[NSDate date]];
  106. if (result == NSOrderedAscending){
  107. //ShowMsg(@"教练计划已过期,不能取消");
  108. cancelBtn.backgroundColor = kLineColor;
  109. [cancelBtn setTitleColor:KContentTextColor forState:UIControlStateNormal];
  110. [cancelBtn borderColor:kLineColor width:1.3 cornorRadios:5];
  111. cancelBtn.userInteractionEnabled = NO;
  112. }else{
  113. cancelBtn.backgroundColor = [UIColor clearColor];
  114. [cancelBtn setTitleColor:defGreen forState:UIControlStateNormal];
  115. [cancelBtn borderColor:defGreen width:1.3 cornorRadios:5];
  116. cancelBtn.userInteractionEnabled = YES;
  117. }
  118. }
  119. break;
  120. case 2: //预约中
  121. {
  122. stateString = @"教练还未审核您的预约申请,请耐心等待哦";
  123. cancelBtn.hidden = NO;
  124. //判断时间是否已经过期 过期就不能再取消了 这里用的是计划的结束时间 服务器好像是开始时间 改lastObject这个就好了
  125. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  126. [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  127. NSDate *taskDate = [formatter dateFromString:[NSString stringWithFormat:@"%@ %@:00",_dataDic[@"PI_TASK_TIME"],[[_dataDic[@"PI_TIMES"] componentsSeparatedByString:@"-"] firstObject]]];
  128. NSComparisonResult result = [taskDate compare:[NSDate date]];
  129. if (result == NSOrderedAscending){
  130. //ShowMsg(@"教练计划已过期,不能取消");
  131. cancelBtn.backgroundColor = kLineColor;
  132. [cancelBtn setTitleColor:KContentTextColor forState:UIControlStateNormal];
  133. cancelBtn.userInteractionEnabled = NO;
  134. }else{
  135. cancelBtn.backgroundColor = [UIColor clearColor];
  136. [cancelBtn setTitleColor:defGreen forState:UIControlStateNormal];
  137. cancelBtn.userInteractionEnabled = YES;
  138. }
  139. }
  140. break;
  141. case 3: //已取消
  142. stateString = @"您已取消了本次预约,可在教练计划中重新申请哦";
  143. cancelBtn.hidden = YES;
  144. break;
  145. default:
  146. break;
  147. }
  148. [stateLabel setText:stateString Font:Font16 TextColor:KTitleColor Alignment:NSTextAlignmentLeft];
  149. [reasonLabel setText:dataDic[@"RI_REASON"] Font:Font16 TextColor:KTitleColor Alignment:NSTextAlignmentLeft];
  150. [nameLabel setText:[NSString stringWithFormat:@"教练:%@",dataDic[@"PI_USER_NAME"]] Font:Font16 TextColor:KTitleColor Alignment:NSTextAlignmentLeft];
  151. [dateLabel setText:[NSString stringWithFormat:@"日期:%@",dataDic[@"PI_TASK_TIME"]] Font:Font16 TextColor:KTitleColor Alignment:NSTextAlignmentLeft];
  152. [timeLabel setText:[NSString stringWithFormat:@"时间:%@",dataDic[@"PI_TIMES"]] Font:Font16 TextColor:KTitleColor Alignment:NSTextAlignmentLeft];
  153. NSString *kmString = @"科目二";
  154. if ([dataDic[@"PI_KM"] isEqualToString:@"3"]) {
  155. kmString = @"科目三";
  156. }
  157. [kmLabel setText:kmString Font:Font16 TextColor:[UIColor orangeColor] Alignment:NSTextAlignmentCenter];
  158. [priceLabel setText:[NSString stringWithFormat:@"%@元/小时",dataDic[@"PI_MONEY"]] Font:Font16 TextColor:[UIColor orangeColor] Alignment:NSTextAlignmentCenter];
  159. NSString *countString = [NSString stringWithFormat:@"已约%@人,可约%@人",dataDic[@"PI_HAV_NUM"],dataDic[@"PI_NUM"]];
  160. [countLabel setText:countString Font:Font16 TextColor:KTitleColor Alignment:NSTextAlignmentCenter];
  161. NSMutableAttributedString *abs = [[NSMutableAttributedString alloc]initWithString:countString];
  162. NSRange range1 = [countString rangeOfString:dataDic[@"PI_HAV_NUM"]];
  163. NSRange range2 = [countString rangeOfString:dataDic[@"PI_NUM"]];
  164. if ([dataDic[@"PI_HAV_NUM"] isEqualToString:dataDic[@"PI_NUM"]]) {
  165. //防止两个值相等的时候 range1 == range2
  166. if ([dataDic[@"PI_HAV_NUM"] length] == 1) {
  167. range2 = NSMakeRange(7, 1);
  168. }
  169. if ([dataDic[@"PI_HAV_NUM"] length] == 2) {
  170. range2 = NSMakeRange(8, 2);
  171. }
  172. }
  173. [abs beginEditing];
  174. //字体大小
  175. [abs addAttribute:NSFontAttributeName
  176. value:[UIFont scaleSize:20.0]
  177. range:range1];
  178. [abs addAttribute:NSFontAttributeName
  179. value:[UIFont scaleSize:20.0]
  180. range:range2];
  181. //字体颜色
  182. [abs addAttribute:NSForegroundColorAttributeName
  183. value:[UIColor orangeColor]
  184. range:range1];
  185. [abs addAttribute:NSForegroundColorAttributeName
  186. value:[UIColor orangeColor]
  187. range:range2];
  188. //下划线
  189. [abs addAttribute:NSUnderlineStyleAttributeName
  190. value:@(NSUnderlineStyleSingle)
  191. range:range1];
  192. [abs addAttribute:NSUnderlineStyleAttributeName
  193. value:@(NSUnderlineStyleSingle)
  194. range:range2];
  195. countLabel.attributedText = abs;
  196. }
  197. -(void)click:(BlockTypeVo)block
  198. {
  199. clkBlock = block;
  200. }
  201. -(void)btnClick:(UIButton*)sender
  202. {
  203. //NSLog(@"当前要取消的预约%@",_dataDic)
  204. //这个地方要写取消预约的操作
  205. [self cancelReserve];
  206. }
  207. -(void)cancelReserve
  208. {
  209. //NSLog(@"取消预约---->%@---->%@",arr,root);
  210. // if (!root)
  211. // {
  212. // [LoadingView showMsg:@"操作失败"];
  213. // return;
  214. // }
  215. // if ([root[@"code"] isEqualToString:@"1"]) {
  216. //
  217. // [LoadingView showMsg:root[@"body"]];
  218. // return;
  219. // }
  220. //
  221. // ShowMsgSuc();
  222. //
  223. // if (clkBlock) {
  224. // clkBlock();
  225. // }
  226. }
  227. @end