// // ImiEquipmentListVC.m // jiaPei // // Created by apple on 2017/5/9. // Copyright © 2017年 JCZ. All rights reserved. // #import "ImiEquipmentListVC.h" #import "CLWeeklyCalendarView.h" #import "EquipmentDetailVC.h" #import "DateView.h" @interface ImiEquipmentListVC () { UILabel *openTimeLabel; UITableView *deviceTableView; UIBarButtonItem *item; UIView *backView; UIButton *beginBtn,*endBtn; NSArray *timeArray; NSMutableArray *deviceMnArray; NSString *searchStartTime; NSString *searchEndTime; NSString *quotaId; BOOL isOpen;//某天是否开放模拟机 NSInteger currentPage; NSMutableArray *calendarSetYesArray; } @property (nonatomic, strong) CLWeeklyCalendarView* calendarView; @end @implementation ImiEquipmentListVC - (void)viewDidLoad { [super viewDidLoad]; [self setTitle:self.trainAppointDic[@"NAME"]]; [self.view setBackgroundColor:backGroundColor]; [self configNavigationBar]; searchStartTime = @""; searchEndTime = @""; timeArray = [NSArray array]; deviceMnArray = [NSMutableArray array]; calendarSetYesArray = [NSMutableArray array]; [self.view addSubview:self.calendarView]; CGFloat x,y,w,h; x = 0; y = self.calendarView.height + 5; w = kSize.width; h = 30; openTimeLabel = [[UILabel alloc] setxywh]; openTimeLabel.backgroundColor = backGroundColor; [openTimeLabel setText:@"暂未获取到开放时间..." Font:Font17 TextColor:subTitleColor Alignment:NSTextAlignmentCenter]; [self.view addSubview:openTimeLabel]; y += h + 5; h = kSize.height - y - kNavOffSet; deviceTableView = [[UITableView alloc] initWithFrame:setDIYFrame style:UITableViewStylePlain]; deviceTableView.delegate = self; deviceTableView.dataSource = self; deviceTableView.tableFooterView = [UIView new]; [self.view addSubview:deviceTableView]; [self getExamQuota]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; RemoveHUD(); } - (void)clickSelect { item.enabled = NO; backView = [[UIView alloc] initWithFrame:kFrame]; backView.backgroundColor = [UIColor colorWithWhite:.1 alpha:.5]; [self.view addSubview:backView]; CGFloat x, y, w, h, bd; x = 20; y = (kSize.height - 230)/2.0 - kNavOffSet; w = kSize.width - 40; h = 230; UIView *searchView = [[UIView alloc] setxywh]; searchView.backgroundColor = backGroundColor; searchView.layer.masksToBounds = YES; searchView.layer.cornerRadius = 5; [backView addSubview:searchView]; x = y = bd = 15; w = searchView.width - 30; h = 50; NSArray *imgArray = @[@"beginDate",@"endDate"]; NSString *beginDateStr = @"开始时间"; NSString *endDateStr = @"结束时间"; if (searchStartTime.length > 0) { beginDateStr = searchStartTime; } if (searchEndTime.length > 0) { endDateStr = searchEndTime; } NSArray *titles = @[beginDateStr,endDateStr]; NSMutableArray *btns = [NSMutableArray arrayWithCapacity:3]; for (int i = 0; i < 2; i ++) { UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(x + bd, 2*y + i*(h + bd), 20, 20)]; imageView.image = [[UIImage imageNamed:imgArray[i]] tint:RQ_MAIN_COLOR]; [searchView addSubview:imageView]; UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(x, y + i*(h + bd) , w, h)]; [button setTitle:titles[i] textColor:contentTextColor Font:16 fotState:UIControlStateNormal]; button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; button.titleEdgeInsets = UIEdgeInsetsMake(0, 3*bd, 0, 0); [button borderColor:RQlineColor width:2 cornorRadius:5]; [button target:self tag:i + 1]; [searchView addSubview:button]; [btns addObject:button]; } beginBtn = btns[0]; endBtn = btns[1]; y += 2*(h + bd); w = (w - 2*bd)/2.0; NSArray *titleArrays = @[@"取消",@"查询"]; for (int i = 0; i < 2; i ++) { UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(x + i*(w + 2*bd), y , w, h)]; [button setTitle:titleArrays[i] textColor:RQ_MAIN_COLOR Font:16 fotState:UIControlStateNormal]; [button borderColor:RQlineColor width:2 cornorRadius:5]; [button target:self tag:i + 3]; [searchView addSubview:button]; } } -(CLWeeklyCalendarView *)calendarView { if(!_calendarView){ _calendarView = [[CLWeeklyCalendarView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 120)]; _calendarView.delegate = self; _calendarView.isLimitDate = YES; } return _calendarView; } #pragma mark - CLWeeklyCalendarViewDelegate -(NSDictionary *)CLCalendarBehaviorAttributes { //CLCalendarSelectedDatePrintFormatDefault 显示选中日期格式 return @{ //CLCalendarWeekStartDay : @2, //Start Day of the week, from 1-7 Mon-Sun -- default 1 // CLCalendarDayTitleTextColor : [UIColor yellowColor], // CLCalendarSelectedDatePrintColor : [UIColor greenColor], }; } -(void)dailyCalendarViewDidSelect:(NSDate *)date { NSTimeInterval timeDif = [date timeIntervalSinceNow]; if (timeDif < -10000.0) {//过期的天数 ShowMsg(@"所选日期已过期"); openTimeLabel.text = @"所选日期已过期"; [deviceMnArray removeAllObjects]; [deviceTableView reloadData]; return; } //NSLog(@"date--><>%@-------><>%f",date,timeDif); NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]; [formatter setDateFormat:@"yyyy-MM-dd"]; NSString *selectDay = [formatter stringFromDate:date]; if (timeArray.count > 0) { isOpen = NO; for (NSDictionary *dic in timeArray) { if ([dic[@"PXRQ"] isEqualToString:selectDay]) { //改变Label上的 开始、结束时间。记录一个请求状态 if (currentPage == 1) { [calendarSetYesArray addObject:@"阿离"]; } openTimeLabel.text = [NSString stringWithFormat:@"开放时间:%@-%@",dic[@"STARTTIME"],dic[@"ENDTIME"]]; isOpen = YES; quotaId = dic[@"ID"]; item = [[UIBarButtonItem alloc] initWithTitle:@"筛选" style:UIBarButtonItemStylePlain target:self action:@selector(clickSelect)]; self.navigationItem.rightBarButtonItem = item; currentPage = 1; [self getDeviceMnList]; break; } } if (!isOpen) { //该天未开放 openTimeLabel.text = @"模拟设备未开放"; self.navigationItem.rightBarButtonItem = nil; [deviceMnArray removeAllObjects]; [deviceTableView reloadData]; } } } -(void)btnClick:(UIButton *)sender { switch (sender.tag) { case 1: { DateView *dateV = [[DateView alloc] init]; [dateV setStyle:3]; [dateV showWithComplete:^(NSString * result) { searchStartTime = result; [beginBtn setTitle:searchStartTime forState:UIControlStateNormal]; }]; } break; case 2: { DateView *dateV = [[DateView alloc] init]; [dateV setStyle:3]; [dateV showWithComplete:^(NSString * result) { searchEndTime = result; [endBtn setTitle:searchEndTime forState:UIControlStateNormal]; }]; } break; case 3: { if (backView) { [backView removeFromSuperview]; } item.enabled = YES; } break; case 4: { if (backView) { [backView removeFromSuperview]; } item.enabled = YES; //如果是重新选择时间 需要将currentPage重置为1 if (currentPage == 1) { [calendarSetYesArray addObject:@"阿离"]; } currentPage = 1; [self getDeviceMnList]; } break; default: break; } } #pragma mark tableView -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return deviceMnArray.count; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"]; cell.backgroundColor = backGroundColor; cell.selectionStyle = UITableViewCellSelectionStyleNone; } NSDictionary *dic = deviceMnArray[indexPath.row]; cell.textLabel.text = dic[@"CODE"]; cell.textLabel.textColor = kTitleColor; cell.detailTextLabel.text = [dic[@"TYPE"] integerValue] == 2 ? @"VR模拟器":@"传统模拟器"; cell.detailTextLabel.textColor = subTitleColor; return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSDictionary *dic = deviceMnArray[indexPath.row]; EquipmentDetailVC *vc = [[EquipmentDetailVC alloc] init]; vc.imiAppoint = _trainAppointDic[@"NAME"]; vc.quotaId = quotaId; vc.devDic = dic; [self navPushHideTabbarToVC:vc]; } #pragma mark 数据请求 - (void)getExamQuota { [LoadingView showHUD]; if (![Util connectedToNetWork]) { return; } NSMutableArray *arr=[NSMutableArray array]; [arr addPro:@"dqbh" Value:RQ_USER_MANAGER.currentUser.city]; [arr addPro:@"tcId" Value:_trainAppointDic[@"ID"]]; NSString* method = @"getExamQuota"; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) { RemoveHUD(); if (!root) { return; } if ([root[@"code"] intValue] == 1) { ShowMsg(root[@"body"]); return; } timeArray = root[@"body"]; if (timeArray.count > 0) { NSMutableArray *dateArray = [NSMutableArray array]; for (NSDictionary *dic in timeArray) { [dateArray addObject:dic[@"PXRQ"]]; } self.calendarView.greenDayArray = dateArray; [self dailyCalendarViewDidSelect:[NSDate date]]; //[self performSelector:@selector(dailyCalendarViewDidSelect:) withObject:[NSDate date] afterDelay:1.0]; } }]; } - (void)getDeviceMnList { [LoadingView showHUD]; if (![Util connectedToNetWork]) { return; } NSMutableArray *arr=[NSMutableArray array]; [arr addPro:@"dqbh" Value:RQ_USER_MANAGER.currentUser.city]; [arr addPro:@"tcId" Value:_trainAppointDic[@"ID"]]; [arr addPro:@"quotaId" Value:quotaId]; [arr addPro:@"startTime" Value:searchStartTime]; [arr addPro:@"endTime" Value:searchEndTime]; [arr addPro:@"isPage" Value:@"1"]; [arr addPro:@"pageSize" Value:@"20"]; [arr addPro:@"currentPage" Value:[NSString stringWithFormat:@"%d",(int)currentPage]]; NSString* method = @"getDeviceMnList"; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) { //NSLog(@"getDeviceMnList------>>>>%@\n----->>>>>%@",arr,root); RemoveHUD(); if (calendarSetYesArray.count > 0) { if (currentPage != 1) { currentPage = 1; } [calendarSetYesArray removeLastObject]; } if (!root) { ShowMsg(@"获取模拟设备失败!"); return; } if ([root[@"code"] intValue] == 1) { ShowMsg(root[@"body"]); return; } if (currentPage == 1) { [deviceMnArray removeAllObjects]; } if ([(NSArray *)root[@"body"] count] > 0) { currentPage ++; [deviceMnArray addObjectsFromArray:root[@"body"]]; [deviceTableView reloadData]; }else { if (currentPage == 1) { ShowMsg(@"暂无数据"); }else { ShowMsg(@"已加载全部数据"); } } }]; } -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { CGPoint off = scrollView.contentOffset; if (scrollView.contentSize.height - off.y - scrollView.frame.size.height < 1) { [scrollView setContentOffset:CGPointMake(off.x, off.y - 10) animated:YES]; [self getDeviceMnList]; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end