CarDetail.m 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. _dataArr = [[NSArray alloc]init];
  23. [self setSegmentControllWithTitles:@[@"基本信息",@"锁定历史记录"] isBttomBar:NO];
  24. // [self createBottomBarWithtoolTitles:@[@"锁定/解锁"]];
  25. [self getRequsetData];
  26. [self getLockRecords];
  27. UITableView * tabV = _tableViews[1];
  28. _holderV = [[HolderView alloc] initWithFrame:tabV.frame];
  29. [_holderV freshBlock:^{
  30. [self getLockRecords];
  31. }];
  32. [_mainScroolView addSubview:_holderV];
  33. }
  34. -(void)setData{
  35. _keysArr = @[
  36. // @[@"培训机构编号",@"TCO_INSCODE"],
  37. @[@"车牌号",@"TCO_LICNUM"],
  38. @[@"车牌颜色",@"TCO_PLATECOLOR"],
  39. @[@"生产厂家",@"TCO_MANUFACTURE"],
  40. @[@"车辆品牌",@"TCO_BRAND"],
  41. @[@"培训车型",@"TCO_PERDRITYPE"],
  42. @[@"车辆型号",@"TCO_MODEL"],
  43. @[@"车架号",@"TCO_FRANUM"],
  44. @[@"发动机号",@"TCO_ENGNUM"],
  45. @[@"购买日期",@"TCO_BUYDATE"],
  46. @[@"创建时间",@"TCO_CREATE_DATE"],
  47. @[@"全国统一编号",@"TCO_CARNUM"],
  48. @[@"备案日期",@"TCO_RECORD_DATE"],
  49. @[@"锁定状态",@"TCO_LOCK_STATUS"],
  50. @[@"锁定/解锁时间",@"TCO_LOCK_DATE"],
  51. ];
  52. [super setData];
  53. }
  54. -(void)getRequsetData{
  55. [self getDataWithDic:self.requesetDic method:@"cars" block:^(NSDictionary *successDic) {
  56. self.dataSource = [NSMutableDictionary dictionaryWithDictionary:successDic[@"body"][0]];
  57. [_tableViews[0] reloadData];
  58. _isLock = [[NSString stringWithFormat:@"%@",self.dataSource[@"TCO_LOCK_STATUS"]] isEqualToString:@"1"];
  59. [_locakBtn setTitle:_isLock ? @"解锁" : @"锁定" forState:UIControlStateNormal];
  60. }];
  61. }
  62. -(void)getLockRecords{
  63. //判断网络是否连接
  64. if (![NetManager connectedToNetWork]) {
  65. showMsgUnconnect();
  66. return;
  67. }
  68. NSMutableDictionary * mDic = [[NSMutableDictionary alloc]init];
  69. [mDic setObject:self.carNum forKey:@"qgcode"];
  70. [mDic setObject:@"3" forKey:@"type"];
  71. [NetManager requestAnythingWithURL:@"getLockRecords" dictionary:mDic dataArray:nil completion:^(NSDictionary *root) {
  72. _holderV.hidden = NO;
  73. if (!root) {
  74. ShowMsg(@"数据请求失败,请重试");
  75. return;
  76. }
  77. if ([root[@"code"] integerValue] == 1) {
  78. ShowMsg(root[@"msg"]);
  79. return;
  80. }
  81. _dataArr = root[@"body"];
  82. if (_dataArr.count > 0) {
  83. _holderV.hidden = YES;
  84. }
  85. [_tableViews[1] reloadData];
  86. _isLock = [[NSString stringWithFormat:@"%@",self.dataSource[@"TCI_LOCK_STATUS"]] isEqualToString:@"1"];
  87. [_locakBtn setTitle:_isLock ? @"解锁" : @"锁定" forState:UIControlStateNormal];
  88. }];
  89. }
  90. #pragma mark 创建BottomBarButton
  91. -(void)createBottomBarWithtoolTitles:(NSArray *)toolTitles{
  92. float widthBtn = (kSize.width-1*toolTitles.count+1)/toolTitles.count;
  93. float HeightBth = JOb_DETAIL_BOTTOMBAR_HEIGHT;
  94. for (int i=0; i<toolTitles.count; i++) {
  95. UIButton * button = [UIButton buttonWithType:UIButtonTypeSystem];
  96. button.frame = CGRectMake(i*(widthBtn+1), kSize.height-kNavOffSet-HeightBth-kSafeAreaBottomHeight, widthBtn, HeightBth);
  97. if (i == 0) {
  98. [button setTitle:@"锁定" forState:UIControlStateNormal];
  99. _locakBtn = button;
  100. }else{
  101. [button setTitle:toolTitles[i] forState:UIControlStateNormal];
  102. }
  103. UIColor * color = RQMianColor;
  104. button.backgroundColor = color;
  105. [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  106. [button addTarget:self action:@selector(lockReason) forControlEvents:UIControlEventTouchUpInside];
  107. button.tag = 100+i;
  108. [self.view addSubview:button];
  109. }
  110. }
  111. -(void)lockReason{
  112. NSString * title = _isLock ? @"解锁":@"锁定";
  113. NSString *message = [NSString stringWithFormat:@"请输入%@理由:",title];
  114. UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
  115. [alertFind addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
  116. textField.placeholder = [NSString stringWithFormat:@"(必须填写,否则将无法完成%@)",title];
  117. }];
  118. [alertFind addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
  119. [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  120. UITextField *tf = alertFind.textFields[0];
  121. if (tf.text.length > 0) {
  122. [self lockCarWithReason:tf.text];
  123. }else{
  124. ShowMsg(@"操作失败,请输入锁定/解锁理由");
  125. }
  126. }]];
  127. [self presentViewController:alertFind animated:true completion:nil];
  128. }
  129. -(void)lockCarWithReason:(NSString *)reason{
  130. NSMutableDictionary * mdic = [NSMutableDictionary new];
  131. [mdic setValue:defUser.userDict[@"id"] forKey:@"userId"];
  132. [mdic setValue:reason forKey:@"reason"];
  133. [mdic setValue:_isLock ? @"0" : @"1" forKey:@"status"];//类型 类型 1 锁定 0 解锁
  134. [mdic setValue:self.dataSource[@"TCO_CARNUM"] forKey:@"carnum"];
  135. [self getDataWithDic:mdic method:@"lockCar" block:^(NSDictionary *successdic) {
  136. //解锁成功,重新请求数据
  137. [self getRequsetData];
  138. [self getLockRecords];
  139. }];
  140. }
  141. #pragma mark 重写代理方法
  142. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  143. if ([_tableViews indexOfObject:tableView] == 1) {
  144. return _dataArr.count;
  145. }
  146. return [super tableView:tableView numberOfRowsInSection:section];
  147. }
  148. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  149. if ([_tableViews indexOfObject:tableView] == 1) {
  150. return 85;
  151. }
  152. return [super tableView:tableView heightForRowAtIndexPath:indexPath];
  153. }
  154. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  155. {
  156. if ([_tableViews indexOfObject:tableView] == 1) {
  157. LockCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"];
  158. if (!cell) {
  159. cell = [[[NSBundle mainBundle] loadNibNamed:@"LockCell" owner:nil options:nil]lastObject];
  160. }
  161. [cell upDataWithDic:_dataArr[indexPath.row]];
  162. return cell;
  163. }
  164. return [super tableView:tableView cellForRowAtIndexPath:indexPath];
  165. }
  166. - (void)didReceiveMemoryWarning {
  167. [super didReceiveMemoryWarning];
  168. // Dispose of any resources that can be recreated.
  169. }
  170. /*
  171. #pragma mark - Navigation
  172. // In a storyboard-based application, you will often want to do a little preparation before navigation
  173. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  174. // Get the new view controller using [segue destinationViewController].
  175. // Pass the selected object to the new view controller.
  176. }
  177. */
  178. @end