ImitateAppiontMentVC.m 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. //
  2. // ImitateAppiontMentVC.m
  3. // jiaPei
  4. //
  5. // Created by apple on 2017/5/5.
  6. // Copyright © 2017年 JCZ. All rights reserved.
  7. //
  8. #import "ImitateAppiontMentVC.h"
  9. #import "ImiEquipmentListVC.h"
  10. #import "HolderView.h"
  11. @interface ImitateAppiontMentVC ()<UITableViewDelegate,UITableViewDataSource,UIPickerViewDataSource,UIPickerViewDelegate>
  12. {
  13. UIBarButtonItem *item;
  14. UITableView *mainTableView;
  15. //地区选择栏
  16. UIPickerView *picker;
  17. UIView *bgView;
  18. NSArray *dataArray;
  19. NSArray *areaArray;
  20. NSString *qxbh;
  21. NSInteger pickRow;
  22. NSString *oldTitle;
  23. HolderView *holderV;
  24. }
  25. @end
  26. @implementation ImitateAppiontMentVC
  27. - (void)viewDidLoad {
  28. [super viewDidLoad];
  29. self.title = @"模拟预约";
  30. self.view.backgroundColor = backGroundColor;
  31. [self configNavigationBar];
  32. areaArray = [DB_Que_Helper queryArea];
  33. NSMutableArray *array = [NSMutableArray array];
  34. for (NSDictionary *dic in areaArray) {
  35. if ([dic[@"code"] isEqualToString:RQ_USER_MANAGER.currentUser.city] || [dic[@"parent_code"] isEqualToString:RQ_USER_MANAGER.currentUser.city]) {
  36. [array addObject:dic];
  37. }
  38. }
  39. if (array.count > 0) {
  40. areaArray = [NSArray arrayWithArray:array];
  41. }
  42. qxbh = @"";
  43. pickRow = 0;
  44. item = [[UIBarButtonItem alloc] initWithTitle:@"区县选择" style:UIBarButtonItemStylePlain target:self action:@selector(clickQX)];
  45. item.tintColor = RQ_MAIN_COLOR;
  46. self.navigationItem.rightBarButtonItem = item;
  47. mainTableView = [[UITableView alloc] initWithFrame:kFrame style:UITableViewStylePlain];
  48. mainTableView.height -= kNavOffSet;
  49. mainTableView.delegate = self;
  50. mainTableView.dataSource = self;
  51. mainTableView.tableFooterView = [UIView new];
  52. [self.view addSubview:mainTableView];
  53. [mainTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
  54. //
  55. holderV = [[HolderView alloc]initWithFrame:mainTableView.frame];
  56. holderV.title = @"当前区县未设定训练点";
  57. [self.view addSubview:holderV];
  58. [self getTrainInsList];
  59. }
  60. - (void)clickQX {
  61. if (bgView) {
  62. [bgView removeFromSuperview];
  63. bgView = nil;
  64. item.title = oldTitle;
  65. //既然是取消就什么也别做
  66. // if (qxbh.length == 0) {
  67. // for (NSDictionary *dic in areaArray) {
  68. // if ([dic[@"code"] isEqualToString:RQ_USER_MANAGER.currentUser.city]) {
  69. // item.title = dic[@"name"];
  70. // return;
  71. // }
  72. // }
  73. // }else {
  74. // for (NSDictionary *dic in areaArray) {
  75. // if ([dic[@"code"] isEqualToString:qxbh]) {
  76. // item.title = dic[@"name"];
  77. // return;
  78. // }
  79. // }
  80. // }
  81. return;
  82. }
  83. oldTitle = item.title;
  84. item.title = @"取消";
  85. bgView = [[UIView alloc] initWithFrame:CGRectMake(0, kSize.height - 285 - kNavOffSet - kSafeAreaBottomHeight, kSize.width, 285)];
  86. bgView.backgroundColor = backGroundColor;
  87. [self.view addSubview:bgView];
  88. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(kSize.width/2.0, 0, kSize.width/2.0 - 20, 40)];
  89. [label setText:@"完成" Font:Font17 TextColor:RQ_MAIN_COLOR Alignment:NSTextAlignmentRight];
  90. [bgView addSubview:label];
  91. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(kSize.width/2.0, 0, kSize.width/2.0, 40)];
  92. [btn target:self tag:1];
  93. [bgView addSubview:btn];
  94. picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 40, kSize.width, 245)];
  95. picker.delegate = self;
  96. picker.dataSource = self;
  97. [picker selectRow:pickRow inComponent:0 animated:NO];
  98. [bgView addSubview:picker];
  99. [btn addViewWithRect:CGRectMake(0, 40, kSize.width, 1.5) Color:contentTextColor];
  100. }
  101. - (void)btnClick:(UIButton *)sender
  102. {
  103. if (sender.tag == 1) {
  104. if (bgView) {
  105. [bgView removeFromSuperview];
  106. bgView = nil;
  107. if (qxbh.length == 0) {
  108. for (NSDictionary *dic in areaArray) {
  109. if ([dic[@"code"] isEqualToString:RQ_USER_MANAGER.currentUser.city]) {
  110. item.title = dic[@"name"];
  111. break;
  112. }
  113. }
  114. }else {
  115. for (NSDictionary *dic in areaArray) {
  116. if ([dic[@"code"] isEqualToString:qxbh]) {
  117. item.title = dic[@"name"];
  118. break;
  119. }
  120. }
  121. }
  122. }
  123. [self getTrainInsList];
  124. }
  125. }
  126. #pragma mark pickerView
  127. -(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
  128. return 1;
  129. }
  130. //每列对应多少行
  131. -(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
  132. return areaArray.count;
  133. }
  134. //每列每行对应显示的数据
  135. -(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
  136. NSDictionary *dic = areaArray[row];
  137. return dic[@"name"];
  138. }
  139. -(CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component {
  140. return 40;
  141. }
  142. //选中
  143. -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
  144. pickRow = row;
  145. NSDictionary *dic = areaArray[row];
  146. qxbh = dic[@"code"];
  147. if ([qxbh isEqualToString:RQ_USER_MANAGER.currentUser.city]) {
  148. qxbh = @"";
  149. }
  150. }
  151. #pragma mark tableView
  152. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  153. return dataArray.count;
  154. }
  155. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  156. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  157. cell.backgroundColor = backGroundColor;
  158. NSDictionary *dic = dataArray[indexPath.row];
  159. cell.textLabel.text = dic[@"NAME"];
  160. cell.textLabel.textColor = kTitleColor;
  161. return cell;
  162. }
  163. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  164. NSDictionary *dic = dataArray[indexPath.row];
  165. ImiEquipmentListVC *vc = [[ImiEquipmentListVC alloc] init];
  166. vc.trainAppointDic = dic;
  167. [self navPushHideTabbarToVC:vc];
  168. }
  169. - (void)getTrainInsList {
  170. [LoadingView showHUD];
  171. if (![Util connectedToNetWork]) {
  172. return;
  173. }
  174. NSMutableArray *arr=[NSMutableArray array];
  175. [arr addPro:@"dqbh" Value:RQ_USER_MANAGER.currentUser.city];
  176. [arr addPro:@"qxbh" Value:qxbh];
  177. NSString* method = @"getTrainInsList";
  178. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
  179. RemoveHUD();
  180. if (!root) {
  181. ShowMsg(@"网络异常,未查询到训练点");
  182. return;
  183. }
  184. if ([root[@"code"] intValue] == 1) {
  185. ShowMsg(root[@"body"]);
  186. return;
  187. }
  188. if ([(NSArray *)root[@"body"] count] < 1) {
  189. ShowMsg(@"当前区县未设定训练点");
  190. dataArray = [NSArray array];
  191. [mainTableView reloadData];
  192. holderV.hidden = NO;
  193. return;
  194. }
  195. dataArray = root[@"body"];
  196. holderV.hidden = YES;
  197. [mainTableView reloadData];
  198. }];
  199. }
  200. - (void)didReceiveMemoryWarning {
  201. [super didReceiveMemoryWarning];
  202. }
  203. @end