ImiEquipmentListVC.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. //
  2. // ImiEquipmentListVC.m
  3. // jiaPei
  4. //
  5. // Created by apple on 2017/5/9.
  6. // Copyright © 2017年 JCZ. All rights reserved.
  7. //
  8. #import "ImiEquipmentListVC.h"
  9. #import "CLWeeklyCalendarView.h"
  10. #import "EquipmentDetailVC.h"
  11. #import "DateView.h"
  12. @interface ImiEquipmentListVC ()<CLWeeklyCalendarViewDelegate,UITableViewDelegate,UITableViewDataSource>
  13. {
  14. UILabel *openTimeLabel;
  15. UITableView *deviceTableView;
  16. UIBarButtonItem *item;
  17. UIView *backView;
  18. UIButton *beginBtn,*endBtn;
  19. NSArray *timeArray;
  20. NSMutableArray *deviceMnArray;
  21. NSString *searchStartTime;
  22. NSString *searchEndTime;
  23. NSString *quotaId;
  24. BOOL isOpen;//某天是否开放模拟机
  25. NSInteger currentPage;
  26. NSMutableArray *calendarSetYesArray;
  27. }
  28. @property (nonatomic, strong) CLWeeklyCalendarView* calendarView;
  29. @end
  30. @implementation ImiEquipmentListVC
  31. - (void)viewDidLoad {
  32. [super viewDidLoad];
  33. [self setTitle:self.trainAppointDic[@"NAME"]];
  34. [self.view setBackgroundColor:backGroundColor];
  35. [self configNavigationBar];
  36. searchStartTime = @"";
  37. searchEndTime = @"";
  38. timeArray = [NSArray array];
  39. deviceMnArray = [NSMutableArray array];
  40. calendarSetYesArray = [NSMutableArray array];
  41. [self.view addSubview:self.calendarView];
  42. CGFloat x,y,w,h;
  43. x = 0;
  44. y = self.calendarView.height + 5;
  45. w = kSize.width;
  46. h = 30;
  47. openTimeLabel = [[UILabel alloc] setxywh];
  48. openTimeLabel.backgroundColor = backGroundColor;
  49. [openTimeLabel setText:@"暂未获取到开放时间..." Font:Font17 TextColor:subTitleColor Alignment:NSTextAlignmentCenter];
  50. [self.view addSubview:openTimeLabel];
  51. y += h + 5;
  52. h = kSize.height - y - kNavOffSet;
  53. deviceTableView = [[UITableView alloc] initWithFrame:setDIYFrame style:UITableViewStylePlain];
  54. deviceTableView.delegate = self;
  55. deviceTableView.dataSource = self;
  56. deviceTableView.tableFooterView = [UIView new];
  57. [self.view addSubview:deviceTableView];
  58. [self getExamQuota];
  59. }
  60. - (void)viewWillDisappear:(BOOL)animated {
  61. [super viewWillDisappear:animated];
  62. RemoveHUD();
  63. }
  64. - (void)clickSelect {
  65. item.enabled = NO;
  66. backView = [[UIView alloc] initWithFrame:kFrame];
  67. backView.backgroundColor = [UIColor colorWithWhite:.1 alpha:.5];
  68. [self.view addSubview:backView];
  69. CGFloat x, y, w, h, bd;
  70. x = 20;
  71. y = (kSize.height - 230)/2.0 - kNavOffSet;
  72. w = kSize.width - 40;
  73. h = 230;
  74. UIView *searchView = [[UIView alloc] setxywh];
  75. searchView.backgroundColor = backGroundColor;
  76. searchView.layer.masksToBounds = YES;
  77. searchView.layer.cornerRadius = 5;
  78. [backView addSubview:searchView];
  79. x = y = bd = 15;
  80. w = searchView.width - 30;
  81. h = 50;
  82. NSArray *imgArray = @[@"beginDate",@"endDate"];
  83. NSString *beginDateStr = @"开始时间";
  84. NSString *endDateStr = @"结束时间";
  85. if (searchStartTime.length > 0) {
  86. beginDateStr = searchStartTime;
  87. }
  88. if (searchEndTime.length > 0) {
  89. endDateStr = searchEndTime;
  90. }
  91. NSArray *titles = @[beginDateStr,endDateStr];
  92. NSMutableArray *btns = [NSMutableArray arrayWithCapacity:3];
  93. for (int i = 0; i < 2; i ++) {
  94. UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(x + bd, 2*y + i*(h + bd), 20, 20)];
  95. imageView.image = [[UIImage imageNamed:imgArray[i]] tint:RQ_MAIN_COLOR];
  96. [searchView addSubview:imageView];
  97. UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(x, y + i*(h + bd) , w, h)];
  98. [button setTitle:titles[i] textColor:contentTextColor Font:16 fotState:UIControlStateNormal];
  99. button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  100. button.titleEdgeInsets = UIEdgeInsetsMake(0, 3*bd, 0, 0);
  101. [button borderColor:RQlineColor width:2 cornorRadius:5];
  102. [button target:self tag:i + 1];
  103. [searchView addSubview:button];
  104. [btns addObject:button];
  105. }
  106. beginBtn = btns[0];
  107. endBtn = btns[1];
  108. y += 2*(h + bd);
  109. w = (w - 2*bd)/2.0;
  110. NSArray *titleArrays = @[@"取消",@"查询"];
  111. for (int i = 0; i < 2; i ++) {
  112. UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(x + i*(w + 2*bd), y , w, h)];
  113. [button setTitle:titleArrays[i] textColor:RQ_MAIN_COLOR Font:16 fotState:UIControlStateNormal];
  114. [button borderColor:RQlineColor width:2 cornorRadius:5];
  115. [button target:self tag:i + 3];
  116. [searchView addSubview:button];
  117. }
  118. }
  119. -(CLWeeklyCalendarView *)calendarView
  120. {
  121. if(!_calendarView){
  122. _calendarView = [[CLWeeklyCalendarView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 120)];
  123. _calendarView.delegate = self;
  124. _calendarView.isLimitDate = YES;
  125. }
  126. return _calendarView;
  127. }
  128. #pragma mark - CLWeeklyCalendarViewDelegate
  129. -(NSDictionary *)CLCalendarBehaviorAttributes
  130. {
  131. //CLCalendarSelectedDatePrintFormatDefault 显示选中日期格式
  132. return @{
  133. //CLCalendarWeekStartDay : @2, //Start Day of the week, from 1-7 Mon-Sun -- default 1
  134. // CLCalendarDayTitleTextColor : [UIColor yellowColor],
  135. // CLCalendarSelectedDatePrintColor : [UIColor greenColor],
  136. };
  137. }
  138. -(void)dailyCalendarViewDidSelect:(NSDate *)date
  139. {
  140. NSTimeInterval timeDif = [date timeIntervalSinceNow];
  141. if (timeDif < -10000.0) {//过期的天数
  142. ShowMsg(@"所选日期已过期");
  143. openTimeLabel.text = @"所选日期已过期";
  144. [deviceMnArray removeAllObjects];
  145. [deviceTableView reloadData];
  146. return;
  147. }
  148. //NSLog(@"date--><>%@-------><>%f",date,timeDif);
  149. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  150. formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
  151. [formatter setDateFormat:@"yyyy-MM-dd"];
  152. NSString *selectDay = [formatter stringFromDate:date];
  153. if (timeArray.count > 0) {
  154. isOpen = NO;
  155. for (NSDictionary *dic in timeArray) {
  156. if ([dic[@"PXRQ"] isEqualToString:selectDay]) {
  157. //改变Label上的 开始、结束时间。记录一个请求状态
  158. if (currentPage == 1) {
  159. [calendarSetYesArray addObject:@"阿离"];
  160. }
  161. openTimeLabel.text = [NSString stringWithFormat:@"开放时间:%@-%@",dic[@"STARTTIME"],dic[@"ENDTIME"]];
  162. isOpen = YES;
  163. quotaId = dic[@"ID"];
  164. item = [[UIBarButtonItem alloc] initWithTitle:@"筛选" style:UIBarButtonItemStylePlain target:self action:@selector(clickSelect)];
  165. self.navigationItem.rightBarButtonItem = item;
  166. currentPage = 1;
  167. [self getDeviceMnList];
  168. break;
  169. }
  170. }
  171. if (!isOpen) {
  172. //该天未开放
  173. openTimeLabel.text = @"模拟设备未开放";
  174. self.navigationItem.rightBarButtonItem = nil;
  175. [deviceMnArray removeAllObjects];
  176. [deviceTableView reloadData];
  177. }
  178. }
  179. }
  180. -(void)btnClick:(UIButton *)sender
  181. {
  182. switch (sender.tag) {
  183. case 1:
  184. {
  185. DateView *dateV = [[DateView alloc] init];
  186. [dateV setStyle:3];
  187. [dateV showWithComplete:^(NSString * result) {
  188. searchStartTime = result;
  189. [beginBtn setTitle:searchStartTime forState:UIControlStateNormal];
  190. }];
  191. }
  192. break;
  193. case 2:
  194. {
  195. DateView *dateV = [[DateView alloc] init];
  196. [dateV setStyle:3];
  197. [dateV showWithComplete:^(NSString * result) {
  198. searchEndTime = result;
  199. [endBtn setTitle:searchEndTime forState:UIControlStateNormal];
  200. }];
  201. }
  202. break;
  203. case 3:
  204. {
  205. if (backView) {
  206. [backView removeFromSuperview];
  207. }
  208. item.enabled = YES;
  209. }
  210. break;
  211. case 4:
  212. {
  213. if (backView) {
  214. [backView removeFromSuperview];
  215. }
  216. item.enabled = YES;
  217. //如果是重新选择时间 需要将currentPage重置为1
  218. if (currentPage == 1) {
  219. [calendarSetYesArray addObject:@"阿离"];
  220. }
  221. currentPage = 1;
  222. [self getDeviceMnList];
  223. }
  224. break;
  225. default:
  226. break;
  227. }
  228. }
  229. #pragma mark tableView
  230. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  231. return deviceMnArray.count;
  232. }
  233. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  234. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  235. if (cell == nil) {
  236. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
  237. cell.backgroundColor = backGroundColor;
  238. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  239. }
  240. NSDictionary *dic = deviceMnArray[indexPath.row];
  241. cell.textLabel.text = dic[@"CODE"];
  242. cell.textLabel.textColor = kTitleColor;
  243. cell.detailTextLabel.text = [dic[@"TYPE"] integerValue] == 2 ? @"VR模拟器":@"传统模拟器";
  244. cell.detailTextLabel.textColor = subTitleColor;
  245. return cell;
  246. }
  247. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  248. NSDictionary *dic = deviceMnArray[indexPath.row];
  249. EquipmentDetailVC *vc = [[EquipmentDetailVC alloc] init];
  250. vc.imiAppoint = _trainAppointDic[@"NAME"];
  251. vc.quotaId = quotaId;
  252. vc.devDic = dic;
  253. [self navPushHideTabbarToVC:vc];
  254. }
  255. #pragma mark 数据请求
  256. - (void)getExamQuota {
  257. [LoadingView showHUD];
  258. if (![Util connectedToNetWork]) {
  259. return;
  260. }
  261. NSMutableArray *arr=[NSMutableArray array];
  262. [arr addPro:@"dqbh" Value:RQ_USER_MANAGER.currentUser.city];
  263. [arr addPro:@"tcId" Value:_trainAppointDic[@"ID"]];
  264. NSString* method = @"getExamQuota";
  265. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
  266. RemoveHUD();
  267. if (!root) {
  268. return;
  269. }
  270. if ([root[@"code"] intValue] == 1) {
  271. ShowMsg(root[@"body"]);
  272. return;
  273. }
  274. timeArray = root[@"body"];
  275. if (timeArray.count > 0) {
  276. NSMutableArray *dateArray = [NSMutableArray array];
  277. for (NSDictionary *dic in timeArray) {
  278. [dateArray addObject:dic[@"PXRQ"]];
  279. }
  280. self.calendarView.greenDayArray = dateArray;
  281. [self dailyCalendarViewDidSelect:[NSDate date]];
  282. //[self performSelector:@selector(dailyCalendarViewDidSelect:) withObject:[NSDate date] afterDelay:1.0];
  283. }
  284. }];
  285. }
  286. - (void)getDeviceMnList {
  287. [LoadingView showHUD];
  288. if (![Util connectedToNetWork]) {
  289. return;
  290. }
  291. NSMutableArray *arr=[NSMutableArray array];
  292. [arr addPro:@"dqbh" Value:RQ_USER_MANAGER.currentUser.city];
  293. [arr addPro:@"tcId" Value:_trainAppointDic[@"ID"]];
  294. [arr addPro:@"quotaId" Value:quotaId];
  295. [arr addPro:@"startTime" Value:searchStartTime];
  296. [arr addPro:@"endTime" Value:searchEndTime];
  297. [arr addPro:@"isPage" Value:@"1"];
  298. [arr addPro:@"pageSize" Value:@"20"];
  299. [arr addPro:@"currentPage" Value:[NSString stringWithFormat:@"%d",(int)currentPage]];
  300. NSString* method = @"getDeviceMnList";
  301. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
  302. //NSLog(@"getDeviceMnList------>>>>%@\n----->>>>>%@",arr,root);
  303. RemoveHUD();
  304. if (calendarSetYesArray.count > 0) {
  305. if (currentPage != 1) {
  306. currentPage = 1;
  307. }
  308. [calendarSetYesArray removeLastObject];
  309. }
  310. if (!root) {
  311. ShowMsg(@"获取模拟设备失败!");
  312. return;
  313. }
  314. if ([root[@"code"] intValue] == 1) {
  315. ShowMsg(root[@"body"]);
  316. return;
  317. }
  318. if (currentPage == 1) {
  319. [deviceMnArray removeAllObjects];
  320. }
  321. if ([(NSArray *)root[@"body"] count] > 0) {
  322. currentPage ++;
  323. [deviceMnArray addObjectsFromArray:root[@"body"]];
  324. [deviceTableView reloadData];
  325. }else {
  326. if (currentPage == 1) {
  327. ShowMsg(@"暂无数据");
  328. }else {
  329. ShowMsg(@"已加载全部数据");
  330. }
  331. }
  332. }];
  333. }
  334. -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
  335. {
  336. CGPoint off = scrollView.contentOffset;
  337. if (scrollView.contentSize.height - off.y - scrollView.frame.size.height < 1) {
  338. [scrollView setContentOffset:CGPointMake(off.x, off.y - 10) animated:YES];
  339. [self getDeviceMnList];
  340. }
  341. }
  342. - (void)didReceiveMemoryWarning {
  343. [super didReceiveMemoryWarning];
  344. // Dispose of any resources that can be recreated.
  345. }
  346. @end