// // TrainPriceList.m // LN_School // // Created by EchoShacolee on 2017/4/19. // Copyright © 2017年 Danson. All rights reserved. // #import "TrainPriceList.h" #import "TrainPriceListCell.h" #import "TrainPriceDetail.h" #import "EditPriceVC.h" @interface TrainPriceList () { NSArray * _dataArr; UITableView * _tableView; UISegmentedControl * _seg; //用于记录选中的cell NSMutableArray *_selectedIndexPathes; HolderView * holderV; //记录搜索条件 NSString *_charegeModeStr; NSString *_trainningtimeStr; NSString *_trainningmodeStr; NSString *_subjectStr; } @end @implementation TrainPriceList - (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.title = @"培训价格列表"; self.view.backgroundColor = KBackGroundColor; _dataArr = [NSArray new]; _selectedIndexPathes = [[NSMutableArray alloc] init]; _charegeModeStr = @""; _trainningmodeStr = @""; _trainningtimeStr = @""; _subjectStr = @""; [self myInit]; [self createBottomBarWithtoolTitles:@[@"新增",@"删除"]]; } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self getData]; } -(void)myInit{ // [self goBackByNavigation]; // self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"全部价格" style:UIBarButtonItemStylePlain target:self action:@selector(rightBtn)]; [self.navigationItem.rightBarButtonItem setTintColor:RQMianColor]; // UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, 25)]; [lab setText:@"设置搜索条件:" Font:Font14 TextColor:RQMianColor]; [self.view addSubview:lab]; _seg = [[UISegmentedControl alloc]initWithItems:@[@"收费模式",@"培训阶段",@"培训模式",@"培训部分"]]; _seg.frame = CGRectMake(10, 25, kSize.width-20, 40); _seg.tintColor = RQMianColor; _seg.backgroundColor = [UIColor whiteColor]; _seg.momentary = YES; [_seg addTarget:self action:@selector(segClick:) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:_seg]; _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_seg.frame), kSize.width, kSize.height-kNavOffSet-CGRectGetMaxY(_seg.frame)-JOb_DETAIL_BOTTOMBAR_HEIGHT-kSafeAreaBottomHeight) style:UITableViewStylePlain]; _tableView.estimatedRowHeight = 100.0f; _tableView.tableFooterView = [UIView new]; _tableView.dataSource = self; _tableView.delegate = self; [_tableView registerNib:[UINib nibWithNibName:@"TrainPriceListCell" bundle:nil] forCellReuseIdentifier:@"cellId"]; [self.view addSubview:_tableView]; holderV = [[HolderView alloc]initWithFrame:_tableView.frame]; [holderV freshBlock:^{ [self getData]; }]; [self.view addSubview:holderV]; } -(void)rightBtn{ _charegeModeStr = @""; _trainningmodeStr = @""; _trainningtimeStr = @""; _subjectStr = @""; [self getData]; } -(void)segClick:(UISegmentedControl *)seg{ switch (seg.selectedSegmentIndex) { case 0: { UIActionSheet * sheet = [[UIActionSheet alloc] initWithTitle:@"选择收费模式" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"全部",@"一次性收费",@"计时收费",@"分段式收费",@"其它", nil]; sheet.tag = 1; [sheet showInView:self.view]; } break; case 1: { UIActionSheet * sheet = [[UIActionSheet alloc] initWithTitle:@"选择培训阶段" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"全部",@"普通时段",@"高峰时段",@"节假日时段", nil]; sheet.tag = 2; [sheet showInView:self.view]; } break; case 2: { UIActionSheet * sheet = [[UIActionSheet alloc] initWithTitle:@"选择培训模式" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"全部",@"定时培训",@"预约培训",@"其它", nil]; sheet.tag = 3; [sheet showInView:self.view]; } break; case 3: { UIActionSheet * sheet = [[UIActionSheet alloc] initWithTitle:@"选择培训部分" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"全部",@"第一部份集中教学",@"第一部份网络教学",@"第四部份集中教学",@"第四部份网络教学",@"模拟器教学",@"第二部份普通教学",@"第二部份智能教学",@"第三部份普通教学",@"第三部份智能教学", nil]; sheet.tag = 4; [sheet showInView:self.view]; } break; default: break; } } #pragma mark 创建BottomBarButton -(void)createBottomBarWithtoolTitles:(NSArray *)toolTitles{ float widthBtn = (kSize.width-1*toolTitles.count+1)/toolTitles.count; float HeightBth = JOb_DETAIL_BOTTOMBAR_HEIGHT; for (int i=0; i 4) { break; } if (buttonIndex == 4) { buttonIndex = 9; } _charegeModeStr = [NSString stringWithFormat:@"%ld",(long)buttonIndex]; if (buttonIndex == 0) { _charegeModeStr = @""; } [self getData]; } break; case 2: { if (buttonIndex > 3) { break; } //0,1,2,3 _trainningtimeStr = [NSString stringWithFormat:@"%ld",(long)buttonIndex]; if (buttonIndex == 0) { _trainningtimeStr = @""; } [self getData]; } break; case 3: { //0,1,2,9 if (buttonIndex > 3) { break; } if (buttonIndex == 3) { buttonIndex = 9; } _trainningmodeStr = [NSString stringWithFormat:@"%ld",(long)buttonIndex]; if (buttonIndex == 0) { _trainningmodeStr = @""; } [self getData]; } break; case 4: { //0,1-9 if (buttonIndex > 9) { break; } _subjectStr = [NSString stringWithFormat:@"%ld",(long)buttonIndex]; if (buttonIndex == 0) { _subjectStr = @""; } [self getData]; } break; default: break; } } #pragma mark tableview代理方法 - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert; } - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath { //当取消选中cell时,从记录的数组中删除其indexPath [_selectedIndexPathes removeObject:indexPath]; self.navigationItem.leftBarButtonItem.title = @"全选"; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return _dataArr.count; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ TrainPriceListCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellId" forIndexPath:indexPath]; [cell upDataWithDic:_dataArr[indexPath.row]]; return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ if (_tableView.editing) { //当选中cell时,记录其indexPath [_selectedIndexPathes addObject:indexPath]; return; } TrainPriceDetail * vc = [[TrainPriceDetail alloc]init]; vc.theId = _dataArr[indexPath.row][@"CSI_ID"]; [self navPushHideTabbarToVC:vc]; } //-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ // return 0.1f; //} - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark 删除全选择 - (void)selectAll:(UIBarButtonItem *)item { //获取表格视图内容的尺寸 CGSize size = _tableView.contentSize; CGRect rect = CGRectMake(0, 0, size.width, size.height); //获取指定区域的cell的indexPath NSArray *indexPathes = [_tableView indexPathsForRowsInRect:rect]; if ([item.title isEqualToString:@"全选"]) { item.title = @"取消"; for (NSIndexPath *indexPath in indexPathes) { //使用代码方式选中一行 [_tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; } //更新选中数组 _selectedIndexPathes.array = indexPathes; } else { item.title = @"全选"; for (NSIndexPath *indexPath in indexPathes) { //使用代码方式取消选中一行 [_tableView deselectRowAtIndexPath:indexPath animated:YES]; } //清空选中cell的记录数组 [_selectedIndexPathes removeAllObjects]; } } #pragma mark 数据请求 -(void)getData{ if (![NetManager connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableDictionary *dic = [NSMutableDictionary dictionary]; [dic setObject:defUser.userDict[@"id"] forKey:@"userId"]; [dic setObject:defUser.userDict[@"school"] forKey:@"schoolId"]; [dic setObject:defUser.userDict[@"dqbh"] forKey:@"dqbh"]; [dic setObject:defUser.userDict[@"qxbh"] forKey:@"qxbh"]; [dic setObject:_charegeModeStr forKey:@"chargemode"]; [dic setObject:_trainningtimeStr forKey:@"trainningtime"]; [dic setObject:_trainningmodeStr forKey:@"trainningmode"]; [dic setObject:_subjectStr forKey:@"subject"]; NSString *method = @"prices"; [NetManager requestAnythingWithURL:method dictionary:dic dataArray:nil completion:^(NSDictionary *root) { holderV.hidden = NO; if (!root) { ShowErrorMsg(@"请求失败!"); return; } if ([root[@"code"] isEqualToString:@"1"]) { ShowErrorMsg(root[@"msg"]); return; } _dataArr = root[@"body"]; if (_dataArr.count > 0) { holderV.hidden = YES; } [_tableView reloadData]; }]; } -(void)delPrice{ if (_selectedIndexPathes.count == 0) { return; } NSMutableString *mStr = [NSMutableString new]; for (int i=0; i<_selectedIndexPathes.count; i++) { NSIndexPath * indexPath = _selectedIndexPathes[i]; [mStr appendFormat:@",%@",_dataArr[indexPath.row][@"CSI_ID"]]; } NSString * idsStr = [mStr substringFromIndex:1]; if (![NetManager connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableDictionary *dic = [NSMutableDictionary dictionary]; [dic setObject:idsStr forKey:@"ids"]; [dic setObject:defUser.userDict[@"id"] forKey:@"userId"]; [NetManager requestAnythingWithURL:@"delPrice" dictionary:dic dataArray:nil completion:^(NSDictionary *root) { if (!root) { ShowErrorMsg(@"请求失败!"); return; } if ([root[@"code"] isEqualToString:@"1"]) { ShowErrorMsg(root[@"msg"]); return; } ShowMsg(@"删除成功!"); [self getData]; }]; } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end