PickTimeV.m 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. #import "PickTimeV.h"
  2. #import "Tools.h"
  3. @interface PickTimeV()<UITableViewDataSource,UITableViewDelegate>
  4. {
  5. UITableView *myTableView;
  6. /**保存那些删除时间段的按钮。数目为defState.planTimes.count;
  7. */
  8. NSMutableArray *btns;
  9. /**用于动画,不过已废弃。不好看。
  10. */
  11. UIView *centerV;
  12. UIButton *btnSt,*btnEnd;
  13. UILabel *titleLabel;
  14. NSArray *_dataArray;
  15. }
  16. @end
  17. @implementation PickTimeV
  18. -(id)init
  19. {
  20. self = [super initWithFrame:kFrame];
  21. if (self) {
  22. _dataArray = [NSArray array];
  23. [self setBackgroundColor:[UIColor colorWithWhite:.01 alpha:.3]];
  24. UIView *aView, *line;
  25. UILabel *label;
  26. UIButton *btn;
  27. CGFloat x,y,w,h,bd;
  28. x = bd = 10;
  29. y = 0;
  30. w = kSize.width - bd*2;
  31. h = 40;
  32. aView = [[UIView alloc] initWithFrame:CGRectMake(x, y, w, h*8 + 10)];
  33. aView.center = CGPointMake(kSize.width/2.0, kSize.height/2.0);
  34. [self addSubview:aView];
  35. [aView setBackgroundColor:[UIColor whiteColor]];
  36. centerV = aView;
  37. y = 0;
  38. label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, w, h)];
  39. [label setText:@"请选择"];
  40. [aView addSubview:label];
  41. [label setTextAlignment:NSTextAlignmentCenter];
  42. titleLabel = label;
  43. y += h;
  44. line = [[UIView alloc] initWithFrame:CGRectMake(0, y, w, 3)];
  45. [line setBackgroundColor:defGreen];
  46. [aView addSubview:line];
  47. y += 1;
  48. h *= 6;
  49. UITableView *tv = [[UITableView alloc] initWithFrame:CGRectMake(0, y, w, h)];
  50. [tv setDataSource:self];
  51. [tv setDelegate:self];
  52. [aView addSubview:tv];
  53. [tv setTableHeaderView:[UIView new]];
  54. myTableView = tv;
  55. y += h;
  56. h /=6.0;
  57. w = 200;
  58. x = (kSize.width - w)*.5;
  59. btn = [[UIButton alloc] initWithFrame:CGRectMake(x, y+5, w, h)];
  60. [btn setTitle:@"取消" forState:UIControlStateNormal];
  61. [btn setBackgroundColor:defGreen];
  62. btn.layer.masksToBounds = YES;
  63. btn.layer.cornerRadius = h*.5;
  64. [btn addTarget:self action:@selector(removeFromSuperview) forControlEvents:UIControlEventTouchUpInside];
  65. [aView addSubview:btn];
  66. }
  67. return self;
  68. }
  69. -(void)setWhichVC:(NSString *)whichVC
  70. {
  71. _whichVC = whichVC;
  72. if ([whichVC isEqualToString:@"ComplainVC"]) {
  73. titleLabel.text = @"请选择投诉类型";
  74. [self getComplainStyle];
  75. }else{
  76. [myTableView reloadData];
  77. }
  78. }
  79. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  80. {
  81. return _dataArray.count;
  82. }
  83. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  84. {
  85. UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  86. if (!cell) {
  87. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
  88. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  89. cell.textLabel.font = [UIFont scaleSize:FontTitle];
  90. }
  91. NSDictionary* obj = _dataArray[indexPath.row];
  92. if ([_whichVC isEqualToString:@"ComplainVC"]) {
  93. [cell.textLabel setText:obj[@"RT_TITLE"]];
  94. }
  95. return cell;
  96. }
  97. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  98. {
  99. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  100. if (clkBlock) {
  101. NSDictionary* obj = _dataArray[indexPath.row];
  102. clkBlock(obj);
  103. }
  104. [self removeFromSuperview];
  105. }
  106. -(void)complete:(MyBlockType)comp
  107. {
  108. clkBlock = comp;
  109. }
  110. -(void)show
  111. {
  112. [[UIApplication sharedApplication].keyWindow addSubview:self];
  113. }
  114. -(void)getComplainStyle
  115. {
  116. if (![Util connectedToNetWork]) {
  117. showMsgUnconnect();
  118. return;
  119. }
  120. NSMutableArray *arr=[NSMutableArray array];
  121. [arr addPro:@"type" Value:@"2"]; //1 驾校 2教练
  122. NSString* method = @"getComplaintsTypes";
  123. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
  124. //NSLog(@"获取投诉类型-->%@---->%@",arr,root);
  125. if (!root) {
  126. return;
  127. }
  128. if ([root[@"code"] isEqualToString:@"1"]) {
  129. ShowMsg(root[@"body"]);
  130. return;
  131. }
  132. _dataArray = root[@"body"];
  133. [myTableView reloadData];
  134. }];
  135. }
  136. @end