RepairApplyVC.m 12 KB

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