CoachPlanVC.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  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 "HolderView.h"
  10. #import "CLWeeklyCalendarView.h"
  11. #import "PlanCollectionCell.h"
  12. #import "ApplyPlanStuListVC.h"
  13. #import "UIImageView+WebCache.h"
  14. @interface CoachPlanVC ()<CLWeeklyCalendarViewDelegate,UICollectionViewDelegateFlowLayout,UICollectionViewDataSource,UITableViewDelegate,UITableViewDataSource>
  15. {
  16. NSString *taskTime;
  17. NSArray *models;
  18. NSArray *coachsArray;
  19. NSMutableArray *mockDatas;
  20. CGFloat calendarY;
  21. NSIndexPath *lastIndex;
  22. NSString *coachNum;
  23. NSString *lackMoney;
  24. UICollectionView *mainCollection;
  25. HolderView *holderV;
  26. UILabel *nameLabel,*countLabel,*addressLabel;
  27. UITableView *stuListTV;
  28. NSArray *stuListArray;
  29. NSDictionary *stuDic;
  30. UIButton *applyPlanBtn;
  31. }
  32. @property (nonatomic, strong) CLWeeklyCalendarView *calendarView;
  33. //预约弹出框
  34. @property (nonatomic, strong) UIView *reserveBackView;
  35. @property (nonatomic, strong) UITextField *searchTF;
  36. @end
  37. @implementation CoachPlanVC
  38. - (void)viewDidLoad {
  39. [super viewDidLoad];
  40. [self myInit];
  41. }
  42. -(void)viewWillDisappear:(BOOL)animated
  43. {
  44. [super viewWillDisappear:animated];
  45. RemoveHUD();
  46. }
  47. -(void)myInit
  48. {
  49. [self setTitle:@"教练计划"];
  50. [self.view setBackgroundColor:KBackGroundColor];
  51. [self goBackByNavigation];
  52. //初始化数据容器
  53. mockDatas = [[NSMutableArray alloc] init];
  54. coachsArray = [NSArray array];
  55. CGFloat x,y,w,h,bd;
  56. x = bd = 10;
  57. y = 5;
  58. w = kSize.width - 20;
  59. h = 25;
  60. //上面显示的信息
  61. UILabel *label;
  62. label = [[UILabel alloc] KSetxywh];
  63. [label setText:@"当前计划信息:暂无" Font:Font18 TextColor:KTitleColor Alignment:NSTextAlignmentLeft];
  64. [self.view addSubview:label];
  65. nameLabel = label;
  66. y += h;
  67. label = [[UILabel alloc] KSetxywh];
  68. [label setText:@"场地信息:暂无" Font:Font18 TextColor:KTitleColor Alignment:NSTextAlignmentLeft];
  69. [self.view addSubview:label];
  70. addressLabel = label;
  71. y += h;
  72. h += bd;
  73. label = [[UILabel alloc] KSetxywh];
  74. [label setText:@"暂无预约人数信息" Font:Font17 TextColor:[UIColor orangeColor] Alignment:NSTextAlignmentLeft];
  75. label.numberOfLines = 0;
  76. [self.view addSubview:label];
  77. countLabel = label;
  78. //日历控件
  79. y += h;
  80. calendarY = y;
  81. [self.view addSubview:self.calendarView];
  82. y += self.calendarView.height;
  83. //因为Y是从64开始算的 即把64当做0 所以要有补偿
  84. h = kSize.height - y - kNavOffSet - 60;
  85. //用collection吧
  86. CGFloat width = (kSize.width - 45)/3.0;
  87. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  88. [layout setItemSize:CGSizeMake(width, width)];
  89. [layout setSectionInset:UIEdgeInsetsMake(8, 10, 8, 10)];
  90. mainCollection = [[UICollectionView alloc] initWithFrame:CGRectMake(0, y, kSize.width, h) collectionViewLayout:layout];
  91. mainCollection.backgroundColor = KBackGroundColor;
  92. mainCollection.delegate = self;
  93. mainCollection.dataSource = self;
  94. [self.view addSubview:mainCollection];
  95. [mainCollection addViewWithRect:CGRectMake(10, y + h, kSize.width - 20, 1)];
  96. [mainCollection registerNib:[UINib nibWithNibName:@"PlanCollectionCell" bundle:nil] forCellWithReuseIdentifier:@"collection"];
  97. holderV = [[HolderView alloc] initWithFrame:mainCollection.frame];
  98. [self.view addSubview:holderV];
  99. [holderV setHidden:YES];
  100. //将日历放前边 防止被遮挡
  101. [self.view bringSubviewToFront:self.calendarView];
  102. x = 0;
  103. y += h + 1;
  104. w = kSize.width;
  105. h = 59;
  106. UIView *btnBar = [[UIView alloc] KSetxywh];
  107. btnBar.backgroundColor = kLineColor;
  108. [self.view addSubview:btnBar];
  109. x = 10;
  110. y = 5;
  111. w = kSize.width/2.0 - 20;
  112. h = 49;
  113. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  114. btn.frame = CGRectMake(x, y, w, h);
  115. [btn setTitle:@"预约" textColor:[UIColor whiteColor] font:20 fotState:UIControlStateNormal];
  116. btn.layer.masksToBounds = YES;
  117. btn.layer.cornerRadius = 10;
  118. btn.backgroundColor = [UIColor orangeColor];
  119. [btn target:self];
  120. btn.tag = 1;
  121. [btnBar addSubview:btn];
  122. applyPlanBtn = btn;
  123. x = kSize.width/2.0 + 10;
  124. btn = [UIButton buttonWithType:UIButtonTypeCustom];
  125. btn.frame = CGRectMake(x, y, w, h);
  126. [btn setTitle:@"查看预约学员" textColor:[UIColor whiteColor] font:20 fotState:UIControlStateNormal];
  127. btn.layer.masksToBounds = YES;
  128. btn.layer.cornerRadius = 10;
  129. btn.backgroundColor = [UIColor orangeColor];
  130. [btn target:self];
  131. btn.tag = 2;
  132. [btnBar addSubview:btn];
  133. }
  134. -(void)btnClick:(UIButton*)sender
  135. {
  136. int tag = (int)sender.tag;
  137. if (1 == tag) {
  138. if (!lastIndex) {
  139. ShowMsg(@"请选择要预约的计划");
  140. return;
  141. }
  142. [myDelegate.window addSubview:self.reserveBackView];
  143. }
  144. if (2 == tag) {
  145. if (!lastIndex) {
  146. ShowMsg(@"请选择要查看的计划");
  147. return;
  148. }
  149. if (models.count > lastIndex.row) {
  150. NSDictionary *dic = models[lastIndex.row];
  151. ApplyPlanStuListVC *vc = [[ApplyPlanStuListVC alloc] init];
  152. vc.planDic = dic;
  153. [self navPushHideTabbarToVC:vc];
  154. }else {
  155. ShowMsg(@"请选择未过期教练排班");
  156. }
  157. }
  158. if (3 == tag) {
  159. if (_searchTF.text.length < 1) {
  160. ShowMsg(@"请输入学员信息");
  161. return;
  162. }
  163. [_reserveBackView endEditing:YES];
  164. [self getStudentData];
  165. }
  166. if (4 == tag) {//取消
  167. [_reserveBackView removeFromSuperview];
  168. }
  169. if (5 == tag) {//预约
  170. [_reserveBackView removeFromSuperview];
  171. [self saveReserve];
  172. }
  173. }
  174. -(void)setLabelUIWithDic:(NSDictionary *)dic
  175. {
  176. if (dic.allKeys.count == 1) {
  177. //这个if是应对虚拟数据的
  178. nameLabel.text = @"当前计划信息:暂无";
  179. countLabel.text = @"暂无预约人数信息";
  180. return;
  181. }
  182. NSString *kmString = @"科目二";
  183. if ([[NSString stringWithFormat:@"%@",dic[@"KM"]] isEqualToString:@"3"]) {
  184. kmString = @"科目三";
  185. }
  186. nameLabel.text = [NSString stringWithFormat:@"当前计划信息:%@ %@ %@元/小时",dic[@"USERNAME"],kmString,dic[@"MONEY"]];
  187. addressLabel.text = [NSString stringWithFormat:@"场地信息:%@",dic[@"JSADDRESS"]];
  188. if ([dic[@"JSADDRESS"] length] < 1) {
  189. addressLabel.text = @"场地信息:暂无";
  190. }
  191. countLabel.text = [NSString stringWithFormat:@"计划可预约%@人,已预约%@人,有%@人也申请了预约计划",dic[@"PI_NUM"],dic[@"PI_HAV_NUM"],dic[@"HAVNUM"]];
  192. }
  193. -(CLWeeklyCalendarView *)calendarView
  194. {
  195. if(!_calendarView){
  196. _calendarView = [[CLWeeklyCalendarView alloc] initWithFrame:CGRectMake(0, calendarY, kSize.width, 120)];
  197. _calendarView.delegate = self;
  198. }
  199. return _calendarView;
  200. }
  201. - (UIView *)reserveBackView {
  202. if (!_reserveBackView) {
  203. _reserveBackView = [[UIView alloc] initWithFrame:kFrame];
  204. _reserveBackView.backgroundColor = [UIColor colorWithWhite:.2 alpha:.4];
  205. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyBored)];
  206. [_reserveBackView addGestureRecognizer:tap];
  207. CGFloat w = kSize.width - 40;
  208. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(20, kSize.height/2.0 - 140, w, 240)];
  209. view.backgroundColor = [UIColor whiteColor];
  210. [view borderCornorRadios:5];
  211. [_reserveBackView addSubview:view];
  212. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, w - 40, 30)];
  213. [label setText:@"请选择预约学员" Font:Font21 TextColor:KTitleColor Alignment:NSTextAlignmentCenter];
  214. [view addSubview:label];
  215. _searchTF = [[UITextField alloc] initWithFrame:CGRectMake(20, 40, w - 40 - 60, 30)];
  216. _searchTF.placeholder = @"请输入学员姓名或证件号码";
  217. _searchTF.font = [UIFont scaleSize:Font17];
  218. [_searchTF borderColor:kLineColor width:1 cornorRadios:3];
  219. [view addSubview:_searchTF];
  220. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(w - 75, 40, 55, 30)];
  221. btn.backgroundColor = [UIColor orangeColor];
  222. [btn setTitle:@"搜索" textColor:[UIColor whiteColor] font:Font17 fotState:UIControlStateNormal];
  223. [btn borderCornorRadios:5];
  224. [btn target:self Tag:3];
  225. [view addSubview:btn];
  226. stuListArray = [NSArray array];
  227. stuListTV = [[UITableView alloc] initWithFrame:CGRectMake(20, 80, w - 40, 110) style:UITableViewStylePlain];
  228. stuListTV.delegate = self;
  229. stuListTV.dataSource = self;
  230. stuListTV.tableFooterView = [UIView new];
  231. [view addSubview:stuListTV];
  232. [stuListTV borderColor:kLineColor width:1 cornorRadios:4];
  233. // label = [[UILabel alloc] initWithFrame:CGRectMake(20, 80, w - 40, 110)];
  234. // [label setText:@"这里是个表 显示搜索到的学员信息" Font:Font17 TextColor:KTitleColor Alignment:NSTextAlignmentCenter];
  235. // label.numberOfLines = 0;
  236. // [label borderColor:kLineColor width:1 cornorRadios:4];
  237. // [view addSubview:label];
  238. btn = [[UIButton alloc] initWithFrame:CGRectMake(20, 200, w/2.0 - 30, 30)];
  239. btn.backgroundColor = [UIColor lightGrayColor];
  240. [btn setTitle:@"取消" textColor:KTitleColor font:Font17 fotState:UIControlStateNormal];
  241. [btn borderCornorRadios:5];
  242. [btn target:self Tag:4];
  243. [view addSubview:btn];
  244. btn = [[UIButton alloc] initWithFrame:CGRectMake(w/2.0 + 10, 200, w/2.0 - 30, 30)];
  245. btn.backgroundColor = [UIColor lightGrayColor];
  246. [btn setTitle:@"预约" textColor:KTitleColor font:Font17 fotState:UIControlStateNormal];
  247. [btn borderCornorRadios:5];
  248. [btn target:self Tag:5];
  249. [view addSubview:btn];
  250. }
  251. return _reserveBackView;
  252. }
  253. - (void)closeKeyBored {
  254. [_reserveBackView endEditing:YES];
  255. }
  256. #pragma mark - CLWeeklyCalendarViewDelegate
  257. -(NSDictionary *)CLCalendarBehaviorAttributes
  258. {
  259. //CLCalendarSelectedDatePrintFormatDefault 显示选中日期格式
  260. return @{
  261. //CLCalendarWeekStartDay : @2, //Start Day of the week, from 1-7 Mon-Sun -- default 1
  262. // CLCalendarDayTitleTextColor : [UIColor yellowColor],
  263. // CLCalendarSelectedDatePrintColor : [UIColor greenColor],
  264. };
  265. }
  266. -(void)dailyCalendarViewDidSelect:(NSDate *)date
  267. {
  268. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  269. [formatter setDateFormat:@"yyyy-MM-dd"];
  270. taskTime = [formatter stringFromDate:date];
  271. //ShowHUD();
  272. if (lastIndex) {
  273. PlanCollectionCell *lastCell = (PlanCollectionCell *)[mainCollection cellForItemAtIndexPath:lastIndex];
  274. lastCell.backImageView.image = [UIImage imageNamed:@"plancell3.png"];
  275. }
  276. [self getPlanInfos];
  277. }
  278. #pragma mark - collection dalegate
  279. -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  280. {
  281. if (models.count == 0) {
  282. return mockDatas.count;
  283. }
  284. return models.count;
  285. }
  286. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  287. {
  288. PlanCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collection" forIndexPath:indexPath];
  289. //每次获取cell 把隐藏的控件全显示出来 还有会改变的默认属性 这样的话 下面就方便了
  290. cell.countLabel.hidden = NO;
  291. cell.headImgView.hidden = NO;
  292. cell.timeLabel.textColor = KTitleColor;
  293. cell.kmLabel.textColor = KTitleColor;
  294. cell.countLabel.textColor = KTitleColor;
  295. //把所有情况设置为不可点击 然后在可以点击的情况改变这个状态
  296. cell.isCanSelect = NO;
  297. if (models.count == 0) {
  298. cell.timeLabel.text = mockDatas[indexPath.row];
  299. cell.countLabel.hidden = YES;
  300. cell.headImgView.hidden = YES;
  301. cell.backImageView.image = [UIImage imageNamed:@"plancell1.png"];
  302. cell.kmLabel.text = @"已过期";
  303. return cell;
  304. }
  305. NSDictionary *dic = models[indexPath.row];
  306. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  307. [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  308. NSDate *crDate = [NSDate date];
  309. if ([dic[@"TIMES"] rangeOfString:@"-"].location != NSNotFound && [dic[@"TASKTIME"] rangeOfString:@"-"].location != NSNotFound) {
  310. NSString *endTime = [NSString stringWithFormat:@"%@ %@:00",dic[@"TASKTIME"],[[dic[@"TIMES"] componentsSeparatedByString:@"-"] lastObject]];
  311. crDate = [formatter dateFromString:endTime];
  312. }
  313. NSDate *nowDate = [NSDate date];
  314. NSComparisonResult result = [crDate compare:nowDate];
  315. //NSLog(@"result--->%d-crDate-%@-nowDate-%@",(int)result,crDate,nowDate);
  316. //过期不能预约 预约过不能预约 人数已经预约满不能预约 这个判断顺序是没问题的
  317. if (result == NSOrderedAscending){
  318. //NSLog(@"已过期");
  319. cell.backImageView.image = [UIImage imageNamed:@"plancell1.png"];
  320. cell.kmLabel.text = @"已过期";
  321. cell.headImgView.hidden = YES;
  322. cell.countLabel.hidden = YES;
  323. if ([[NSString stringWithFormat:@"%@",dic[@"STATUS"]] isEqualToString:@"0"]) {
  324. cell.kmLabel.text = @"被拒,已过期";
  325. }else if ([[NSString stringWithFormat:@"%@",dic[@"STATUS"]] isEqualToString:@"1"]){
  326. cell.kmLabel.text = @"已预约,已过期";
  327. }else if ([[NSString stringWithFormat:@"%@",dic[@"STATUS"]] isEqualToString:@"2"]){
  328. cell.kmLabel.text = @"预约中,已过期";
  329. }
  330. }
  331. if (result == NSOrderedDescending) {
  332. //NSLog(@"未过期");
  333. cell.backImageView.image = [UIImage imageNamed:@"plancell3.png"];
  334. cell.countLabel.text = [NSString stringWithFormat:@"%d/%d",[dic[@"PI_HAV_NUM"] intValue],[dic[@"PI_NUM"] intValue]];
  335. cell.kmLabel.text = [[NSString stringWithFormat:@"%@",dic[@"KM"]] isEqualToString:@"2"]?@"科目二":@"科目三";
  336. if (indexPath == lastIndex) {
  337. cell.backImageView.image = [UIImage imageNamed:@"plancell2.png"];
  338. }
  339. if ([[NSString stringWithFormat:@"%@",dic[@"STATUS"]] isEqualToString:@"0"]) {
  340. cell.kmLabel.text = @"预约被拒";
  341. cell.kmLabel.textColor = [UIColor orangeColor];
  342. }else if ([[NSString stringWithFormat:@"%@",dic[@"STATUS"]] isEqualToString:@"1"]){
  343. cell.kmLabel.text = @"已预约";
  344. cell.kmLabel.textColor = [UIColor orangeColor];
  345. }else if ([[NSString stringWithFormat:@"%@",dic[@"STATUS"]] isEqualToString:@"2"]){
  346. cell.kmLabel.text = @"预约中";
  347. cell.kmLabel.textColor = [UIColor orangeColor];
  348. }else if ([[NSString stringWithFormat:@"%@",dic[@"STATUS"]] isEqualToString:@"-1"]){
  349. if ([[NSString stringWithFormat:@"%@",dic[@"PI_HAV_NUM"]] isEqualToString:[NSString stringWithFormat:@"%@",dic[@"PI_NUM"]]]) {
  350. cell.kmLabel.text = @"已约满";
  351. cell.backImageView.image = [UIImage imageNamed:@"plancell1.png"];
  352. }else{
  353. cell.isCanSelect = YES;
  354. }
  355. }
  356. }
  357. cell.timeLabel.text = dic[@"TIMES"];
  358. return cell;
  359. }
  360. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  361. {
  362. [collectionView deselectItemAtIndexPath:indexPath animated:YES];
  363. PlanCollectionCell *cell = (PlanCollectionCell *)[collectionView cellForItemAtIndexPath:indexPath];
  364. if (models.count > indexPath.row) {
  365. NSDictionary *dic = models[indexPath.row];
  366. [self setLabelUIWithDic:dic];
  367. }
  368. //如果之前操作过 找到改变状态 移除数据
  369. if (lastIndex) {
  370. if (![lastIndex isEqual:indexPath]) {
  371. PlanCollectionCell *lastCell = (PlanCollectionCell *)[collectionView cellForItemAtIndexPath:lastIndex];
  372. if (lastCell.isCanSelect) {
  373. lastCell.backImageView.image = [UIImage imageNamed:@"plancell3.png"];
  374. }else {
  375. lastCell.backImageView.image = [UIImage imageNamed:@"plancell1.png"];
  376. }
  377. }
  378. }
  379. cell.backImageView.image = [UIImage imageNamed:@"plancell2.png"];
  380. if (cell.isCanSelect == NO) {
  381. //不能点击预约按钮
  382. applyPlanBtn.backgroundColor = [UIColor lightGrayColor];
  383. applyPlanBtn.userInteractionEnabled = NO;
  384. }else {
  385. //可以点击预约按钮
  386. applyPlanBtn.backgroundColor = [UIColor orangeColor];
  387. applyPlanBtn.userInteractionEnabled = YES;
  388. }
  389. //记录上一次点击按钮
  390. lastIndex = indexPath;
  391. }
  392. #pragma mark tableView
  393. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  394. return stuListArray.count;
  395. }
  396. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  397. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  398. if (cell == nil) {
  399. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
  400. [cell.imageView borderCornorRadios:3];
  401. cell.imageView.contentMode = UIViewContentModeScaleAspectFit;
  402. }
  403. NSDictionary *dic = stuListArray[indexPath.row];
  404. NSString *faceImgPath = dic[@"TSO_PHOTO_PATH"];
  405. if (!faceImgPath) {
  406. faceImgPath = @"";
  407. }
  408. [cell.imageView sd_setImageWithURL:[NSURL URLWithString:faceImgPath] placeholderImage:[UIImage imageNamed:@"NOImg"]];
  409. cell.textLabel.text = dic[@"TSO_NAME"];
  410. cell.detailTextLabel.text = dic[@"TSO_IDCARD"];
  411. return cell;
  412. }
  413. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  414. stuDic = stuListArray[indexPath.row];
  415. }
  416. #pragma mark - 获取数据
  417. -(void)getPlanInfos
  418. {
  419. if (![NetManager connectedToNetWork]) {
  420. [holderV setHidden:NO];
  421. return;
  422. }
  423. if (!taskTime) {
  424. NSDateFormatter* fm = [NSDateFormatter new];
  425. [fm setDateFormat:@"yyyy-MM-dd"];
  426. taskTime = [fm stringFromDate:[NSDate date]];
  427. }
  428. if (_coachDic) {
  429. coachNum = _coachDic[@"SFZHM"];
  430. }
  431. if (coachNum.length < 1) {
  432. coachNum = @"";
  433. }
  434. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  435. [dic setObject:taskTime forKey:@"planTime"];
  436. [dic setObject:coachNum forKey:@"idcard"];
  437. NSString *method = @"getPlans";
  438. [NetManager requestAnythingWithURL:method dictionary:dic dataArray:nil completion:^(NSDictionary *root) {
  439. // NSLog(@"找计划------>%@------>%@",dic,root);
  440. if (!root)
  441. {
  442. ShowMsg(@"网络请求失败");
  443. [holderV setHidden:NO];
  444. return;
  445. }
  446. NSString* code = root[@"code"];
  447. if (code.intValue >0) {
  448. ShowMsg(root[@"body"]);
  449. [holderV setHidden:NO];
  450. return;
  451. }
  452. models = root[@"body"];
  453. if (models.count > 0) {
  454. NSDictionary *dic = [models firstObject];
  455. [self setLabelUIWithDic:dic];
  456. [mainCollection reloadData];
  457. [holderV setHidden:YES];
  458. }else{
  459. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  460. [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  461. NSDate *taskDate = [formatter dateFromString:[NSString stringWithFormat:@"%@ 23:59:59",taskTime]];
  462. NSComparisonResult result = [taskDate compare:[NSDate date]];
  463. if (result == NSOrderedAscending){
  464. //NSLog(@"已过期");
  465. [holderV setHidden:YES];
  466. [self getMockDates];
  467. }
  468. if (result == NSOrderedDescending || result == NSOrderedSame) {
  469. //NSLog(@"未过期");
  470. ShowMsg(@"暂无计划");
  471. [holderV setHidden:NO];
  472. }
  473. }
  474. }];
  475. }
  476. -(void)getMockDates
  477. {
  478. mockDatas = [[NSMutableArray alloc] init];
  479. NSInteger time = 8;
  480. for (int i = 0; i < 10; i ++) {
  481. NSInteger beginTime = time;
  482. time += arc4random()%2 + 1;
  483. if (time > 18) {
  484. break;
  485. }
  486. NSString *timeString = [NSString stringWithFormat:@"%d:00-%d:00",(int)beginTime,(int)time];
  487. [mockDatas addObject:timeString];
  488. }
  489. //NSLog(@"---->%@",mockDatas);
  490. [mainCollection reloadData];
  491. NSDictionary *dic = [NSDictionary dictionaryWithObject:@"NOPLAN" forKey:@"NOPLAN"];
  492. [self setLabelUIWithDic:dic];
  493. }
  494. //获取学员信息
  495. -(void)getStudentData{
  496. //判断网络是否连接
  497. if (![NetManager connectedToNetWork]) {
  498. showMsgUnconnect();
  499. return;
  500. }
  501. NSMutableDictionary * mdic = [NSMutableDictionary new];
  502. [mdic setValue:_searchTF.text forKey:@"keyWord"];
  503. [NetManager requestAnythingWithURL:@"getStudentList" dictionary:mdic dataArray:nil completion:^(NSDictionary *root) {
  504. if (!root) {
  505. ShowMsg(@"学员信息查询失败,请重试");
  506. return;
  507. }
  508. if ([root[@"code"] integerValue] == 1) {
  509. ShowMsg(root[@"msg"]);
  510. return;
  511. }
  512. if ([root[@"body"] count] < 1) {
  513. ShowMsg(@"查询不到该学员,请确认查询条件");
  514. return;
  515. }else {
  516. if ([root[@"body"] count] == 1) {
  517. stuDic = [root[@"body"] firstObject];
  518. }
  519. //查询到多个学员 展示列表
  520. stuListArray = root[@"body"];
  521. [stuListTV reloadData];
  522. }
  523. }];
  524. }
  525. //预约教练计划
  526. -(void)saveReserve{
  527. //判断网络是否连接
  528. if (![NetManager connectedToNetWork]) {
  529. showMsgUnconnect();
  530. return;
  531. }
  532. NSDictionary *planDic = [NSDictionary dictionary];
  533. if (models.count > lastIndex.row) {
  534. planDic = models[lastIndex.row];
  535. }
  536. NSMutableDictionary * mdic = [NSMutableDictionary new];
  537. [mdic setValue:planDic[@"ID"] forKey:@"planId"];
  538. [mdic setValue:stuDic[@"TSO_IDCARD"] forKey:@"idcard"];
  539. [mdic setValue:stuDic[@"TSO_PHONE"] forKey:@"telphone"];
  540. [NetManager requestAnythingWithURL:@"saveReserve" dictionary:mdic dataArray:nil completion:^(NSDictionary *root) {
  541. if (!root) {
  542. ShowMsg(@"预约失败,请重试");
  543. return;
  544. }
  545. if ([root[@"code"] integerValue] == 1) {
  546. ShowMsg(root[@"msg"]);
  547. return;
  548. }
  549. ShowMsg(@"预约成功!");
  550. [self getPlanInfos];
  551. }];
  552. }
  553. #pragma mark
  554. -(void)playAudioWithString:(NSString *)string
  555. {
  556. [Tools playAudioWithString:string];
  557. }
  558. - (void)didReceiveMemoryWarning {
  559. [super didReceiveMemoryWarning];
  560. // Dispose of any resources that can be recreated.
  561. }
  562. @end