IssueBaseSettingVC.m 31 KB

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