123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405 |
- //
- // RepairApplyVC.m
- // LN_School
- //
- // Created by EchoShacolee on 2017/6/16.
- // Copyright © 2017年 Danson. All rights reserved.
- //
- #import "RepairApplyVC.h"
- #import "applyCell.h"
- #import "QuitTextViewCell.h"
- #import "DateView.h"
- @interface RepairApplyVC ()<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate,UITextViewDelegate,UINavigationControllerDelegate>
- {
- UITableView * _tableView;
-
- NSArray *_titles;
- NSArray *_dataArr;
- NSArray *_sheetsArray;
- NSArray *_placeholders;
- }
- @end
- @implementation RepairApplyVC
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- if ([self.type isEqualToString:@"1"]) {
- self.navigationItem.title = @"申请报修";
- }else{
- self.navigationItem.title = @"修改报修";
- }
- self.navigationController.navigationBar.translucent = NO;
- self.view.backgroundColor = KBackGroundColor;
-
- [self goBackByNavigation];
-
- [self myInit];
- }
- -(void)myInit{
-
- _titles = @[@[@"终端型号",@"设备场厂",@"车牌号码",@"联系电话",@"故障描述"],@[@"故障等级",@"发生故障时间"],@[@"其它说明"]];
- _sheetsArray = @[@"一级",@"二级",@"三级"];
-
- //新增
- _dataArr = @[[NSMutableArray arrayWithArray:@[@"请填写终端型号",@"请填写设备场厂",@"请填写车牌号码",@"请填写联系电话",@"请填写故障描述"]],
- [NSMutableArray arrayWithArray:@[@" >",@" >"]],//请选择 故障等级
- [NSMutableArray arrayWithArray:@[@""]]//请输入其它说明
- ];
- _placeholders = [NSArray arrayWithArray:_dataArr[0]];
- if ([self.type isEqualToString:@"2"]) {
- if ([_theDic[@"AR_MODEL"] length] != 0) {
- NSMutableArray *marr = _dataArr[0];
- [marr replaceObjectAtIndex:0 withObject:_theDic[@"AR_MODEL"]];
- }
- if ([_theDic[@"AR_FACTORY"] length] != 0) {
- NSMutableArray *marr = _dataArr[0];
- [marr replaceObjectAtIndex:1 withObject:_theDic[@"AR_FACTORY"]];
- }
- if ([_theDic[@"AR_CARNUM"] length] != 0) {
- NSMutableArray *marr = _dataArr[0];
- [marr replaceObjectAtIndex:2 withObject:_theDic[@"AR_CARNUM"]];
- }
- if ([_theDic[@"AR_TELPHONE"] length] != 0) {
- NSMutableArray *marr = _dataArr[0];
- [marr replaceObjectAtIndex:3 withObject:_theDic[@"AR_TELPHONE"]];
- }
- if ([_theDic[@"AR_REASON"] length] != 0) {
- NSMutableArray *marr = _dataArr[0];
- [marr replaceObjectAtIndex:4 withObject:_theDic[@"AR_REASON"]];
- }
- if ([_theDic[@"AR_LEVEL"] length] != 0) {
- NSMutableArray *marr = _dataArr[1];
- NSString *status = [NSString stringWithFormat:@"%@",self.theDic[@"AR_LEVEL"]];
- NSString * str = @"";
- switch ([status integerValue]) {
- case 1:
- str = @"一级";
- break;
- case 2:
- str = @"二级";
- break;
- case 3:
- str = @"三级";
- break;
-
- default:
- break;
- }
- [marr replaceObjectAtIndex:0 withObject:str];
- }
- if ([_theDic[@"AR_TIME"] length] != 0) {
- NSMutableArray *marr = _dataArr[1];
- [marr replaceObjectAtIndex:1 withObject:_theDic[@"AR_TIME"]];
- }
- if ([_theDic[@"AR_REMARK"] length] != 0) {
- NSMutableArray *marr = _dataArr[2];
- [marr replaceObjectAtIndex:0 withObject:_theDic[@"AR_REMARK"]];
- }
-
- }
-
- _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kSize.width, kSize.height-kNavOffSet) style:UITableViewStyleGrouped];
- _tableView.estimatedSectionHeaderHeight = 0;
- _tableView.estimatedSectionFooterHeight = 0;
- _tableView.dataSource = self;
- _tableView.delegate = self;
- [self.view addSubview:_tableView];
-
- //
- UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 100)];
- UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(10, 25, kSize.width - 20, 50)];
- btn.backgroundColor = RQMianColor;
- [btn borderCornorRadios:5];
- [btn setTitle:@"提交" textColor:[UIColor whiteColor] font:Font18 fotState:UIControlStateNormal];
- [btn target:self Tag:1];
- [view addSubview:btn];
- _tableView.tableFooterView = view;
- }
- - (void)btnClick:(UIButton *)sender
- {
- //新增/修改
- if ([self.type isEqualToString:@"1"]) {
- [self RepairWithMethod:@"addRepair"];
- }else{
- [self RepairWithMethod:@"updateRepair"];
- }
-
- }
- #pragma mark tableview代理方法
- -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return _titles.count;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return [_titles[section] count];
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
-
- if (indexPath.section == 2) {
- return 106;
- }
- return 44;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- //textView
- if (indexPath.section == 2) {
- QuitTextViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellID"];
- if (!cell) {
- cell = [[[NSBundle mainBundle]loadNibNamed:@"QuitTextViewCell" owner:nil options:nil]lastObject];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- cell.titleLab.text = @"其它说明:";
- cell.textView.text = _dataArr[2][0];
- }
- cell.textView.delegate = self;
- return cell;
- }
-
- applyCell* cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
- if (cell == nil)
- {
- cell = [[applyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- }
-
- [cell.titLabel setText:[_titles[indexPath.section] objectAtIndex:indexPath.row]];
-
- NSArray *detailArray = _dataArr[indexPath.section];
-
- cell.detailField.delegate = self;
- cell.detailField.tag = indexPath.section * 10 + indexPath.row;
-
- if (indexPath.section == 1)
- {
- cell.detailField.userInteractionEnabled = NO;
- cell.detailField.textColor = RQMianColor;
- cell.detailField.text = detailArray[indexPath.row];
- }else if (indexPath.section == 0) {
-
- cell.detailField.userInteractionEnabled = YES;
- if ([_placeholders containsObject:detailArray[indexPath.row]]) {
- cell.detailField.placeholder = detailArray[indexPath.row];
- }else {
- cell.detailField.textColor = KTitleColor;
- cell.detailField.text = detailArray[indexPath.row];
- }
- }
- return cell;
- }
- -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- [self.view endEditing:YES];
-
- if (indexPath.section == 1){
- if (indexPath.row == 0) {
- [RQ_SHARE_FUNCTION showAlertWithTitle:@"故障等级" message:nil alertControllerStyle:UIAlertControllerStyleActionSheet cancelButtonTitle:@"取消" otherButtonTitles:_sheetsArray otherButtonStyles:nil completion:^(NSUInteger selectedOtherButtonIndex) {
- if (selectedOtherButtonIndex != NSNotFound) {
- [_dataArr[1] replaceObjectAtIndex:0 withObject:_sheetsArray[selectedOtherButtonIndex]];
- [_tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
- }
- }];
- }else if (indexPath.row == 1){
-
- DateView *dateV = [[DateView alloc] init];
-
- [dateV setStyle:0];
- [dateV showWithComplete:^(NSString * result) {
- [_dataArr[1] replaceObjectAtIndex:1 withObject:result];
- [_tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
- }];
- }
-
- }
-
-
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
- {
- return .1;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- {
- return 25;
- }
- #pragma scroollView 代理方法
- -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
- if ([scrollView isKindOfClass:[UITextView class]]) {
- return;
- }
- [self.view endEditing:YES];
- }
- #pragma mark textField
- -(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
- {
- NSIndexPath *indexpath= [NSIndexPath indexPathForRow:textField.tag%10 inSection:0];
-
- //获取当前cell在tableview中的位置
- CGRect rectintableview=[_tableView rectForRowAtIndexPath:indexpath];
-
- [_tableView setContentOffset:CGPointMake(_tableView.contentOffset.x,rectintableview.origin.y-25) animated:YES];
-
- return YES;
- }
- -(BOOL)textFieldShouldEndEditing:(UITextField *)textField
- {
-
- NSString *textString = textField.text;
- NSMutableArray *array = _dataArr[textField.tag/10];
- [array replaceObjectAtIndex:textField.tag%10 withObject:textString];
-
- [_tableView reloadData];
-
- return YES;
- }
- -(BOOL)textFieldShouldReturn:(UITextField *)textField
- {
- [textField endEditing:YES];
- return YES;
- }
- #pragma mark textview代理
- -(BOOL)textViewShouldBeginEditing:(UITextView *)textView{
-
-
- NSIndexPath *indexpath= [NSIndexPath indexPathForRow:0 inSection:2];
-
- //获取当前cell在tableview中的位置
- CGRect rectintableview=[_tableView rectForRowAtIndexPath:indexpath];
-
- [_tableView setContentOffset:CGPointMake(_tableView.contentOffset.x,rectintableview.origin.y-25) animated:YES];
-
- return YES;
- }
- - (BOOL)textViewShouldEndEditing:(UITextView *)textView{
- NSString * str = textView.text;
- [_dataArr[2] replaceObjectAtIndex:0 withObject:str];
- return YES;
- }
- - (void)textViewDidChange:(UITextView *)textView{
-
- NSString * str = textView.text;
- [_dataArr[2] replaceObjectAtIndex:0 withObject:str];
- return;
- }
- #pragma mark 网络请求
- -(void)RepairWithMethod:(NSString *)method{
-
- for (NSString *str in _dataArr[0]) {
- if (str.length == 0 || [_placeholders containsObject:str]) {
- ShowMsg(@"请填写完整信息");
- return;
- }
- }
-
- for (NSString * str in _dataArr[1]) {
- if([str isEqualToString:@" >"])
- {
- ShowMsg(@"请填写完整信息");
- return;
- }
- }
-
- for (NSString *str in _dataArr[2]) {
- if (str.length == 0) {
- ShowMsg(@"请填写完整信息");
- return;
- }
- }
-
- //
- if (![NetManager connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- NSMutableDictionary *dic = [NSMutableDictionary dictionary];
- if ([method isEqualToString:@"updateRepair"]) {
- [dic setObject:self.theDic[@"AR_ID"] forKey:@"id"];
- }
- [dic setObject:_dataArr[0][0] forKey:@"model"];
- [dic setObject:_dataArr[0][2] forKey:@"carnum"];
- [dic setObject:_dataArr[0][1] forKey:@"factory"];
- [dic setObject:_dataArr[0][3] forKey:@"telphone"];
- [dic setObject:_dataArr[0][4] forKey:@"reason"];
-
- NSString * level = @"";//_dataArr[1][0]
- if ([_dataArr[1][0] isEqualToString:@"一级"]) {
- level = @"1";
- }else if ([_dataArr[1][0] isEqualToString:@"二级"]) {
- level = @"2";
- }else if ([_dataArr[1][0] isEqualToString:@"三级"]) {
- level = @"3";
- }
- [dic setObject:level forKey:@"level"];
- [dic setObject:_dataArr[1][1] forKey:@"time"];
- [dic setObject:_dataArr[2][0] forKey:@"remark"];
- [dic setObject:@"" forKey:@"coachOutId"];
-
- [NetManager requestAnythingWithURL:method dictionary:dic dataArray:nil completion:^(NSDictionary *root) {
- if (!root) {
- ShowErrorMsg(@"请求失败!");
- return;
- }
- if ([root[@"code"] isEqualToString:@"1"]) {
- ShowErrorMsg(root[@"msg"]);
- NSLog(@"%@",root[@"msg"]);
- return;
- }
-
- if ([self.type isEqualToString:@"1"]) {
- ShowMsg(@"申请成功");
- [self.navigationController popViewControllerAnimated:YES];
- }else{
- ShowMsg(@"修改成功");
- UIViewController *vc = self.navigationController.childViewControllers[1];
- [self.navigationController popToViewController:vc animated:YES];
- }
-
- if (self.blcok) {
- self.blcok();
- }
- }];
-
- }
- - (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
|