123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434 |
- //
- // EquipmentDetailVC.m
- // jiaPei
- //
- // Created by apple on 2017/5/10.
- // Copyright © 2017年 JCZ. All rights reserved.
- //
- #import "EquipmentDetailVC.h"
- #import "DateView.h"
- @interface EquipmentDetailVC ()<UITableViewDelegate,UITableViewDataSource>
- {
- UILabel *priceLabel;
- UITableView *mainTableView;
- UILabel *noReserveLabel;
- UIButton *beginBtn, *endBtn;
- UIButton *discountBtn;
-
- NSArray *dataArray;
- NSString *beginTime, *endTime;
- CGFloat price;
- BOOL isUseDisCount;
- }
- @end
- @implementation EquipmentDetailVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.title = [NSString stringWithFormat:@" 模拟设备%@",_devDic[@"CODE"]];
- self.view.backgroundColor = backGroundColor;
- [self configNavigationBar];
-
-
- isUseDisCount = NO;
- beginTime = endTime = @"";
- dataArray = [NSArray array];
-
- CGFloat x,y,w,h,bd;
-
- x = y = bd = 10;
- w = kSize.width - 2*x;
- h = 40;
- UILabel *label = [[UILabel alloc] setxywh];
- label.backgroundColor = backGroundColor;
- [label borderColor:RQlineColor width:1 cornorRadius:5];
- [label setText:[NSString stringWithFormat:@" 训练点:%@",_imiAppoint] Font:Font17 TextColor:kTitleColor];
- [self.view addSubview:label];
-
- y += h + bd;
- h = 90;
- label = [[UILabel alloc] setxywh];
- label.backgroundColor = backGroundColor;
- [label borderColor:RQlineColor width:1 cornorRadius:5];
- label.numberOfLines = 3;
- [label setText:@" 培训日期:\n 开放时间:\n 培训价格:" Font:Font17 TextColor:kTitleColor];
- [self.view addSubview:label];
- priceLabel = label;
-
- y += h + bd;
- h = 30;
- label = [[UILabel alloc] setxywh];
- [label setText:@" 已约时段:" Font:Font17 TextColor:kTitleColor];
- [self.view addSubview:label];
-
- y += h + bd/2.0;
- h = kSize.height - y - kNavOffSet - 200;
- mainTableView = [[UITableView alloc] initWithFrame:setDIYFrame style:UITableViewStylePlain];
- mainTableView.backgroundColor = backGroundColor;
- [mainTableView borderColor:RQlineColor width:1 cornorRadius:5];
- mainTableView.delegate = self;
- mainTableView.dataSource = self;
- [self.view addSubview:mainTableView];
-
- [mainTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
-
-
- //如果有预约就隐藏
- label = [[UILabel alloc] setxywh];
- label.x += 10;
- label.y += 10;
- label.width -= 20;
- label.height = 50;
- label.numberOfLines = 0;
- [label setText:@"恭喜您,该设备还没有任何预约!" Font:FontTitle TextColor:[UIColor orangeColor]];
- [self.view addSubview:label];
- noReserveLabel = label;
-
- //200 的尺寸 需要 选择时间 是否优惠 预约按钮 20+30 + 20+60+20 + 50
- NSString *labelString = @" 选择时段:";
- w = [labelString sizeForFont:Font17].width;
- y += h + 2*bd;
- h = 30;
- label = [[UILabel alloc] setxywh];
- [label setText:labelString Font:Font17 TextColor:kTitleColor];
- [self.view addSubview:label];
-
- x += w + bd;
- w = (kSize.width - x - bd - 30)/2.0;
- UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
- btn.frame = setDIYFrame;
- [btn setTitle:@"开始时间" textColor:RQ_MAIN_COLOR Font:Font17 fotState:UIControlStateNormal];
- [btn borderColor:RQ_MAIN_COLOR width:1 cornorRadius:5];
- [btn target:self tag:1];
- [self.view addSubview:btn];
- beginBtn = btn;
-
- x += w + 30;
- btn = [UIButton buttonWithType:UIButtonTypeSystem];
- btn.frame = setDIYFrame;
- [btn setTitle:@"结束时间" textColor:RQ_MAIN_COLOR Font:Font17 fotState:UIControlStateNormal];
- [btn borderColor:RQ_MAIN_COLOR width:1 cornorRadius:5];
- [btn target:self tag:2];
- [self.view addSubview:btn];
- endBtn = btn;
-
- x -= 25;
- w = 2 * bd;
- label = [[UILabel alloc] setxywh];
- [label setText:@"--" Font:Font17 TextColor:kTitleColor Alignment:NSTextAlignmentCenter];
- [self.view addSubview:label];
-
-
- //优惠
- x = bd;
- y += h + 2*bd;
- w = kSize.width - 2*x;
- h = 40;
- btn = [[UIButton alloc] setxywh];
- btn.titleLabel.numberOfLines = 0;
- [btn setTitle:@"暂无可用优惠券" textColor:contentTextColor Font:Font17 fotState:UIControlStateNormal];
- [btn borderColor:contentTextColor width:1 cornorRadius:5];
- [btn target:self tag:3];
- [self.view addSubview:btn];
- btn.userInteractionEnabled = NO;
- discountBtn = btn;
-
-
- //预约按钮
- x = 0;
- w += 2*bd;
- y += 60 + 2*bd;
- h = 50;
- btn = [[UIButton alloc] setxywh];
- btn.backgroundColor = backGroundColor;
- [btn setTitle:@"我要预约" textColor:RQ_MAIN_COLOR Font:FontTitle fotState:UIControlStateNormal];
- [btn target:self tag:4];
- [self.view addSubview:btn];
-
-
- [self getReserveMnByDevId];
- }
- - (void)btnClick:(UIButton *)sender {
-
- if (sender.tag == 1) {
- DateView *dateV = [[DateView alloc] init];
- [dateV setStyle:3];
- [dateV showWithComplete:^(NSString * result) {
-
- beginTime = result;
- [beginBtn setTitle:beginTime forState:UIControlStateNormal];
- }];
- }
-
- if (sender.tag == 2) {
- DateView *dateV = [[DateView alloc] init];
- [dateV setStyle:3];
- [dateV showWithComplete:^(NSString * result) {
-
- endTime = result;
- [endBtn setTitle:endTime forState:UIControlStateNormal];
- }];
- }
-
- if (sender.tag == 3) {
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"是否使用优惠券?" message:nil preferredStyle:UIAlertControllerStyleAlert];
-
- UIAlertAction *noAction = [UIAlertAction actionWithTitle:@"不使用" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- isUseDisCount = NO;
- [discountBtn setTitle:@"您有免费半小时优惠券,点击使用" forState:UIControlStateNormal];
- }];
-
- UIAlertAction *yesAction = [UIAlertAction actionWithTitle:@"使用" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- isUseDisCount = YES;
- [discountBtn setTitle:@"已选择使用免费半小时优惠券,请选择时长为半小时的时间段" forState:UIControlStateNormal];
- }];
-
- [alert addAction:noAction];
- [alert addAction:yesAction];
-
- [self presentViewController:alert animated:NO completion:nil];
- }
-
- if (sender.tag == 4) {
- if (![self isValueTime]) {
- return;
- }
-
- if (isUseDisCount) {
- if (![self isHalfOfHour]) {
- return;
- }
- }
-
- [self uploadReserveMn];
- }
- }
- - (BOOL)isValueTime {
-
- if (beginTime.length < 1) {
- ShowMsg(@"请选择开始时间");
- return NO;
- }
- if (endTime.length < 1) {
- ShowMsg(@"请选择结束时间");
- return NO;
- }
-
- if ([beginTime isEqualToString:endTime]) {
- ShowMsg(@"开始时间不能等于结束时间");
- return NO;
- }
-
- NSString *beginHou = [[beginTime componentsSeparatedByString:@":"] firstObject];
- NSString *beginMin = [[beginTime componentsSeparatedByString:@":"] lastObject];
-
- NSString *endHou = [[endTime componentsSeparatedByString:@":"] firstObject];
- NSString *endMin = [[endTime componentsSeparatedByString:@":"] lastObject];
-
- if (beginHou.integerValue > endHou.integerValue) {
- ShowMsg(@"开始时间不能大于结束时间");
- return NO;
- }
-
-
- if (beginHou.integerValue == endHou.integerValue) {
- if (beginMin.integerValue > endMin.integerValue) {
- ShowMsg(@"开始时间不能大于结束时间");
- return NO;
- }
- }
-
- return YES;
- }
- - (BOOL)isHalfOfHour {
-
- NSString *beginHou = [[beginTime componentsSeparatedByString:@":"] firstObject];
- NSString *beginMin = [[beginTime componentsSeparatedByString:@":"] lastObject];
-
- NSString *endHou = [[endTime componentsSeparatedByString:@":"] firstObject];
- NSString *endMin = [[endTime componentsSeparatedByString:@":"] lastObject];
-
- if (endHou.integerValue - beginHou.integerValue > 1) {
- return NO;
- }
-
- if (![beginHou isEqualToString:endHou] && [beginMin isEqualToString:endMin]) {
- return NO;
- }
-
- return YES;
- }
- #pragma mark tableView
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return dataArray.count;
- }
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
- if (cell == nil) {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- cell.textLabel.textAlignment = NSTextAlignmentCenter;
- }
-
- NSDictionary *dic = dataArray[indexPath.row];
- cell.textLabel.text = [NSString stringWithFormat:@"%@--%@ %@",dic[@"startTime"],dic[@"endTime"],dic[@"userName"]];
- return cell;
- }
- -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
- return [UIView new];
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
- return .1;
- }
- #pragma mark 数据请求
- - (void)getReserveMnByDevId {
-
- [LoadingView showHUD];
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- NSMutableArray *arr=[NSMutableArray array];
- [arr addPro:@"dqbh" Value:RQ_USER_MANAGER.currentUser.city];
- [arr addPro:@"devId" Value:_devDic[@"ID"]];
- [arr addPro:@"quotaId" Value:_quotaId];
-
- NSString* method = @"getReserveMnByDevId";
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
-
- RemoveHUD();
- // NSLog(@"getReserveMnByDevId--><>%@",root);
- if (!root) {
- return;
- }
-
- if ([root[@"code"] intValue] == 1) {
- ShowMsg(root[@"body"]);
- return;
- }
-
-
- price = [[root[@"body"] objectForKey:@"price"] floatValue];
- if ([[root[@"body"] objectForKey:@"price"] floatValue] > 0.0) {
-
- priceLabel.text = [NSString stringWithFormat:@" 培训日期:%@\n 开放时间:%@-%@\n 培训价格:%@元",[root[@"body"] objectForKey:@"PXRQ"],[root[@"body"] objectForKey:@"STARTTIME"],[root[@"body"] objectForKey:@"ENDTIME"],[root[@"body"] objectForKey:@"price"]];
- [self getDiscountHalfHour];
- }else {
- priceLabel.text = [NSString stringWithFormat:@" 培训日期:%@\n\n 开放时间:%@-%@",[root[@"body"] objectForKey:@"PXRQ"],[root[@"body"] objectForKey:@"STARTTIME"],[root[@"body"] objectForKey:@"ENDTIME"]];
- }
-
-
- dataArray = [root[@"body"] objectForKey:@"rmlist"];
-
- if (dataArray.count > 0) {
- noReserveLabel.hidden = YES;
- }else {
- noReserveLabel.hidden = NO;
- }
- [mainTableView reloadData];
- }];
- }
- - (void)getDiscountHalfHour {
-
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- NSMutableArray *arr=[NSMutableArray array];
- [arr addPro:@"dqbh" Value:RQ_USER_MANAGER.currentUser.city];
- [arr addPro:@"userId" Value:RQ_USER_MANAGER.currentUser._id];
-
- NSString* method = @"getDiscountHalfHour";
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
-
- if (!root) {
- return;
- }
-
- if ([root[@"code"] intValue] == 1) {
- ShowMsg(root[@"body"]);
- return;
- }
-
- if ([root[@"body"] integerValue] == 1) {
- discountBtn.userInteractionEnabled = YES;
- discountBtn.height = 50;
- [discountBtn setTitle:@"您有免费半小时优惠券,点击使用" textColor:[UIColor orangeColor] Font:Font17 fotState:UIControlStateNormal];
- discountBtn.layer.borderColor = [UIColor orangeColor].CGColor;
- }
- }];
- }
- - (void)uploadReserveMn {
-
- [LoadingView showHUD];
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- NSString *isPay = @"2";
- if (price > 0.00) {
- if (isUseDisCount) {
- isPay = @"1";
- }else{
- isPay = @"0";
- }
- }
-
- NSMutableArray *arr=[NSMutableArray array];
- [arr addPro:@"dqbh" Value:RQ_USER_MANAGER.currentUser.city];
- [arr addPro:@"deviceId" Value:_devDic[@"ID"]];
- [arr addPro:@"quotaId" Value:_quotaId];
- [arr addPro:@"isPay" Value:isPay];
- [arr addPro:@"startTime" Value:beginTime];
- [arr addPro:@"endTime" Value:endTime];
- [arr addPro:@"userId" Value:RQ_USER_MANAGER.currentUser._id];
-
-
- NSString* method = @"uploadReserveMn";
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
-
- RemoveHUD();
-
- if (!root) {
- return;
- }
-
- if ([root[@"code"] intValue] == 1) {
- ShowMsg(root[@"body"]);
- return;
- }
-
-
- [self getReserveMnByDevId];
- }];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- @end
|