// // payinRealityVC.m // LN_School // // Created by apple on 2017/4/21. // Copyright © 2017年 Danson. All rights reserved. // #import "payinRealityVC.h" #import "PayInRealityTableViewCell.h" @interface payinRealityVC () { UITableView *maintableView; UIView *examerView; UITableView *examertableView; NSArray *dataArray; NSArray *examDataArray; NSDictionary *examerDic; NSDictionary *orderDic; NSString *auditType; NSString *auditStatusString;//1同意 2不同意 NSString *reasonString; // HolderView * holderV; } @end @implementation payinRealityVC - (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.title = @"线下支付"; self.view.backgroundColor = KBackGroundColor; [self goBackByNavigation]; auditType = @"0"; dataArray = [NSArray array]; examDataArray = [NSArray array]; orderDic = [NSDictionary dictionary]; examerDic = [NSDictionary dictionary]; reasonString = @""; maintableView = [[UITableView alloc] initWithFrame:kFrame style:UITableViewStylePlain]; maintableView.height -= kNavOffSet; maintableView.delegate = self; maintableView.dataSource = self; maintableView.rowHeight = 100; [self.view addSubview:maintableView]; [self getStudentAuditOrders]; [self getAuditUserInfo]; holderV = [[HolderView alloc]initWithFrame:maintableView.frame]; [holderV freshBlock:^{ [self getStudentAuditOrders]; }]; [self.view addSubview:holderV]; } - (void)setExamer { //懒加载 没有的时候就init一个 if (!examerView) { examerView = [[UIView alloc] initWithFrame:kFrame]; examerView.backgroundColor = windowBlockColor; examertableView = [[UITableView alloc] initWithFrame:CGRectMake(30, (kSize.height - kNavOffSet - 200)/2.0, kSize.width - 60, 200) style:UITableViewStylePlain]; [examertableView borderCornorRadios:7]; examertableView.backgroundColor = KBackGroundColor; examertableView.delegate = self; examertableView.dataSource = self; [examerView addSubview:examertableView]; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kSize.width - 60, 50)]; [label setText:@"请选择审核人" Font:Font18 TextColor:KSubTitleColor Alignment:NSTextAlignmentCenter]; [label addSelfViewWithRect:CGRectMake(10, 48, kSize.width - 80, 2) Color:kLineColor]; examertableView.tableHeaderView = label; UIView *view = [[UIView alloc] initWithFrame:CGRectMake(30, examertableView.y + examertableView.height, kSize.width - 60, 40)]; view.backgroundColor = KBackGroundColor; [examerView addSubview:view]; [view borderCornorRadios:7]; UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, kSize.width/3.0 - 20, 40)]; [btn setTitle:@"取消" textColor:KTitleColor font:Font18 fotState:UIControlStateNormal]; [btn target:self Tag:1]; [view addSubview:btn]; [btn addViewWithRect:CGRectMake(0, 0, kSize.width - 60, 1)]; [btn addViewWithRect:CGRectMake(kSize.width/3.0 - 21, 0, 1, 40)]; btn = [[UIButton alloc] initWithFrame:CGRectMake(kSize.width/3.0 - 20, 0, kSize.width/3.0 - 20, 40)]; [btn setTitle:@"拒绝" textColor:defGreen font:Font18 fotState:UIControlStateNormal]; [btn target:self Tag:2]; [view addSubview:btn]; [btn addViewWithRect:CGRectMake(kSize.width*2.0/3.0 - 41, 0, 1, 40)]; btn = [[UIButton alloc] initWithFrame:CGRectMake(kSize.width*2.0/3.0 - 40, 0, kSize.width/3.0 - 20, 40)]; [btn setTitle:@"同意" textColor:defGreen font:Font18 fotState:UIControlStateNormal]; [btn target:self Tag:2]; [view addSubview:btn]; } examerDic = [NSDictionary dictionary]; [self.view addSubview:examerView]; examDataArray = [NSArray array]; [self getAuditUserInfo]; } - (void)btnClick:(UIButton *)sender { if (sender.tag == 1) { //取消选择考核人 examerDic = [NSDictionary dictionary]; [examerView removeFromSuperview]; return; } if (sender.tag == 2) { //拒绝 if (examerDic.count < 1) { ShowMsg(@"请选择考核人"); return; } [examerView removeFromSuperview]; auditStatusString = @"2"; //输入拒绝原因 UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:nil message:@"审核不通过" preferredStyle:UIAlertControllerStyleAlert]; [alertFind addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) { textField.placeholder = @"请输入原因:"; }]; [alertFind addAction:[UIAlertAction actionWithTitle:@"" style:UIAlertActionStyleCancel handler:nil]]; [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { UITextField * tf = [[alertFind textFields]lastObject]; if (tf.text.length == 0) { ShowMsg(@"审核失败!未输入不通过理由"); }else{ reasonString = tf.text; auditStatusString = @"2"; [self auditOrderPay]; } }]]; [self presentViewController:alertFind animated:true completion:nil]; return; } if (sender.tag == 3) { //同意 if (examerDic.count < 1) { ShowMsg(@"请选择考核人"); return; } [examerView removeFromSuperview]; auditStatusString = @"1"; [self auditOrderPay]; return; } } #pragma mark tableview -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (tableView == examertableView) { return examDataArray.count; } return dataArray.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if (tableView == examertableView) { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"examCell"]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"examCell"]; cell.backgroundColor = KBackGroundColor; [cell.textLabel setTextAlignment:NSTextAlignmentCenter]; } NSDictionary *dic = examDataArray[indexPath.row]; cell.textLabel.text = [NSString stringWithFormat:@"%d、%@",(int)indexPath.row+1,dic[@"text"]]; return cell; } PayInRealityTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"payCell"]; if (!cell) { //加载xib文件创建cell cell = [[[NSBundle mainBundle] loadNibNamed:@"PayInRealityTableViewCell" owner:nil options:nil] lastObject]; cell.selectionStyle = UITableViewCellSelectionStyleNone; } NSDictionary *dic = dataArray[indexPath.row]; cell.dataDic = dic; return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (tableView == examertableView) { examerDic = examDataArray[indexPath.row]; }else { //选中某行 orderDic = dataArray[indexPath.row]; // [self setExamer]; UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:nil message:@"线下订单审核" preferredStyle:UIAlertControllerStyleAlert]; [alertFind addAction:[UIAlertAction actionWithTitle:@"不同意" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { [self refuse]; }]]; [alertFind addAction:[UIAlertAction actionWithTitle:@"同意" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { auditStatusString = @"1"; [self auditOrderPay]; }]]; [self presentViewController:alertFind animated:true completion:nil]; } } - (void)refuse{ //输入拒绝原因 UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:nil message:@"审核不通过" preferredStyle:UIAlertControllerStyleAlert]; [alertFind addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) { textField.placeholder = @"请输入原因:"; }]; [alertFind addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]]; [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { UITextField * tf = [[alertFind textFields]lastObject]; if (tf.text.length == 0) { ShowMsg(@"审核失败!未输入不通过理由"); }else{ reasonString = tf.text; auditStatusString = @"2"; [self auditOrderPay]; } }]]; [self presentViewController:alertFind animated:true completion:nil]; } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return 10; } - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { return [UIView new]; } #pragma mark 数据请求 - (void)getStudentAuditOrders { if (![NetManager connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableDictionary *dic = [NSMutableDictionary dictionary]; [dic setObject:defUser.userDict[@"id"] forKey:@"userId"]; [dic setObject:auditType forKey:@"status"]; NSString *method = @"getStudentAuditOrders"; [MBProgressHUD showLoadToView:self.view]; [NetManager requestAnythingWithURL:method dictionary:dic dataArray:nil completion:^(NSDictionary *root) { [MBProgressHUD hideHUDForView:self.view]; holderV.hidden = NO; if (!root) { ShowErrorMsg(@"请求失败"); return; } if ([root[@"code"] integerValue] == 1) { ShowMsg(root[@"msg"]); return; } dataArray = root[@"body"]; if (dataArray.count > 0) { holderV.hidden = YES; } [maintableView reloadData]; }]; } -(void)getAuditUserInfo{ if (![NetManager connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableDictionary * dic = [NSMutableDictionary new]; [dic setObject:defUser.userDict[@"school"] forKey:@"schoolId"]; [MBProgressHUD showLoadToView:self.view]; [NetManager requestAnythingWithURL:@"getAuditUserInfo" dictionary:dic dataArray:nil completion:^(NSDictionary *root) { [MBProgressHUD hideHUDForView:self.view]; if (!root) { ShowErrorMsg(@"请求失败!"); return; } if ([root[@"code"] isEqualToString:@"1"]) { ShowErrorMsg(root[@"msg"]); return; } examDataArray = root[@"body"]; [examertableView reloadData]; }]; } -(void)auditOrderPay{ if (![NetManager connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableDictionary * dic = [NSMutableDictionary new]; [dic setObject:orderDic[@"ID"] forKey:@"id"]; [dic setObject:orderDic[@"ORDER_ID"] forKey:@"orderId"]; [dic setObject:auditStatusString forKey:@"status"]; [dic setObject:reasonString forKey:@"reason"]; [dic setObject:defUser.userDict[@"id"] forKey:@"audituser"]; [dic setObject:defUser.userDict[@"realName"] forKey:@"auditusername"]; [MBProgressHUD showLoadToView:self.view]; [NetManager requestAnythingWithURL:@"auditOrderPay" dictionary:dic dataArray:nil completion:^(NSDictionary *root) { [MBProgressHUD hideHUDForView:self.view]; if (!root) { ShowErrorMsg(@"请求失败!"); return; } if ([root[@"code"] isEqualToString:@"1"]) { ShowErrorMsg(root[@"msg"]); return; } }]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } @end