IssueBaseSettingVC.m 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908
  1. //
  2. // IssueBaseSettingVC.m
  3. // jiaPeiC
  4. //
  5. // Created by apple on 16/6/14.
  6. // Copyright © 2016年 JCZ. All rights reserved.
  7. //
  8. #import "IssueBaseSettingVC.h"
  9. #import "TimeBar.h"
  10. #import "Tools.h"
  11. @interface IssueBaseSettingVC ()<UIScrollViewDelegate,UIAlertViewDelegate,UIActionSheetDelegate,UITextFieldDelegate>
  12. {
  13. UIScrollView *mainScrollView;
  14. UIView *bottomView;
  15. TimeBar *lastTimeBar;
  16. UITextField *numberField, *priceField, *phoneNumField, *temperatureTextField;
  17. UIButton *keErBtn, *keSanBtn, *yesBtn, *noBtn, *publicYesBtn, *publicNoBtn;
  18. NSMutableArray *timeBarArray;
  19. NSString *keMuString;
  20. //NSString *isPayString;
  21. //NSString *isPublic;
  22. NSInteger alertIndex;
  23. }
  24. @property (strong, readwrite, nonatomic) NSString *temperatureStr;
  25. @end
  26. @implementation IssueBaseSettingVC
  27. - (void)viewDidLoad {
  28. [super viewDidLoad];
  29. self.title = @"预约设置";
  30. [self configNavBar];
  31. self.view.backgroundColor = backGroundColor;
  32. //移除导航栏对UIScrollView坐标的影响
  33. self.automaticallyAdjustsScrollViewInsets = NO;
  34. UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"保存" style:UIBarButtonItemStyleDone target:self action:@selector(itemClick)];
  35. [item setTintColor:defGreen];
  36. [self.navigationItem setRightBarButtonItem:item];
  37. if (_moneyArray.count < 1) {
  38. [self getTrainPrice];
  39. }
  40. [self myInit];
  41. }
  42. -(void)viewWillDisappear:(BOOL)animated
  43. {
  44. [super viewWillDisappear:animated];
  45. [self.view endEditing:YES];
  46. }
  47. -(void)myInit
  48. {
  49. CGFloat x,y,w,h;
  50. keMuString = @"2"; //要默认出来一个科目值
  51. mainScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, kNavOffSet, kScreenWidth, kScreenHeight - kNavOffSet - kSafeAreaBottomHeight)];
  52. mainScrollView.delegate = self;
  53. [self.view addSubview:mainScrollView];
  54. // UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyBoard)];
  55. // [mainScrollView addGestureRecognizer:tapGesture];
  56. x = 0;
  57. y = 0;
  58. w = kSize.width;
  59. h = 40;
  60. UILabel *label = [[UILabel alloc] setxywh];
  61. label.backgroundColor = lineColor;
  62. [label setText:@"修改设置,已保存的约车安排将不受影响" Font:Font14 TextColor:[UIColor orangeColor] Alignment:NSTextAlignmentCenter];
  63. [mainScrollView addSubview:label];
  64. y += h;
  65. label = [[UILabel alloc] setxywh];
  66. [label setText:@" 预约时间段" Font:Font16 TextColor:kTitleColor];
  67. [mainScrollView addSubview:label];
  68. y += h;
  69. //NSLog(@"初始的计划------>%@",_dataArray);
  70. timeBarArray = [NSMutableArray array];
  71. if (_dataArray.count > 0) {
  72. for (int i = 0; i < _dataArray.count; i ++) {
  73. NSDictionary *dic = _dataArray[i];
  74. TimeBar *bar = [[TimeBar alloc] initWithFrame:CGRectMake(0, y + i*h, w, h)];
  75. [mainScrollView addSubview:bar];
  76. bar.timeTag = [NSString stringWithFormat:@"%d",i];
  77. bar.taskTime = dic[@"times"];
  78. if ([dic[@"times"] length] > 6) {
  79. NSArray *timeArray = [dic[@"times"] componentsSeparatedByString:@"-"];
  80. [bar setBeginAndEndTimeWithBeginTime:[timeArray firstObject] EndTime:[timeArray lastObject]];
  81. }
  82. //删除按钮
  83. [bar showWithRemove:^(NSString *index) {
  84. //这里的方法中要判断,是否是已发布的计划 如果是已发布的计划,提醒用户可能删除失败 如果有人已经预约的话 如果正常删除 只需要在timeBarArray删除对应的bar就好了
  85. if ([dic[@"status"] isEqualToString:@"1"]) {
  86. //已发布 做个提示
  87. alertIndex = [index integerValue];
  88. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"该计划时间已发布,如果学员已预约成功,可能导致删除失败" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
  89. [alert show];
  90. }else{
  91. [self refreshUIWithTag:[index integerValue]];
  92. }
  93. }];
  94. //选择结束时间
  95. [bar finishEndTime:^(NSString *index) {
  96. //填写结束时间
  97. for (TimeBar *allBar in timeBarArray) {
  98. //将二次迭代里面 是自己的情况剔除
  99. if ([bar.beginTime isEqualToString:allBar.beginTime] && [bar.endTime isEqualToString:allBar.endTime]) {
  100. continue;
  101. }
  102. if ([self judgeSectionAIsInTheSectionBWithAPre:bar.beginTime AEnd:bar.endTime SectionPre:allBar.beginTime SectionEnd:allBar.endTime]){
  103. ShowMsg(@"时间段有重复");
  104. return;
  105. }
  106. }
  107. }];
  108. [timeBarArray addObject:bar];
  109. }
  110. }else{
  111. //如果没有数值 先查本地 如果本地也没有 就添加几个
  112. NSArray *times = nil;
  113. NSString *filePath = [Tools getPathWithFileName:@"issueLocalDic.plist"];
  114. if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
  115. times = [NSArray arrayWithContentsOfFile:filePath];
  116. }else{
  117. times = @[@"08:00-11:00",@"14:00-17:00"];
  118. }
  119. for (int i = 0; i < times.count; i ++) {
  120. TimeBar *bar = [[TimeBar alloc] initWithFrame:CGRectMake(0, y + i*h, w, h)];
  121. [mainScrollView addSubview:bar];
  122. bar.timeTag = [NSString stringWithFormat:@"%d",i];
  123. bar.taskTime = times[i];
  124. NSArray *timeArray = [times[i] componentsSeparatedByString:@"-"];
  125. //NSLog(@"timeArray-------><>%@",timeArray);
  126. [bar setBeginAndEndTimeWithBeginTime:[timeArray firstObject] EndTime:[timeArray lastObject]];
  127. //[bar setBeginAndEndTimeWithBeginTime:[times[i] substringToIndex:5] EndTime:[times[i] substringFromIndex:6]];
  128. //删除按钮
  129. [bar showWithRemove:^(NSString *index) {
  130. [self refreshUIWithTag:[index integerValue]];
  131. }];
  132. //选择结束时间
  133. [bar finishEndTime:^(NSString *index) {
  134. //填写结束时间
  135. for (TimeBar *allBar in timeBarArray) {
  136. //将二次迭代里面 是自己的情况剔除
  137. if ([bar.beginTime isEqualToString:allBar.beginTime] && [bar.endTime isEqualToString:allBar.endTime]) {
  138. continue;
  139. }
  140. if ([self judgeSectionAIsInTheSectionBWithAPre:bar.beginTime AEnd:bar.endTime SectionPre:allBar.beginTime SectionEnd:allBar.endTime]){
  141. ShowMsg(@"时间段有重复");
  142. return;
  143. }
  144. }
  145. }];
  146. [timeBarArray addObject:bar];
  147. }
  148. }
  149. if (timeBarArray.count > 0) {
  150. lastTimeBar = [timeBarArray lastObject];
  151. y = lastTimeBar.y + lastTimeBar.height;
  152. }
  153. h = 310;
  154. bottomView = [[UIView alloc] setxywh];
  155. [mainScrollView addSubview:bottomView];
  156. //设置mainScrollView的总大小 后面 每一次添加或者减少都要重新执行这个方法
  157. [mainScrollView setContentSize:CGSizeMake(w, y + h)];
  158. x = 20;
  159. y = 15;
  160. w -= 40;
  161. h = 35;
  162. UIButton *btn = [[UIButton alloc] setxywh];
  163. [btn setTitle:@"添加更多时段" textColor:defGreen font:Font16 fotState:UIControlStateNormal];
  164. [btn borderColor:defGreen width:1 cornorRadios:5];
  165. [btn target:self Tag:1];
  166. [bottomView addSubview:btn];
  167. y += h + 5;
  168. //分割线
  169. [btn addViewWithRect:CGRectMake(0, y, kSize.width, 5)];
  170. y += 5;
  171. h = 40;
  172. NSArray *textArray = @[@"学车人数",@"学员练车价格",@"学员约车电话",@"教练当前体温",@"科目选择",@"是否是先学后付",@"是否公开"];
  173. NSArray *measureArray = @[@"人",@"元/时",@"",@"°C"];
  174. NSString *telString = defUser.userDict[@"mobile"];
  175. if (telString.length < 10) {
  176. telString = defUser.userDict[@"telephone"];
  177. if (telString.length < 8) {
  178. telString = @"请填写手机号";
  179. }
  180. }
  181. NSArray *textStringArray = @[@"1",@"0",telString,@""];
  182. NSMutableArray *fieldArray = [NSMutableArray arrayWithCapacity:5];
  183. for (int i = 0; i < 5; i ++) {//是否先学后付 是否公开先不要 UI暂保留 i<7开启
  184. label = [[UILabel alloc] initWithFrame:CGRectMake(x, y + i*h, w, h)];
  185. [label setText:textArray[i] Font:Font16 TextColor:kTitleColor Alignment:NSTextAlignmentLeft];
  186. [bottomView addSubview:label];
  187. if (i < 4) {
  188. label = [[UILabel alloc] initWithFrame:CGRectMake(kSize.width - 55, y + i*h, 50, h)];
  189. [label setText:measureArray[i] Font:Font16 TextColor:contentTextColor Alignment:NSTextAlignmentCenter];
  190. [bottomView addSubview:label];
  191. UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(x + 150, y + i*h, kSize.width - x - 205, h)];
  192. if (i == 2) {
  193. textField.frame = CGRectMake(x + 150, y + i*h, kSize.width - x - 160, h);
  194. }
  195. [textField setTextAlignment:NSTextAlignmentRight];
  196. [textField setTextColor:[UIColor orangeColor]];
  197. [textField setFont:[UIFont scaleSize:Font16]];
  198. textField.keyboardType = (i == 3 || i == 1)? UIKeyboardTypeDecimalPad : UIKeyboardTypeNumberPad;
  199. if ([textStringArray[i] isEqualToString:@"请填写手机号"]) {
  200. textField.placeholder = textStringArray[i];
  201. }else{
  202. textField.text = textStringArray[i];
  203. }
  204. [bottomView addSubview:textField];
  205. [fieldArray addObject:textField];
  206. }
  207. if (i == 4) {
  208. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  209. button.frame = CGRectMake(kSize.width/2.0, y + i*h, kSize.width/4.0, h);
  210. [button setImage:[UIImage imageNamed:@"selectAll"] Tit:@"科目二" Font:Font16 State:UIControlStateNormal];
  211. [button setImage:[UIImage imageNamed:@"selectedAll"] forState:UIControlStateSelected];
  212. [button setTitleColor:kTitleColor forState:UIControlStateNormal];
  213. [button setTitleColor:defGreen forState:UIControlStateSelected];
  214. [button target:self Tag:2];
  215. [bottomView addSubview:button];
  216. keErBtn = button;
  217. button = [UIButton buttonWithType:UIButtonTypeCustom];
  218. button.frame = CGRectMake(kSize.width - kSize.width/4.0, y + i*h, kSize.width/4.0, h);
  219. [button setImage:[UIImage imageNamed:@"selectAll"] Tit:@"科目三" Font:Font16 State:UIControlStateNormal];
  220. [button setImage:[UIImage imageNamed:@"selectedAll"] forState:UIControlStateSelected];
  221. [button setTitleColor:kTitleColor forState:UIControlStateNormal];
  222. [button setTitleColor:defGreen forState:UIControlStateSelected];
  223. [button target:self Tag:3];
  224. [bottomView addSubview:button];
  225. keSanBtn = button;
  226. keErBtn.selected = YES;
  227. }
  228. if (i == 5) {
  229. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  230. button.frame = CGRectMake(kSize.width/2.0, y + i*h, kSize.width/4.0, h);
  231. [button setImage:[UIImage imageNamed:@"selectAll"] Tit:@"是 " Font:Font16 State:UIControlStateNormal];
  232. [button setImage:[UIImage imageNamed:@"selectedAll"] forState:UIControlStateSelected];
  233. [button setTitleColor:kTitleColor forState:UIControlStateNormal];
  234. [button setTitleColor:defGreen forState:UIControlStateSelected];
  235. [button target:self Tag:4];
  236. [bottomView addSubview:button];
  237. [button setSelected:YES];
  238. yesBtn = button;
  239. button = [UIButton buttonWithType:UIButtonTypeCustom];
  240. button.frame = CGRectMake(kSize.width - kSize.width/4.0, y + i*h, kSize.width/4.0, h);
  241. [button setImage:[UIImage imageNamed:@"selectAll"] Tit:@"否 " Font:Font16 State:UIControlStateNormal];
  242. [button setImage:[UIImage imageNamed:@"selectedAll"] forState:UIControlStateSelected];
  243. [button setTitleColor:kTitleColor forState:UIControlStateNormal];
  244. [button setTitleColor:defGreen forState:UIControlStateSelected];
  245. [button target:self Tag:5];
  246. [bottomView addSubview:button];
  247. noBtn = button;
  248. }
  249. if (i == 6) {
  250. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  251. button.frame = CGRectMake(kSize.width/2.0, y + i*h, kSize.width/4.0, h);
  252. [button setImage:[UIImage imageNamed:@"selectAll"] Tit:@"是 " Font:Font16 State:UIControlStateNormal];
  253. [button setImage:[UIImage imageNamed:@"selectedAll"] forState:UIControlStateSelected];
  254. [button setTitleColor:kTitleColor forState:UIControlStateNormal];
  255. [button setTitleColor:defGreen forState:UIControlStateSelected];
  256. [button target:self Tag:6];
  257. [bottomView addSubview:button];
  258. publicYesBtn = button;
  259. button = [UIButton buttonWithType:UIButtonTypeCustom];
  260. button.frame = CGRectMake(kSize.width - kSize.width/4.0, y + i*h, kSize.width/4.0, h);
  261. [button setImage:[UIImage imageNamed:@"selectAll"] Tit:@"否 " Font:Font16 State:UIControlStateNormal];
  262. [button setImage:[UIImage imageNamed:@"selectedAll"] forState:UIControlStateSelected];
  263. [button setTitleColor:kTitleColor forState:UIControlStateNormal];
  264. [button setTitleColor:defGreen forState:UIControlStateSelected];
  265. [button target:self Tag:7];
  266. [button setSelected:YES];
  267. [bottomView addSubview:button];
  268. publicNoBtn = button;
  269. }
  270. }
  271. numberField = fieldArray[0];
  272. priceField = fieldArray[1];
  273. phoneNumField = fieldArray[2];
  274. temperatureTextField = fieldArray[3];
  275. RAC(temperatureTextField, text) = RACObserve(self, temperatureStr);
  276. // UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  277. // button.frame = priceField.frame;
  278. // button.backgroundColor = [UIColor clearColor];
  279. //[button setTitle:@"0" textColor:[UIColor orangeColor] font:Font16 fotState:UIControlStateNormal];
  280. // [button target:self Tag:8];
  281. // [bottomView addSubview:button];
  282. // priceBtn = button;
  283. // priceField.userInteractionEnabled = NO;
  284. // //注册键盘出现的通知
  285. // [[NSNotificationCenter defaultCenter] addObserver:self
  286. // selector:@selector(keyboardWasShown:)
  287. // name:UIKeyboardWillShowNotification object:nil];
  288. //
  289. // //注册键盘消失的通知
  290. // [[NSNotificationCenter defaultCenter] addObserver:self
  291. // selector:@selector(keyboardWillBeHidden:)
  292. // name:UIKeyboardWillHideNotification object:nil];
  293. }
  294. -(void)saveFail
  295. {
  296. //如果删除失败 要将之前页面移除 重洗添加
  297. [mainScrollView removeFromSuperview];
  298. if (timeBarArray) {
  299. //NSLog(@"清除数组信息");
  300. [timeBarArray removeAllObjects];
  301. timeBarArray = nil;
  302. }
  303. [self myInit];
  304. }
  305. //创建新的bar
  306. -(void)creatNewTimeBar
  307. {
  308. CGFloat y = 80;
  309. if (timeBarArray.count > 0) {
  310. y = lastTimeBar.y + lastTimeBar.height;
  311. }
  312. TimeBar *bar = [[TimeBar alloc] initWithFrame:CGRectMake(0, y, kSize.width, 40)];
  313. [mainScrollView addSubview:bar];
  314. bar.timeTag = [NSString stringWithFormat:@"%d",(int)timeBarArray.count];
  315. //删除按钮
  316. [bar showWithRemove:^(NSString *index) {
  317. //这里的方法中要判断,是否是已发布的计划 如果是已发布的计划,提醒用户可能删除失败 如果有人已经预约的话 如果正常删除 只需要在timeBarArray删除对应的bar就好了
  318. [self refreshUIWithTag:[index integerValue]];
  319. }];
  320. //选择结束时间
  321. [bar finishEndTime:^(NSString *index) {
  322. //判断是否合法 即开始时间是否小于结束时间
  323. if (![self judgeTimeIsRightWithPre:bar.beginTime End:bar.endTime]) {
  324. ShowMsg(@"开始时间不能大于结束时间");
  325. return;
  326. }
  327. //判断是否与现有的重复
  328. for (TimeBar *allBar in timeBarArray) {
  329. //将二次迭代里面 是自己的情况剔除
  330. if ([bar.beginTime isEqualToString:allBar.beginTime] && [bar.endTime isEqualToString:allBar.endTime]) {
  331. continue;
  332. }
  333. if ([self judgeSectionAIsInTheSectionBWithAPre:bar.beginTime AEnd:bar.endTime SectionPre:allBar.beginTime SectionEnd:allBar.endTime]){
  334. ShowMsg(@"时间段有重复");
  335. return;
  336. }
  337. }
  338. }];
  339. [timeBarArray addObject:bar];
  340. lastTimeBar = bar;
  341. y = lastTimeBar.y + lastTimeBar.height;
  342. bottomView.y = y;
  343. [mainScrollView setContentSize:CGSizeMake(kSize.width, y + 310)];
  344. }
  345. //这个是每次删除后对UI的刷新
  346. -(void)refreshUIWithTag:(NSInteger)tag
  347. {
  348. //先从页面删除 再从数组中删除掉
  349. TimeBar *delBar = timeBarArray[tag];
  350. [delBar removeFromSuperview];
  351. [timeBarArray removeObjectAtIndex:tag];
  352. CGFloat y = 80;
  353. CGFloat w = kSize.width;
  354. CGFloat h = 40;
  355. for (int i = 0; i < timeBarArray.count; i ++) {
  356. TimeBar *bar = timeBarArray[i];
  357. bar.frame = CGRectMake(0, y + i*h, w, h);
  358. bar.timeTag = [NSString stringWithFormat:@"%d",i];
  359. }
  360. if (timeBarArray.count > 0) {
  361. lastTimeBar = [timeBarArray lastObject];
  362. y = lastTimeBar.y + lastTimeBar.height;
  363. }else{
  364. //这里表示 如果全部删除了 则将最后一个bar置空
  365. lastTimeBar = nil;
  366. }
  367. bottomView.y = y;
  368. [mainScrollView setContentSize:CGSizeMake(kSize.width, y + 270)];
  369. }
  370. #pragma mark 点击事件
  371. -(void)itemClick
  372. {
  373. if (timeBarArray.count > 0) {
  374. if ([lastTimeBar.beginTime isEqualToString:@"开始时间"] || [lastTimeBar.endTime isEqualToString:@"结束时间"]) {
  375. ShowMsg(@"请设置时间段信息");
  376. return;
  377. }
  378. }
  379. for (TimeBar *testBar in timeBarArray) {
  380. //判断当前测试的时间段是否合法 如果不合法则无法发布 如果合法 在判断当前测试与其他时间段是否重复
  381. if (![self judgeTimeIsRightWithPre:testBar.beginTime End:testBar.endTime]) {
  382. ShowMsg(@"开始时间不能大于结束时间");
  383. return;
  384. }
  385. int i = 0;
  386. for (TimeBar *bar in timeBarArray) {
  387. //将二次迭代里面 是自己的情况剔除
  388. if ([testBar.beginTime isEqualToString:bar.beginTime] && [testBar.endTime isEqualToString:bar.endTime]) {
  389. i += 1;
  390. if (i > 1) { //等1是正常的 表示遍历到了自己 大于1则表示有重复
  391. ShowMsg(@"时间段有重复");
  392. return;
  393. }
  394. continue;
  395. }
  396. if ([self judgeSectionAIsInTheSectionBWithAPre:testBar.beginTime AEnd:testBar.endTime SectionPre:bar.beginTime SectionEnd:bar.endTime])
  397. {
  398. ShowMsg(@"时间段有重复");
  399. return;
  400. }
  401. }
  402. }
  403. [self savePlanInfoAsyc];
  404. }
  405. -(void)btnClick:(UIButton *)sender
  406. {
  407. switch (sender.tag) {
  408. case 1:
  409. {
  410. if (timeBarArray.count > 0) {
  411. if ([lastTimeBar.beginTime isEqualToString:@"开始时间"] || [lastTimeBar.endTime isEqualToString:@"结束时间"]) {
  412. //如果有未完成的 就不能继续添加
  413. ShowMsg(@"已经存在一个未完成的时间段");
  414. return;
  415. }
  416. }
  417. //判断最后一个是否合法 即开始时间是否小于结束时间 不合法则不法创建下一个
  418. if (![self judgeTimeIsRightWithPre:lastTimeBar.beginTime End:lastTimeBar.endTime]) {
  419. ShowMsg(@"开始时间不能大于结束时间");
  420. return;
  421. }
  422. //判断最后一个是否与之前的重复 如果有重复则不能创建下一个
  423. for (TimeBar *bar in timeBarArray) {
  424. //防止因为lastTimeBar没有
  425. if ([lastTimeBar.beginTime isEqualToString:bar.beginTime] && [lastTimeBar.endTime isEqualToString:bar.endTime]) {
  426. continue;
  427. }
  428. if ([self judgeSectionAIsInTheSectionBWithAPre:lastTimeBar.beginTime AEnd:lastTimeBar.endTime SectionPre:bar.beginTime SectionEnd:bar.endTime])
  429. {
  430. ShowMsg(@"时间段有重复");
  431. return;
  432. }
  433. }
  434. [self creatNewTimeBar];
  435. }
  436. break;
  437. // case 8:
  438. // [self selectPrice];
  439. // break;
  440. default:
  441. [self setWhiceSelectWithTag:sender.tag];
  442. break;
  443. }
  444. }
  445. -(void)setWhiceSelectWithTag:(NSInteger)tag
  446. {
  447. //设置信息也是在这里边写的
  448. if (tag == 2) {
  449. keSanBtn.selected = NO;
  450. keErBtn.selected = YES;
  451. keMuString = @"2";
  452. }
  453. if (tag == 3) {
  454. keErBtn.selected = NO;
  455. keSanBtn.selected = YES;
  456. keMuString = @"3";
  457. }
  458. // if (tag == 4) {
  459. // temYesBtn.selected = NO;
  460. // temNoBtn.selected = YES;
  461. // self.temperatureIsNormal = temYesBtn.selected;
  462. // }
  463. // if (tag == 5) {
  464. // noBtn.selected = NO;
  465. // yesBtn.selected = YES;
  466. // isPayString = @"1";
  467. // }
  468. // if (tag == 6) {
  469. // yesBtn.selected = NO;
  470. // noBtn.selected = YES;
  471. // isPayString = @"0";
  472. // //将price置为0
  473. // priceField.text = @"0";
  474. // }
  475. // if (tag == 7) {
  476. // publicNoBtn.selected = NO;
  477. // publicYesBtn.selected = YES;
  478. // isPublic = @"1";
  479. // }
  480. // if (tag == 8) {
  481. // publicYesBtn.selected = NO;
  482. // publicNoBtn.selected = YES;
  483. // isPublic = @"0";
  484. // }
  485. }
  486. //-(void)selectPrice
  487. //{
  488. // NSMutableArray *titleArray = [NSMutableArray array];
  489. //
  490. // for (NSDictionary *dic in self.moneyArray) {
  491. // NSString * strSD = @"";
  492. // switch ([dic[@"CSI_TRAINNINGTIME"] integerValue]) {
  493. // case 1:
  494. // strSD = @"普通时段";
  495. // break;
  496. // case 2:
  497. // strSD = @"高峰时段";
  498. // break;
  499. // case 3:
  500. // strSD = @"节假日时段";
  501. // break;
  502. // default:
  503. // break;
  504. // }
  505. //
  506. // NSString *titleString = [NSString stringWithFormat:@"%@ %@ %@元 ",strSD,dic[@"CSI_VEHICLETYPE"],dic[@"CSI_PRICE"]];
  507. // [titleArray addObject:titleString];
  508. // }
  509. //
  510. // //UIActionSheet对按钮数量不确定时候的处理
  511. // UIActionSheet* sheet = [[UIActionSheet alloc] initWithTitle:@"选择培训价格" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
  512. //
  513. // for (NSString *title in titleArray) {
  514. // [sheet addButtonWithTitle:title];
  515. // }
  516. //
  517. // [sheet addButtonWithTitle:@"取消"];
  518. // sheet.cancelButtonIndex = sheet.numberOfButtons - 1;
  519. // sheet.actionSheetStyle = UIActionSheetStyleDefault;
  520. // [sheet showInView:self.view];
  521. //}
  522. //-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
  523. //{
  524. // if (buttonIndex == actionSheet.cancelButtonIndex) {
  525. // return;
  526. // }
  527. //
  528. // NSDictionary *dic = self.moneyArray[buttonIndex];
  529. // priceField.text = dic[@"CSI_PRICE"];
  530. // //[priceBtn setTitle:dic[@"CSI_PRICE"] forState:UIControlStateNormal];
  531. //}
  532. -(BOOL)judgeTimeIsRightWithPre:(NSString *)pre End:(NSString *)end
  533. {
  534. int preHour = [[pre substringToIndex:2] intValue];
  535. int preMin = [[pre substringFromIndex:3] intValue];
  536. int endHour = [[end substringToIndex:2] intValue];
  537. int endMin = [[end substringFromIndex:3] intValue];
  538. if (preHour > endHour) {
  539. return NO;
  540. }else{
  541. if (preHour == endHour) {
  542. if (preMin > endMin) {
  543. return NO;
  544. }
  545. }
  546. }
  547. return YES;
  548. }
  549. -(BOOL)judgeSectionAIsInTheSectionBWithAPre:(NSString *)APre AEnd:(NSString *)AEnd SectionPre:(NSString *)pre SectionEnd:(NSString *)end
  550. {
  551. int APreHour = [[APre substringToIndex:2] intValue];
  552. int APreMin = [[APre substringFromIndex:3] intValue];
  553. int AEndHour = [[AEnd substringToIndex:2] intValue];
  554. int AEndMin = [[AEnd substringFromIndex:3] intValue];
  555. int preHour = [[pre substringToIndex:2] intValue];
  556. int preMin = [[pre substringFromIndex:3] intValue];
  557. int endHour = [[end substringToIndex:2] intValue];
  558. int endMin = [[end substringFromIndex:3] intValue];
  559. //NSLog(@"--%d:%d----%d:%d-- --%d:%d----%d:%d--",APreHour,APreMin,AEndHour,AEndMin,preHour,preMin,endHour,endMin);
  560. if (APreHour > endHour) {
  561. return NO;
  562. }else if (APreHour == endHour){
  563. if (APreMin >= endMin) {
  564. return NO;
  565. }
  566. }
  567. if (AEndHour < preHour) {
  568. return NO;
  569. }else if (AEndHour == preHour){
  570. if (AEndMin <= preMin) {
  571. return NO;
  572. }
  573. }
  574. return YES;
  575. }
  576. -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  577. {
  578. if (buttonIndex == 0) {
  579. return;
  580. }else{
  581. [self refreshUIWithTag:alertIndex];
  582. }
  583. }
  584. #pragma mark -- 页面设置
  585. //-(void)scrollViewDidScroll:(UIScrollView *)scrollView
  586. //{
  587. // [self.view endEditing:YES];
  588. //}
  589. //-(void)hideKeyBoard
  590. //{
  591. // [self.view endEditing:YES];
  592. //}
  593. ////展示键盘
  594. //- (void)keyboardWasShown:(NSNotification*)aNotification
  595. //{
  596. // CGRect keyBoardFrame = [[[aNotification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
  597. // [UIView animateWithDuration:.3 animations:^{
  598. // mainScrollView.y = -keyBoardFrame.size.height;
  599. // }];
  600. //}
  601. ////隐藏键盘
  602. //-(void)keyboardWillBeHidden:(NSNotification*)aNotification
  603. //{
  604. // [UIView animateWithDuration:.4 animations:^{
  605. // mainScrollView.frame = kFrame;
  606. // }];
  607. //}
  608. #pragma mark 数据请求
  609. //发布接口
  610. -(void)savePlanInfoAsyc{
  611. NSMutableArray *timeArrray = [NSMutableArray array];
  612. NSMutableArray *newTimeArrray = [NSMutableArray array];
  613. for (NSDictionary *dic in _dataArray) {
  614. if ([dic[@"taskTime"] isEqualToString:_dateString]) {
  615. [timeArrray addObject:dic[@"times"]];
  616. }
  617. }
  618. for (TimeBar *bar in timeBarArray) {
  619. NSString *timeString = [NSString stringWithFormat:@"%@-%@",bar.beginTime,bar.endTime];
  620. [newTimeArrray addObject:timeString];
  621. }
  622. //将最新的结果保存到本地
  623. NSString *filePath = [Tools getPathWithFileName:@"issueLocalDic.plist"];
  624. [newTimeArrray writeToFile:filePath atomically:YES];
  625. NSString *addString = @"";
  626. NSString *delString = @"";
  627. //删掉的
  628. for (NSString *string in timeArrray) {
  629. if (![newTimeArrray containsObject:string]) {
  630. if (string.length > 0) {
  631. delString = [delString stringByAppendingString:[NSString stringWithFormat:@"%@,",string]];
  632. }
  633. continue;
  634. }
  635. }
  636. if (delString.length > 0) {
  637. delString = [delString substringToIndex:delString.length - 1];
  638. }
  639. //添加的
  640. for (NSString *newString in newTimeArrray) {
  641. if (![timeArrray containsObject:newString]) {
  642. if (newString.length > 0) {
  643. addString = [addString stringByAppendingString:[NSString stringWithFormat:@"%@,",newString]];
  644. }
  645. continue;
  646. }
  647. }
  648. if (addString.length > 0) {
  649. addString = [addString substringToIndex:addString.length - 1];
  650. }
  651. //NSLog(@"原计划----->%@-----现计划------>%@----------del--->%@---add--->%@",timeArrray,newTimeArrray,delString,addString);
  652. if (delString.length < 1 && addString.length < 1) {
  653. //说明没做任何处理
  654. ShowMsg(@"当前计划时间没有改动");
  655. [self.navigationController popViewControllerAnimated:YES];
  656. return;
  657. }
  658. if (phoneNumField.text.length < 1) {
  659. ShowMsg(@"请输入您的手机号码");
  660. return;
  661. }
  662. if (numberField.text.length == 0 || [numberField.text integerValue]==0 || [numberField.text integerValue]>10) {
  663. ShowMsg(@"请设置合理的学车人数");
  664. return;
  665. }
  666. self.temperatureStr = temperatureTextField.text;
  667. CGFloat temperature = _temperatureStr.floatValue;
  668. if (_temperatureStr.length < 1) {
  669. ShowMsg(@"请输入您的体温");
  670. return;
  671. } else if (temperature < 35.0 || temperature > 37.2) {
  672. ShowMsg(@"您的体温异常!无法发布计划!");
  673. return;
  674. }
  675. NSArray *addAndDelArray = @[addString,delString];
  676. if (addString.length > 0) {
  677. if ([priceField.text floatValue] <= 0) {
  678. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"学员练车价格为免费,是否发布?" preferredStyle:(UIAlertControllerStyleAlert)];
  679. UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"是" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  680. [self savePlanInfo:addAndDelArray];
  681. }];
  682. UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:@"否" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  683. return;
  684. }];
  685. [alert addAction:sureAction];
  686. [alert addAction:cancleAction];
  687. [self presentViewController:alert animated:YES completion:nil];
  688. }else {
  689. [self savePlanInfo:addAndDelArray];
  690. }
  691. }else {
  692. [self savePlanInfo:addAndDelArray];
  693. }
  694. }
  695. - (void)savePlanInfo:(NSArray *)addAndDel
  696. {
  697. NSMutableArray *arr=[NSMutableArray array];
  698. [arr addPro:@"user" Value:defUser.sfzmhm];
  699. [arr addPro:@"title" Value:@""];
  700. [arr addPro:@"content" Value:@""];
  701. [arr addPro:@"num" Value:numberField.text];
  702. [arr addPro:@"tel" Value:phoneNumField.text];
  703. [arr addPro:@"taskTime" Value:_dateString];
  704. [arr addPro:@"userName" Value:defUser.userDict[@"name"]];
  705. [arr addPro:@"km" Value:keMuString];
  706. [arr addPro:@"jsAddress" Value:@""];
  707. [arr addPro:@"money" Value:priceField.text];
  708. [arr addPro:@"addTimesArr" Value:addAndDel[0]];
  709. [arr addPro:@"delTimesArr" Value:addAndDel[1]];
  710. [arr addPro:@"temperature" Value:_temperatureStr];
  711. NSString* method = @"uploadPlanInfo";
  712. ShowHUD();
  713. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  714. RemoveHUD();
  715. //NSLog(@"保存计划--arr---->%@ /n---->root->%@",arr,root);
  716. //如果保存失败 如何回到之前的状态
  717. if (!root) {
  718. ShowMsgFailed();
  719. [self saveFail];
  720. return ;
  721. }
  722. if ([root[@"code"] isEqualToString:@"1"]) {
  723. ShowMsg(root[@"body"]);
  724. [self saveFail];
  725. return;
  726. }
  727. ShowMsgSuc();
  728. self.successBlock(_dateString);
  729. [self.navigationController popViewControllerAnimated:YES];
  730. }];
  731. }
  732. //获取价格
  733. -(void)getTrainPrice
  734. {
  735. NSMutableArray *arr=[NSMutableArray array];
  736. [arr addPro:@"schoolId" Value:defUser.userDict[@"jxbh"]];
  737. [arr addPro:@"dqbh" Value:defUser.userDict[@"cityId"]];
  738. NSString* method = @"getPrice";
  739. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * dict) {
  740. RemoveHUD();
  741. //NSLog(@"获取价格-->%@->%@",arr,dict);
  742. if (!dict) {
  743. return ;
  744. }
  745. if ( [dict[@"code"] isEqualToString:@"1"]) {
  746. return ;
  747. }
  748. _moneyArray = dict[@"body"];
  749. }];
  750. }
  751. - (void)dealloc
  752. {
  753. [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
  754. [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
  755. }
  756. - (void)didReceiveMemoryWarning {
  757. [super didReceiveMemoryWarning];
  758. }
  759. - (void)initSuccessBlock:(SuccessBlock)block {
  760. self.successBlock = block;
  761. }
  762. @end