MyPlanVCHeader.m 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. //
  2. // MyPlanVCHeader.m
  3. // jiaPeiC
  4. //
  5. // Created by apple on 16/8/17.
  6. // Copyright © 2016年 JCZ. All rights reserved.
  7. //
  8. #import "MyPlanVCHeader.h"
  9. //NSInteger typeInt;
  10. @implementation MyPlanVCHeader
  11. -(instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
  12. {
  13. self = [super initWithReuseIdentifier:reuseIdentifier];
  14. if (self) {
  15. self.contentView.backgroundColor = [UIColor whiteColor];
  16. UILabel *label;
  17. UIButton *btn;
  18. UIImageView *iv;
  19. UIView *blackV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 15)];
  20. blackV.backgroundColor = lineColor;
  21. [self.contentView addSubview:blackV];
  22. label = [UILabel new];
  23. [self.contentView addSubview:label];
  24. _waitLabel = label;
  25. label = [UILabel new];
  26. [self.contentView addSubview:label];
  27. _stateLabel = label;
  28. label = [UILabel new];
  29. [self.contentView addSubview:label];
  30. lblDate = label;
  31. label = [UILabel new];
  32. [self.contentView addSubview:label];
  33. lblNum = label;
  34. label = [UILabel new];
  35. [self.contentView addSubview:label];
  36. titNum = label;
  37. label = [UILabel new];
  38. [self.contentView addSubview:label];
  39. titDate = label;
  40. label = [UILabel new];
  41. [self.contentView addSubview:label];
  42. titCountLabel = label;
  43. label = [UILabel new];
  44. [self.contentView addSubview:label];
  45. countLabel = label;
  46. label = [UILabel new];
  47. [self.contentView addSubview:label];
  48. moneyLabel = label;
  49. iv = [UIImageView new];
  50. [self.contentView addSubview:iv];
  51. imgDate = iv;
  52. iv = [UIImageView new];
  53. [self.contentView addSubview:iv];
  54. imgNum = iv;
  55. btn = [UIButton new];
  56. [self.contentView addSubview:btn];
  57. _btnScan = btn;
  58. btn = [UIButton new];
  59. [btn addTarget:self action:@selector(headerBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  60. btn.tag = 1;
  61. [self.contentView addSubview:btn];
  62. _btnEdit = btn;
  63. btn = [UIButton new];
  64. [btn addTarget:self action:@selector(headerBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  65. btn.tag = 2;
  66. [self.contentView addSubview:btn];
  67. btn.hidden = YES;
  68. _btnAll = btn;
  69. //下面要用 所以先写出来
  70. [titDate setText:@"练车时间:"];
  71. [titNum setText:@"可约人数:"];
  72. [titCountLabel setText:@"已约人数:"];
  73. CGFloat wid = kSize.width;
  74. CGFloat x,y,w,h,bd;
  75. //预约情况
  76. x = y = bd = 20;
  77. w = 180;
  78. h = 30;
  79. _waitLabel.frame = setDIYFrame;
  80. //是否计时中
  81. w = wid - x - 120;
  82. _stateLabel.frame = setDIYFrame;
  83. //展开按钮
  84. w = 70;
  85. x = wid - w - 20;
  86. _btnScan.frame = setDIYFrame;
  87. [_btnScan addViewWithRect:CGRectMake(10, y + h + 4, kSize.width - 20, 1)];
  88. x = 15;
  89. y += h + 5;
  90. w = h = 25;
  91. imgDate.frame = setDIYFrame;
  92. imgNum.frame = CGRectMake(x, y + h, w, h);
  93. x += w +10;
  94. w = [titDate.text sizeForFont:Font14].width;
  95. titDate.frame = setDIYFrame;
  96. titCountLabel.frame = CGRectMake(x, y + h, w, h);
  97. x += w;
  98. w = wid - 100;
  99. lblDate.frame = setDIYFrame;//日期值
  100. w = 40;
  101. countLabel.frame = CGRectMake(x, y + h, w, h);//已约人数
  102. x = wid - 100;
  103. w = 80;
  104. moneyLabel.frame = setDIYFrame;
  105. w = [titNum.text sizeForFont:Font14].width;
  106. x = wid - w - 60;
  107. y += h;
  108. titNum.frame = setDIYFrame;
  109. x += w;
  110. w = 40;
  111. lblNum.frame = setDIYFrame;//可约人数
  112. //全选按钮
  113. x = bd;
  114. y += h + 5;
  115. w = 80;
  116. h = 25;
  117. _btnAll.frame = setDIYFrame;
  118. //批量按钮
  119. x = wid - 100;
  120. w = 80;
  121. h = 25;
  122. _btnEdit.frame = CGRectMake(x, y, w, h);
  123. //字体等固定设置
  124. [imgNum imageName:@"send_people_num_icon.png"];
  125. [imgDate imageName:@"send_time_icon.png"];
  126. [_waitLabel setFont:Font14 TextColor:[UIColor orangeColor]];
  127. [_stateLabel setFont:Font14 TextColor:[UIColor orangeColor]];
  128. [titNum setFont:Font14 TextColor:contentTextColor];
  129. [titDate setFont:Font14 TextColor:contentTextColor];
  130. [titCountLabel setFont:Font14 TextColor:contentTextColor];
  131. [countLabel setFont:Font16 TextColor:contentTextColor];
  132. [lblNum setFont:Font16 TextColor:contentTextColor];
  133. [lblDate setFont:Font16 TextColor:contentTextColor];
  134. [moneyLabel setFont:Font16 TextColor:[UIColor redColor]];
  135. lblNum.textAlignment = NSTextAlignmentCenter;
  136. countLabel.textAlignment = NSTextAlignmentCenter;
  137. moneyLabel.textAlignment = NSTextAlignmentRight;
  138. _stateLabel.textAlignment = NSTextAlignmentRight;
  139. [_btnScan setTitleEdgeInsets:UIEdgeInsetsMake(0, -20, 0, 30)];
  140. [_btnScan setImageEdgeInsets:UIEdgeInsetsMake(3, 40, 3, -5)];
  141. _btnScan.backgroundColor = lineColor;
  142. [_btnScan borderCornorRadios:15];
  143. _btnEdit.backgroundColor = lineColor;
  144. [_btnEdit setTitle:@"批量操作" textColor:contentTextColor font:Font14 fotState:UIControlStateNormal];
  145. [_btnEdit borderCornorRadios:15];
  146. //全选与非全选
  147. [_btnAll setImage:[UIImage imageNamed:@"selectAll.png"] Tit:@"全选" Font:Font14 State:UIControlStateNormal];
  148. [_btnAll setImage:[UIImage imageNamed:@"selectedAll.png"] Tit:@"全选" Font:Font14 State:UIControlStateSelected];
  149. }
  150. return self;
  151. }
  152. -(void)setType:(NSInteger)type
  153. {
  154. _type = type;
  155. //计划信息
  156. if (_type == 1) {
  157. _btnEdit.hidden = NO;
  158. _btnAll.hidden = NO;
  159. }else{
  160. //不带编辑按钮
  161. _btnEdit.hidden = YES;
  162. _btnAll.hidden = YES;
  163. }
  164. }
  165. //-(void)layoutSubviews
  166. //{
  167. // [super layoutSubviews];
  168. // NSLog(@"_type-----><>%d",(int)_type);
  169. //
  170. //
  171. //
  172. //}
  173. //-(void)setHeaderStateLabel
  174. //{
  175. //
  176. //}
  177. -(void)setModel:(NSDictionary *)model
  178. {
  179. //NSLog(@"myplanVC---->%@",model);
  180. _model = model;
  181. NSInteger count = [_model[@"reserveInfoList"] count];
  182. NSString *waitSate = nil;
  183. NSInteger orderNum = 0;
  184. switch (_type) {//_type 区头样式 0已同意 1待确认 2已拒绝
  185. case 0:
  186. waitSate = [NSString stringWithFormat:@"预约成功%d人",(int)count];
  187. orderNum = 4;
  188. if (count == 0) {
  189. waitSate = @"暂无人成功预约";
  190. }
  191. break;
  192. case 1:
  193. waitSate = [NSString stringWithFormat:@"有%d条预约待确认",(int)count];
  194. orderNum = 1;
  195. if (count == 0) {
  196. waitSate = @"暂无待确认预约";
  197. [_btnEdit setHidden:YES];
  198. }else{
  199. [_btnEdit setHidden:NO];
  200. }
  201. break;
  202. case 2:
  203. waitSate = [NSString stringWithFormat:@"已拒绝%d条预约",(int)count];
  204. orderNum = 3;
  205. if (count == 0) {
  206. waitSate = @"暂无已拒绝的预约";
  207. }
  208. break;
  209. default:
  210. break;
  211. }
  212. if (count == 0) {
  213. [_waitLabel setText:waitSate];
  214. }else{
  215. NSInteger aLength = [[NSString stringWithFormat:@"%d",(int)count] length];
  216. NSMutableAttributedString * aAttributedString = [[NSMutableAttributedString alloc] initWithString:waitSate];
  217. //颜色
  218. // [aAttributedString addAttribute:NSForegroundColorAttributeName
  219. // value:defGreen
  220. // range:NSMakeRange(0, 5)];
  221. [aAttributedString addAttribute:NSFontAttributeName
  222. value:[UIFont scaleSize:22.0]
  223. range:NSMakeRange(orderNum, aLength)];
  224. [aAttributedString addAttribute:NSUnderlineStyleAttributeName
  225. value:@(NSUnderlineStyleSingle)
  226. range:NSMakeRange(orderNum, aLength)];
  227. _waitLabel.attributedText = aAttributedString;
  228. }
  229. //[lblName setText:model[@"PI_USER_NAME"]];
  230. [lblNum setText:[NSString stringWithFormat:@"%@人",model[@"PI_NUM"]]];
  231. [countLabel setText:[NSString stringWithFormat:@"%@人",model[@"PI_HAV_NUM"]]];
  232. [lblDate setText:[NSString stringWithFormat:@" %@",model[@"PI_TIMES"]]];
  233. [moneyLabel setText:[NSString stringWithFormat:@"%@元/时",model[@"PI_MONEY"]]];
  234. }
  235. -(void)click:(MyBlockType)block
  236. {
  237. clkBlock = block;
  238. }
  239. -(void)headerBtnClick:(UIButton*)sender
  240. {
  241. UIButton *btn = (UIButton *)sender;
  242. btn.selected = !btn.selected;
  243. if (sender.tag == 1) {
  244. if (btn.selected) {
  245. _btnAll.hidden = NO;
  246. [btn setTitle:@"取消" forState:UIControlStateNormal];
  247. if (clkBlock) {
  248. clkBlock(_aTag);
  249. }
  250. }else{
  251. _btnAll.hidden = YES;
  252. [btn setTitle:@"批量操作" forState:UIControlStateNormal];
  253. if (clkBlock) {
  254. clkBlock([NSString stringWithFormat:@"%d",[_aTag intValue] + 500]);
  255. }
  256. }
  257. }
  258. if (sender.tag == 2) {
  259. //这里是改变_btnAll的图片 并且要对上个页面表示全选
  260. if (btn.selected) {
  261. if (clkBlock) {
  262. clkBlock([NSString stringWithFormat:@"%d",-1]);
  263. }
  264. }else{
  265. if (clkBlock) {
  266. clkBlock([NSString stringWithFormat:@"%d",-2]);
  267. }
  268. }
  269. }
  270. }
  271. @end