123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476 |
- //
- // 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 ()<UITableViewDelegate,UITableViewDataSource,UIActionSheetDelegate>
- {
- 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<toolTitles.count; i++) {
- UIButton * button = [UIButton buttonWithType:UIButtonTypeSystem];
- button.frame = CGRectMake(i*(widthBtn+1), kSize.height-HeightBth-kNavOffSet-kSafeAreaBottomHeight, widthBtn, HeightBth);
- [button setTitle:toolTitles[i] forState:UIControlStateNormal];
- button.backgroundColor = RQMianColor;
- [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- [button addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
- button.tag = 10+i;
-
- [self.view addSubview:button];
- }
- }
- -(void)btnClick:(UIButton *)sender{
-
- switch (sender.tag) {
- case 11:
- {
- //删除培训价格
-
- if ([sender.currentTitle isEqualToString:@"删除"]) {
- [_tableView setEditing:YES animated:YES];
- [sender setTitle:@"确定删除" forState:UIControlStateNormal];
- } else {
- [_tableView setEditing:NO animated:YES];
- [sender setTitle:@"删除" forState:UIControlStateNormal];
- UIButton * btn = [self.view viewWithTag:100];
- [btn removeFromSuperview];
- }
- if (_tableView.isEditing) {
- //清空原有的记录
- [_selectedIndexPathes removeAllObjects];
- //添加全选 取消删除
- float widthBtn = (kSize.width-1)/2-20;
- float HeightBth = JOb_DETAIL_BOTTOMBAR_HEIGHT-5;
- UIButton * button = [UIButton buttonWithType:UIButtonTypeSystem];
- button.frame = CGRectMake(10+widthBtn+20, kSize.height-kNavOffSet-JOb_DETAIL_BOTTOMBAR_HEIGHT*2-kSafeAreaBottomHeight, widthBtn, HeightBth);
- [button setTitle:@"取消删除" forState:UIControlStateNormal];
- button.backgroundColor = [UIColor lightGrayColor];
- [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- [button addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
- button.tag = 100;
-
- [self.view addSubview:button];
-
- //添加左侧item
- UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithTitle:@"全选" style:UIBarButtonItemStylePlain target:self action:@selector(selectAll:)];
- self.navigationItem.leftBarButtonItem = leftItem;
- self.navigationItem.leftBarButtonItem.tintColor = [UIColor redColor];
-
- } else {
- //删除数据源中的数据
- [self delPrice];
- [self goBackByNavigation];
- }
-
- }
- break;
- case 10:
- {
- [self willEditPrice];//新增培训价格
- }
- break;
- case 100:
- {
- [_tableView setEditing:NO animated:YES];
- [_selectedIndexPathes removeAllObjects];
- [sender removeFromSuperview];
- [self goBackByNavigation];
- UIButton * btn = [self.view viewWithTag:11];
- [btn setTitle:@"删除" forState:UIControlStateNormal];
- }
- break;
-
- default:
- break;
- }
- }
- -(void)willEditPrice{
- EditPriceVC * vc = [[EditPriceVC alloc]init];
- vc.type = @"1";
- [self navPushHideTabbarToVC:vc];
- }
- #pragma mark action代理方法
- - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
-
- switch (actionSheet.tag) {
- case 1:
- {
- //0,123,9
- if (buttonIndex > 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
|