CarDetail.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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. if (self.lockBlock) {
  64. self.lockBlock(self.dataSource);
  65. }
  66. }];
  67. }
  68. -(void)getLockRecords{
  69. //判断网络是否连接
  70. if (![NetworkManager connectedToNetWork]) {
  71. [self showMsgByAlertVCWithString:@"网络连接异常"];
  72. return;
  73. }
  74. NSMutableDictionary * mDic = [[NSMutableDictionary alloc]init];
  75. [mDic setObject:self.objNum forKey:@"objnum"];
  76. [mDic setObject:@"3" forKey:@"type"];
  77. [MBProgressHUD hideHUDForView:self.view animated:NO];
  78. [MBProgressHUD showHUDAddedTo:self.view animated:NO];
  79. [NetworkManager requestWithMethod:@"lockLogs" parameters:mDic type:0 handler:^(NSDictionary *successDic, NSString *failureStr) {
  80. [MBProgressHUD hideHUDForView:self.view animated:YES];
  81. _holderV.hidden = NO;
  82. if (failureStr) {
  83. [self showMsgByAlertVCWithString:failureStr];
  84. return;
  85. }
  86. if ([successDic[@"code"] isEqualToString:@"1"]) {
  87. [self showMsgByAlertVCWithString:successDic[@"msg"]];
  88. return;
  89. }
  90. _dataArr = successDic[@"body"];
  91. if (_dataArr.count != 0) {
  92. _holderV.hidden = YES;
  93. }
  94. [_tableViews[1] reloadData];
  95. // _isLock = [[NSString stringWithFormat:@"%@",self.dataSource[@"TCI_LOCK_STATUS"]] isEqualToString:@"1"];
  96. // [_locakBtn setTitle:_isLock ? @"解锁" : @"锁定" forState:UIControlStateNormal];
  97. }];
  98. }
  99. #pragma mark 创建BottomBarButton
  100. -(void)createBottomBarWithtoolTitles:(NSArray *)toolTitles{
  101. float widthBtn = (kSize.width-1*toolTitles.count+1)/toolTitles.count;
  102. float HeightBth = JOb_DETAIL_BOTTOMBAR_HEIGHT;
  103. for (int i=0; i<toolTitles.count; i++) {
  104. UIButton * button = [UIButton buttonWithType:UIButtonTypeSystem];
  105. button.frame = CGRectMake(i*(widthBtn+1), kSize.height-HeightBth-SafeAreaBottomHeight, widthBtn, HeightBth);
  106. if (i == 0 && self.byWillDo == NO) {
  107. [button setTitle:@"锁定" forState:UIControlStateNormal];
  108. _locakBtn = button;
  109. }else{
  110. [button setTitle:toolTitles[i] forState:UIControlStateNormal];
  111. }
  112. UIColor * color = COLOR_THEME;
  113. button.backgroundColor = color;
  114. [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  115. [button addTarget:self action:@selector(lockReason) forControlEvents:UIControlEventTouchUpInside];
  116. button.tag = 100+i;
  117. [self.view addSubview:button];
  118. }
  119. }
  120. -(void)lockReason{
  121. if (self.byWillDo && self.shenheBLock) {
  122. self.shenheBLock();
  123. return;
  124. }
  125. NSString * title = _isLock ? @"解锁":@"锁定";
  126. NSString *message = [NSString stringWithFormat:@"请输入%@理由:",title];
  127. UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
  128. [alertFind addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
  129. textField.placeholder = [NSString stringWithFormat:@"(必须填写,否则将无法完成%@)",title];
  130. }];
  131. [alertFind addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
  132. [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  133. UITextField *tf = alertFind.textFields[0];
  134. if (tf.text.length > 0) {
  135. [self lockCarWithReason:tf.text];
  136. }else{
  137. [self showMsgByMBWithString:@"操作失败,请输入锁定/解锁理由"];
  138. }
  139. }]];
  140. NSString *theID = _isLock?@"552":@"551";
  141. [Tools permissionValidationWithID:theID result:^(BOOL isCan, NSString *failureStr) {
  142. if (!isCan) {
  143. if (failureStr) {
  144. [self showMsgByMBWithString:failureStr];
  145. }
  146. return;
  147. }
  148. [self presentViewController:alertFind animated:true completion:nil];
  149. }];
  150. }
  151. -(void)lockCarWithReason:(NSString *)reason{
  152. NSMutableDictionary * mdic = [NSMutableDictionary new];
  153. [mdic setValue:MYAPPDELEGATE.userDic[@"id"] forKey:@"userId"];
  154. [mdic setValue:reason forKey:@"reason"];
  155. [mdic setValue:_isLock ? @"0" : @"1" forKey:@"status"];//类型 类型 1 锁定 0 解锁
  156. [mdic setValue:self.dataSource[@"TCO_CARNUM"] forKey:@"carnum"];
  157. [self getDataWithDic:mdic method:@"lockCar" block:^(NSDictionary *successdic) {
  158. //解锁成功,重新请求数据
  159. [self getRequsetData];
  160. [self getLockRecords];
  161. }];
  162. }
  163. #pragma mark 重写代理方法
  164. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  165. NSInteger index = [_tableViews indexOfObject:tableView];
  166. if (index == 1) {
  167. return _dataArr.count;
  168. }
  169. return [_keysArr count];
  170. }
  171. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  172. if ([_tableViews indexOfObject:tableView] == 1) {
  173. return [LockCell heightForDic:_dataArr[indexPath.row]];
  174. }
  175. return [super tableView:tableView heightForRowAtIndexPath:indexPath];
  176. }
  177. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  178. {
  179. if ([_tableViews indexOfObject:tableView] == 1) {
  180. LockCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"];
  181. if (!cell) {
  182. cell = [[[NSBundle mainBundle] loadNibNamed:@"LockCell" owner:nil options:nil]lastObject];
  183. }
  184. [cell upDataWithDic:_dataArr[indexPath.row]];
  185. return cell;
  186. }
  187. //这里不想把父类搞得太复杂(else if key==xxx),就自己实现一次
  188. UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"];
  189. if (!cell) {
  190. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cellId"];
  191. }
  192. if ([_statusArr[indexPath.row] isEqualToNumber:@1]) {
  193. cell.detailTextLabel.numberOfLines = 0;
  194. cell.detailTextLabel.textAlignment = NSTextAlignmentLeft;
  195. }else{
  196. cell.detailTextLabel.numberOfLines = 1;
  197. cell.detailTextLabel.textAlignment = NSTextAlignmentRight;
  198. }
  199. NSString * key = _keysArr[indexPath.row][1];
  200. cell.textLabel.text = _keysArr[indexPath.row][0];
  201. cell.detailTextLabel.numberOfLines = 0;
  202. if ([key isEqualToString:@"TCO_RECORD_STATUS"]){
  203. NSString *status = [NSString stringWithFormat:@"%@",self.dataSource[key]];
  204. cell.detailTextLabel.text = [status isEqualToString:@"1"] ? @"已备案" : @"未备案" ;
  205. }else if ([key isEqualToString:@"TCO_PLATECOLOR"]){
  206. NSString *status = [NSString stringWithFormat:@"%@",self.dataSource[key]];
  207. //车牌颜色(1:蓝色; 2:黄色; 3:黑色; 4:白色; 5:绿色; 9:其他;)
  208. switch ([status integerValue]) {
  209. case 1:
  210. cell.detailTextLabel.text = @"蓝色";
  211. break;
  212. case 2:
  213. cell.detailTextLabel.text = @"黄色";
  214. break;
  215. case 3:
  216. cell.detailTextLabel.text = @"黑色";
  217. break;
  218. case 4:
  219. cell.detailTextLabel.text = @"白色";
  220. break;
  221. case 5:
  222. cell.detailTextLabel.text = @"绿色";
  223. break;
  224. case 9:
  225. cell.detailTextLabel.text = @"其它";
  226. break;
  227. default:
  228. break;
  229. }
  230. }else if ([key isEqualToString:@"TCO_LOCK_STATUS"]){
  231. NSString *status = [NSString stringWithFormat:@"%@",self.dataSource[key]];
  232. cell.detailTextLabel.text = [status isEqualToString:@"1"] ? @"已锁定" : @"未锁定" ;
  233. }else{
  234. cell.detailTextLabel.text = [NSString stringWithFormat:@"%@",self.dataSource[key]];
  235. }
  236. return cell;
  237. }
  238. - (void)didReceiveMemoryWarning {
  239. [super didReceiveMemoryWarning];
  240. // Dispose of any resources that can be recreated.
  241. }
  242. /*
  243. #pragma mark - Navigation
  244. // In a storyboard-based application, you will often want to do a little preparation before navigation
  245. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  246. // Get the new view controller using [segue destinationViewController].
  247. // Pass the selected object to the new view controller.
  248. }
  249. */
  250. @end