// // IssueBaseSettingVC.m // jiaPeiC // // Created by apple on 16/6/14. // Copyright © 2016年 JCZ. All rights reserved. // #import "IssueBaseSettingVC.h" #import "TimeBar.h" #import "Tools.h" @interface IssueBaseSettingVC () { UIScrollView *mainScrollView; UIView *bottomView; TimeBar *lastTimeBar; UITextField *numberField, *priceField, *phoneNumField; UIButton *keErBtn, *keSanBtn, *yesBtn, *noBtn, *publicYesBtn, *publicNoBtn, *priceBtn; NSMutableArray *timeBarArray; NSString *keMuString; //NSString *isPayString; //NSString *isPublic; NSInteger alertIndex; } @end @implementation IssueBaseSettingVC - (void)viewDidLoad { [super viewDidLoad]; self.title = @"预约设置"; [self configNavBar]; self.view.backgroundColor = backGroundColor; //移除导航栏对UIScrollView坐标的影响 self.automaticallyAdjustsScrollViewInsets = NO; UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"保存" style:UIBarButtonItemStyleDone target:self action:@selector(itemClick)]; [item setTintColor:defGreen]; [self.navigationItem setRightBarButtonItem:item]; if (_moneyArray.count < 1) { [self getTrainPrice]; } [self myInit]; } -(void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [self.view endEditing:YES]; } -(void)myInit { CGFloat x,y,w,h; keMuString = @"2"; //要默认出来一个科目值 mainScrollView = [[UIScrollView alloc] initWithFrame:kFrame]; mainScrollView.delegate = self; [self.view addSubview:mainScrollView]; UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyBoard)]; [mainScrollView addGestureRecognizer:tapGesture]; x = 0; y = kNavOffSet; w = kSize.width; h = 40; UILabel *label = [[UILabel alloc] setxywh]; label.backgroundColor = lineColor; [label setText:@"修改设置,已保存的约车安排将不受影响" Font:Font14 TextColor:[UIColor orangeColor] Alignment:NSTextAlignmentCenter]; [mainScrollView addSubview:label]; y += h; label = [[UILabel alloc] setxywh]; [label setText:@" 预约时间段" Font:Font16 TextColor:titleColor]; [mainScrollView addSubview:label]; y += h; //NSLog(@"初始的计划------>%@",_dataArray); timeBarArray = [NSMutableArray array]; if (_dataArray.count > 0) { for (int i = 0; i < _dataArray.count; i ++) { NSDictionary *dic = _dataArray[i]; TimeBar *bar = [[TimeBar alloc] initWithFrame:CGRectMake(0, y + i*h, w, h)]; [mainScrollView addSubview:bar]; bar.timeTag = [NSString stringWithFormat:@"%d",i]; bar.taskTime = dic[@"times"]; if ([dic[@"times"] length] > 6) { NSArray *timeArray = [dic[@"times"] componentsSeparatedByString:@"-"]; [bar setBeginAndEndTimeWithBeginTime:[timeArray firstObject] EndTime:[timeArray lastObject]]; } //删除按钮 [bar showWithRemove:^(NSString *index) { //这里的方法中要判断,是否是已发布的计划 如果是已发布的计划,提醒用户可能删除失败 如果有人已经预约的话 如果正常删除 只需要在timeBarArray删除对应的bar就好了 if ([dic[@"status"] isEqualToString:@"1"]) { //已发布 做个提示 alertIndex = [index integerValue]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"该计划时间已发布,如果学员已预约成功,可能导致删除失败" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil]; [alert show]; }else{ [self refreshUIWithTag:[index integerValue]]; } }]; //选择结束时间 [bar finishEndTime:^(NSString *index) { //填写结束时间 for (TimeBar *allBar in timeBarArray) { //将二次迭代里面 是自己的情况剔除 if ([bar.beginTime isEqualToString:allBar.beginTime] && [bar.endTime isEqualToString:allBar.endTime]) { continue; } if ([self judgeSectionAIsInTheSectionBWithAPre:bar.beginTime AEnd:bar.endTime SectionPre:allBar.beginTime SectionEnd:allBar.endTime]){ ShowMsg(@"时间段有重复"); return; } } }]; [timeBarArray addObject:bar]; } }else{ //如果没有数值 先查本地 如果本地也没有 就添加几个 NSArray *times = nil; NSString *filePath = [Tools getPathWithFileName:@"issueLocalDic.plist"]; if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) { times = [NSArray arrayWithContentsOfFile:filePath]; }else{ times = @[@"08:00-11:00",@"14:00-17:00"]; } for (int i = 0; i < times.count; i ++) { TimeBar *bar = [[TimeBar alloc] initWithFrame:CGRectMake(0, y + i*h, w, h)]; [mainScrollView addSubview:bar]; bar.timeTag = [NSString stringWithFormat:@"%d",i]; bar.taskTime = times[i]; NSArray *timeArray = [times[i] componentsSeparatedByString:@"-"]; //NSLog(@"timeArray-------><>%@",timeArray); [bar setBeginAndEndTimeWithBeginTime:[timeArray firstObject] EndTime:[timeArray lastObject]]; //[bar setBeginAndEndTimeWithBeginTime:[times[i] substringToIndex:5] EndTime:[times[i] substringFromIndex:6]]; //删除按钮 [bar showWithRemove:^(NSString *index) { [self refreshUIWithTag:[index integerValue]]; }]; //选择结束时间 [bar finishEndTime:^(NSString *index) { //填写结束时间 for (TimeBar *allBar in timeBarArray) { //将二次迭代里面 是自己的情况剔除 if ([bar.beginTime isEqualToString:allBar.beginTime] && [bar.endTime isEqualToString:allBar.endTime]) { continue; } if ([self judgeSectionAIsInTheSectionBWithAPre:bar.beginTime AEnd:bar.endTime SectionPre:allBar.beginTime SectionEnd:allBar.endTime]){ ShowMsg(@"时间段有重复"); return; } } }]; [timeBarArray addObject:bar]; } } if (timeBarArray.count > 0) { lastTimeBar = [timeBarArray lastObject]; y = lastTimeBar.y + lastTimeBar.height; } h = 310; bottomView = [[UIView alloc] setxywh]; [mainScrollView addSubview:bottomView]; //设置mainScrollView的总大小 后面 每一次添加或者减少都要重新执行这个方法 [mainScrollView setContentSize:CGSizeMake(w, y + h)]; x = 20; y = 15; w -= 40; h = 35; UIButton *btn = [[UIButton alloc] setxywh]; [btn setTitle:@"添加更多时段" textColor:defGreen font:Font16 fotState:UIControlStateNormal]; [btn borderColor:defGreen width:1 cornorRadios:5]; [btn target:self Tag:1]; [bottomView addSubview:btn]; y += h + 5; //分割线 [btn addViewWithRect:CGRectMake(0, y, kSize.width, 5)]; y += 5; h = 40; NSArray *textArray = @[@"学车人数",@"学员练车价格",@"学员约车电话",@"科目选择",@"是否是先学后付",@"是否公开"]; NSArray *measureArray = @[@"人",@"元/时",@""]; NSString *telString = defUser.userDict[@"mobile"]; if (telString.length < 10) { telString = defUser.userDict[@"telephone"]; if (telString.length < 8) { telString = @"请填写手机号"; } } NSArray *textStringArray = @[@"4",@"0",telString]; NSMutableArray *fieldArray = [NSMutableArray arrayWithCapacity:5]; for (int i = 0; i < 4; i ++) {//是否先学后付 是否公开先不要 UI暂保留 i<6开启 label = [[UILabel alloc] initWithFrame:CGRectMake(x, y + i*h, w, h)]; [label setText:textArray[i] Font:Font16 TextColor:titleColor Alignment:NSTextAlignmentLeft]; [bottomView addSubview:label]; if (i < 3) { label = [[UILabel alloc] initWithFrame:CGRectMake(kSize.width - 55, y + i*h, 50, h)]; [label setText:measureArray[i] Font:Font16 TextColor:contentTextColor Alignment:NSTextAlignmentCenter]; [bottomView addSubview:label]; UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(x + 150, y + i*h, kSize.width - x - 205, h)]; if (i == 2) { textField.frame = CGRectMake(x + 150, y + i*h, kSize.width - x - 160, h); } [textField setTextAlignment:NSTextAlignmentRight]; [textField setTextColor:[UIColor orangeColor]]; [textField setFont:[UIFont scaleSize:Font16]]; textField.keyboardType = UIKeyboardTypeNumberPad; if ([textStringArray[i] isEqualToString:@"请填写手机号"]) { textField.placeholder = textStringArray[i]; }else{ textField.text = textStringArray[i]; } [bottomView addSubview:textField]; [fieldArray addObject:textField]; } if (i == 3) { UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame = CGRectMake(kSize.width/2.0, y + i*h, kSize.width/4.0, h); [button setImage:[UIImage imageNamed:@"selectAll"] Tit:@"科目二" Font:Font16 State:UIControlStateNormal]; [button setImage:[UIImage imageNamed:@"selectedAll"] forState:UIControlStateSelected]; [button setTitleColor:titleColor forState:UIControlStateNormal]; [button setTitleColor:defGreen forState:UIControlStateSelected]; [button target:self Tag:2]; [bottomView addSubview:button]; keErBtn = button; button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame = CGRectMake(kSize.width - kSize.width/4.0, y + i*h, kSize.width/4.0, h); [button setImage:[UIImage imageNamed:@"selectAll"] Tit:@"科目三" Font:Font16 State:UIControlStateNormal]; [button setImage:[UIImage imageNamed:@"selectedAll"] forState:UIControlStateSelected]; [button setTitleColor:titleColor forState:UIControlStateNormal]; [button setTitleColor:defGreen forState:UIControlStateSelected]; [button target:self Tag:3]; [bottomView addSubview:button]; keSanBtn = button; keErBtn.selected = YES; } if (i == 4) { UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame = CGRectMake(kSize.width/2.0, y + i*h, kSize.width/4.0, h); [button setImage:[UIImage imageNamed:@"selectAll"] Tit:@"是 " Font:Font16 State:UIControlStateNormal]; [button setImage:[UIImage imageNamed:@"selectedAll"] forState:UIControlStateSelected]; [button setTitleColor:titleColor forState:UIControlStateNormal]; [button setTitleColor:defGreen forState:UIControlStateSelected]; [button target:self Tag:4]; [bottomView addSubview:button]; [button setSelected:YES]; yesBtn = button; button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame = CGRectMake(kSize.width - kSize.width/4.0, y + i*h, kSize.width/4.0, h); [button setImage:[UIImage imageNamed:@"selectAll"] Tit:@"否 " Font:Font16 State:UIControlStateNormal]; [button setImage:[UIImage imageNamed:@"selectedAll"] forState:UIControlStateSelected]; [button setTitleColor:titleColor forState:UIControlStateNormal]; [button setTitleColor:defGreen forState:UIControlStateSelected]; [button target:self Tag:5]; [bottomView addSubview:button]; noBtn = button; } if (i == 5) { UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame = CGRectMake(kSize.width/2.0, y + i*h, kSize.width/4.0, h); [button setImage:[UIImage imageNamed:@"selectAll"] Tit:@"是 " Font:Font16 State:UIControlStateNormal]; [button setImage:[UIImage imageNamed:@"selectedAll"] forState:UIControlStateSelected]; [button setTitleColor:titleColor forState:UIControlStateNormal]; [button setTitleColor:defGreen forState:UIControlStateSelected]; [button target:self Tag:6]; [bottomView addSubview:button]; publicYesBtn = button; button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame = CGRectMake(kSize.width - kSize.width/4.0, y + i*h, kSize.width/4.0, h); [button setImage:[UIImage imageNamed:@"selectAll"] Tit:@"否 " Font:Font16 State:UIControlStateNormal]; [button setImage:[UIImage imageNamed:@"selectedAll"] forState:UIControlStateSelected]; [button setTitleColor:titleColor forState:UIControlStateNormal]; [button setTitleColor:defGreen forState:UIControlStateSelected]; [button target:self Tag:7]; [button setSelected:YES]; [bottomView addSubview:button]; publicNoBtn = button; } } numberField = fieldArray[0]; priceField = fieldArray[1]; phoneNumField = fieldArray[2]; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame = priceField.frame; button.backgroundColor = [UIColor clearColor]; //[button setTitle:@"0" textColor:[UIColor orangeColor] font:Font16 fotState:UIControlStateNormal]; [button target:self Tag:8]; [bottomView addSubview:button]; priceBtn = button; priceField.userInteractionEnabled = NO; //注册键盘出现的通知 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardWillShowNotification object:nil]; //注册键盘消失的通知 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillBeHidden:) name:UIKeyboardWillHideNotification object:nil]; } -(void)saveFail { //如果删除失败 要将之前页面移除 重洗添加 [mainScrollView removeFromSuperview]; if (timeBarArray) { //NSLog(@"清除数组信息"); [timeBarArray removeAllObjects]; timeBarArray = nil; } [self myInit]; } //创建新的bar -(void)creatNewTimeBar { CGFloat y = 80 + kNavOffSet; if (timeBarArray.count > 0) { y = lastTimeBar.y + lastTimeBar.height; } TimeBar *bar = [[TimeBar alloc] initWithFrame:CGRectMake(0, y, kSize.width, 40)]; [mainScrollView addSubview:bar]; bar.timeTag = [NSString stringWithFormat:@"%d",(int)timeBarArray.count]; //删除按钮 [bar showWithRemove:^(NSString *index) { //这里的方法中要判断,是否是已发布的计划 如果是已发布的计划,提醒用户可能删除失败 如果有人已经预约的话 如果正常删除 只需要在timeBarArray删除对应的bar就好了 [self refreshUIWithTag:[index integerValue]]; }]; //选择结束时间 [bar finishEndTime:^(NSString *index) { //判断是否合法 即开始时间是否小于结束时间 if (![self judgeTimeIsRightWithPre:bar.beginTime End:bar.endTime]) { ShowMsg(@"开始时间不能大于结束时间"); return; } //判断是否与现有的重复 for (TimeBar *allBar in timeBarArray) { //将二次迭代里面 是自己的情况剔除 if ([bar.beginTime isEqualToString:allBar.beginTime] && [bar.endTime isEqualToString:allBar.endTime]) { continue; } if ([self judgeSectionAIsInTheSectionBWithAPre:bar.beginTime AEnd:bar.endTime SectionPre:allBar.beginTime SectionEnd:allBar.endTime]){ ShowMsg(@"时间段有重复"); return; } } }]; [timeBarArray addObject:bar]; lastTimeBar = bar; y = lastTimeBar.y + lastTimeBar.height; bottomView.y = y; [mainScrollView setContentSize:CGSizeMake(kSize.width, y + 310)]; } //这个是每次删除后对UI的刷新 -(void)refreshUIWithTag:(NSInteger)tag { //先从页面删除 再从数组中删除掉 TimeBar *delBar = timeBarArray[tag]; [delBar removeFromSuperview]; [timeBarArray removeObjectAtIndex:tag]; CGFloat y = 80 + kNavOffSet; CGFloat w = kSize.width; CGFloat h = 40; for (int i = 0; i < timeBarArray.count; i ++) { TimeBar *bar = timeBarArray[i]; bar.frame = CGRectMake(0, y + i*h, w, h); bar.timeTag = [NSString stringWithFormat:@"%d",i]; } if (timeBarArray.count > 0) { lastTimeBar = [timeBarArray lastObject]; y = lastTimeBar.y + lastTimeBar.height; }else{ //这里表示 如果全部删除了 则将最后一个bar置空 lastTimeBar = nil; } bottomView.y = y; [mainScrollView setContentSize:CGSizeMake(kSize.width, y + 270)]; } #pragma mark 点击事件 -(void)itemClick { if (timeBarArray.count > 0) { if ([lastTimeBar.beginTime isEqualToString:@"开始时间"] || [lastTimeBar.endTime isEqualToString:@"结束时间"]) { ShowMsg(@"请设置时间段信息"); return; } } for (TimeBar *testBar in timeBarArray) { //判断当前测试的时间段是否合法 如果不合法则无法发布 如果合法 在判断当前测试与其他时间段是否重复 if (![self judgeTimeIsRightWithPre:testBar.beginTime End:testBar.endTime]) { ShowMsg(@"开始时间不能大于结束时间"); return; } int i = 0; for (TimeBar *bar in timeBarArray) { //将二次迭代里面 是自己的情况剔除 if ([testBar.beginTime isEqualToString:bar.beginTime] && [testBar.endTime isEqualToString:bar.endTime]) { i += 1; if (i > 1) { //等1是正常的 表示遍历到了自己 大于1则表示有重复 ShowMsg(@"时间段有重复"); return; } continue; } if ([self judgeSectionAIsInTheSectionBWithAPre:testBar.beginTime AEnd:testBar.endTime SectionPre:bar.beginTime SectionEnd:bar.endTime]) { ShowMsg(@"时间段有重复"); return; } } } [self savePlanInfoAsyc]; } -(void)btnClick:(UIButton *)sender { switch (sender.tag) { case 1: { if (timeBarArray.count > 0) { if ([lastTimeBar.beginTime isEqualToString:@"开始时间"] || [lastTimeBar.endTime isEqualToString:@"结束时间"]) { //如果有未完成的 就不能继续添加 ShowMsg(@"已经存在一个未完成的时间段"); return; } } //判断最后一个是否合法 即开始时间是否小于结束时间 不合法则不法创建下一个 if (![self judgeTimeIsRightWithPre:lastTimeBar.beginTime End:lastTimeBar.endTime]) { ShowMsg(@"开始时间不能大于结束时间"); return; } //判断最后一个是否与之前的重复 如果有重复则不能创建下一个 for (TimeBar *bar in timeBarArray) { //防止因为lastTimeBar没有 if ([lastTimeBar.beginTime isEqualToString:bar.beginTime] && [lastTimeBar.endTime isEqualToString:bar.endTime]) { continue; } if ([self judgeSectionAIsInTheSectionBWithAPre:lastTimeBar.beginTime AEnd:lastTimeBar.endTime SectionPre:bar.beginTime SectionEnd:bar.endTime]) { ShowMsg(@"时间段有重复"); return; } } [self creatNewTimeBar]; } break; case 8: [self selectPrice]; break; default: [self setWhiceSelectWithTag:sender.tag]; break; } } -(void)setWhiceSelectWithTag:(NSInteger)tag { //设置信息也是在这里边写的 if (tag == 2) { keSanBtn.selected = NO; keErBtn.selected = YES; keMuString = @"2"; } if (tag == 3) { keErBtn.selected = NO; keSanBtn.selected = YES; keMuString = @"3"; } // if (tag == 4) { // noBtn.selected = NO; // yesBtn.selected = YES; // isPayString = @"1"; // } // if (tag == 5) { // yesBtn.selected = NO; // noBtn.selected = YES; // isPayString = @"0"; // //将price置为0 // priceField.text = @"0"; // } // if (tag == 6) { // publicNoBtn.selected = NO; // publicYesBtn.selected = YES; // isPublic = @"1"; // } // if (tag == 7) { // publicYesBtn.selected = NO; // publicNoBtn.selected = YES; // isPublic = @"0"; // } } -(void)selectPrice { NSMutableArray *titleArray = [NSMutableArray array]; [titleArray addObject:@"免费模式"]; for (NSDictionary *dic in self.moneyArray) { NSString * strSD = @""; switch ([dic[@"CSI_TRAINNINGTIME"] integerValue]) { case 1: strSD = @"普通时段"; break; case 2: strSD = @"高峰时段"; break; case 3: strSD = @"节假日时段"; break; default: break; } NSString *titleString = [NSString stringWithFormat:@"%@ %@ %@元 ",strSD,dic[@"CSI_VEHICLETYPE"],dic[@"CSI_PRICE"]]; [titleArray addObject:titleString]; } //UIActionSheet对按钮数量不确定时候的处理 UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"选择培训价格" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil]; for (NSString *title in titleArray) { [sheet addButtonWithTitle:title]; } [sheet addButtonWithTitle:@"取消"]; sheet.cancelButtonIndex = sheet.numberOfButtons - 1; sheet.actionSheetStyle = UIActionSheetStyleDefault; [sheet showInView:self.view]; } -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { if (buttonIndex == actionSheet.cancelButtonIndex) { return; } if (buttonIndex == 0) { priceField.text = @"免费模式"; return; } NSDictionary *dic = self.moneyArray[buttonIndex - 1]; priceField.text = dic[@"CSI_PRICE"]; //[priceBtn setTitle:dic[@"CSI_PRICE"] forState:UIControlStateNormal]; } -(BOOL)judgeTimeIsRightWithPre:(NSString *)pre End:(NSString *)end { int preHour = [[pre substringToIndex:2] intValue]; int preMin = [[pre substringFromIndex:3] intValue]; int endHour = [[end substringToIndex:2] intValue]; int endMin = [[end substringFromIndex:3] intValue]; if (preHour > endHour) { return NO; }else{ if (preHour == endHour) { if (preMin > endMin) { return NO; } } } return YES; } -(BOOL)judgeSectionAIsInTheSectionBWithAPre:(NSString *)APre AEnd:(NSString *)AEnd SectionPre:(NSString *)pre SectionEnd:(NSString *)end { int APreHour = [[APre substringToIndex:2] intValue]; int APreMin = [[APre substringFromIndex:3] intValue]; int AEndHour = [[AEnd substringToIndex:2] intValue]; int AEndMin = [[AEnd substringFromIndex:3] intValue]; int preHour = [[pre substringToIndex:2] intValue]; int preMin = [[pre substringFromIndex:3] intValue]; int endHour = [[end substringToIndex:2] intValue]; int endMin = [[end substringFromIndex:3] intValue]; //NSLog(@"--%d:%d----%d:%d-- --%d:%d----%d:%d--",APreHour,APreMin,AEndHour,AEndMin,preHour,preMin,endHour,endMin); if (APreHour > endHour) { return NO; }else if (APreHour == endHour){ if (APreMin >= endMin) { return NO; } } if (AEndHour < preHour) { return NO; }else if (AEndHour == preHour){ if (AEndMin <= preMin) { return NO; } } return YES; } -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { if (buttonIndex == 0) { return; }else{ [self refreshUIWithTag:alertIndex]; } } #pragma mark -- 页面设置 -(void)scrollViewDidScroll:(UIScrollView *)scrollView { [self.view endEditing:YES]; } -(void)hideKeyBoard { [self.view endEditing:YES]; } //展示键盘 - (void)keyboardWasShown:(NSNotification*)aNotification { CGRect keyBoardFrame = [[[aNotification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; [UIView animateWithDuration:.3 animations:^{ mainScrollView.y = -keyBoardFrame.size.height; }]; } //隐藏键盘 -(void)keyboardWillBeHidden:(NSNotification*)aNotification { [UIView animateWithDuration:.4 animations:^{ mainScrollView.frame = kFrame; }]; } #pragma mark 数据请求 //发布接口 -(void)savePlanInfoAsyc{ NSMutableArray *timeArrray = [NSMutableArray array]; NSMutableArray *newTimeArrray = [NSMutableArray array]; for (NSDictionary *dic in _dataArray) { [timeArrray addObject:dic[@"times"]]; } for (TimeBar *bar in timeBarArray) { NSString *timeString = [NSString stringWithFormat:@"%@-%@",bar.beginTime,bar.endTime]; [newTimeArrray addObject:timeString]; } //将最新的结果保存到本地 NSString *filePath = [Tools getPathWithFileName:@"issueLocalDic.plist"]; [newTimeArrray writeToFile:filePath atomically:YES]; NSString *addString = @""; NSString *delString = @""; //删掉的 for (NSString *string in timeArrray) { if (![newTimeArrray containsObject:string]) { if (string.length > 0) { delString = [delString stringByAppendingString:[NSString stringWithFormat:@"%@,",string]]; } continue; } } if (delString.length > 0) { delString = [delString substringToIndex:delString.length - 1]; } //添加的 for (NSString *newString in newTimeArrray) { if (![timeArrray containsObject:newString]) { if (newString.length > 0) { addString = [addString stringByAppendingString:[NSString stringWithFormat:@"%@,",newString]]; } continue; } } if (addString.length > 0) { addString = [addString substringToIndex:addString.length - 1]; } //NSLog(@"原计划----->%@-----现计划------>%@----------del--->%@---add--->%@",timeArrray,newTimeArrray,delString,addString); if (delString.length < 1 && addString.length < 1) { //说明没做任何处理 ShowMsg(@"当前计划时间没有改动"); [self.navigationController popViewControllerAnimated:YES]; return; } // if (addString.length > 0) { // //如果有添加的 要判断价格是否大于0 // if ([priceField.text integerValue] <= 0) { // ShowMsg(@"请选择培训价格"); // return; // } // } if (phoneNumField.text.length < 1) { ShowMsg(@"请输入您的手机号码"); return; } if (numberField.text.length == 0 || [numberField.text integerValue]==0 || [numberField.text integerValue]>10) { ShowMsg(@"请设置合理的学车人数"); return; } NSArray *addAndDelArray = @[addString,delString]; [self savePlanInfo:addAndDelArray]; } - (void)savePlanInfo:(NSArray *)addAndDel { NSString *priceString = priceField.text; if ([priceString isEqualToString:@"免费模式"]) { priceString = @"0"; } NSMutableArray *arr=[NSMutableArray array]; [arr addPro:@"user" Value:defUser.sfzmhm]; [arr addPro:@"title" Value:@""]; [arr addPro:@"content" Value:@""]; [arr addPro:@"num" Value:numberField.text]; [arr addPro:@"tel" Value:phoneNumField.text]; [arr addPro:@"taskTime" Value:_dateString]; [arr addPro:@"userName" Value:defUser.userDict[@"name"]]; [arr addPro:@"km" Value:keMuString]; [arr addPro:@"jsAddress" Value:@""]; [arr addPro:@"money" Value:priceString]; [arr addPro:@"addTimesArr" Value:addAndDel[0]]; [arr addPro:@"delTimesArr" Value:addAndDel[1]]; NSString* method = @"uploadPlanInfo"; ShowHUD(); [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) { RemoveHUD(); //NSLog(@"保存计划--arr---->%@ /n---->root->%@",arr,root); //如果保存失败 如何回到之前的状态 if (!root) { ShowMsgFailed(); [self saveFail]; return ; } if ([root[@"code"] isEqualToString:@"1"]) { ShowMsg(root[@"body"]); [self saveFail]; return; } ShowMsgSuc(); [self.navigationController popViewControllerAnimated:YES]; }]; } //获取价格 -(void)getTrainPrice { NSMutableArray *arr=[NSMutableArray array]; [arr addPro:@"schoolId" Value:defUser.userDict[@"jxbh"]]; [arr addPro:@"dqbh" Value:defUser.userDict[@"cityId"]]; NSString* method = @"getPrice"; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * dict) { RemoveHUD(); //NSLog(@"获取价格-->%@->%@",arr,dict); if (!dict) { return ; } if ( [dict[@"code"] isEqualToString:@"1"]) { return ; } _moneyArray = dict[@"body"]; }]; } - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } @end