TrainPriceList.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. //
  2. // TrainPriceList.m
  3. // LN_School
  4. //
  5. // Created by EchoShacolee on 2017/4/19.
  6. // Copyright © 2017年 Danson. All rights reserved.
  7. //
  8. #import "TrainPriceList.h"
  9. #import "TrainPriceListCell.h"
  10. #import "TrainPriceDetail.h"
  11. #import "EditPriceVC.h"
  12. @interface TrainPriceList ()<UITableViewDelegate,UITableViewDataSource,UIActionSheetDelegate>
  13. {
  14. NSArray * _dataArr;
  15. UITableView * _tableView;
  16. UISegmentedControl * _seg;
  17. //用于记录选中的cell
  18. NSMutableArray *_selectedIndexPathes;
  19. HolderView * holderV;
  20. //记录搜索条件
  21. NSString *_charegeModeStr;
  22. NSString *_trainningtimeStr;
  23. NSString *_trainningmodeStr;
  24. NSString *_subjectStr;
  25. BOOL isPermission;
  26. BOOL haveRequestPermission;
  27. }
  28. @end
  29. @implementation TrainPriceList
  30. - (void)viewDidLoad {
  31. [super viewDidLoad];
  32. self.navigationItem.title = @"培训价格列表";
  33. self.view.backgroundColor = KBackGroundColor;
  34. _dataArr = [NSArray new];
  35. _selectedIndexPathes = [[NSMutableArray alloc] init];
  36. _charegeModeStr = @"";
  37. _trainningmodeStr = @"";
  38. _trainningtimeStr = @"";
  39. _subjectStr = @"";
  40. [Tools permissionValidationWithID:@"43" view:self.view result:^(BOOL isCan, NSString *failureStr) {
  41. isPermission = isCan;
  42. haveRequestPermission = YES;
  43. if (isCan) {
  44. [self createBottomBarWithtoolTitles:@[@"新增",@"删除"]];
  45. }
  46. [self myInit];
  47. [self getData];
  48. }];
  49. }
  50. -(void)viewWillAppear:(BOOL)animated{
  51. [super viewWillAppear:animated];
  52. if (haveRequestPermission) {
  53. [self getData];
  54. }
  55. }
  56. -(void)myInit{
  57. //
  58. [self goBackByNavigation];
  59. //
  60. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"全部价格" style:UIBarButtonItemStylePlain target:self action:@selector(rightBtn)];
  61. [self.navigationItem.rightBarButtonItem setTintColor:defGreen];
  62. //
  63. UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, 25)];
  64. [lab setText:@"设置搜索条件:" Font:Font14 TextColor:defGreen];
  65. [self.view addSubview:lab];
  66. _seg = [[UISegmentedControl alloc]initWithItems:@[@"收费模式",@"培训阶段",@"培训模式",@"培训部分"]];
  67. _seg.frame = CGRectMake(10, 25, kSize.width-20, 40);
  68. _seg.tintColor = defGreen;
  69. _seg.backgroundColor = [UIColor whiteColor];
  70. _seg.momentary = YES;
  71. [_seg addTarget:self action:@selector(segClick:) forControlEvents:UIControlEventValueChanged];
  72. [self.view addSubview:_seg];
  73. CGFloat height = isPermission ? JOb_DETAIL_BOTTOMBAR_HEIGHT : 0;
  74. _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_seg.frame), kSize.width, kSize.height-kNavOffSet-CGRectGetMaxY(_seg.frame)-height-SafeAreaBottomHeight) style:UITableViewStylePlain];
  75. _tableView.estimatedRowHeight = 100.0f;
  76. _tableView.tableFooterView = [UIView new];
  77. _tableView.dataSource = self;
  78. _tableView.delegate = self;
  79. [_tableView registerNib:[UINib nibWithNibName:@"TrainPriceListCell" bundle:nil] forCellReuseIdentifier:@"cellId"];
  80. [self.view addSubview:_tableView];
  81. holderV = [[HolderView alloc]initWithFrame:_tableView.frame];
  82. [holderV freshBlock:^{
  83. [self getData];
  84. }];
  85. [self.view addSubview:holderV];
  86. }
  87. -(void)rightBtn{
  88. _charegeModeStr = @"";
  89. _trainningmodeStr = @"";
  90. _trainningtimeStr = @"";
  91. _subjectStr = @"";
  92. [self getData];
  93. }
  94. -(void)segClick:(UISegmentedControl *)seg{
  95. switch (seg.selectedSegmentIndex) {
  96. case 0:
  97. {
  98. UIActionSheet * sheet = [[UIActionSheet alloc] initWithTitle:@"选择收费模式" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"全部",@"一次性收费",@"计时收费",@"分段式收费",@"其它", nil];
  99. sheet.tag = 1;
  100. [sheet showInView:self.view];
  101. }
  102. break;
  103. case 1:
  104. {
  105. UIActionSheet * sheet = [[UIActionSheet alloc] initWithTitle:@"选择培训阶段" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"全部",@"普通时段",@"高峰时段",@"节假日时段", nil];
  106. sheet.tag = 2;
  107. [sheet showInView:self.view];
  108. }
  109. break;
  110. case 2:
  111. {
  112. UIActionSheet * sheet = [[UIActionSheet alloc] initWithTitle:@"选择培训模式" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"全部",@"定时培训",@"预约培训",@"其它", nil];
  113. sheet.tag = 3;
  114. [sheet showInView:self.view];
  115. }
  116. break;
  117. case 3:
  118. {
  119. UIActionSheet * sheet = [[UIActionSheet alloc] initWithTitle:@"选择培训部分" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"全部",@"第一部份集中教学",@"第一部份网络教学",@"第四部份集中教学",@"第四部份网络教学",@"模拟器教学",@"第二部份普通教学",@"第二部份智能教学",@"第三部份普通教学",@"第三部份智能教学", nil];
  120. sheet.tag = 4;
  121. [sheet showInView:self.view];
  122. }
  123. break;
  124. default:
  125. break;
  126. }
  127. }
  128. #pragma mark 创建BottomBarButton
  129. -(void)createBottomBarWithtoolTitles:(NSArray *)toolTitles{
  130. float widthBtn = (kSize.width-1*toolTitles.count+1)/toolTitles.count;
  131. float HeightBth = JOb_DETAIL_BOTTOMBAR_HEIGHT;
  132. for (int i=0; i<toolTitles.count; i++) {
  133. UIButton * button = [UIButton buttonWithType:UIButtonTypeSystem];
  134. button.frame = CGRectMake(i*(widthBtn+1), kSize.height-HeightBth-kNavOffSet-SafeAreaBottomHeight, widthBtn, HeightBth);
  135. [button setTitle:toolTitles[i] forState:UIControlStateNormal];
  136. button.backgroundColor = defGreen;
  137. [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  138. [button addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  139. button.tag = 10+i;
  140. [self.view addSubview:button];
  141. }
  142. }
  143. -(void)btnClick:(UIButton *)sender{
  144. switch (sender.tag) {
  145. case 11:
  146. {
  147. //删除培训价格
  148. if ([sender.currentTitle isEqualToString:@"删除"]) {
  149. [_tableView setEditing:YES animated:YES];
  150. [sender setTitle:@"确定删除" forState:UIControlStateNormal];
  151. } else {
  152. [_tableView setEditing:NO animated:YES];
  153. [sender setTitle:@"删除" forState:UIControlStateNormal];
  154. UIButton * btn = [self.view viewWithTag:100];
  155. [btn removeFromSuperview];
  156. }
  157. if (_tableView.isEditing) {
  158. //清空原有的记录
  159. [_selectedIndexPathes removeAllObjects];
  160. //添加全选 取消删除
  161. float widthBtn = (kSize.width-1)/2-20;
  162. float HeightBth = JOb_DETAIL_BOTTOMBAR_HEIGHT-5;
  163. UIButton * button = [UIButton buttonWithType:UIButtonTypeSystem];
  164. button.frame = CGRectMake(10+widthBtn+20, kSize.height-kNavOffSet-JOb_DETAIL_BOTTOMBAR_HEIGHT*2-SafeAreaBottomHeight, widthBtn, HeightBth);
  165. [button setTitle:@"取消删除" forState:UIControlStateNormal];
  166. button.backgroundColor = [UIColor lightGrayColor];
  167. [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  168. [button addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  169. button.tag = 100;
  170. [self.view addSubview:button];
  171. //添加左侧item
  172. UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithTitle:@"全选" style:UIBarButtonItemStylePlain target:self action:@selector(selectAll:)];
  173. self.navigationItem.leftBarButtonItem = leftItem;
  174. self.navigationItem.leftBarButtonItem.tintColor = [UIColor redColor];
  175. } else {
  176. //删除数据源中的数据
  177. [self delPrice];
  178. [self goBackByNavigation];
  179. }
  180. }
  181. break;
  182. case 10:
  183. {
  184. [self willEditPrice];//新增培训价格
  185. }
  186. break;
  187. case 100:
  188. {
  189. [_tableView setEditing:NO animated:YES];
  190. [_selectedIndexPathes removeAllObjects];
  191. [sender removeFromSuperview];
  192. [self goBackByNavigation];
  193. UIButton * btn = [self.view viewWithTag:11];
  194. [btn setTitle:@"删除" forState:UIControlStateNormal];
  195. }
  196. break;
  197. default:
  198. break;
  199. }
  200. }
  201. -(void)willEditPrice{
  202. EditPriceVC * vc = [[EditPriceVC alloc]init];
  203. vc.type = @"1";
  204. [self navPushHideTabbarToVC:vc];
  205. }
  206. #pragma mark action代理方法
  207. - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
  208. switch (actionSheet.tag) {
  209. case 1:
  210. {
  211. //0,123,9
  212. if (buttonIndex > 4) {
  213. break;
  214. }
  215. if (buttonIndex == 4) {
  216. buttonIndex = 9;
  217. }
  218. _charegeModeStr = [NSString stringWithFormat:@"%ld",buttonIndex];
  219. if (buttonIndex == 0) {
  220. _charegeModeStr = @"";
  221. }
  222. [self getData];
  223. }
  224. break;
  225. case 2:
  226. {
  227. if (buttonIndex > 3) {
  228. break;
  229. }
  230. //0,1,2,3
  231. _trainningtimeStr = [NSString stringWithFormat:@"%ld",buttonIndex];
  232. if (buttonIndex == 0) {
  233. _trainningtimeStr = @"";
  234. }
  235. [self getData];
  236. }
  237. break;
  238. case 3:
  239. {
  240. //0,1,2,9
  241. if (buttonIndex > 3) {
  242. break;
  243. }
  244. if (buttonIndex == 3) {
  245. buttonIndex = 9;
  246. }
  247. _trainningmodeStr = [NSString stringWithFormat:@"%ld",buttonIndex];
  248. if (buttonIndex == 0) {
  249. _trainningmodeStr = @"";
  250. }
  251. [self getData];
  252. }
  253. break;
  254. case 4:
  255. {
  256. //0,1-9
  257. if (buttonIndex > 9) {
  258. break;
  259. }
  260. _subjectStr = [NSString stringWithFormat:@"%ld",buttonIndex];
  261. if (buttonIndex == 0) {
  262. _subjectStr = @"";
  263. }
  264. [self getData];
  265. }
  266. break;
  267. default:
  268. break;
  269. }
  270. }
  271. #pragma mark tableview代理方法
  272. - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
  273. return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;
  274. }
  275. - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
  276. //当取消选中cell时,从记录的数组中删除其indexPath
  277. [_selectedIndexPathes removeObject:indexPath];
  278. self.navigationItem.leftBarButtonItem.title = @"全选";
  279. }
  280. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  281. return _dataArr.count;
  282. }
  283. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  284. TrainPriceListCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellId" forIndexPath:indexPath];
  285. [cell upDataWithDic:_dataArr[indexPath.row]];
  286. return cell;
  287. }
  288. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  289. if (_tableView.editing) {
  290. //当选中cell时,记录其indexPath
  291. [_selectedIndexPathes addObject:indexPath];
  292. return;
  293. }
  294. TrainPriceDetail * vc = [[TrainPriceDetail alloc]init];
  295. vc.isPermission = isPermission;
  296. vc.theId = _dataArr[indexPath.row][@"CSI_ID"];
  297. [self navPushHideTabbarToVC:vc];
  298. }
  299. //-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  300. // return 0.1f;
  301. //}
  302. - (void)didReceiveMemoryWarning {
  303. [super didReceiveMemoryWarning];
  304. // Dispose of any resources that can be recreated.
  305. }
  306. #pragma mark 删除全选择
  307. - (void)selectAll:(UIBarButtonItem *)item {
  308. //获取表格视图内容的尺寸
  309. CGSize size = _tableView.contentSize;
  310. CGRect rect = CGRectMake(0, 0, size.width, size.height);
  311. //获取指定区域的cell的indexPath
  312. NSArray *indexPathes = [_tableView indexPathsForRowsInRect:rect];
  313. if ([item.title isEqualToString:@"全选"]) {
  314. item.title = @"取消";
  315. for (NSIndexPath *indexPath in indexPathes) {
  316. //使用代码方式选中一行
  317. [_tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
  318. }
  319. //更新选中数组
  320. _selectedIndexPathes.array = indexPathes;
  321. } else {
  322. item.title = @"全选";
  323. for (NSIndexPath *indexPath in indexPathes) {
  324. //使用代码方式取消选中一行
  325. [_tableView deselectRowAtIndexPath:indexPath animated:YES];
  326. }
  327. //清空选中cell的记录数组
  328. [_selectedIndexPathes removeAllObjects];
  329. }
  330. }
  331. #pragma mark 数据请求
  332. -(void)getData{
  333. if (![NetManager connectedToNetWork]) {
  334. showMsgUnconnect();
  335. return;
  336. }
  337. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  338. [dic setObject:defUser.userDict[@"id"] forKey:@"userId"];
  339. [dic setObject:defUser.userDict[@"school"] forKey:@"schoolId"];
  340. [dic setObject:defUser.userDict[@"dqbh"] forKey:@"dqbh"];
  341. [dic setObject:defUser.userDict[@"qxbh"] forKey:@"qxbh"];
  342. [dic setObject:_charegeModeStr forKey:@"chargemode"];
  343. [dic setObject:_trainningtimeStr forKey:@"trainningtime"];
  344. [dic setObject:_trainningmodeStr forKey:@"trainningmode"];
  345. [dic setObject:_subjectStr forKey:@"subject"];
  346. NSString *method = @"prices";
  347. [MBProgressHUD showLoadToView:self.view];
  348. [NetManager requestAnythingWithURL:method dictionary:dic dataArray:nil completion:^(NSDictionary *root) {
  349. [MBProgressHUD hideHUDForView:self.view];
  350. holderV.hidden = NO;
  351. if (!root) {
  352. ShowErrorMsg(@"请求失败!");
  353. return;
  354. }
  355. if ([root[@"code"] isEqualToString:@"1"]) {
  356. ShowErrorMsg(root[@"msg"]);
  357. return;
  358. }
  359. _dataArr = root[@"body"];
  360. if (_dataArr.count > 0) {
  361. holderV.hidden = YES;
  362. }
  363. [_tableView reloadData];
  364. }];
  365. }
  366. -(void)delPrice{
  367. if (_selectedIndexPathes.count == 0) {
  368. return;
  369. }
  370. NSMutableString *mStr = [NSMutableString new];
  371. for (int i=0; i<_selectedIndexPathes.count; i++) {
  372. NSIndexPath * indexPath = _selectedIndexPathes[i];
  373. [mStr appendFormat:@",%@",_dataArr[indexPath.row][@"CSI_ID"]];
  374. }
  375. NSString * idsStr = [mStr substringFromIndex:1];
  376. if (![NetManager connectedToNetWork]) {
  377. showMsgUnconnect();
  378. return;
  379. }
  380. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  381. [dic setObject:idsStr forKey:@"ids"];
  382. [dic setObject:defUser.userDict[@"id"] forKey:@"userId"];
  383. [MBProgressHUD showLoadToView:self.view];
  384. [NetManager requestAnythingWithURL:@"delPrice" dictionary:dic dataArray:nil completion:^(NSDictionary *root) {
  385. [MBProgressHUD hideHUDForView:self.view];
  386. if (!root) {
  387. ShowErrorMsg(@"请求失败!");
  388. return;
  389. }
  390. if ([root[@"code"] isEqualToString:@"1"]) {
  391. ShowErrorMsg(root[@"msg"]);
  392. return;
  393. }
  394. ShowMsg(@"删除成功!");
  395. [self getData];
  396. }];
  397. }
  398. /*
  399. #pragma mark - Navigation
  400. // In a storyboard-based application, you will often want to do a little preparation before navigation
  401. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  402. // Get the new view controller using [segue destinationViewController].
  403. // Pass the selected object to the new view controller.
  404. }
  405. */
  406. @end