ReserveCell.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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] setxywh];
  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] setxywh];
  57. [self.contentView addSubview:label];
  58. stateLabel = label;
  59. y += h;
  60. h = 40;
  61. label = [[UILabel alloc] setxywh];
  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] setxywh];
  69. [cancelBtn borderColor:defGreen width:1.3 cornorRadios:5];
  70. [cancelBtn setTitle:@"取消预约" textColor:defGreen font:NormalFont fotState:UIControlStateNormal];
  71. [cancelBtn target:self];
  72. [self.contentView addSubview:cancelBtn];
  73. // nameLabel = label;
  74. //
  75. // x += w;
  76. // label = [[UILabel alloc] setxywh];
  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:NormalFont 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 rq_defaultDateFormatter];
  103. NSDate *taskDate = [formatter dateFromString:[NSString stringWithFormat:@"%@ %@:00",_dataDic[@"PI_TASK_TIME"],[[_dataDic[@"PI_TIMES"] componentsSeparatedByString:@"-"] lastObject]]];
  104. NSComparisonResult result = [taskDate compare:[NSDate date]];
  105. if (result == NSOrderedAscending){
  106. //ShowMsg(@"教练计划已过期,不能取消");
  107. cancelBtn.backgroundColor = KlineColor;
  108. [cancelBtn setTitleColor:contentTextColor forState:UIControlStateNormal];
  109. [cancelBtn borderColor:KlineColor width:1.3 cornorRadios:5];
  110. cancelBtn.userInteractionEnabled = NO;
  111. cancelBtn.hidden = YES;
  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. cancelBtn.hidden = NO;
  118. }
  119. }
  120. break;
  121. case 2: //预约中
  122. {
  123. stateString = @"教练还未审核您的预约申请,请耐心等待哦";
  124. cancelBtn.hidden = NO;
  125. //判断时间是否已经过期 过期就不能再取消了 这里用的是计划的结束时间 服务器好像是开始时间 改lastObject这个就好了
  126. NSDateFormatter *formatter = [NSDateFormatter rq_defaultDateFormatter];
  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:contentTextColor forState:UIControlStateNormal];
  133. [cancelBtn borderColor:KlineColor width:1.3 cornorRadios:5];
  134. cancelBtn.userInteractionEnabled = NO;
  135. cancelBtn.hidden = YES;
  136. }else{
  137. cancelBtn.backgroundColor = [UIColor clearColor];
  138. [cancelBtn setTitleColor:defGreen forState:UIControlStateNormal];
  139. [cancelBtn borderColor:defGreen width:1.3 cornorRadios:5];
  140. cancelBtn.userInteractionEnabled = YES;
  141. cancelBtn.hidden = NO;
  142. }
  143. }
  144. break;
  145. case 3: //已取消
  146. stateString = @"您已取消了本次预约,可在教练计划中重新申请哦";
  147. cancelBtn.hidden = YES;
  148. break;
  149. default:
  150. break;
  151. }
  152. [stateLabel setText:stateString Font:NormalFont TextColor:kTitleColor Alignment:NSTextAlignmentLeft];
  153. [reasonLabel setText:dataDic[@"RI_REASON"] Font:NormalFont TextColor:kTitleColor Alignment:NSTextAlignmentLeft];
  154. [nameLabel setText:[NSString stringWithFormat:@"教练:%@",dataDic[@"PI_USER_NAME"]] Font:NormalFont TextColor:kTitleColor Alignment:NSTextAlignmentLeft];
  155. [dateLabel setText:[NSString stringWithFormat:@"日期:%@",dataDic[@"PI_TASK_TIME"]] Font:NormalFont TextColor:kTitleColor Alignment:NSTextAlignmentLeft];
  156. [timeLabel setText:[NSString stringWithFormat:@"时间:%@",dataDic[@"PI_TIMES"]] Font:NormalFont TextColor:kTitleColor Alignment:NSTextAlignmentLeft];
  157. NSString *kmString = @"科目二";
  158. if ([dataDic[@"PI_KM"] isEqualToString:@"3"]) {
  159. kmString = @"科目三";
  160. }
  161. [kmLabel setText:kmString Font:NormalFont TextColor:[UIColor orangeColor] Alignment:NSTextAlignmentCenter];
  162. [priceLabel setText:[NSString stringWithFormat:@"%@元/小时",dataDic[@"PI_MONEY"]] Font:NormalFont TextColor:[UIColor orangeColor] Alignment:NSTextAlignmentCenter];
  163. NSString *countString = [NSString stringWithFormat:@"已约%@人,可约%@人",dataDic[@"PI_HAV_NUM"],dataDic[@"PI_NUM"]];
  164. [countLabel setText:countString Font:NormalFont TextColor:kTitleColor Alignment:NSTextAlignmentCenter];
  165. NSMutableAttributedString *abs = [[NSMutableAttributedString alloc]initWithString:countString];
  166. NSRange range1 = [countString rangeOfString:dataDic[@"PI_HAV_NUM"]];
  167. NSRange range2 = [countString rangeOfString:dataDic[@"PI_NUM"]];
  168. if ([dataDic[@"PI_HAV_NUM"] isEqualToString:dataDic[@"PI_NUM"]]) {
  169. //防止两个值相等的时候 range1 == range2
  170. if ([dataDic[@"PI_HAV_NUM"] length] == 1) {
  171. range2 = NSMakeRange(7, 1);
  172. }
  173. if ([dataDic[@"PI_HAV_NUM"] length] == 2) {
  174. range2 = NSMakeRange(8, 2);
  175. }
  176. }
  177. [abs beginEditing];
  178. //字体大小
  179. [abs addAttribute:NSFontAttributeName
  180. value:[UIFont scaleSize:20.0]
  181. range:range1];
  182. [abs addAttribute:NSFontAttributeName
  183. value:[UIFont scaleSize:20.0]
  184. range:range2];
  185. //字体颜色
  186. [abs addAttribute:NSForegroundColorAttributeName
  187. value:[UIColor orangeColor]
  188. range:range1];
  189. [abs addAttribute:NSForegroundColorAttributeName
  190. value:[UIColor orangeColor]
  191. range:range2];
  192. //下划线
  193. [abs addAttribute:NSUnderlineStyleAttributeName
  194. value:@(NSUnderlineStyleSingle)
  195. range:range1];
  196. [abs addAttribute:NSUnderlineStyleAttributeName
  197. value:@(NSUnderlineStyleSingle)
  198. range:range2];
  199. countLabel.attributedText = abs;
  200. }
  201. -(void)click:(BlockTypeVo)block
  202. {
  203. clkBlock = block;
  204. }
  205. -(void)btnClick:(UIButton*)sender
  206. {
  207. //NSLog(@"当前要取消的预约%@",_dataDic)
  208. //这个地方要写取消预约的操作
  209. [self cancelReserve];
  210. }
  211. -(void)cancelReserve
  212. {
  213. if (![Util connectedToNetWork]) {
  214. return;
  215. }
  216. //NSLog(@"cell---->%@",_dataDic);
  217. NSMutableArray *arr=[NSMutableArray array];
  218. [arr addPro:@"pid" Value:_dataDic[@"PI_ID"]];
  219. [arr addPro:@"reserveId" Value:_dataDic[@"RI_ID"]];
  220. [arr addPro:@"jxbh" Value:_dataDic[@"JXBH"]];
  221. NSString* method = @"cancelReserve";
  222. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  223. //NSLog(@"取消预约---->%@---->%@",arr,root);
  224. if (!root)
  225. {
  226. [LoadingView showMsg:@"操作失败"];
  227. return;
  228. }
  229. if ([root[@"code"] isEqualToString:@"1"]) {
  230. [LoadingView showMsg:root[@"body"]];
  231. return;
  232. }
  233. ShowMsgSuc();
  234. if (clkBlock) {
  235. clkBlock();
  236. }
  237. }];
  238. }
  239. @end