CarDetail.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. //
  2. // CarDetail.m
  3. // LNManager
  4. //
  5. // Created by EchoShacolee on 2017/4/10.
  6. // Copyright © 2017年 lee. All rights reserved.
  7. //
  8. #import "CarDetail.h"
  9. #import "LockCell.h"
  10. @interface CarDetail ()
  11. {
  12. BOOL _isLock;//锁定状态
  13. UIButton * _locakBtn;//锁定/解锁
  14. NSArray * _dataArr;//锁定记录
  15. HolderView * _holderV;
  16. }
  17. @end
  18. @implementation CarDetail
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. self.navigationItem.title = @"车辆详情";
  22. if (self.byWillDo) {
  23. [self createBottomBarWithtoolTitles:@[@"审核"]];
  24. [self setSegmentControllWithTitles:@[@"基本信息"]];
  25. }else{
  26. [self createBottomBarWithtoolTitles:@[@"锁定/解锁"]];
  27. [self setSegmentControllWithTitles:@[@"基本信息",@"锁定历史记录"]];
  28. [self getLockRecords];
  29. [self getRequsetData];
  30. UITableView * tabV = [_tableViews lastObject];
  31. _holderV = [[HolderView alloc] initWithFrame:tabV.frame];
  32. [_holderV freshBlock:^{
  33. [self getLockRecords];
  34. }];
  35. [_mainScroolView addSubview:_holderV];
  36. }
  37. }
  38. -(void)setData{
  39. _keysArr = @[@[@"培训机构编号",@"TCO_INSCODE"],
  40. @[@"车架号",@"TCO_FRANUM"],
  41. @[@"发动机号",@"TCO_ENGNUM"],
  42. @[@"车辆牌号",@"TCO_LICNUM"],
  43. @[@"车牌颜色",@"TCO_PLATECOLOR"],
  44. @[@"生产厂家",@"TCO_MANUFACTURE"],
  45. @[@"车辆品牌",@"TCO_BRAND"],
  46. @[@"车辆型号",@"TCO_MODEL"],
  47. @[@"培训车型 ",@"TCO_PERDRITYPE"],
  48. @[@"购买日期 ",@"TCO_BUYDATE"],
  49. @[@"备案状态",@"TCO_RECORD_STATUS"],
  50. @[@"备案日期",@"TCO_RECORD_DATE"],
  51. @[@"锁定状态",@"TCO_LOCK_STATUS"],
  52. @[@"锁定/解锁时间",@"TCO_LOCK_DATE"],
  53. @[@"教练车编号",@"TCO_CARNUM"]];
  54. [super setData];
  55. }
  56. -(void)getRequsetData{
  57. [self getDataWithDic:self.requesetDic method:@"cars" block:^(NSDictionary *successDic) {
  58. self.dataSource = [NSMutableDictionary dictionaryWithDictionary:successDic[@"body"][0]];
  59. [_tableViews[0] reloadData];
  60. _isLock = [[NSString stringWithFormat:@"%@",self.dataSource[@"TCO_LOCK_STATUS"]] isEqualToString:@"1"];
  61. [_locakBtn setTitle:_isLock ? @"解锁" : @"锁定" forState:UIControlStateNormal];
  62. }];
  63. }
  64. -(void)getLockRecords{
  65. //判断网络是否连接
  66. if (![NetworkManager connectedToNetWork]) {
  67. [self showMsgByAlertVCWithString:@"网络连接异常"];
  68. return;
  69. }
  70. NSMutableDictionary * mDic = [[NSMutableDictionary alloc]init];
  71. [mDic setObject:self.objNum forKey:@"objnum"];
  72. [mDic setObject:@"3" forKey:@"type"];
  73. [MBProgressHUD hideHUDForView:self.view animated:NO];//强行先掉一次@lee
  74. [MBProgressHUD showHUDAddedTo:self.view animated:NO];
  75. [NetworkManager requestWithMethod:@"lockLogs" parameters:mDic type:0 handler:^(NSDictionary *successDic, NSString *failureStr) {
  76. [MBProgressHUD hideHUDForView:self.view animated:YES];
  77. _holderV.hidden = NO;
  78. if (failureStr) {
  79. [self showMsgByAlertVCWithString:failureStr];
  80. return;
  81. }
  82. if ([successDic[@"code"] isEqualToString:@"1"]) {
  83. [self showMsgByAlertVCWithString:successDic[@"msg"]];
  84. return;
  85. }
  86. _dataArr = successDic[@"body"];
  87. if (_dataArr.count != 0) {
  88. _holderV.hidden = YES;
  89. }
  90. [_tableViews[1] reloadData];
  91. // _isLock = [[NSString stringWithFormat:@"%@",self.dataSource[@"TCI_LOCK_STATUS"]] isEqualToString:@"1"];
  92. // [_locakBtn setTitle:_isLock ? @"解锁" : @"锁定" forState:UIControlStateNormal];
  93. }];
  94. }
  95. #pragma mark 创建BottomBarButton
  96. -(void)createBottomBarWithtoolTitles:(NSArray *)toolTitles{
  97. float widthBtn = (kSize.width-1*toolTitles.count+1)/toolTitles.count;
  98. float HeightBth = JOb_DETAIL_BOTTOMBAR_HEIGHT;
  99. for (int i=0; i<toolTitles.count; i++) {
  100. UIButton * button = [UIButton buttonWithType:UIButtonTypeSystem];
  101. button.frame = CGRectMake(i*(widthBtn+1), kSize.height-HeightBth-SafeAreaBottomHeight, widthBtn, HeightBth);
  102. if (i == 0 && self.byWillDo == NO) {
  103. [button setTitle:@"锁定" forState:UIControlStateNormal];
  104. _locakBtn = button;
  105. }else{
  106. [button setTitle:toolTitles[i] forState:UIControlStateNormal];
  107. }
  108. UIColor * color = COLOR_THEME;
  109. button.backgroundColor = color;
  110. [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  111. [button addTarget:self action:@selector(lockReason) forControlEvents:UIControlEventTouchUpInside];
  112. button.tag = 100+i;
  113. [self.view addSubview:button];
  114. }
  115. }
  116. -(void)lockReason{
  117. if (self.byWillDo && self.shenheBLock) {
  118. self.shenheBLock();
  119. return;
  120. }
  121. NSString * title = _isLock ? @"解锁":@"锁定";
  122. NSString *message = [NSString stringWithFormat:@"请输入%@理由:",title];
  123. UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
  124. [alertFind addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
  125. textField.placeholder = [NSString stringWithFormat:@"(必须填写,否则将无法完成%@)",title];
  126. }];
  127. [alertFind addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
  128. [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  129. UITextField *tf = alertFind.textFields[0];
  130. if (tf.text.length > 0) {
  131. [self lockCarWithReason:tf.text];
  132. }else{
  133. [self showMsgByMBWithString:@"操作失败,请输入锁定/解锁理由"];
  134. }
  135. }]];
  136. [self presentViewController:alertFind animated:true completion:nil];
  137. }
  138. -(void)lockCarWithReason:(NSString *)reason{
  139. NSMutableDictionary * mdic = [NSMutableDictionary new];
  140. [mdic setValue:MYAPPDELEGATE.userDic[@"id"] forKey:@"userId"];
  141. [mdic setValue:reason forKey:@"reason"];
  142. [mdic setValue:_isLock ? @"0" : @"1" forKey:@"status"];//类型 类型 1 锁定 0 解锁
  143. [mdic setValue:self.dataSource[@"TCO_CARNUM"] forKey:@"carnum"];
  144. [self getDataWithDic:mdic method:@"lockCar" block:^(NSDictionary *successdic) {
  145. //解锁成功,重新请求数据
  146. [self getRequsetData];
  147. [self getLockRecords];
  148. }];
  149. }
  150. #pragma mark 重写代理方法
  151. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  152. NSInteger index = [_tableViews indexOfObject:tableView];
  153. if (index == 1) {
  154. return _dataArr.count;
  155. }
  156. return [_keysArr count];
  157. }
  158. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  159. if ([_tableViews indexOfObject:tableView] == 1) {
  160. return 85;
  161. }
  162. return [super tableView:tableView heightForRowAtIndexPath:indexPath];
  163. }
  164. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  165. {
  166. if ([_tableViews indexOfObject:tableView] == 1) {
  167. LockCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"];
  168. if (!cell) {
  169. cell = [[[NSBundle mainBundle] loadNibNamed:@"LockCell" owner:nil options:nil]lastObject];
  170. }
  171. [cell upDataWithDic:_dataArr[indexPath.row]];
  172. return cell;
  173. }
  174. //这里不想把父类搞得太复杂(else if key==xxx),就自己实现一次
  175. UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"];
  176. if (!cell) {
  177. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cellId"];
  178. }
  179. if ([_statusArr[indexPath.row] isEqualToNumber:@1]) {
  180. cell.detailTextLabel.numberOfLines = 0;
  181. cell.detailTextLabel.textAlignment = NSTextAlignmentLeft;
  182. }else{
  183. cell.detailTextLabel.numberOfLines = 1;
  184. cell.detailTextLabel.textAlignment = NSTextAlignmentRight;
  185. }
  186. NSString * key = _keysArr[indexPath.row][1];
  187. cell.textLabel.text = _keysArr[indexPath.row][0];
  188. cell.detailTextLabel.numberOfLines = 0;
  189. if ([key isEqualToString:@"TCO_RECORD_STATUS"]){
  190. NSString *status = [NSString stringWithFormat:@"%@",self.dataSource[key]];
  191. cell.detailTextLabel.text = [status isEqualToString:@"1"] ? @"已备案" : @"未备案" ;
  192. }else if ([key isEqualToString:@"TCO_PLATECOLOR"]){
  193. NSString *status = [NSString stringWithFormat:@"%@",self.dataSource[key]];
  194. //车牌颜色(1:蓝色; 2:黄色; 3:黑色; 4:白色; 5:绿色; 9:其他;)
  195. switch ([status integerValue]) {
  196. case 1:
  197. cell.detailTextLabel.text = @"蓝色";
  198. break;
  199. case 2:
  200. cell.detailTextLabel.text = @"黄色";
  201. break;
  202. case 3:
  203. cell.detailTextLabel.text = @"黑色";
  204. break;
  205. case 4:
  206. cell.detailTextLabel.text = @"白色";
  207. break;
  208. case 5:
  209. cell.detailTextLabel.text = @"绿色";
  210. break;
  211. case 9:
  212. cell.detailTextLabel.text = @"其它";
  213. break;
  214. default:
  215. break;
  216. }
  217. }else if ([key isEqualToString:@"TCO_LOCK_STATUS"]){
  218. NSString *status = [NSString stringWithFormat:@"%@",self.dataSource[key]];
  219. cell.detailTextLabel.text = [status isEqualToString:@"1"] ? @"已锁定" : @"未锁定" ;
  220. }else{
  221. cell.detailTextLabel.text = [NSString stringWithFormat:@"%@",self.dataSource[key]];
  222. }
  223. return cell;
  224. }
  225. - (void)didReceiveMemoryWarning {
  226. [super didReceiveMemoryWarning];
  227. // Dispose of any resources that can be recreated.
  228. }
  229. /*
  230. #pragma mark - Navigation
  231. // In a storyboard-based application, you will often want to do a little preparation before navigation
  232. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  233. // Get the new view controller using [segue destinationViewController].
  234. // Pass the selected object to the new view controller.
  235. }
  236. */
  237. @end