CoachPlanVC.m 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. //
  2. // CoachPlanVC.m
  3. // jiaPei
  4. //
  5. // Created by apple on 16/3/25.
  6. // Copyright © 2016年 JCZ. All rights reserved.
  7. //
  8. #import "CoachPlanVC.h"
  9. #import "PlanCell.h"
  10. #import "HolderView.h"
  11. #import "CLWeeklyCalendarView.h"
  12. #import "PlanCollectionCell.h"
  13. #import "Tools.h"
  14. #import "SDSoundPlayer.h"
  15. #import "TopUpMoneyVC.h"
  16. @interface CoachPlanVC ()<CLWeeklyCalendarViewDelegate,UICollectionViewDelegateFlowLayout,UICollectionViewDataSource,UIAlertViewDelegate>
  17. {
  18. NSString *taskTime;
  19. NSArray *models;
  20. NSArray *coachsArray;
  21. NSMutableArray *mockDatas;
  22. NSMutableArray *selectModel;
  23. CGFloat calendarY;
  24. NSIndexPath *lastIndex;
  25. NSString *coachNum;
  26. NSString *lackMoney;
  27. UICollectionView *mainCollection;
  28. HolderView *holderV;
  29. UILabel *nameLabel,*countLabel,*addressLabel,*remindLabel,*timeLabel;
  30. UIBarButtonItem *item;
  31. }
  32. @property (nonatomic, strong) CLWeeklyCalendarView* calendarView;
  33. @end
  34. @implementation CoachPlanVC
  35. - (id)initWithCoder:(NSCoder*)coder
  36. {
  37. self = [super initWithCoder:coder];
  38. if (self) {
  39. //加这句 不让导航栏影响xib中控件的布局 现在不加也行 因为xib取消使用自动布局 问题解决 bingo
  40. //self.automaticallyAdjustsScrollViewInsets = NO;
  41. }
  42. return self;
  43. }
  44. - (void)viewDidLoad {
  45. [super viewDidLoad];
  46. [self myInit];
  47. }
  48. -(void)myInit
  49. {
  50. [self setTitle:@"教练计划"];
  51. [self.view setBackgroundColor:backGroundColor];
  52. if (_isNotification == NO)
  53. {
  54. //正常状态
  55. [self configNavigationBar];
  56. }
  57. else
  58. {
  59. //推送状态 要将根视图变回去
  60. UIBarButtonItem* backBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"question_pre_checked_icon.png"] style:UIBarButtonItemStylePlain target:self action:@selector(dismissNavgation)];
  61. [backBtn setTintColor:defGreen];
  62. self.navigationController.navigationBar.translucent = NO;
  63. [self.navigationItem setLeftBarButtonItem:backBtn];
  64. }
  65. //初始化数据容器
  66. mockDatas = [[NSMutableArray alloc] init];
  67. selectModel = [[NSMutableArray alloc] init];
  68. coachsArray = [NSArray array];
  69. CGFloat x,y,w,h,bd;
  70. x = bd = 10;
  71. y = 5;
  72. w = kSize.width - 20;
  73. h = 25;
  74. //上面显示的信息
  75. UILabel *label;
  76. label = [[UILabel alloc] setxywh];
  77. [label setText:@"当前计划信息:暂无" Font:FontTitle TextColor:kTitleColor Alignment:NSTextAlignmentLeft];
  78. [self.view addSubview:label];
  79. nameLabel = label;
  80. y += h;
  81. label = [[UILabel alloc] setxywh];
  82. [label setText:@"场地信息:暂无" Font:FontTitle TextColor:kTitleColor Alignment:NSTextAlignmentLeft];
  83. [self.view addSubview:label];
  84. addressLabel = label;
  85. y += h;
  86. h += bd;
  87. label = [[UILabel alloc] setxywh];
  88. [label setText:@"暂无预约人数信息" Font:NormalFont TextColor:[UIColor orangeColor] Alignment:NSTextAlignmentLeft];
  89. label.numberOfLines = 0;
  90. [self.view addSubview:label];
  91. countLabel = label;
  92. //日历控件
  93. y += h;
  94. calendarY = y;
  95. [self.view addSubview:self.calendarView];
  96. y += self.calendarView.height;
  97. //因为Y是从64开始算的 即把64当做0 所以要有补偿
  98. h = kSize.height - y - 90 - kNavOffSet - kSafeAreaBottomHeight - 4;
  99. //用collection吧
  100. CGFloat width = (kSize.width - 45)/3.0;
  101. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  102. [layout setItemSize:CGSizeMake(width, width)];
  103. [layout setSectionInset:UIEdgeInsetsMake(8, 10, 8, 10)];
  104. mainCollection = [[UICollectionView alloc] initWithFrame:CGRectMake(0, y, kSize.width, h) collectionViewLayout:layout];
  105. mainCollection.backgroundColor = backGroundColor;
  106. mainCollection.delegate = self;
  107. mainCollection.dataSource = self;
  108. [self.view addSubview:mainCollection];
  109. [mainCollection registerNib:[UINib nibWithNibName:@"PlanCollectionCell" bundle:nil] forCellWithReuseIdentifier:@"collection"];
  110. holderV = [[HolderView alloc] initWithFrame:mainCollection.frame];
  111. [self.view addSubview:holderV];
  112. [holderV setHidden:YES];
  113. //将日历放前边 防止被遮挡
  114. [self.view bringSubviewToFront:self.calendarView];
  115. y += h + 4;
  116. h = 30;
  117. label = [[UILabel alloc] initWithFrame:CGRectMake(0, y, kSize.width, h)];
  118. label.backgroundColor = contentTextColor;
  119. [label setText:@" 每条计划只能取消预约一次哦,请您慎重" Font:NormalFont TextColor:[UIColor orangeColor]];
  120. [self.view addSubview:label];
  121. remindLabel = label;
  122. x = 10;
  123. y += h;
  124. w = 200;
  125. h = 60;
  126. label = [[UILabel alloc] initWithFrame:CGRectMake(0, y - 3, kSize.width, 3)];
  127. label.backgroundColor = KlineColor;
  128. [self.view addSubview:label];
  129. label = [[UILabel alloc] setxywh];
  130. [label setText:@"你已选了0个预约哦" Font:20 TextColor:kTitleColor Alignment:NSTextAlignmentLeft];
  131. [self.view addSubview:label];
  132. timeLabel = label;
  133. x = kSize.width - 100;
  134. y += 9;
  135. w = 90;
  136. h = 42;
  137. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  138. btn.frame = CGRectMake(x, y, w, h);
  139. [btn setTitle:@"确认预约" textColor:[UIColor whiteColor] font:20 fotState:UIControlStateNormal];
  140. btn.layer.masksToBounds = YES;
  141. btn.layer.cornerRadius = 10;
  142. btn.backgroundColor = [UIColor orangeColor];
  143. [btn target:self];
  144. btn.tag = 1;
  145. [self.view addSubview:btn];
  146. }
  147. -(void)dismissNavgation
  148. {
  149. //推送过来 返回主页面
  150. [myDelegate gotoLoad];
  151. }
  152. -(void)btnClick:(UIButton*)sender
  153. {
  154. int tag = (int)sender.tag;
  155. if (1 == tag) {
  156. [self saveReserveInfo];
  157. }
  158. }
  159. -(void)setLabelUIWithDic:(NSDictionary *)dic
  160. {
  161. if (dic.allKeys.count == 1) {
  162. //这个if是应对虚拟数据的
  163. nameLabel.text = @"当前计划信息:暂无";
  164. countLabel.text = @"暂无预约人数信息";
  165. return;
  166. }
  167. NSString *kmString = @"科目二";
  168. if ([dic[@"KM"] isEqualToString:@"3"]) {
  169. kmString = @"科目三";
  170. }
  171. nameLabel.text = [NSString stringWithFormat:@"当前计划信息:%@ %@ %@元/小时",dic[@"USERNAME"],kmString,dic[@"MONEY"]];
  172. addressLabel.text = [NSString stringWithFormat:@"场地信息:%@",dic[@"JSADDRESS"]];
  173. if ([dic[@"JSADDRESS"] length] < 1) {
  174. addressLabel.text = @"场地信息:暂无";
  175. }
  176. countLabel.text = [NSString stringWithFormat:@"计划可预约%@人,已预约%@人,有%@人也申请了预约计划",dic[@"PI_NUM"],dic[@"PI_HAV_NUM"],dic[@"HAVNUM"]];
  177. }
  178. -(CLWeeklyCalendarView *)calendarView
  179. {
  180. if(!_calendarView){
  181. _calendarView = [[CLWeeklyCalendarView alloc] initWithFrame:CGRectMake(0, calendarY, kSize.width, 120)];
  182. _calendarView.delegate = self;
  183. }
  184. return _calendarView;
  185. }
  186. #pragma mark - CLWeeklyCalendarViewDelegate
  187. -(NSDictionary *)CLCalendarBehaviorAttributes
  188. {
  189. //CLCalendarSelectedDatePrintFormatDefault 显示选中日期格式
  190. return @{
  191. //CLCalendarWeekStartDay : @2, //Start Day of the week, from 1-7 Mon-Sun -- default 1
  192. // CLCalendarDayTitleTextColor : [UIColor yellowColor],
  193. // CLCalendarSelectedDatePrintColor : [UIColor greenColor],
  194. };
  195. }
  196. -(void)dailyCalendarViewDidSelect:(NSDate *)date
  197. {
  198. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  199. formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
  200. [formatter setDateFormat:@"yyyy-MM-dd"];
  201. taskTime = [formatter stringFromDate:date];
  202. if (lastIndex) {
  203. PlanCollectionCell *lastCell = (PlanCollectionCell *)[mainCollection cellForItemAtIndexPath:lastIndex];
  204. lastCell.backImageView.image = [UIImage imageNamed:@"plancell3.png"];
  205. lastCell.isSelected = NO;
  206. if (selectModel.count > 0) {
  207. [selectModel removeAllObjects];
  208. }
  209. timeLabel.text = @"您已选了0个预约哦";
  210. }
  211. [self getPlanInfos];
  212. }
  213. #pragma mark - collection dalegate
  214. -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  215. {
  216. if (models.count == 0) {
  217. return mockDatas.count;
  218. }
  219. return models.count;
  220. }
  221. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  222. {
  223. PlanCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collection" forIndexPath:indexPath];
  224. //每次获取cell 把隐藏的控件全显示出来 还有会改变的默认属性 这样的话 下面就方便了
  225. cell.countLabel.hidden = NO;
  226. cell.headImgView.hidden = NO;
  227. cell.timeLabel.textColor = kTitleColor;
  228. cell.kmLabel.textColor = kTitleColor;
  229. cell.countLabel.textColor = kTitleColor;
  230. //把所有情况设置为不可点击 然后在可以点击的情况改变这个状态
  231. cell.isCanSelect = NO;
  232. if (models.count == 0) {
  233. cell.timeLabel.text = mockDatas[indexPath.row];
  234. cell.countLabel.hidden = YES;
  235. cell.headImgView.hidden = YES;
  236. cell.backImageView.image = [UIImage imageNamed:@"plancell1.png"];
  237. cell.kmLabel.text = @"已过期";
  238. return cell;
  239. }
  240. NSDictionary *dic = models[indexPath.row];
  241. NSDateFormatter *formatter = [NSDateFormatter rq_defaultDateFormatter];
  242. NSDate *crDate = [NSDate date];
  243. if ([dic[@"TIMES"] rangeOfString:@"-"].location != NSNotFound && [dic[@"TASKTIME"] rangeOfString:@"-"].location != NSNotFound) {
  244. NSString *endTime = [NSString stringWithFormat:@"%@ %@:00",dic[@"TASKTIME"],[[dic[@"TIMES"] componentsSeparatedByString:@"-"] lastObject]];
  245. crDate = [formatter dateFromString:endTime];
  246. }
  247. NSDate *nowDate = [NSDate date];
  248. NSComparisonResult result = [crDate compare:nowDate];
  249. //NSLog(@"result--->%d-crDate-%@-nowDate-%@",(int)result,crDate,nowDate);
  250. //过期不能预约 预约过不能预约 人数已经预约满不能预约 这个判断顺序是没问题的
  251. if (result == NSOrderedAscending){
  252. //NSLog(@"已过期");
  253. cell.backImageView.image = [UIImage imageNamed:@"plancell1.png"];
  254. cell.kmLabel.text = @"已过期";
  255. cell.headImgView.hidden = YES;
  256. cell.countLabel.hidden = YES;
  257. if ([dic[@"STATUS"] isEqualToString:@"0"]) {
  258. cell.kmLabel.text = @"被拒,已过期";
  259. }else if ([dic[@"STATUS"] isEqualToString:@"1"]){
  260. cell.kmLabel.text = @"已预约,已过期";
  261. }else if ([dic[@"STATUS"] isEqualToString:@"2"]){
  262. cell.kmLabel.text = @"预约中,已过期";
  263. }
  264. }
  265. if (result == NSOrderedDescending) {
  266. //NSLog(@"未过期");
  267. cell.backImageView.image = [UIImage imageNamed:@"plancell3.png"];
  268. cell.countLabel.text = [NSString stringWithFormat:@"%d/%d",[dic[@"PI_HAV_NUM"] intValue],[dic[@"PI_NUM"] intValue]];
  269. cell.kmLabel.text = [dic[@"KM"] isEqualToString:@"2"]?@"科目二":@"科目三";
  270. if (cell.isSelected) {
  271. cell.backImageView.image = [UIImage imageNamed:@"plancell2.png"];
  272. }
  273. if ([dic[@"STATUS"] isEqualToString:@"0"]) {
  274. cell.kmLabel.text = @"预约被拒";
  275. cell.kmLabel.textColor = [UIColor orangeColor];
  276. }else if ([dic[@"STATUS"] isEqualToString:@"1"]){
  277. cell.kmLabel.text = @"已预约";
  278. cell.kmLabel.textColor = [UIColor orangeColor];
  279. }else if ([dic[@"STATUS"] isEqualToString:@"2"]){
  280. cell.kmLabel.text = @"预约中";
  281. cell.kmLabel.textColor = [UIColor orangeColor];
  282. }else if ([dic[@"STATUS"] isEqualToString:@"-1"]){
  283. if ([dic[@"PI_HAV_NUM"] isEqualToString:dic[@"PI_NUM"]]) {
  284. cell.kmLabel.text = @"已约满";
  285. cell.backImageView.image = [UIImage imageNamed:@"plancell1.png"];
  286. }else{
  287. cell.isCanSelect = YES;
  288. }
  289. }
  290. }
  291. cell.timeLabel.text = dic[@"TIMES"];
  292. return cell;
  293. }
  294. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  295. {
  296. [collectionView deselectItemAtIndexPath:indexPath animated:YES];
  297. PlanCollectionCell *cell = (PlanCollectionCell *)[collectionView cellForItemAtIndexPath:indexPath];
  298. if (models.count > 0) {
  299. NSDictionary *dic = models[indexPath.row];
  300. [self setLabelUIWithDic:dic];
  301. //NSLog(@"进了没---->%@",dic[@"STATUS"]);
  302. if ([dic[@"STATUS"] isEqualToString:@"0"]) {
  303. //拒绝
  304. remindLabel.text = @" 教练已拒绝您的预约申请,试试其他的吧";
  305. }else if ([dic[@"STATUS"] isEqualToString:@"1"]){
  306. //已预约
  307. remindLabel.text = @" 教练已同意您的预约申请";
  308. }else if ([dic[@"STATUS"] isEqualToString:@"2"]){
  309. //待审核
  310. remindLabel.text = @" 您的预约申请正在等待审核,请耐心等待";
  311. }else if ([dic[@"STATUS"] isEqualToString:@"-1"]){
  312. if ([dic[@"PI_HAV_NUM"] isEqualToString:dic[@"PI_NUM"]]) {
  313. //已约满
  314. remindLabel.text = @" 本条计划已被约满,试试其他的吧";
  315. }else{
  316. //正常可约
  317. remindLabel.text = @" 每条计划只能取消预约一次哦,请您慎重";
  318. }
  319. }
  320. }
  321. if (cell.isCanSelect == NO) {
  322. return;
  323. }
  324. //如果之前操作过 找到改变状态 移除数据
  325. if (lastIndex) {
  326. if (![lastIndex isEqual:indexPath]) {
  327. PlanCollectionCell *lastCell = (PlanCollectionCell *)[collectionView cellForItemAtIndexPath:lastIndex];
  328. if (lastCell.isSelected == YES) {
  329. lastCell.isSelected = NO;
  330. lastCell.backImageView.image = [UIImage imageNamed:@"plancell3.png"];
  331. if (selectModel.count > 0) {
  332. [selectModel removeAllObjects];
  333. }
  334. }
  335. }
  336. }
  337. if (cell.isSelected == YES) {
  338. if ([selectModel containsObject:models[indexPath.row]]) {
  339. [selectModel removeObject:models[indexPath.row]];
  340. }
  341. cell.backImageView.image = [UIImage imageNamed:@"plancell3.png"];
  342. }else{
  343. [selectModel addObject:models[indexPath.row]];
  344. cell.backImageView.image = [UIImage imageNamed:@"plancell2.png"];
  345. }
  346. timeLabel.text = [NSString stringWithFormat:@"您已选了%d个预约哦",(int)selectModel.count];
  347. //改变按钮状态
  348. cell.isSelected = !cell.isSelected;
  349. //记录上一次点击按钮
  350. lastIndex = indexPath;
  351. }
  352. #pragma mark - 获取数据
  353. -(void)getPlanInfos
  354. {
  355. if (![Util connectedToNetWork]) {
  356. [holderV setHidden:NO];
  357. return;
  358. }
  359. if (!taskTime) {
  360. NSDateFormatter* fm = [NSDateFormatter new];
  361. fm.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
  362. [fm setDateFormat:@"yyyy-MM-dd"];
  363. taskTime = [fm stringFromDate:[NSDate date]];
  364. }
  365. if (_coachDic) {
  366. coachNum = _coachDic[@"SFZHM"];
  367. }
  368. if (coachNum.length < 1) {
  369. coachNum = defUser.userDict[@"sjjlbh"];
  370. }
  371. NSMutableArray *arr=[NSMutableArray array];
  372. [arr addPro:@"taskTime" Value:taskTime];
  373. //要调接口获取教练
  374. [arr addPro:@"account" Value:coachNum];
  375. [arr addPro:@"userId" Value:defUser.userDict[@"id"]];
  376. [arr addPro:@"isPage" Value:@""];
  377. [arr addPro:@"pageSize" Value:@""];
  378. [arr addPro:@"currentPage" Value:@""];
  379. NSString* method = @"getPlanInfos";
  380. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
  381. //NSLog(@"找计划------>%@------>%@",arr,root);
  382. if (!root)
  383. {
  384. [LoadingView showMsg:@"网络请求失败"];
  385. [holderV setHidden:NO];
  386. return;
  387. }
  388. NSString* code = root[@"code"];
  389. if (code.intValue >0) {
  390. ShowMsgFailed();
  391. [holderV setHidden:NO];
  392. return;
  393. }
  394. models = root[@"body"];
  395. if (models.count > 0) {
  396. NSDictionary *dic = [models firstObject];
  397. [self setLabelUIWithDic:dic];
  398. [mainCollection reloadData];
  399. [holderV setHidden:YES];
  400. }else{
  401. NSDateFormatter *formatter = [NSDateFormatter rq_defaultDateFormatter];
  402. NSDate *taskDate = [formatter dateFromString:[NSString stringWithFormat:@"%@ 23:59:59",taskTime]];
  403. NSComparisonResult result = [taskDate compare:[NSDate date]];
  404. if (result == NSOrderedAscending){
  405. //NSLog(@"已过期");
  406. [holderV setHidden:YES];
  407. [self getMockDates];
  408. }
  409. if (result == NSOrderedDescending || result == NSOrderedSame) {
  410. //NSLog(@"未过期");
  411. ShowMsg(@"暂无计划");
  412. [holderV setHidden:NO];
  413. }
  414. }
  415. }];
  416. }
  417. -(void)getMockDates
  418. {
  419. mockDatas = [[NSMutableArray alloc] init];
  420. NSInteger time = 8;
  421. for (int i = 0; i < 10; i ++) {
  422. NSInteger beginTime = time;
  423. time += arc4random()%2 + 1;
  424. if (time > 18) {
  425. break;
  426. }
  427. NSString *timeString = [NSString stringWithFormat:@"%d:00-%d:00",(int)beginTime,(int)time];
  428. [mockDatas addObject:timeString];
  429. }
  430. //NSLog(@"---->%@",mockDatas);
  431. [mainCollection reloadData];
  432. NSDictionary *dic = [NSDictionary dictionaryWithObject:@"NOPLAN" forKey:@"NOPLAN"];
  433. [self setLabelUIWithDic:dic];
  434. }
  435. #pragma mark 保存预约信息
  436. -(void)saveReserveInfo
  437. {
  438. NSDictionary *dic;
  439. if (selectModel.count > 0) {
  440. dic = [selectModel firstObject];
  441. }else{
  442. ShowMsg(@"您还未选择预约哦!");
  443. return;
  444. }
  445. NSMutableArray *arr=[NSMutableArray array];
  446. [arr addPro:@"taskId" Value:dic[@"ID"]];
  447. [arr addPro:@"userId" Value:defUser.userDict[@"id"]];
  448. [arr addPro:@"userName" Value:defUser.userDict[@"userName"]];
  449. [arr addPro:@"userTel" Value:defUser.userDict[@"telphone"]];
  450. NSString* method = @"saveReserveInfo";
  451. [MBProgressHUD showLoadToView:self.view];
  452. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
  453. [MBProgressHUD hideHUDForView:self.view];
  454. //NSLog(@"保存计划-->%@->%@",arr,root);
  455. if (!root)
  456. {
  457. [LoadingView showMsg:@"操作失败"];
  458. return;
  459. }
  460. NSString* code = root[@"code"];
  461. if (code.intValue == 1) {
  462. ShowMsg(root[@"body"]);
  463. [self playAudioWithString:root[@"body"]];
  464. return;
  465. }
  466. if (code.intValue == 2) {
  467. //账户没有开户
  468. [self playAudioWithString:root[@"body"]];
  469. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:root[@"body"] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
  470. [alert show];
  471. return;
  472. }
  473. if (code.intValue == 3) {
  474. //余额不足 跳转余额页面
  475. [self playAudioWithString:[NSString stringWithFormat:@"您的账户余额不足,还需要充值%@元",root[@"body"]]];
  476. lackMoney = root[@"body"];
  477. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:[NSString stringWithFormat:@"您的账户余额不足,还需要充值%@元",root[@"body"]] delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
  478. alert.tag = 1;
  479. [alert show];
  480. }
  481. if (code.intValue == 0) {
  482. ShowMsgSuc();
  483. [self playAudioWithString:root[@"body"]];
  484. PlanCollectionCell *lastCell = (PlanCollectionCell *)[mainCollection cellForItemAtIndexPath:lastIndex];
  485. lastCell.backImageView.image = [UIImage imageNamed:@"plancell3.png"];
  486. lastCell.isSelected = NO;
  487. if (selectModel.count > 0) {
  488. [selectModel removeAllObjects];
  489. }
  490. timeLabel.text = @"您已选了0个预约哦";
  491. [self getPlanInfos];
  492. }
  493. }];
  494. }
  495. -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  496. {
  497. if (alertView.tag == 1) {
  498. if (buttonIndex != alertView.cancelButtonIndex) {
  499. TopUpMoneyVC *topUpVC = [[TopUpMoneyVC alloc] init];
  500. topUpVC.type = 1;
  501. topUpVC.neededMoney = lackMoney;
  502. [self navPushHideTabbarToVC:topUpVC];
  503. }
  504. }
  505. }
  506. -(void)playAudioWithString:(NSString *)string
  507. {
  508. [Tools playAudioWithString:string];
  509. }
  510. - (void)didReceiveMemoryWarning {
  511. [super didReceiveMemoryWarning];
  512. // Dispose of any resources that can be recreated.
  513. }
  514. @end