// // MyOrderVC.m // jiaPei // // Created by apple on 16/5/27. // Copyright © 2016年 JCZ. All rights reserved. // #import "MyOrderVC.h" #import "STSegView.h" #import "HolderView.h" #import "DateView.h" #import "OrderCell.h" #import "APViewController.h" @interface MyOrderVC () { STSegView *seg; UIScrollView *scroll; UITableView *mainTableView; UIBarButtonItem *item; UIView *backView; UIButton *beginBtn; UIButton *endBtn; HolderView *holder; NSMutableArray *dataArray; NSString *beginDate; NSString *endDate; NSInteger currentPage; NSString *orderState; } @end @implementation MyOrderVC - (void)viewDidLoad { [super viewDidLoad]; //测试微信支付 可以直接从这里进入 // APViewController *ap = [[APViewController alloc] init]; // ap.orderDic = _dataDic; // [self.navigationController pushViewController:ap animated:YES]; [self myInit]; } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; currentPage = 1; [self getMyOrderInfo]; } -(void)myInit { [self.view setBackgroundColor:[UIColor whiteColor]]; [self setTitle:@"查看我的订单"]; [self configNavigationBar]; currentPage = 1; orderState = @"0"; beginDate = @""; endDate = @""; dataArray = [NSMutableArray array]; item = [[UIBarButtonItem alloc] initWithTitle:@"查找" style:UIBarButtonItemStyleDone target:self action:@selector(clickToSearch)]; [item setTintColor:defGreen]; [self.navigationItem setRightBarButtonItem:item]; CGFloat x,y,w,h; x = y = 0; w = kSize.width; h = 50; seg = [[STSegView alloc] initWithFrame:CGRectMake(x, y, w, h)]; [seg setTitles:@[@"计时中",@"待支付",@"待评价",@"已完成",@"已投诉"]]; seg.selectedIndex = 0; [self.view addSubview:seg]; y += h; h = kSize.height - y - kNavOffSet; mainTableView = [[UITableView alloc] initWithFrame:CGRectMake(x, y, w, h) style:UITableViewStyleGrouped]; mainTableView.delegate = self; mainTableView.dataSource = self; mainTableView.rowHeight = 174; [self.view addSubview:mainTableView]; [seg click:^(NSString* sInd) { currentPage = 1; orderState = sInd; beginDate = @""; endDate = @""; [self getMyOrderInfo]; }]; holder = [[HolderView alloc] initWithFrame:mainTableView.frame]; [holder freshBlock:^{ currentPage = 1; [self getMyOrderInfo]; }]; [self.view addSubview:holder]; } -(void)clickToSearch { item.enabled = NO; backView = [[UIView alloc] initWithFrame:kFrame]; backView.backgroundColor = [UIColor colorWithWhite:.1 alpha:.5]; [self.view addSubview:backView]; CGFloat x, y, w, h, bd; x = 20; y = (kSize.height - 250 - kNavOffSet)/2.0; w = kSize.width - 40; h = 250; UIView *searchView = [[UIView alloc] setxywh]; searchView.backgroundColor = backGroundColor; searchView.layer.masksToBounds = YES; searchView.layer.cornerRadius = 5; [backView addSubview:searchView]; x = y = bd = 15; w = searchView.width - 30; h = 50; NSArray *imgArray = @[@"beginDate",@"endDate"]; NSString *beginDateStr = @"订单开始日期"; NSString *endDateStr = @"订单结束日期"; if (beginDate.length > 0) { beginDateStr = beginDate; } if (endDate.length > 0) { endDateStr = endDate; } NSArray *titles = @[beginDateStr,endDateStr]; NSMutableArray *btns = [NSMutableArray arrayWithCapacity:3]; for (int i = 0; i < 2; i ++) { UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(x + bd, 2*y + i*(h + bd), 20, 20)]; imageView.image = [[UIImage imageNamed:imgArray[i]] tint:defGreen]; [searchView addSubview:imageView]; UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(x, y + i*(h + bd) , w, h)]; [button setTitle:titles[i] textColor:contentTextColor font:16 fotState:UIControlStateNormal]; button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; button.titleEdgeInsets = UIEdgeInsetsMake(0, 3*bd, 0, 0); [button borderColor:KlineColor width:2 cornorRadios:5]; [button target:self tag:i]; [searchView addSubview:button]; [btns addObject:button]; } beginBtn = btns[0]; endBtn = btns[1]; y += 2*(h + bd); w = (w - 2*bd)/2.0; NSArray *titleArrays = @[@"取消",@"查询"]; for (int i = 0; i < 2; i ++) { UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(x + i*(w + 2*bd), y , w, h)]; [button setTitle:titleArrays[i] textColor:defGreen font:16 fotState:UIControlStateNormal]; [button borderColor:KlineColor width:2 cornorRadios:5]; [button target:self tag:i + 2]; [searchView addSubview:button]; } } -(void)btnClick:(UIButton *)sender { switch (sender.tag) { case 0: { DateView *dateV = [[DateView alloc] init]; [dateV setStyle:0]; [dateV showWithComplete:^(NSString * result) { beginDate = result; [beginBtn setTitle:beginDate forState:UIControlStateNormal]; }]; } break; case 1: { DateView *dateV = [[DateView alloc] init]; [dateV setStyle:0]; [dateV showWithComplete:^(NSString * result) { endDate = result; [endBtn setTitle:endDate forState:UIControlStateNormal]; }]; } break; case 2: { if (backView) { [backView removeFromSuperview]; } item.enabled = YES; } break; case 3: { if (backView) { [backView removeFromSuperview]; } item.enabled = YES; //如果是重新选择时间 需要将currentPage重置为1 currentPage = 1; [self getMyOrderInfo]; } break; default: break; } } #pragma mark tableView -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return dataArray.count; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 1; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { OrderCell *cell = [OrderCell cellForTabelView:tableView]; [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; cell.type = orderState; [cell setDataDic:dataArray[indexPath.section]]; cell.skipVC = self; return cell; } -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 15)]; view.backgroundColor = KlineColor; return view; } -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 15; } -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { UIView *view = [UIView new]; return view; } -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return .1; } -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { CGPoint off = scrollView.contentOffset; if (scrollView.contentSize.height - off.y - scrollView.frame.size.height < 1) { [scrollView setContentOffset:CGPointMake(off.x, off.y - 10) animated:YES]; // NSLog(@"AT bottom"); [self getMyOrderInfo]; } } #pragma mark 数据请求 -(void)getMyOrderInfo { if (![Util connectedToNetWork]) { return; } NSMutableArray *arr=[NSMutableArray array]; [arr addPro:@"dqbh" Value:defUser.userDict[@"city"]]; [arr addPro:@"cx" Value:defUser.userDict[@"carType"]]; [arr addPro:@"type" Value:@"1"];// 1 学员端 2 教练端 [arr addPro:@"zjhm" Value:defUser.userDict[@"loginCode"]]; [arr addPro:@"startTime" Value:beginDate]; [arr addPro:@"endTime" Value:endDate]; [arr addPro:@"status" Value:orderState]; [arr addPro:@"isPage" Value:@"1"]; [arr addPro:@"pageSize" Value:@"15"]; [arr addPro:@"currentPage" Value:[NSString stringWithFormat:@"%d",(int)currentPage]]; NSString* method = @"getMyReserveOrders"; [MBProgressHUD showLoadToView:self.view]; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) { [MBProgressHUD hideHUDForView:self.view]; if (currentPage == 1) { holder.hidden = NO; [dataArray removeAllObjects]; } if (!root) { ShowMsgFailed(); return; } if ([root[@"code"] isEqualToString:@"1"]) { ShowMsg(root[@"body"]); return; } NSArray *array = root[@"body"]; if ([array count] < 1) { ShowMsg(@"已加载全部"); [mainTableView reloadData]; return; } [dataArray addObjectsFromArray:array]; currentPage += 1; holder.hidden = YES; [mainTableView reloadData]; }]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } @end