IssuePlanVC.m 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848
  1. //
  2. // IssuePlanVC.m
  3. // jiaPeiC
  4. //
  5. // Created by apple on 16/6/13.
  6. // Copyright © 2016年 JCZ. All rights reserved.
  7. //
  8. #import "IssuePlanVC.h"
  9. #import "CLWeeklyCalendarView.h"
  10. #import "PlanCollectionViewCell.h"
  11. #import "IssueBaseSettingVC.h"
  12. #import "myCollectionHeadView.h"
  13. @interface IssuePlanVC ()<CLWeeklyCalendarViewDelegate,UICollectionViewDelegateFlowLayout,UICollectionViewDataSource,UICollectionViewDelegate,UIActionSheetDelegate>
  14. {
  15. UICollectionView *mainCollection;
  16. UIView *backView;
  17. UIButton *sendBtn, *keErBtn, *keSanBtn, *yesBtn, *noBtn, *priceBtn;
  18. UITextField *numField, *priceField;
  19. HolderView *holderV;
  20. NSMutableArray *dataArray;
  21. NSMutableArray *dataSendArray;
  22. NSMutableArray *allData;
  23. NSString *keMuString;
  24. NSString *payAfterLearn;
  25. NSString *dateString;
  26. NSArray *moneyArray;
  27. NSDictionary *currentDic;
  28. }
  29. @property (nonatomic, strong) CLWeeklyCalendarView *calendarView;
  30. @end
  31. @implementation IssuePlanVC
  32. - (void)viewDidLoad {
  33. [super viewDidLoad];
  34. dataArray = [NSMutableArray array];
  35. dataSendArray = [NSMutableArray array];
  36. allData = [NSMutableArray array];
  37. [self myInit];
  38. }
  39. -(void)viewDidAppear:(BOOL)animated
  40. {
  41. [super viewDidAppear:animated];
  42. [self getPlanInfos];
  43. }
  44. -(void)viewWillDisappear:(BOOL)animated
  45. {
  46. [super viewWillDisappear:animated];
  47. [self.view endEditing:YES];
  48. }
  49. -(void)myInit
  50. {
  51. self.title = @"预约练车";
  52. self.view.backgroundColor = backGroundColor;
  53. [self configNavBar];
  54. self.navigationController.navigationBar.translucent = YES;
  55. UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"创建" style:UIBarButtonItemStyleDone target:self action:@selector(clickToAddPlan)];
  56. [item setTintColor:defGreen];
  57. [self.navigationItem setRightBarButtonItem:item];
  58. [self.view addSubview:self.calendarView];
  59. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  60. CGFloat width = (kSize.width - 40) / 3.0;
  61. [layout setItemSize:CGSizeMake(width, width * .7)];
  62. layout.minimumLineSpacing = 10;
  63. layout.minimumInteritemSpacing = 8;
  64. [layout setSectionInset:UIEdgeInsetsMake(0, 10, 5, 10)];
  65. //区头高度 这个如果不设置 下面代理不会执行
  66. layout.headerReferenceSize = CGSizeMake(kSize.width, 40);
  67. //尾部高度
  68. layout.footerReferenceSize = CGSizeMake(kSize.width, .1);
  69. CGFloat y = kNavOffSet + self.calendarView.height;
  70. mainCollection = [[UICollectionView alloc] initWithFrame:CGRectMake(0, y, kSize.width, kSize.height - y - 100) collectionViewLayout:layout];
  71. mainCollection.backgroundColor = backGroundColor;
  72. //自适应大小
  73. mainCollection.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  74. mainCollection.delegate = self;
  75. mainCollection.dataSource = self;
  76. [self addV:mainCollection];
  77. [mainCollection registerClass:[PlanCollectionViewCell class] forCellWithReuseIdentifier:@"PlanCollectionViewCell"];
  78. [mainCollection registerClass:[myCollectionHeadView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"myCollectionHeadView"];
  79. [mainCollection registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"UICollectionReusableView"];
  80. holderV = [[HolderView alloc] initWithFrame:mainCollection.frame];
  81. [holderV freshBlock:^{
  82. [self getPlanInfos];
  83. }];
  84. [self addV:holderV];
  85. //获取驾校分配价格
  86. [self getTrainPrice];
  87. UIView *issueBar = [[UIView alloc] initWithFrame:CGRectMake(0, kSize.height - 100, kSize.width, 100)];
  88. issueBar.backgroundColor = backGroundColor;
  89. [self addV:issueBar];
  90. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 50)];
  91. label.numberOfLines = 0;
  92. [label setText:@"点击时间段可修改对应时间段信息\n发布后,学员可以在“优易学车学员版”进行预约" Font:Font14 TextColor:contentTextColor Alignment:NSTextAlignmentCenter];
  93. [issueBar addSubview:label];
  94. UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  95. btn.frame = CGRectMake(20, 50, kSize.width - 40, 35);
  96. btn.backgroundColor = defGreen;
  97. [btn setTitle:@"确认发布" textColor:[UIColor whiteColor] font:Font16 fotState:UIControlStateNormal];
  98. [btn borderCornorRadios:5];
  99. [btn target:self Tag:1];
  100. sendBtn = btn;
  101. [issueBar addSubview:btn];
  102. }
  103. -(void)initPlanInformationWithIndexPath:(NSIndexPath *)indexPath
  104. {
  105. backView = [[UIView alloc] initWithFrame:kFrame];
  106. backView.backgroundColor = [UIColor colorWithWhite:.01 alpha:.4];
  107. //用window添加才能遮盖住导航栏
  108. [[UIApplication sharedApplication].keyWindow addSubview:backView];
  109. UIView *informationView = [[UIView alloc] initWithFrame:CGRectMake(10, kSize.height/2.0 - 150, kSize.width - 20, 240)];
  110. informationView.backgroundColor = backGroundColor;
  111. [informationView borderColor:lineColor width:1 cornorRadios:10];
  112. [backView addSubview:informationView];
  113. //crash
  114. if (dataArray.count > 0 && dataSendArray.count > 0) {
  115. if (indexPath.section == 0) {
  116. currentDic = dataSendArray[indexPath.row];
  117. }else{
  118. currentDic = dataArray[indexPath.row];
  119. }
  120. }else{
  121. currentDic = allData[indexPath.row];
  122. }
  123. keMuString = currentDic[@"km"];
  124. payAfterLearn = currentDic[@"isPay"];
  125. CGFloat x,y,w,h,wid;
  126. x = 0;
  127. y = 0;
  128. w = wid = kSize.width - 20;
  129. h = 50;
  130. //------时间------
  131. UILabel *label = [[UILabel alloc] setxywh];
  132. [label setText:currentDic[@"times"] Font:Font16 TextColor:titleColor Alignment:NSTextAlignmentCenter];
  133. [informationView addSubview:label];
  134. //------科目------
  135. x = 20;
  136. y += h;
  137. w = (wid-40)/3.0;
  138. h = 30;
  139. label = [[UILabel alloc] setxywh];
  140. [label setText:@"培训科目:" Font:Font16 TextColor:titleColor Alignment:NSTextAlignmentLeft];
  141. [informationView addSubview:label];
  142. x += w;
  143. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  144. button.frame = setDIYFrame;
  145. [button setImage:[UIImage imageNamed:@"selectAll"] Tit:@"科目二" Font:Font16 State:UIControlStateNormal];
  146. [button setImage:[UIImage imageNamed:@"selectedAll"] forState:UIControlStateSelected];
  147. [button setTitleColor:titleColor forState:UIControlStateNormal];
  148. [button setTitleColor:defGreen forState:UIControlStateSelected];
  149. [button target:self Tag:2];
  150. [informationView addSubview:button];
  151. keErBtn = button;
  152. x += w;
  153. button = [UIButton buttonWithType:UIButtonTypeCustom];
  154. button.frame = setDIYFrame;
  155. [button setImage:[UIImage imageNamed:@"selectAll"] Tit:@"科目三" Font:Font16 State:UIControlStateNormal];
  156. [button setImage:[UIImage imageNamed:@"selectedAll"] forState:UIControlStateSelected];
  157. [button setTitleColor:titleColor forState:UIControlStateNormal];
  158. [button setTitleColor:defGreen forState:UIControlStateSelected];
  159. [button target:self Tag:3];
  160. [informationView addSubview:button];
  161. keSanBtn = button;
  162. if ([currentDic[@"km"] isEqualToString:@"2"]) {
  163. keErBtn.selected = YES;
  164. }else{
  165. keSanBtn.selected = YES;
  166. }
  167. //------先学后付------
  168. // x = 20;
  169. // y += h;
  170. // w = (wid-40)/3.0;
  171. // h = 30;
  172. // label = [[UILabel alloc] setxywh];
  173. // [label setText:@"先学后付:" Font:Font16 TextColor:titleColor Alignment:NSTextAlignmentLeft];
  174. // [informationView addSubview:label];
  175. //
  176. // x += w;
  177. // button = [UIButton buttonWithType:UIButtonTypeCustom];
  178. // button.frame = setDIYFrame;
  179. // [button setImage:[UIImage imageNamed:@"selectAll"] Tit:@"是 " Font:Font16 State:UIControlStateNormal];
  180. // [button setImage:[UIImage imageNamed:@"selectedAll"] forState:UIControlStateSelected];
  181. // [button setTitleColor:titleColor forState:UIControlStateNormal];
  182. // [button setTitleColor:defGreen forState:UIControlStateSelected];
  183. // [button target:self Tag:4];
  184. // [informationView addSubview:button];
  185. // yesBtn = button;
  186. //
  187. // x += w;
  188. // button = [UIButton buttonWithType:UIButtonTypeCustom];
  189. // button.frame = setDIYFrame;
  190. // [button setImage:[UIImage imageNamed:@"selectAll"] Tit:@"否 " Font:Font16 State:UIControlStateNormal];
  191. // [button setImage:[UIImage imageNamed:@"selectedAll"] forState:UIControlStateSelected];
  192. // [button setTitleColor:titleColor forState:UIControlStateNormal];
  193. // [button setTitleColor:defGreen forState:UIControlStateSelected];
  194. // [button target:self Tag:5];
  195. // [informationView addSubview:button];
  196. // noBtn = button;
  197. //
  198. // if ([currentDic[@"isPay"] isEqualToString:@"1"]) {
  199. // yesBtn.selected = YES;
  200. //
  201. // }else{
  202. // noBtn.selected = YES;
  203. // }
  204. //-----练车人数及价格设置-------
  205. NSString *textString = @"练车人数";
  206. x = 20;
  207. y += h;
  208. w = [textString sizeForFont:Font16].width;
  209. h = 30;
  210. label = [[UILabel alloc] setxywh];
  211. [label setText:textString Font:Font16 TextColor:titleColor Alignment:NSTextAlignmentLeft];
  212. [informationView addSubview:label];
  213. x += w;
  214. w = 30;
  215. numField = [[UITextField alloc] setxywh];
  216. numField.textColor = [UIColor orangeColor];
  217. numField.font = [UIFont scaleSize:Font16];
  218. numField.textAlignment = NSTextAlignmentCenter;
  219. numField.keyboardType = UIKeyboardTypeNumberPad;
  220. numField.text = currentDic[@"num"];
  221. [informationView addSubview:numField];
  222. [numField addViewWithRect:CGRectMake(x + 2, y + h - 5, 26, 1) Color:[UIColor orangeColor]];
  223. x += w;
  224. label = [[UILabel alloc] setxywh];
  225. [label setText:@"人" Font:Font16 TextColor:titleColor Alignment:NSTextAlignmentLeft];
  226. [informationView addSubview:label];
  227. x = wid - 60;
  228. w = 45;
  229. label = [[UILabel alloc] setxywh];
  230. [label setText:@"元/时" Font:Font16 TextColor:titleColor Alignment:NSTextAlignmentLeft];
  231. [informationView addSubview:label];
  232. x -= w;
  233. //NSLog(@"moneyDic--->%@",moneyDic);
  234. NSString *money = currentDic[@"money"];
  235. if ([money containsString:@"."]) {
  236. money = [[money componentsSeparatedByString:@"."] firstObject];
  237. }
  238. button = [UIButton buttonWithType:UIButtonTypeCustom];
  239. button.frame = setDIYFrame;
  240. [button setTitle:money textColor:[UIColor orangeColor] font:Font16 fotState:UIControlStateNormal];
  241. [button target:self Tag:6];
  242. [informationView addSubview:button];
  243. priceBtn = button;
  244. [priceBtn addViewWithRect:CGRectMake(x + 2, y + h - 5, 36, 1) Color:[UIColor orangeColor]];
  245. x -= 80;
  246. w = 80;
  247. label = [[UILabel alloc] setxywh];
  248. [label setText:@"培训价格" Font:Font16 TextColor:titleColor Alignment:NSTextAlignmentRight];
  249. [informationView addSubview:label];
  250. x = 20;
  251. y = informationView.height - 90;
  252. w = wid - 40;
  253. h = 40;
  254. UILabel *remindLabel = [[UILabel alloc] setxywh];
  255. [remindLabel setText:@"提示:已有预约的计划不能做任何操作" Font:Font16 TextColor:[UIColor orangeColor] Alignment:NSTextAlignmentCenter];
  256. remindLabel.numberOfLines = 2;
  257. [informationView addSubview:remindLabel];
  258. x = 0;
  259. y = informationView.height - 50;;
  260. w = wid/3.0;
  261. h = 50;
  262. button = [[UIButton alloc] setxywh];
  263. [button setTitle:@"取消" textColor:titleColor font:Font18 fotState:UIControlStateNormal];
  264. [button target:self Tag:7];
  265. [informationView addSubview:button];
  266. x += w;
  267. button = [[UIButton alloc] setxywh];
  268. [button setTitle:@"删除" textColor:titleColor font:Font18 fotState:UIControlStateNormal];
  269. [button target:self Tag:8];
  270. [informationView addSubview:button];
  271. [button addViewWithRect:CGRectMake(x - .5, y, 1, h)];
  272. x += w;
  273. button = [[UIButton alloc] setxywh];
  274. [button setTitle:@"修改" textColor:defGreen font:Font18 fotState:UIControlStateNormal];
  275. [button target:self Tag:9];
  276. [informationView addSubview:button];
  277. [button addViewWithRect:CGRectMake(0, y - 1, wid, 1)];
  278. [button addViewWithRect:CGRectMake(x - .5, y, 1, h)];
  279. }
  280. //日历控件的初始化和点击回调
  281. -(CLWeeklyCalendarView *)calendarView
  282. {
  283. if(!_calendarView){
  284. _calendarView = [[CLWeeklyCalendarView alloc] initWithFrame:CGRectMake(0, kNavOffSet, kSize.width, 120)];
  285. _calendarView.delegate = self;
  286. }
  287. return _calendarView;
  288. }
  289. #pragma mark - CLWeeklyCalendarViewDelegate
  290. -(NSDictionary *)CLCalendarBehaviorAttributes
  291. {
  292. //CLCalendarSelectedDatePrintFormatDefault 显示选中日期格式
  293. return @{
  294. //CLCalendarWeekStartDay : @2, //Start Day of the week, from 1-7 Mon-Sun -- default 1
  295. // CLCalendarDayTitleTextColor : [UIColor yellowColor],
  296. // CLCalendarSelectedDatePrintColor : [UIColor greenColor],
  297. };
  298. }
  299. -(void)dailyCalendarViewDidSelect:(NSDate *)date
  300. {
  301. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  302. [formatter setDateFormat:@"yyyy-MM-dd"];
  303. dateString = [formatter stringFromDate:date];
  304. //这里做个接口 是请求这一页的数据的
  305. [self getPlanInfos];
  306. }
  307. #pragma mark 按钮事件
  308. -(void)clickToAddPlan
  309. {
  310. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  311. [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  312. NSString *todayString = [formatter stringFromDate:[NSDate date]];
  313. todayString = [NSString stringWithFormat:@"%@ 23:59:59",[todayString substringToIndex:10]];
  314. NSDate *today = [formatter dateFromString:todayString];
  315. NSTimeInterval todayTime = [today timeIntervalSince1970];
  316. NSString *playDateString = [NSString stringWithFormat:@"%@ 23:59:59",dateString];
  317. NSDate *playDay = [formatter dateFromString:playDateString];
  318. NSTimeInterval playTime = [playDay timeIntervalSince1970];
  319. if (todayTime > playTime) {
  320. ShowMsg(@"所选时间已过期,请核对日期!");
  321. return;
  322. }
  323. IssueBaseSettingVC *setting = [[IssueBaseSettingVC alloc] init];
  324. setting.dateString = dateString;
  325. setting.dataArray = allData;
  326. setting.moneyArray = moneyArray;
  327. [self.navigationController pushViewController:setting animated:YES];
  328. }
  329. -(void)btnClick:(UIButton *)sender
  330. {
  331. //按钮 如果有键盘 要先将键盘搞下去
  332. [backView endEditing:YES];
  333. //NSLog(@"btnClick-->%d",(int)sender.tag);
  334. switch (sender.tag) {
  335. case 1:
  336. //发布
  337. [self updatePlanStatus:@"1"];
  338. break;
  339. case 6:
  340. if ([currentDic[@"havNum"] integerValue] > 0) {
  341. ShowMsg(@"已有学员预约,无法修改价格");
  342. return;
  343. }
  344. [self selectPrice];
  345. break;
  346. case 7:
  347. [backView removeFromSuperview];
  348. break;
  349. case 8:
  350. {
  351. //确认删除
  352. if ([currentDic[@"havNum"] integerValue] > 0) {
  353. ShowMsg(@"已有学员预约,无法删除");
  354. return;
  355. }
  356. [self deletePlanInfo];
  357. [backView removeFromSuperview];
  358. }
  359. break;
  360. case 9:
  361. //确定修改
  362. if (numField.text.length == 0 || [numField.text integerValue]==0 || [numField.text integerValue]>10) {
  363. ShowMsg(@"请设置合理的练车人数");
  364. return;
  365. }
  366. [self updatePlanInfoNew];
  367. [backView removeFromSuperview];
  368. break;
  369. default:
  370. [self setWhiceSelectWithTag:sender.tag];
  371. break;
  372. }
  373. }
  374. -(void)setWhiceSelectWithTag:(NSInteger)tag
  375. {
  376. if ([currentDic[@"havNum"] integerValue] > 0) {
  377. ShowMsg(@"已有学员预约,无法修改");
  378. return;
  379. }
  380. //设置信息也是在这里边写的
  381. if (tag == 2) {
  382. if (keSanBtn.isSelected == YES) {
  383. keSanBtn.selected = NO;
  384. }
  385. keErBtn.selected = YES;
  386. keMuString = @"2";
  387. }
  388. if (tag == 3) {
  389. if (keErBtn.isSelected == YES) {
  390. keErBtn.selected = NO;
  391. }
  392. keSanBtn.selected = YES;
  393. keMuString = @"3";
  394. }
  395. NSString *money = currentDic[@"money"];
  396. if ([money containsString:@"."]) {
  397. money = [[money componentsSeparatedByString:@"."] firstObject];
  398. }
  399. if (money == nil) {
  400. money = @"0";
  401. }
  402. if (tag == 4) {
  403. noBtn.selected = NO;
  404. yesBtn.selected = YES;
  405. payAfterLearn = @"1";
  406. [priceBtn setTitle:money forState:UIControlStateNormal];
  407. }
  408. if (tag == 5) {
  409. yesBtn.selected = NO;
  410. noBtn.selected = YES;
  411. payAfterLearn = @"0";
  412. [priceBtn setTitle:@"0" forState:UIControlStateNormal];
  413. }
  414. }
  415. -(void)selectPrice
  416. {
  417. NSMutableArray *titleArray = [NSMutableArray array];
  418. [titleArray addObject:@"免费模式"];
  419. for (NSDictionary *dic in moneyArray) {
  420. NSString * strSD = @"";
  421. switch ([dic[@"CSI_TRAINNINGTIME"] integerValue]) {
  422. case 1:
  423. strSD = @"普通时段";
  424. break;
  425. case 2:
  426. strSD = @"高峰时段";
  427. break;
  428. case 3:
  429. strSD = @"节假日时段";
  430. break;
  431. default:
  432. break;
  433. }
  434. NSString *titleString = [NSString stringWithFormat:@"%@ %@ %@元 ",strSD,dic[@"CSI_VEHICLETYPE"],dic[@"CSI_PRICE"]];
  435. [titleArray addObject:titleString];
  436. }
  437. //UIActionSheet对按钮数量不确定时候的处理
  438. UIActionSheet* sheet = [[UIActionSheet alloc] initWithTitle:@"选择培训价格" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
  439. for (NSString *title in titleArray) {
  440. [sheet addButtonWithTitle:title];
  441. }
  442. [sheet addButtonWithTitle:@"取消"];
  443. sheet.cancelButtonIndex = sheet.numberOfButtons - 1;
  444. sheet.actionSheetStyle = UIActionSheetStyleDefault;
  445. [sheet showInView:self.view];
  446. }
  447. -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
  448. {
  449. if (buttonIndex == actionSheet.cancelButtonIndex) {
  450. return;
  451. }
  452. if (buttonIndex == 0) {
  453. [priceBtn setTitle:@"免费模式" forState:UIControlStateNormal];
  454. return;
  455. }
  456. NSDictionary *dic = moneyArray[buttonIndex - 1];
  457. [priceBtn setTitle:dic[@"CSI_PRICE"] forState:UIControlStateNormal];
  458. }
  459. #pragma mark collection delegate
  460. -(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
  461. {
  462. UICollectionReusableView *reusableview = nil;
  463. if (kind == UICollectionElementKindSectionHeader){
  464. myCollectionHeadView *headerV = (myCollectionHeadView *)[collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"myCollectionHeadView" forIndexPath:indexPath];
  465. if (dataArray.count > 0 && dataSendArray.count > 0) {
  466. //这个有已发布的和未发布的
  467. if (indexPath.section == 0) {
  468. [headerV setTextTitle:@"已发布计划"];
  469. }else{
  470. [headerV setTextTitle:@"未发布计划"];
  471. }
  472. }else if (dataArray.count > 0){
  473. //未发布
  474. [headerV setTextTitle:@"未发布计划"];
  475. }else{
  476. //已发布
  477. [headerV setTextTitle:@"已发布计划"];
  478. }
  479. reusableview = headerV;
  480. }else{
  481. reusableview = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"UICollectionReusableView" forIndexPath:indexPath];
  482. }
  483. return reusableview;
  484. }
  485. -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  486. {
  487. if (dataArray.count > 0 && dataSendArray.count > 0) {
  488. return 2;
  489. }else{
  490. return 1;
  491. }
  492. }
  493. -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  494. {
  495. if (dataArray.count > 0 && dataSendArray.count > 0) {
  496. //这个有已发布的和未发布的
  497. if (section == 0) {
  498. return dataSendArray.count;
  499. }else{
  500. return dataArray.count;
  501. }
  502. }else if (dataArray.count > 0){
  503. //未发布
  504. return dataArray.count;
  505. }else{
  506. //已发布
  507. return dataSendArray.count;
  508. }
  509. }
  510. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  511. {
  512. PlanCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"PlanCollectionViewCell" forIndexPath:indexPath];
  513. [cell setNeedsDisplay];
  514. NSDictionary *dic;
  515. if (dataArray.count > 0 && dataSendArray.count > 0) {
  516. //这个有已发布的和未发布的
  517. if (indexPath.section == 0) {
  518. dic = dataSendArray[indexPath.row];
  519. }else{
  520. dic = dataArray[indexPath.row];
  521. }
  522. }else if (dataArray.count > 0){
  523. //未发布
  524. dic = dataArray[indexPath.row];
  525. }else{
  526. //已发布
  527. dic = dataSendArray[indexPath.row];
  528. }
  529. cell.timeLabel.text = dic[@"times"];
  530. if ([dic[@"km"] isEqualToString:@"2"]) {
  531. cell.kemuLabel.text = @"科目二";
  532. }else{
  533. cell.kemuLabel.text = @"科目三";
  534. }
  535. cell.countLabel.text = [NSString stringWithFormat:@"已约%@人 可约%@人",dic[@"havNum"],dic[@"num"]];
  536. return cell;
  537. }
  538. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  539. {
  540. //这个地方 对数组中某串信息进行修改
  541. [self initPlanInformationWithIndexPath:indexPath];
  542. }
  543. #pragma mark - 数据请求
  544. - (void)getPlanInfos
  545. {
  546. if (![Util connectedToNetWork]) {
  547. showMsgUnconnect();
  548. return;
  549. }
  550. NSMutableArray *arr=[NSMutableArray array];
  551. [arr addPro:@"taskTime" Value:dateString];
  552. [arr addPro:@"user" Value:defUser.sfzmhm];
  553. [arr addPro:@"isPage" Value:@""];
  554. [arr addPro:@"pageSize" Value:@""];
  555. [arr addPro:@"currentPage" Value:@""];
  556. [arr addPro:@"status" Value:@""];
  557. NSString* method = @"getPlanInfosForCoa";
  558. ShowHUD();
  559. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  560. RemoveHUD();
  561. //NSLog(@"我的计划-->%@---->%@",arr,root);
  562. //一旦发起 就要remove之前的数据
  563. [allData removeAllObjects];
  564. [dataArray removeAllObjects];
  565. [dataSendArray removeAllObjects];
  566. [holderV setHidden:NO];
  567. if (!root) {
  568. return ;
  569. }
  570. if ([root[@"code"] isEqualToString:@"1"]) {
  571. ShowMsg(root[@"body"]);
  572. return;
  573. }
  574. NSArray *array = root[@"body"];
  575. if (array.count < 1) {
  576. sendBtn.hidden = YES;
  577. return;
  578. }
  579. [allData addObjectsFromArray:root[@"body"]];
  580. for (NSDictionary *dic in array) {
  581. if ([dic[@"status"] isEqualToString:@"0"]) {
  582. //未发布
  583. [dataArray addObject:dic];
  584. }
  585. if ([dic[@"status"] isEqualToString:@"1"]) {
  586. //已发布
  587. [dataSendArray addObject:dic];
  588. }
  589. }
  590. if (dataArray.count < 1) {
  591. sendBtn.hidden = YES;
  592. }else{
  593. sendBtn.hidden = NO;
  594. }
  595. [holderV setHidden:YES];
  596. [mainCollection reloadData];
  597. }];
  598. }
  599. //获取价格
  600. -(void)getTrainPrice
  601. {
  602. NSMutableArray *arr=[NSMutableArray array];
  603. [arr addPro:@"schoolId" Value:defUser.userDict[@"jxbh"]];
  604. [arr addPro:@"dqbh" Value:defUser.userDict[@"cityId"]];
  605. NSString* method = @"getPrice";
  606. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * dict) {
  607. RemoveHUD();
  608. //NSLog(@"获取价格-->%@->%@",arr,dict);
  609. if (!dict) {
  610. return ;
  611. }
  612. if ( [dict[@"code"] isEqualToString:@"1"]) {
  613. return ;
  614. }
  615. moneyArray = dict[@"body"];
  616. }];
  617. }
  618. //更改发布状态
  619. -(void)updatePlanStatus:(NSString *)state
  620. {
  621. NSMutableArray *arr=[NSMutableArray array];
  622. [arr addPro:@"taskTime" Value:dateString];
  623. [arr addPro:@"status" Value:state];
  624. [arr addPro:@"coach" Value:defUser.sfzmhm];
  625. [arr addPro:@"dqbh" Value:defUser.userDict[@"cityId"]];
  626. NSString* method = @"updatePlanStatus";
  627. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * dict) {
  628. RemoveHUD();
  629. //NSLog(@"更改状态---->%@---->%@",arr,dict);
  630. if (!dict) {
  631. ShowMsgFailed();
  632. return ;
  633. }
  634. if ([dict[@"code"] isEqualToString:@"1"]) {
  635. [LoadingView showMsg:dict[@"body"]];
  636. return ;
  637. }
  638. ShowMsgSuc();
  639. [self getPlanInfos];
  640. }];
  641. }
  642. //修改计划
  643. - (void)updatePlanInfoNew
  644. {
  645. if (![Util connectedToNetWork]) {
  646. showMsgUnconnect();
  647. return;
  648. }
  649. NSString *money = priceBtn.titleLabel.text;
  650. if ([money isEqualToString:@"免费模式"]) {
  651. money = @"0";
  652. }
  653. // if ([payAfterLearn isEqualToString:@"1"] && [money isEqualToString:@"0"]) {
  654. // ShowMsg(@"当前价格为0元,不能更改为先学后付计划");
  655. // return;
  656. // }
  657. NSMutableArray *arr=[NSMutableArray array];
  658. [arr addPro:@"id" Value:currentDic[@"id"]];
  659. [arr addPro:@"num" Value:numField.text];
  660. [arr addPro:@"tel" Value:payAfterLearn];
  661. [arr addPro:@"subject" Value:keMuString];
  662. [arr addPro:@"price" Value:money];
  663. NSString* method = @"updatePlanInfo";
  664. ShowHUD();
  665. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  666. RemoveHUD();
  667. //NSLog(@"修改计划---%@----->%@",arr,root);
  668. if (!root) {
  669. ShowMsgFailed();
  670. return ;
  671. }
  672. if ([root[@"code"] isEqualToString:@"1"]) {
  673. ShowMsg(root[@"body"]);
  674. return;
  675. }
  676. //修改完毕之后 要重新刷新
  677. [self getPlanInfos];
  678. }];
  679. }
  680. //删除计划
  681. - (void)deletePlanInfo
  682. {
  683. if (![Util connectedToNetWork]) {
  684. showMsgUnconnect();
  685. return;
  686. }
  687. NSMutableArray *arr=[NSMutableArray array];
  688. [arr addPro:@"id" Value:currentDic[@"id"]];
  689. NSString* method = @"deletePlanInfo";
  690. ShowHUD();
  691. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  692. RemoveHUD();
  693. //NSLog(@"删除计划---%@----->%@",arr,root);
  694. if (!root) {
  695. ShowMsgFailed();
  696. return ;
  697. }
  698. if ([root[@"code"] isEqualToString:@"1"]) {
  699. ShowMsg(root[@"body"]);
  700. return;
  701. }
  702. //删除完毕之后 要重新刷新
  703. [self getPlanInfos];
  704. }];
  705. }
  706. - (void)didReceiveMemoryWarning {
  707. [super didReceiveMemoryWarning];
  708. }
  709. @end