RepairApplyVC.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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 *_placeholders;
  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. _placeholders = [NSArray arrayWithArray:_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 = RQMianColor;
  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 = RQMianColor;
  160. cell.detailField.text = detailArray[indexPath.row];
  161. }else if (indexPath.section == 0) {
  162. cell.detailField.userInteractionEnabled = YES;
  163. if ([_placeholders 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. [RQ_SHARE_FUNCTION showAlertWithTitle:@"故障等级" message:nil alertControllerStyle:UIAlertControllerStyleActionSheet cancelButtonTitle:@"取消" otherButtonTitles:_sheetsArray otherButtonStyles:nil completion:^(NSUInteger selectedOtherButtonIndex) {
  178. if (selectedOtherButtonIndex != NSNotFound) {
  179. [_dataArr[1] replaceObjectAtIndex:0 withObject:_sheetsArray[selectedOtherButtonIndex]];
  180. [_tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
  181. }
  182. }];
  183. }else if (indexPath.row == 1){
  184. DateView *dateV = [[DateView alloc] init];
  185. [dateV setStyle:0];
  186. [dateV showWithComplete:^(NSString * result) {
  187. [_dataArr[1] replaceObjectAtIndex:1 withObject:result];
  188. [_tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
  189. }];
  190. }
  191. }
  192. }
  193. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  194. {
  195. return .1;
  196. }
  197. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  198. {
  199. return 25;
  200. }
  201. #pragma scroollView 代理方法
  202. -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
  203. if ([scrollView isKindOfClass:[UITextView class]]) {
  204. return;
  205. }
  206. [self.view endEditing:YES];
  207. }
  208. #pragma mark textField
  209. -(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
  210. {
  211. NSIndexPath *indexpath= [NSIndexPath indexPathForRow:textField.tag%10 inSection:0];
  212. //获取当前cell在tableview中的位置
  213. CGRect rectintableview=[_tableView rectForRowAtIndexPath:indexpath];
  214. [_tableView setContentOffset:CGPointMake(_tableView.contentOffset.x,rectintableview.origin.y-25) animated:YES];
  215. return YES;
  216. }
  217. -(BOOL)textFieldShouldEndEditing:(UITextField *)textField
  218. {
  219. NSString *textString = textField.text;
  220. NSMutableArray *array = _dataArr[textField.tag/10];
  221. [array replaceObjectAtIndex:textField.tag%10 withObject:textString];
  222. [_tableView reloadData];
  223. return YES;
  224. }
  225. -(BOOL)textFieldShouldReturn:(UITextField *)textField
  226. {
  227. [textField endEditing:YES];
  228. return YES;
  229. }
  230. #pragma mark textview代理
  231. -(BOOL)textViewShouldBeginEditing:(UITextView *)textView{
  232. NSIndexPath *indexpath= [NSIndexPath indexPathForRow:0 inSection:2];
  233. //获取当前cell在tableview中的位置
  234. CGRect rectintableview=[_tableView rectForRowAtIndexPath:indexpath];
  235. [_tableView setContentOffset:CGPointMake(_tableView.contentOffset.x,rectintableview.origin.y-25) animated:YES];
  236. return YES;
  237. }
  238. - (BOOL)textViewShouldEndEditing:(UITextView *)textView{
  239. NSString * str = textView.text;
  240. [_dataArr[2] replaceObjectAtIndex:0 withObject:str];
  241. return YES;
  242. }
  243. - (void)textViewDidChange:(UITextView *)textView{
  244. NSString * str = textView.text;
  245. [_dataArr[2] replaceObjectAtIndex:0 withObject:str];
  246. return;
  247. }
  248. #pragma mark 网络请求
  249. -(void)RepairWithMethod:(NSString *)method{
  250. for (NSString *str in _dataArr[0]) {
  251. if (str.length == 0 || [_placeholders containsObject:str]) {
  252. ShowMsg(@"请填写完整信息");
  253. return;
  254. }
  255. }
  256. for (NSString * str in _dataArr[1]) {
  257. if([str isEqualToString:@" >"])
  258. {
  259. ShowMsg(@"请填写完整信息");
  260. return;
  261. }
  262. }
  263. for (NSString *str in _dataArr[2]) {
  264. if (str.length == 0) {
  265. ShowMsg(@"请填写完整信息");
  266. return;
  267. }
  268. }
  269. //
  270. if (![NetManager connectedToNetWork]) {
  271. showMsgUnconnect();
  272. return;
  273. }
  274. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  275. if ([method isEqualToString:@"updateRepair"]) {
  276. [dic setObject:self.theDic[@"AR_ID"] forKey:@"id"];
  277. }
  278. [dic setObject:_dataArr[0][0] forKey:@"model"];
  279. [dic setObject:_dataArr[0][2] forKey:@"carnum"];
  280. [dic setObject:_dataArr[0][1] forKey:@"factory"];
  281. [dic setObject:_dataArr[0][3] forKey:@"telphone"];
  282. [dic setObject:_dataArr[0][4] forKey:@"reason"];
  283. NSString * level = @"";//_dataArr[1][0]
  284. if ([_dataArr[1][0] isEqualToString:@"一级"]) {
  285. level = @"1";
  286. }else if ([_dataArr[1][0] isEqualToString:@"二级"]) {
  287. level = @"2";
  288. }else if ([_dataArr[1][0] isEqualToString:@"三级"]) {
  289. level = @"3";
  290. }
  291. [dic setObject:level forKey:@"level"];
  292. [dic setObject:_dataArr[1][1] forKey:@"time"];
  293. [dic setObject:_dataArr[2][0] forKey:@"remark"];
  294. [dic setObject:@"" forKey:@"coachOutId"];
  295. [NetManager requestAnythingWithURL:method dictionary:dic dataArray:nil completion:^(NSDictionary *root) {
  296. if (!root) {
  297. ShowErrorMsg(@"请求失败!");
  298. return;
  299. }
  300. if ([root[@"code"] isEqualToString:@"1"]) {
  301. ShowErrorMsg(root[@"msg"]);
  302. NSLog(@"%@",root[@"msg"]);
  303. return;
  304. }
  305. if ([self.type isEqualToString:@"1"]) {
  306. ShowMsg(@"申请成功");
  307. [self.navigationController popViewControllerAnimated:YES];
  308. }else{
  309. ShowMsg(@"修改成功");
  310. UIViewController *vc = self.navigationController.childViewControllers[1];
  311. [self.navigationController popToViewController:vc animated:YES];
  312. }
  313. if (self.blcok) {
  314. self.blcok();
  315. }
  316. }];
  317. }
  318. - (void)didReceiveMemoryWarning {
  319. [super didReceiveMemoryWarning];
  320. // Dispose of any resources that can be recreated.
  321. }
  322. /*
  323. #pragma mark - Navigation
  324. // In a storyboard-based application, you will often want to do a little preparation before navigation
  325. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  326. // Get the new view controller using [segue destinationViewController].
  327. // Pass the selected object to the new view controller.
  328. }
  329. */
  330. @end