IssuePlanVC.m 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856
  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:kTitleColor 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:kTitleColor 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:kTitleColor 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:kTitleColor 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:kTitleColor 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:kTitleColor 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:kTitleColor 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:kTitleColor 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:kTitleColor Alignment:NSTextAlignmentLeft];
  226. [informationView addSubview:label];
  227. x = wid - 60;
  228. w = 45;
  229. label = [[UILabel alloc] setxywh];
  230. [label setText:@"元/时" Font:Font16 TextColor:kTitleColor Alignment:NSTextAlignmentLeft];
  231. [informationView addSubview:label];
  232. x -= w;
  233. //NSLog(@"moneyDic--->%@",moneyDic);
  234. // NSString *money = currentDic[@"money"];
  235. //
  236. // button = [UIButton buttonWithType:UIButtonTypeCustom];
  237. // button.frame = setDIYFrame;
  238. // [button setTitle:money textColor:[UIColor orangeColor] font:Font16 fotState:UIControlStateNormal];
  239. // [button target:self Tag:6];
  240. // [informationView addSubview:button];
  241. // priceBtn = button;
  242. // [priceBtn addViewWithRect:CGRectMake(x + 2, y + h - 5, 36, 1) Color:[UIColor orangeColor]];
  243. NSString *money = [NSString stringWithFormat:@"%.1f",[currentDic[@"money"] floatValue]? : 0];
  244. priceField = [[UITextField alloc] setxywh];
  245. priceField.textColor = [UIColor orangeColor];
  246. priceField.font = [UIFont scaleSize:Font16];
  247. priceField.textAlignment = NSTextAlignmentCenter;
  248. priceField.keyboardType = UIKeyboardTypeDecimalPad;
  249. priceField.text = money;
  250. [informationView addSubview:priceField];
  251. [priceField addViewWithRect:CGRectMake(x + 2, y + h - 5, 36, 1) Color:[UIColor orangeColor]];
  252. x -= 80;
  253. w = 80;
  254. label = [[UILabel alloc] setxywh];
  255. [label setText:@"培训价格" Font:Font16 TextColor:kTitleColor Alignment:NSTextAlignmentRight];
  256. [informationView addSubview:label];
  257. x = 20;
  258. y = informationView.height - 90;
  259. w = wid - 40;
  260. h = 40;
  261. UILabel *remindLabel = [[UILabel alloc] setxywh];
  262. [remindLabel setText:@"提示:已有预约的计划不能做任何操作" Font:Font16 TextColor:[UIColor orangeColor] Alignment:NSTextAlignmentCenter];
  263. remindLabel.numberOfLines = 2;
  264. [informationView addSubview:remindLabel];
  265. x = 0;
  266. y = informationView.height - 50;;
  267. w = wid/3.0;
  268. h = 50;
  269. button = [[UIButton alloc] setxywh];
  270. [button setTitle:@"取消" textColor:kTitleColor font:Font18 fotState:UIControlStateNormal];
  271. [button target:self Tag:7];
  272. [informationView addSubview:button];
  273. x += w;
  274. button = [[UIButton alloc] setxywh];
  275. [button setTitle:@"删除" textColor:kTitleColor font:Font18 fotState:UIControlStateNormal];
  276. [button target:self Tag:8];
  277. [informationView addSubview:button];
  278. [button addViewWithRect:CGRectMake(x - .5, y, 1, h)];
  279. x += w;
  280. button = [[UIButton alloc] setxywh];
  281. [button setTitle:@"修改" textColor:defGreen font:Font18 fotState:UIControlStateNormal];
  282. [button target:self Tag:9];
  283. [informationView addSubview:button];
  284. [button addViewWithRect:CGRectMake(0, y - 1, wid, 1)];
  285. [button addViewWithRect:CGRectMake(x - .5, y, 1, h)];
  286. }
  287. //日历控件的初始化和点击回调
  288. -(CLWeeklyCalendarView *)calendarView
  289. {
  290. if(!_calendarView){
  291. _calendarView = [[CLWeeklyCalendarView alloc] initWithFrame:CGRectMake(0, kNavOffSet, kSize.width, 120)];
  292. _calendarView.delegate = self;
  293. }
  294. return _calendarView;
  295. }
  296. #pragma mark - CLWeeklyCalendarViewDelegate
  297. -(NSDictionary *)CLCalendarBehaviorAttributes
  298. {
  299. //CLCalendarSelectedDatePrintFormatDefault 显示选中日期格式
  300. return @{
  301. //CLCalendarWeekStartDay : @2, //Start Day of the week, from 1-7 Mon-Sun -- default 1
  302. // CLCalendarDayTitleTextColor : [UIColor yellowColor],
  303. // CLCalendarSelectedDatePrintColor : [UIColor greenColor],
  304. };
  305. }
  306. -(void)dailyCalendarViewDidSelect:(NSDate *)date
  307. {
  308. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  309. [formatter setDateFormat:@"yyyy-MM-dd"];
  310. dateString = [formatter stringFromDate:date];
  311. //这里做个接口 是请求这一页的数据的
  312. [self getPlanInfos];
  313. }
  314. #pragma mark 按钮事件
  315. -(void)clickToAddPlan
  316. {
  317. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  318. [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  319. NSString *todayString = [formatter stringFromDate:[NSDate date]];
  320. todayString = [NSString stringWithFormat:@"%@ 23:59:59",[todayString substringToIndex:10]];
  321. NSDate *today = [formatter dateFromString:todayString];
  322. NSTimeInterval todayTime = [today timeIntervalSince1970];
  323. NSString *playDateString = [NSString stringWithFormat:@"%@ 23:59:59",dateString];
  324. NSDate *playDay = [formatter dateFromString:playDateString];
  325. NSTimeInterval playTime = [playDay timeIntervalSince1970];
  326. if (todayTime > playTime) {
  327. ShowMsg(@"所选时间已过期,请核对日期!");
  328. return;
  329. }
  330. IssueBaseSettingVC *setting = [[IssueBaseSettingVC alloc] init];
  331. setting.dateString = dateString;
  332. setting.dataArray = allData;
  333. setting.moneyArray = moneyArray;
  334. [setting initSuccessBlock:^(NSString *currentDateString) {
  335. // NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  336. // [formatter setDateFormat:@"yyyy-MM-dd"];
  337. //
  338. // NSDate *date = [formatter dateFromString:currentDateString];
  339. // [self.calendarView redrawToDate:date];
  340. }];
  341. [self.navigationController pushViewController:setting animated:YES];
  342. }
  343. -(void)btnClick:(UIButton *)sender
  344. {
  345. //按钮 如果有键盘 要先将键盘搞下去
  346. [backView endEditing:YES];
  347. //NSLog(@"btnClick-->%d",(int)sender.tag);
  348. switch (sender.tag) {
  349. case 1:
  350. //发布
  351. [self updatePlanStatus:@"1"];
  352. break;
  353. case 6:
  354. if ([currentDic[@"havNum"] integerValue] > 0) {
  355. ShowMsg(@"已有学员预约,无法修改价格");
  356. return;
  357. }
  358. // [self selectPrice];
  359. break;
  360. case 7:
  361. [backView removeFromSuperview];
  362. break;
  363. case 8:
  364. {
  365. //确认删除
  366. if ([currentDic[@"havNum"] integerValue] > 0) {
  367. ShowMsg(@"已有学员预约,无法删除");
  368. return;
  369. }
  370. [self deletePlanInfo];
  371. [backView removeFromSuperview];
  372. }
  373. break;
  374. case 9:
  375. //确定修改
  376. if (numField.text.length == 0 || [numField.text integerValue]==0 || [numField.text integerValue]>10) {
  377. ShowMsg(@"请设置合理的练车人数");
  378. return;
  379. }
  380. [self updatePlanInfoNew];
  381. [backView removeFromSuperview];
  382. break;
  383. default:
  384. [self setWhiceSelectWithTag:sender.tag];
  385. break;
  386. }
  387. }
  388. -(void)setWhiceSelectWithTag:(NSInteger)tag
  389. {
  390. if ([currentDic[@"havNum"] integerValue] > 0) {
  391. ShowMsg(@"已有学员预约,无法修改");
  392. return;
  393. }
  394. //设置信息也是在这里边写的
  395. if (tag == 2) {
  396. if (keSanBtn.isSelected == YES) {
  397. keSanBtn.selected = NO;
  398. }
  399. keErBtn.selected = YES;
  400. keMuString = @"2";
  401. }
  402. if (tag == 3) {
  403. if (keErBtn.isSelected == YES) {
  404. keErBtn.selected = NO;
  405. }
  406. keSanBtn.selected = YES;
  407. keMuString = @"3";
  408. }
  409. NSString *money = [NSString stringWithFormat:@"%.1f",[currentDic[@"money"] floatValue]];
  410. // if ([money containsString:@"."]) {
  411. // money = [[money componentsSeparatedByString:@"."] firstObject];
  412. // }
  413. if (money == nil) {
  414. money = @"0";
  415. }
  416. if (tag == 4) {
  417. noBtn.selected = NO;
  418. yesBtn.selected = YES;
  419. payAfterLearn = @"1";
  420. // [priceBtn setTitle:money forState:UIControlStateNormal];
  421. priceField.text = money;
  422. }
  423. if (tag == 5) {
  424. yesBtn.selected = NO;
  425. noBtn.selected = YES;
  426. payAfterLearn = @"0";
  427. // [priceBtn setTitle:@"0" forState:UIControlStateNormal];
  428. priceField.text = @"0";
  429. }
  430. }
  431. //-(void)selectPrice
  432. //{
  433. // NSMutableArray *titleArray = [NSMutableArray array];
  434. //
  435. // for (NSDictionary *dic in moneyArray) {
  436. // NSString * strSD = @"";
  437. // switch ([dic[@"CSI_TRAINNINGTIME"] integerValue]) {
  438. // case 1:
  439. // strSD = @"普通时段";
  440. // break;
  441. // case 2:
  442. // strSD = @"高峰时段";
  443. // break;
  444. // case 3:
  445. // strSD = @"节假日时段";
  446. // break;
  447. // default:
  448. // break;
  449. // }
  450. //
  451. // NSString *titleString = [NSString stringWithFormat:@"%@ %@ %@元 ",strSD,dic[@"CSI_VEHICLETYPE"],dic[@"CSI_PRICE"]];
  452. // [titleArray addObject:titleString];
  453. // }
  454. //
  455. // //UIActionSheet对按钮数量不确定时候的处理
  456. // UIActionSheet* sheet = [[UIActionSheet alloc] initWithTitle:@"选择培训价格" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
  457. //
  458. // for (NSString *title in titleArray) {
  459. // [sheet addButtonWithTitle:title];
  460. // }
  461. //
  462. // [sheet addButtonWithTitle:@"取消"];
  463. // sheet.cancelButtonIndex = sheet.numberOfButtons - 1;
  464. // sheet.actionSheetStyle = UIActionSheetStyleDefault;
  465. // [sheet showInView:self.view];
  466. //}
  467. //-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
  468. //{
  469. // if (buttonIndex == actionSheet.cancelButtonIndex) {
  470. // return;
  471. // }
  472. //
  473. // NSDictionary *dic = moneyArray[buttonIndex];
  474. // [priceBtn setTitle:dic[@"CSI_PRICE"] forState:UIControlStateNormal];
  475. //}
  476. #pragma mark collection delegate
  477. -(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
  478. {
  479. UICollectionReusableView *reusableview = nil;
  480. if (kind == UICollectionElementKindSectionHeader){
  481. myCollectionHeadView *headerV = (myCollectionHeadView *)[collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"myCollectionHeadView" forIndexPath:indexPath];
  482. if (dataArray.count > 0 && dataSendArray.count > 0) {
  483. //这个有已发布的和未发布的
  484. if (indexPath.section == 0) {
  485. [headerV setTextTitle:@"已发布计划"];
  486. }else{
  487. [headerV setTextTitle:@"未发布计划"];
  488. }
  489. }else if (dataArray.count > 0){
  490. //未发布
  491. [headerV setTextTitle:@"未发布计划"];
  492. }else{
  493. //已发布
  494. [headerV setTextTitle:@"已发布计划"];
  495. }
  496. reusableview = headerV;
  497. }else{
  498. reusableview = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"UICollectionReusableView" forIndexPath:indexPath];
  499. }
  500. return reusableview;
  501. }
  502. -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  503. {
  504. if (dataArray.count > 0 && dataSendArray.count > 0) {
  505. return 2;
  506. }else{
  507. return 1;
  508. }
  509. }
  510. -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  511. {
  512. if (dataArray.count > 0 && dataSendArray.count > 0) {
  513. //这个有已发布的和未发布的
  514. if (section == 0) {
  515. return dataSendArray.count;
  516. }else{
  517. return dataArray.count;
  518. }
  519. }else if (dataArray.count > 0){
  520. //未发布
  521. return dataArray.count;
  522. }else{
  523. //已发布
  524. return dataSendArray.count;
  525. }
  526. }
  527. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  528. {
  529. PlanCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"PlanCollectionViewCell" forIndexPath:indexPath];
  530. [cell setNeedsDisplay];
  531. NSDictionary *dic;
  532. if (dataArray.count > 0 && dataSendArray.count > 0) {
  533. //这个有已发布的和未发布的
  534. if (indexPath.section == 0) {
  535. dic = dataSendArray[indexPath.row];
  536. }else{
  537. dic = dataArray[indexPath.row];
  538. }
  539. }else if (dataArray.count > 0){
  540. //未发布
  541. dic = dataArray[indexPath.row];
  542. }else{
  543. //已发布
  544. dic = dataSendArray[indexPath.row];
  545. }
  546. cell.timeLabel.text = dic[@"times"];
  547. if ([dic[@"km"] isEqualToString:@"2"]) {
  548. cell.kemuLabel.text = @"科目二";
  549. }else{
  550. cell.kemuLabel.text = @"科目三";
  551. }
  552. cell.countLabel.text = [NSString stringWithFormat:@"已约%@人 可约%@人",dic[@"havNum"],dic[@"num"]];
  553. return cell;
  554. }
  555. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  556. {
  557. //这个地方 对数组中某串信息进行修改
  558. [self initPlanInformationWithIndexPath:indexPath];
  559. }
  560. #pragma mark - 数据请求
  561. - (void)getPlanInfos
  562. {
  563. if (![Util connectedToNetWork]) {
  564. showMsgUnconnect();
  565. return;
  566. }
  567. NSMutableArray *arr=[NSMutableArray array];
  568. [arr addPro:@"taskTime" Value:dateString];
  569. [arr addPro:@"user" Value:defUser.sfzmhm];
  570. [arr addPro:@"isPage" Value:@""];
  571. [arr addPro:@"pageSize" Value:@""];
  572. [arr addPro:@"currentPage" Value:@""];
  573. [arr addPro:@"status" Value:@""];
  574. NSString* method = @"getPlanInfosForCoa";
  575. ShowHUD();
  576. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  577. RemoveHUD();
  578. //NSLog(@"我的计划-->%@---->%@",arr,root);
  579. //一旦发起 就要remove之前的数据
  580. [allData removeAllObjects];
  581. [dataArray removeAllObjects];
  582. [dataSendArray removeAllObjects];
  583. [holderV setHidden:NO];
  584. if (!root) {
  585. return ;
  586. }
  587. if ([root[@"code"] isEqualToString:@"1"]) {
  588. ShowMsg(root[@"body"]);
  589. return;
  590. }
  591. NSArray *array = root[@"body"];
  592. if (array.count < 1) {
  593. sendBtn.hidden = YES;
  594. return;
  595. }
  596. [allData addObjectsFromArray:root[@"body"]];
  597. for (NSDictionary *dic in array) {
  598. if ([dic[@"status"] isEqualToString:@"0"]) {
  599. //未发布
  600. [dataArray addObject:dic];
  601. }
  602. if ([dic[@"status"] isEqualToString:@"1"]) {
  603. //已发布
  604. [dataSendArray addObject:dic];
  605. }
  606. }
  607. if (dataArray.count < 1) {
  608. sendBtn.hidden = YES;
  609. }else{
  610. sendBtn.hidden = NO;
  611. }
  612. [holderV setHidden:YES];
  613. [mainCollection reloadData];
  614. }];
  615. }
  616. //获取价格
  617. -(void)getTrainPrice
  618. {
  619. NSMutableArray *arr=[NSMutableArray array];
  620. [arr addPro:@"schoolId" Value:defUser.userDict[@"jxbh"]];
  621. [arr addPro:@"dqbh" Value:defUser.userDict[@"cityId"]];
  622. NSString* method = @"getPrice";
  623. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * dict) {
  624. RemoveHUD();
  625. //NSLog(@"获取价格-->%@->%@",arr,dict);
  626. if (!dict) {
  627. return ;
  628. }
  629. if ( [dict[@"code"] isEqualToString:@"1"]) {
  630. return ;
  631. }
  632. moneyArray = dict[@"body"];
  633. }];
  634. }
  635. //更改发布状态
  636. -(void)updatePlanStatus:(NSString *)state
  637. {
  638. NSMutableArray *arr=[NSMutableArray array];
  639. [arr addPro:@"taskTime" Value:dateString];
  640. [arr addPro:@"status" Value:state];
  641. [arr addPro:@"coach" Value:defUser.sfzmhm];
  642. [arr addPro:@"dqbh" Value:defUser.userDict[@"cityId"]];
  643. NSString* method = @"updatePlanStatus";
  644. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * dict) {
  645. RemoveHUD();
  646. //NSLog(@"更改状态---->%@---->%@",arr,dict);
  647. if (!dict) {
  648. ShowMsgFailed();
  649. return ;
  650. }
  651. if ([dict[@"code"] isEqualToString:@"1"]) {
  652. [LoadingView showMsg:dict[@"body"]];
  653. return ;
  654. }
  655. ShowMsgSuc();
  656. [self getPlanInfos];
  657. }];
  658. }
  659. //修改计划
  660. - (void)updatePlanInfoNew
  661. {
  662. if (![Util connectedToNetWork]) {
  663. showMsgUnconnect();
  664. return;
  665. }
  666. // NSString *money = priceBtn.titleLabel.text;
  667. NSString *money = priceField.text;
  668. // if ([payAfterLearn isEqualToString:@"1"] && [money isEqualToString:@"0"]) {
  669. // ShowMsg(@"当前价格为0元,不能更改为先学后付计划");
  670. // return;
  671. // }
  672. NSMutableArray *arr=[NSMutableArray array];
  673. [arr addPro:@"id" Value:currentDic[@"id"]];
  674. [arr addPro:@"num" Value:numField.text];
  675. [arr addPro:@"tel" Value:payAfterLearn];
  676. [arr addPro:@"subject" Value:keMuString];
  677. [arr addPro:@"price" Value:money];
  678. NSString* method = @"updatePlanInfo";
  679. ShowHUD();
  680. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  681. RemoveHUD();
  682. //NSLog(@"修改计划---%@----->%@",arr,root);
  683. if (!root) {
  684. ShowMsgFailed();
  685. return ;
  686. }
  687. if ([root[@"code"] isEqualToString:@"1"]) {
  688. ShowMsg(root[@"body"]);
  689. return;
  690. }
  691. //修改完毕之后 要重新刷新
  692. [self getPlanInfos];
  693. }];
  694. }
  695. //删除计划
  696. - (void)deletePlanInfo
  697. {
  698. if (![Util connectedToNetWork]) {
  699. showMsgUnconnect();
  700. return;
  701. }
  702. NSMutableArray *arr=[NSMutableArray array];
  703. [arr addPro:@"id" Value:currentDic[@"id"]];
  704. NSString* method = @"deletePlanInfo";
  705. ShowHUD();
  706. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  707. RemoveHUD();
  708. //NSLog(@"删除计划---%@----->%@",arr,root);
  709. if (!root) {
  710. ShowMsgFailed();
  711. return ;
  712. }
  713. if ([root[@"code"] isEqualToString:@"1"]) {
  714. ShowMsg(root[@"body"]);
  715. return;
  716. }
  717. //删除完毕之后 要重新刷新
  718. [self getPlanInfos];
  719. }];
  720. }
  721. - (void)didReceiveMemoryWarning {
  722. [super didReceiveMemoryWarning];
  723. }
  724. @end