// // PurchaseintentionViewController.m // jitao // // Created by 罗云飞 on 2017/12/9. // Copyright © 2017年 罗云飞. All rights reserved. // #import "PurchaseintentionViewController.h" #import "PurchaseintentionCell.h" #import "PurchaseintentionModel.h" #import "OrderdetailViewController.h" @interface PurchaseintentionViewController (){ UITableView *newtableView; NSMutableArray *dataArray; int pageIndex; int pageSize; int pageNumber; UIView *showView; } @end @implementation PurchaseintentionViewController - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; if (newtableView) { [self autoRefresh]; } } - (void)viewDidLoad { [super viewDidLoad]; [self dataInitialization]; [self loadsView]; [self addRefreshing]; // Do any additional setup after loading the view. } #pragma mark- 网络请求 - (void)autoRefresh { __weak UITableView *tableView = newtableView; [tableView.mj_header beginRefreshing]; } - (void)networkRequest:(id)object { int pageNumberIndex=1; if (!object) { [MBProgressHUD showLoadToView:self.view title:@"请稍后..."]; }else if ([object isKindOfClass:[MJRefreshNormalHeader class]]) { pageNumberIndex = 1; }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]) { pageNumberIndex = pageNumber+1; } NSMutableDictionary *parameters = NewMutableDictionaryInit; [parameters safeSetObject:@(pageSize) forKey:@"pageSize"]; [parameters safeSetObject:@(pageNumberIndex) forKey:@"pageNo"]; [parameters safeSetObject:@"false" forKey:@"confirm"]; [NetworkRequestManager requestPostWithInterfacePrefix:JT_orderList parameters:parameters onSuccess:^(id requestData) { [self dismiss:object]; if ([requestData[@"error"] count] !=0) { for (NSDictionary *dic in requestData[@"error"]) { [MBProgressHUD showError:dic[@"message"] toView:self.view]; } }else{ pageNumber = pageNumberIndex; if ([object isKindOfClass:[MJRefreshNormalHeader class]] || pageNumber==1) { [dataArray removeAllObjects]; }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]) { NSMutableArray *arr = requestData[@"data"][@"list"]; if ([arr count]<=0) { [self.view makeToast:NewConnectServerNoMoreDataTitle duration:1.0 position:CSToastPositionBottom]; return; } } for (NSDictionary *dic in requestData[@"data"][@"list"]) { PurchaseintentionModel *model = [[PurchaseintentionModel alloc] initWithDictionary:dic error:nil]; [dataArray addObject:model]; } //查询不到类型底图 if (dataArray.count<=0) { [self addErrorLoadingFrame:CGRectMake(0, 44, newtableView.width, newtableView.height) title:@"咦,您还没有意向订单噢" buttonTitle:nil imageString:NewNoDataErrorImage]; }else { [self hideReloadingview]; [newtableView reloadData]; } } } onFailure:^{ [self dismiss:object]; }]; } #pragma mark - 数据初始化 - (void)dataInitialization{ dataArray = NewMutableArrayInit; pageIndex = 1; pageSize = 10; pageNumber = 1; } #pragma mark ----加载界面 - (void)loadsView{ [self.view addSubview:newtableView = [NewControlPackage tableViewInitWithFrame:CGRectMake(0, 44, SCREEN_WIDTH, SCREEN_HEIGHT-(NavHeader+44)) backgroundColor:NewGroupTableViewBackgroundColor style:1 delegate:self dataSource:self showsHorizontalScrollIndicator:NO showsVerticalScrollIndicator:NO hidden:NO tag:100 userInteractionEnabled:YES]]; newtableView.separatorStyle = NO; } #pragma mark-------------------------UITableView------------------------------------ -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } //返回每段行数 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return dataArray.count; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *Cell = @"Cell"; PurchaseintentionCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell]; if (cell == nil) { cell = [[PurchaseintentionCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell]; } [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果) cell.accessoryType = UITableViewCellAccessoryNone; if (dataArray.count>0) { PurchaseintentionModel *model = dataArray[indexPath.row]; [cell assignment:dataArray[indexPath.row] commoditysModel:model.commoditys]; cell.delegate = self; } return cell; } #pragma mark ------操作按钮网络请求----- - (void)transButIndex:(UIButton*)button{ NSString *str = [NSString stringWithFormat:@"是否%@?",button.titleLabel.text]; UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:str preferredStyle:(UIAlertControllerStyleAlert)]; UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction *action) { [self faafa:button]; }]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:^(UIAlertAction *action) { //NSLog(@"取消"); }]; [alertController addAction:okAction]; [alertController addAction:cancelAction]; [self presentViewController:alertController animated:YES completion:nil]; } - (void)faafa:(UIButton *)button{ [MBProgressHUD showLoadToView:self.view title:@"请稍后..."]; PurchaseintentionCell *cell = (PurchaseintentionCell *)button.superview.superview; NSIndexPath *indexPath = [newtableView indexPathForCell:cell]; PurchaseintentionModel *model = dataArray[indexPath.row]; /* 拒绝意向 和 确认意向 调取 /api/user/order/confirmIntention */ NSMutableDictionary *dic = NewMutableDictionaryInit; NSString *url; if ([button.titleLabel.text isEqualToString:@"取消订单"]) { [dic safeSetObject:model.orderNo forKey:@"orderNo"]; url = JT_applyForCancel;//取消订单 }else if ([button.titleLabel.text isEqualToString:@"支付首付"]){ [dic safeSetObject:model.orderNo forKey:@"orderNo"]; [dic safeSetObject:model.orderAmount forKey:@"fundAmount"]; [dic safeSetObject:@"" forKey:@"remarks"]; url = JT_payForFirst;//支付首付 OrderdetailViewController *vc = [[OrderdetailViewController alloc] init]; NewPushViewController(vc); return; }else if ([button.titleLabel.text isEqualToString:@"支付尾款"]){ [dic safeSetObject:model.orderNo forKey:@"orderNo"]; [dic safeSetObject:model.orderAmount forKey:@"fundAmount"]; [dic safeSetObject:@"" forKey:@"remarks"]; url = JT_payForLast;//支付尾款 OrderdetailViewController *vc = [[OrderdetailViewController alloc] init]; NewPushViewController(vc); return; }else if ([button.titleLabel.text isEqualToString:@"拒绝意向"]||[button.titleLabel.text isEqualToString:@"确认意向"]){ [dic safeSetObject:model.orderNo forKey:@"orderNo"]; if ([button.titleLabel.text isEqualToString:@"拒绝意向"]) { [dic safeSetObject:@"false" forKey:@"confirm"]; }else{ [dic safeSetObject:@"true" forKey:@"confirm"]; } url = JT_confirmIntention; }else if ([button.titleLabel.text isEqualToString:@"提现"]){ [dic safeSetObject:model.orderNo forKey:@"orderNo"]; url = JT_applyForWithdraw; OrderdetailViewController *vc = [[OrderdetailViewController alloc] init]; NewPushViewController(vc); return; }else if ([button.titleLabel.text isEqualToString:@"申请退款"]){ [dic safeSetObject:model.orderNo forKey:@"orderNo"]; url = JT_applyForRefund; }else if ([button.titleLabel.text isEqualToString:@"同意退款"]||[button.titleLabel.text isEqualToString:@"拒绝退款"]){ [dic safeSetObject:model.orderNo forKey:@"orderNo"]; if ([button.titleLabel.text isEqualToString:@"同意退款"]) { [dic safeSetObject:@"1" forKey:@"confirm"]; }else{ [dic safeSetObject:@"0" forKey:@"confirm"]; } url = JT_confirmRefund; } [NetworkRequestManager requestPostWithInterfacePrefix:url parameters:dic onSuccess:^(id requestData) { [MBProgressHUD hideHUDForView:self.view]; if ([requestData[@"error"] count] !=0) { for (NSDictionary *dic in requestData[@"error"]) { [MBProgressHUD showError:dic[@"message"] toView:self.view]; } }else{ if ([button.titleLabel.text isEqualToString:@"取消订单"]) { [MBProgressHUD showSuccess:@"取消订单成功" toView:self.view]; }else if ([button.titleLabel.text isEqualToString:@"支付首付"]){ [MBProgressHUD showSuccess:@"支付首付成功" toView:self.view]; }else if ([button.titleLabel.text isEqualToString:@"支付尾款"]){ [MBProgressHUD showSuccess:@"支付尾款成功" toView:self.view]; }else if ([button.titleLabel.text isEqualToString:@"拒绝意向"]){ [MBProgressHUD showSuccess:@"拒绝意向成功" toView:self.view]; }else if ([button.titleLabel.text isEqualToString:@"确认意向"]){ [MBProgressHUD showSuccess:@"确认意向成功" toView:self.view]; }else if ([button.titleLabel.text isEqualToString:@"提现"]){ [MBProgressHUD showSuccess:@"提现成功" toView:self.view]; }else if ([button.titleLabel.text isEqualToString:@"申请退款"]){ [MBProgressHUD showSuccess:@"申请退款" toView:self.view]; }else if ([button.titleLabel.text isEqualToString:@"同意退款"]){ [MBProgressHUD showSuccess:@"同意退款" toView:self.view]; }else if ([button.titleLabel.text isEqualToString:@"拒绝退款"]){ [MBProgressHUD showSuccess:@"拒绝退款" toView:self.view]; } [self networkRequest:nil]; } } onFailure:^{ [MBProgressHUD hideHUDForView:self.view]; }]; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return fitScreenWidth(187+30); } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ PurchaseintentionModel *model = dataArray[indexPath.row]; OrderdetailViewController *vc = [[OrderdetailViewController alloc] init]; vc.orderID = model.orderNo; NewPushViewController(vc); } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ return CGFLOAT_MIN; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return CGFLOAT_MIN; } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { return [[UIView alloc] init]; } - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { return [[UIView alloc] init]; } #pragma mark - 上拉下拉初始化 - (void)addRefreshing { __weak typeof(self) weakSelf = self; __weak UITableView *tableView = newtableView; tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{ if ([NetworkRequestManager connectedToNetwork]) { [weakSelf networkRequest:tableView.mj_header]; }else{ [tableView.mj_header endRefreshing]; } }]; tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{ if ([NetworkRequestManager connectedToNetwork]) { [weakSelf networkRequest:tableView.mj_footer]; }else{ [tableView.mj_footer endRefreshing]; } }]; } - (void)dismiss:(id)object { if ([object isKindOfClass:[MJRefreshNormalHeader class]]) { __weak UITableView *newvc = newtableView; [newvc.mj_header endRefreshing]; }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]){ __weak UITableView *newvc = newtableView; [newvc.mj_footer endRefreshing]; }else { [MBProgressHUD hideHUDForView:self.view]; } } #pragma mark- 外部触发自动刷新 - (void)autoDownRefresh { dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self autoRefresh]; }); } #pragma mark 初始化展示框 - (void) addErrorLoadingFrame:(CGRect)frame title:(NSString *)text buttonTitle:(NSString *)buttonText imageString:(NSString *)image { if(!showView) { [self.view addSubview:showView = [[UIView alloc] initWithFrame:frame]]; [showView setHidden:NO]; [showView setBackgroundColor:NewBgGrayColor]; UIImage *NOimg = [UIImage imageNamed:image]; UIImageView *tempIcon = [[UIImageView alloc]initWithImage:NOimg]; [showView addSubview:tempIcon]; tempIcon.sd_layout .leftSpaceToView(showView, (showView.width/2)-(NOimg.size.width/4.0f)) .topSpaceToView(showView, (showView.height/2)-100.0f-(NOimg.size.height/4.0f)) .widthIs(NOimg.size.width/2.0f) .heightIs(NOimg.size.height/2.0f); UILabel *tipLab = [UILabel new]; [showView addSubview:tipLab]; [tipLab setText:text]; [tipLab setTextAlignment:NSTextAlignmentCenter]; [tipLab setTextColor:NewLightGrayColor]; [tipLab setBackgroundColor:NewClearColor]; [tipLab setFont:NewAutoFont(16.0)]; tipLab.sd_layout .leftEqualToView(showView) .rightEqualToView(showView) .topSpaceToView(tempIcon,10) .heightIs(20.0); if (buttonText.length>0) { UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom]; [showView addSubview:button]; [button setTitle:buttonText forState:UIControlStateNormal]; [button setTitleColor:NewNavigationColor forState:UIControlStateNormal]; ViewBorderRadius(button, 16, 2, NewNavigationColor); [button addTarget:self action:@selector(reloadingData) forControlEvents:UIControlEventTouchUpInside]; CGFloat width = [NewUtils heightforString:[NSString stringWithFormat:@"%@",buttonText] andHeight:34 fontSize:16]; button.sd_layout .leftSpaceToView(showView, (showView.width/2)-((width+35)/2)) .topSpaceToView(tipLab, 30.0) .widthIs(width+35) .heightIs(34); } } [UIView beginAnimations:@"ShowArrow" context:nil]; [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; [UIView setAnimationDuration:0.25f]; [UIView setAnimationDelegate:self]; [showView setAlpha:1.0f]; [UIView commitAnimations]; } - (void)hideReloadingview { [UIView animateWithDuration:0.25 animations:^{ showView.hidden = YES; } completion:^(BOOL finished) { for (id obj in showView.subviews) { [obj removeFromSuperview]; } showView = nil; [showView removeFromSuperview]; }]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #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