CoachPlanVC.m 24 KB

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