RepairApplyVC.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. //
  2. // RepairApplyVC.m
  3. // LN_School
  4. //
  5. // Created by EchoShacolee on 2017/6/16.
  6. // Copyright © 2017年 Danson. All rights reserved.
  7. //
  8. #import "RepairApplyVC.h"
  9. #import "applyCell.h"
  10. #import "QuitTextViewCell.h"
  11. #import "DateView.h"
  12. @interface RepairApplyVC ()<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate,UITextViewDelegate,UINavigationControllerDelegate>
  13. {
  14. UITableView * _tableView;
  15. NSArray *_titles;
  16. NSArray *_dataArr;
  17. NSArray *_sheetsArray;
  18. NSArray *_plcaeholders;
  19. }
  20. @end
  21. @implementation RepairApplyVC
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. if ([self.type isEqualToString:@"1"]) {
  25. self.navigationItem.title = @"申请报修";
  26. }else{
  27. self.navigationItem.title = @"修改报修";
  28. }
  29. self.navigationController.navigationBar.translucent = NO;
  30. self.view.backgroundColor = KBackGroundColor;
  31. [self goBackByNavigation];
  32. [self myInit];
  33. }
  34. -(void)myInit{
  35. _titles = @[@[@"终端型号",@"设备场厂",@"车牌号码",@"联系电话",@"故障描述"],@[@"故障等级",@"发生故障时间"],@[@"其它说明"]];
  36. _sheetsArray = @[@"一级",@"二级",@"三级"];
  37. //新增
  38. _dataArr = @[[NSMutableArray arrayWithArray:@[@"请填写终端型号",@"请填写设备场厂",@"请填写车牌号码",@"请填写联系电话",@"请填写故障描述"]],
  39. [NSMutableArray arrayWithArray:@[@" >",@" >"]],//请选择 故障等级
  40. [NSMutableArray arrayWithArray:@[@""]]//请输入其它说明
  41. ];
  42. _plcaeholders = _dataArr[0];
  43. if ([self.type isEqualToString:@"2"]) {
  44. if ([_theDic[@"AR_MODEL"] length] != 0) {
  45. NSMutableArray *marr = _dataArr[0];
  46. [marr replaceObjectAtIndex:0 withObject:_theDic[@"AR_MODEL"]];
  47. }
  48. if ([_theDic[@"AR_FACTORY"] length] != 0) {
  49. NSMutableArray *marr = _dataArr[0];
  50. [marr replaceObjectAtIndex:1 withObject:_theDic[@"AR_FACTORY"]];
  51. }
  52. if ([_theDic[@"AR_CARNUM"] length] != 0) {
  53. NSMutableArray *marr = _dataArr[0];
  54. [marr replaceObjectAtIndex:2 withObject:_theDic[@"AR_CARNUM"]];
  55. }
  56. if ([_theDic[@"AR_TELPHONE"] length] != 0) {
  57. NSMutableArray *marr = _dataArr[0];
  58. [marr replaceObjectAtIndex:3 withObject:_theDic[@"AR_TELPHONE"]];
  59. }
  60. if ([_theDic[@"AR_REASON"] length] != 0) {
  61. NSMutableArray *marr = _dataArr[0];
  62. [marr replaceObjectAtIndex:4 withObject:_theDic[@"AR_REASON"]];
  63. }
  64. if ([_theDic[@"AR_LEVEL"] length] != 0) {
  65. NSMutableArray *marr = _dataArr[1];
  66. NSString *status = [NSString stringWithFormat:@"%@",self.theDic[@"AR_LEVEL"]];
  67. NSString * str = @"";
  68. switch ([status integerValue]) {
  69. case 1:
  70. str = @"一级";
  71. break;
  72. case 2:
  73. str = @"二级";
  74. break;
  75. case 3:
  76. str = @"三级";
  77. break;
  78. default:
  79. break;
  80. }
  81. [marr replaceObjectAtIndex:0 withObject:str];
  82. }
  83. if ([_theDic[@"AR_TIME"] length] != 0) {
  84. NSMutableArray *marr = _dataArr[1];
  85. [marr replaceObjectAtIndex:1 withObject:_theDic[@"AR_TIME"]];
  86. }
  87. if ([_theDic[@"AR_REMARK"] length] != 0) {
  88. NSMutableArray *marr = _dataArr[2];
  89. [marr replaceObjectAtIndex:0 withObject:_theDic[@"AR_REMARK"]];
  90. }
  91. }
  92. _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kSize.width, kSize.height-kNavOffSet) style:UITableViewStyleGrouped];
  93. _tableView.estimatedSectionHeaderHeight = 0;
  94. _tableView.estimatedSectionFooterHeight = 0;
  95. _tableView.dataSource = self;
  96. _tableView.delegate = self;
  97. [self.view addSubview:_tableView];
  98. //
  99. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 100)];
  100. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(10, 25, kSize.width - 20, 50)];
  101. btn.backgroundColor = defGreen;
  102. [btn borderCornorRadios:5];
  103. [btn setTitle:@"提交" textColor:[UIColor whiteColor] font:Font18 fotState:UIControlStateNormal];
  104. [btn target:self Tag:1];
  105. [view addSubview:btn];
  106. _tableView.tableFooterView = view;
  107. }
  108. - (void)btnClick:(UIButton *)sender
  109. {
  110. //新增/修改
  111. if ([self.type isEqualToString:@"1"]) {
  112. [self RepairWithMethod:@"addRepair"];
  113. }else{
  114. [self RepairWithMethod:@"updateRepair"];
  115. }
  116. }
  117. #pragma mark tableview代理方法
  118. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  119. {
  120. return _titles.count;
  121. }
  122. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  123. {
  124. return [_titles[section] count];
  125. }
  126. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  127. if (indexPath.section == 2) {
  128. return 106;
  129. }
  130. return 44;
  131. }
  132. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  133. {
  134. //textView
  135. if (indexPath.section == 2) {
  136. QuitTextViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellID"];
  137. if (!cell) {
  138. cell = [[[NSBundle mainBundle]loadNibNamed:@"QuitTextViewCell" owner:nil options:nil]lastObject];
  139. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  140. cell.titleLab.text = @"其它说明:";
  141. cell.textView.text = _dataArr[2][0];
  142. }
  143. cell.textView.delegate = self;
  144. return cell;
  145. }
  146. applyCell* cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  147. if (cell == nil)
  148. {
  149. cell = [[applyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
  150. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  151. }
  152. [cell.titLabel setText:[_titles[indexPath.section] objectAtIndex:indexPath.row]];
  153. NSArray *detailArray = _dataArr[indexPath.section];
  154. cell.detailField.delegate = self;
  155. cell.detailField.tag = indexPath.section * 10 + indexPath.row;
  156. if (indexPath.section == 1)
  157. {
  158. cell.detailField.userInteractionEnabled = NO;
  159. cell.detailField.textColor = defGreen;
  160. cell.detailField.text = detailArray[indexPath.row];
  161. }else if (indexPath.section == 0) {
  162. cell.detailField.userInteractionEnabled = YES;
  163. if ([_plcaeholders containsObject:detailArray[indexPath.row]]) {
  164. cell.detailField.placeholder = detailArray[indexPath.row];
  165. }else {
  166. cell.detailField.textColor = KTitleColor;
  167. cell.detailField.text = detailArray[indexPath.row];
  168. }
  169. }
  170. return cell;
  171. }
  172. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  173. {
  174. [self.view endEditing:YES];
  175. if (indexPath.section == 1){
  176. if (indexPath.row == 0) {
  177. UIAlertController * alert = [UIAlertController alertControllerWithTitle:nil message:@"故障等级" preferredStyle:UIAlertControllerStyleActionSheet];
  178. for (NSString * str in _sheetsArray) {
  179. [alert addAction:[UIAlertAction actionWithTitle:str style:0 handler:^(UIAlertAction * _Nonnull action) {
  180. [_dataArr[1] replaceObjectAtIndex:0 withObject:str];
  181. [_tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
  182. }]];
  183. }
  184. [self presentViewController:alert animated:YES completion:nil];
  185. }else if (indexPath.row == 1){
  186. DateView *dateV = [[DateView alloc] init];
  187. [dateV setStyle:0];
  188. [dateV showWithComplete:^(NSString * result) {
  189. [_dataArr[1] replaceObjectAtIndex:1 withObject:result];
  190. [_tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
  191. }];
  192. }
  193. }
  194. }
  195. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  196. {
  197. return .1;
  198. }
  199. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  200. {
  201. return 25;
  202. }
  203. #pragma scroollView 代理方法
  204. -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
  205. if ([scrollView isKindOfClass:[UITextView class]]) {
  206. return;
  207. }
  208. [self.view endEditing:YES];
  209. }
  210. #pragma mark textField
  211. -(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
  212. {
  213. NSIndexPath *indexpath= [NSIndexPath indexPathForRow:textField.tag%10 inSection:0];
  214. //获取当前cell在tableview中的位置
  215. CGRect rectintableview=[_tableView rectForRowAtIndexPath:indexpath];
  216. [_tableView setContentOffset:CGPointMake(_tableView.contentOffset.x,rectintableview.origin.y-25) animated:YES];
  217. return YES;
  218. }
  219. -(BOOL)textFieldShouldEndEditing:(UITextField *)textField
  220. {
  221. NSString *textString = textField.text;
  222. NSMutableArray *array = _dataArr[textField.tag/10];
  223. [array replaceObjectAtIndex:textField.tag%10 withObject:textString];
  224. [_tableView reloadData];
  225. return YES;
  226. }
  227. -(BOOL)textFieldShouldReturn:(UITextField *)textField
  228. {
  229. [textField endEditing:YES];
  230. return YES;
  231. }
  232. #pragma mark textview代理
  233. -(BOOL)textViewShouldBeginEditing:(UITextView *)textView{
  234. NSIndexPath *indexpath= [NSIndexPath indexPathForRow:0 inSection:2];
  235. //获取当前cell在tableview中的位置
  236. CGRect rectintableview=[_tableView rectForRowAtIndexPath:indexpath];
  237. [_tableView setContentOffset:CGPointMake(_tableView.contentOffset.x,rectintableview.origin.y-25) animated:YES];
  238. return YES;
  239. }
  240. - (BOOL)textViewShouldEndEditing:(UITextView *)textView{
  241. NSString * str = textView.text;
  242. [_dataArr[2] replaceObjectAtIndex:0 withObject:str];
  243. return YES;
  244. }
  245. - (void)textViewDidChange:(UITextView *)textView{
  246. NSString * str = textView.text;
  247. [_dataArr[2] replaceObjectAtIndex:0 withObject:str];
  248. return;
  249. }
  250. #pragma mark 网络请求
  251. -(void)RepairWithMethod:(NSString *)method{
  252. for (NSString *str in _dataArr[0]) {
  253. if (str.length == 0 || [_plcaeholders containsObject:str]) {
  254. ShowMsg(@"请填写完整信息");
  255. return;
  256. }
  257. }
  258. for (NSString * str in _dataArr[1]) {
  259. if([str isEqualToString:@" >"])
  260. {
  261. ShowMsg(@"请填写完整信息");
  262. return;
  263. }
  264. }
  265. for (NSString *str in _dataArr[2]) {
  266. if (str.length == 0) {
  267. ShowMsg(@"请填写完整信息");
  268. return;
  269. }
  270. }
  271. //
  272. if (![NetManager connectedToNetWork]) {
  273. showMsgUnconnect();
  274. return;
  275. }
  276. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  277. if ([method isEqualToString:@"updateRepair"]) {
  278. [dic setObject:self.theDic[@"AR_ID"] forKey:@"id"];
  279. }
  280. [dic setObject:_dataArr[0][0] forKey:@"model"];
  281. [dic setObject:_dataArr[0][2] forKey:@"carnum"];
  282. [dic setObject:_dataArr[0][1] forKey:@"factory"];
  283. [dic setObject:_dataArr[0][3] forKey:@"telphone"];
  284. [dic setObject:_dataArr[0][4] forKey:@"reason"];
  285. NSString * level = @"";//_dataArr[1][0]
  286. if ([_dataArr[1][0] isEqualToString:@"一级"]) {
  287. level = @"1";
  288. }else if ([_dataArr[1][0] isEqualToString:@"二级"]) {
  289. level = @"2";
  290. }else if ([_dataArr[1][0] isEqualToString:@"三级"]) {
  291. level = @"3";
  292. }
  293. [dic setObject:level forKey:@"level"];
  294. [dic setObject:_dataArr[1][1] forKey:@"time"];
  295. [dic setObject:_dataArr[2][0] forKey:@"remark"];
  296. [dic setObject:@"" forKey:@"coachOutId"];
  297. [MBProgressHUD showLoadToView:self.view];
  298. [NetManager requestAnythingWithURL:method dictionary:dic dataArray:nil completion:^(NSDictionary *root) {
  299. [MBProgressHUD hideHUDForView:self.view];
  300. if (!root) {
  301. ShowErrorMsg(@"请求失败!");
  302. return;
  303. }
  304. if ([root[@"code"] isEqualToString:@"1"]) {
  305. ShowErrorMsg(root[@"msg"]);
  306. NSLog(@"%@",root[@"msg"]);
  307. return;
  308. }
  309. if ([self.type isEqualToString:@"1"]) {
  310. ShowMsg(@"申请成功");
  311. [self.navigationController popViewControllerAnimated:YES];
  312. }else{
  313. ShowMsg(@"修改成功");
  314. UIViewController *vc = self.navigationController.childViewControllers[1];
  315. [self.navigationController popToViewController:vc animated:YES];
  316. }
  317. if (self.blcok) {
  318. self.blcok();
  319. }
  320. }];
  321. }
  322. - (void)didReceiveMemoryWarning {
  323. [super didReceiveMemoryWarning];
  324. // Dispose of any resources that can be recreated.
  325. }
  326. /*
  327. #pragma mark - Navigation
  328. // In a storyboard-based application, you will often want to do a little preparation before navigation
  329. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  330. // Get the new view controller using [segue destinationViewController].
  331. // Pass the selected object to the new view controller.
  332. }
  333. */
  334. @end