CarDetail.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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. #import "UploadCarCredentials.h"
  11. @interface CarDetail ()
  12. {
  13. BOOL _isLock;//锁定状态
  14. UIButton * _locakBtn;//锁定/解锁
  15. NSArray * _dataArr;
  16. HolderView *_holderV;
  17. BOOL isPermission;//权限
  18. }
  19. @end
  20. @implementation CarDetail
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. [Tools permissionValidationWithID:@"29" view:self.view result:^(BOOL isCan, NSString *failureStr) {
  24. isPermission = isCan;
  25. [self myInit];
  26. }];
  27. }
  28. -(void)myInit{
  29. self.navigationItem.title = @"车辆详情";
  30. _dataArr = [[NSArray alloc]init];
  31. [self setSegmentControllWithTitles:@[@"基本信息",@"锁定历史记录",@"照片文件"] isBttomBar:NO];
  32. // [self createBottomBarWithtoolTitles:@[@"锁定/解锁"]];
  33. // [self createBottomBarWithtoolTitle:@"上传车辆行驶证"];
  34. [self getRequsetData];
  35. [self getLockRecords];
  36. UITableView * tabV = _tableViews[1];
  37. _holderV = [[HolderView alloc] initWithFrame:tabV.frame];
  38. [_holderV freshBlock:^{
  39. [self getLockRecords];
  40. }];
  41. [_mainScroolView addSubview:_holderV];
  42. }
  43. -(void)setData{
  44. _keysArr = @[
  45. // @[@"培训机构编号",@"TCO_INSCODE"],
  46. @[@"车牌号",@"TCO_LICNUM"],
  47. @[@"车牌颜色",@"TCO_PLATECOLOR"],
  48. @[@"生产厂家",@"TCO_MANUFACTURE"],
  49. @[@"车辆品牌",@"TCO_BRAND"],
  50. @[@"培训车型",@"TCO_PERDRITYPE"],
  51. @[@"车辆型号",@"TCO_MODEL"],
  52. @[@"车架号",@"TCO_FRANUM"],
  53. @[@"发动机号",@"TCO_ENGNUM"],
  54. @[@"购买日期",@"TCO_BUYDATE"],
  55. @[@"保单号",@"BDH"],
  56. @[@"保险金额(元)",@"BXJE"],
  57. @[@"保险缴纳时间",@"BXJNSJ"],
  58. @[@"保险有效时间(年)",@"BXYXSJ"],
  59. @[@"年检时间",@"NJSH"],
  60. @[@"下次年检时间",@"XCNJSH"],
  61. @[@"创建时间",@"TCO_CREATE_DATE"],
  62. @[@"全国统一编号",@"TCO_CARNUM"],
  63. @[@"备案日期",@"TCO_RECORD_DATE"],
  64. @[@"锁定状态",@"TCO_LOCK_STATUS"],
  65. @[@"锁定/解锁时间",@"TCO_LOCK_DATE"],
  66. ];
  67. [super setData];
  68. }
  69. -(void)getRequsetData{
  70. [self getDataWithDic:self.requesetDic method:@"cars" block:^(NSDictionary *successDic) {
  71. self.dataSource = [NSMutableDictionary dictionaryWithDictionary:successDic[@"body"][0]];
  72. [_tableViews[0] reloadData];
  73. _isLock = [[NSString stringWithFormat:@"%@",self.dataSource[@"TCO_LOCK_STATUS"]] isEqualToString:@"1"];
  74. [_locakBtn setTitle:_isLock ? @"解锁" : @"锁定" forState:UIControlStateNormal];
  75. [_tableViews[2] reloadData];
  76. }];
  77. }
  78. -(void)getLockRecords{
  79. //判断网络是否连接
  80. if (![NetManager connectedToNetWork]) {
  81. showMsgUnconnect();
  82. return;
  83. }
  84. NSMutableDictionary * mDic = [[NSMutableDictionary alloc]init];
  85. [mDic setObject:self.carNum forKey:@"qgcode"];
  86. [mDic setObject:@"3" forKey:@"type"];
  87. [MBProgressHUD showLoadToView:self.view];
  88. [NetManager requestAnythingWithURL:@"getLockRecords" dictionary:mDic dataArray:nil completion:^(NSDictionary *root) {
  89. [MBProgressHUD hideHUDForView:self.view];
  90. _holderV.hidden = NO;
  91. if (!root) {
  92. ShowMsg(@"数据请求失败,请重试");
  93. return;
  94. }
  95. if ([root[@"code"] integerValue] == 1) {
  96. ShowMsg(root[@"msg"]);
  97. return;
  98. }
  99. _dataArr = root[@"body"];
  100. if (_dataArr.count > 0) {
  101. _holderV.hidden = YES;
  102. }
  103. [_tableViews[1] reloadData];
  104. _isLock = [[NSString stringWithFormat:@"%@",self.dataSource[@"TCI_LOCK_STATUS"]] isEqualToString:@"1"];
  105. [_locakBtn setTitle:_isLock ? @"解锁" : @"锁定" forState:UIControlStateNormal];
  106. }];
  107. }
  108. #pragma mark 创建BottomBarButton
  109. -(void)createBottomBarWithtoolTitle:(NSString *)title{
  110. UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
  111. button.frame = CGRectMake(0, kSize.height-kNavOffSet-JOb_DETAIL_BOTTOMBAR_HEIGHT-SafeAreaBottomHeight, kSize.width, JOb_DETAIL_BOTTOMBAR_HEIGHT);
  112. button.backgroundColor = defGreen;
  113. [button setTitle:title textColor:[UIColor whiteColor] font:Font18 fotState:UIControlStateNormal];
  114. [button addTarget:self action:@selector(goToUploadCarCredentials) forControlEvents:UIControlEventTouchUpInside];
  115. [self.view addSubview:button];
  116. }
  117. -(void)goToUploadCarCredentials {
  118. // NSLog(@"carNum--->%@-----dataSource------>%@",self.carNum,self.dataSource);
  119. // UploadCarCredentials *uploadVC = [[UploadCarCredentials alloc] init];
  120. // uploadVC.carID = [NSString stringWithFormat:@"%@",self.dataSource[@"TCO_ID"]];
  121. // uploadVC.imgPath = self.dataSource[@"TCO_FILE_INFO"];
  122. // [self navPushHideTabbarToVC:uploadVC];
  123. [_seg setSelectedSegmentIndex:2];
  124. }
  125. -(void)createBottomBarWithtoolTitles:(NSArray *)toolTitles{
  126. float widthBtn = (kSize.width-1*toolTitles.count+1)/toolTitles.count;
  127. float HeightBth = JOb_DETAIL_BOTTOMBAR_HEIGHT;
  128. for (int i=0; i<toolTitles.count; i++) {
  129. UIButton * button = [UIButton buttonWithType:UIButtonTypeSystem];
  130. button.frame = CGRectMake(i*(widthBtn+1), kSize.height-kNavOffSet-HeightBth-SafeAreaBottomHeight, widthBtn, HeightBth);
  131. if (i == 0) {
  132. [button setTitle:@"锁定" forState:UIControlStateNormal];
  133. _locakBtn = button;
  134. }else{
  135. [button setTitle:toolTitles[i] forState:UIControlStateNormal];
  136. }
  137. UIColor * color = defGreen;
  138. button.backgroundColor = color;
  139. [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  140. [button addTarget:self action:@selector(lockReason) forControlEvents:UIControlEventTouchUpInside];
  141. button.tag = 100+i;
  142. [self.view addSubview:button];
  143. }
  144. }
  145. -(void)lockReason{
  146. NSString * title = _isLock ? @"解锁":@"锁定";
  147. NSString *message = [NSString stringWithFormat:@"请输入%@理由:",title];
  148. UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
  149. [alertFind addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
  150. textField.placeholder = [NSString stringWithFormat:@"(必须填写,否则将无法完成%@)",title];
  151. }];
  152. [alertFind addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
  153. [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  154. UITextField *tf = alertFind.textFields[0];
  155. if (tf.text.length > 0) {
  156. [self lockCarWithReason:tf.text];
  157. }else{
  158. ShowMsg(@"操作失败,请输入锁定/解锁理由");
  159. }
  160. }]];
  161. [self presentViewController:alertFind animated:true completion:nil];
  162. }
  163. -(void)lockCarWithReason:(NSString *)reason{
  164. NSMutableDictionary * mdic = [NSMutableDictionary new];
  165. [mdic setValue:defUser.userDict[@"id"] forKey:@"userId"];
  166. [mdic setValue:reason forKey:@"reason"];
  167. [mdic setValue:_isLock ? @"0" : @"1" forKey:@"status"];//类型 类型 1 锁定 0 解锁
  168. [mdic setValue:self.dataSource[@"TCO_CARNUM"] forKey:@"carnum"];
  169. [self getDataWithDic:mdic method:@"lockCar" block:^(NSDictionary *successdic) {
  170. //解锁成功,重新请求数据
  171. [self getRequsetData];
  172. [self getLockRecords];
  173. }];
  174. }
  175. #pragma mark 重写代理方法
  176. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  177. if ([_tableViews indexOfObject:tableView] == 1) {
  178. return _dataArr.count;
  179. }
  180. if ([_tableViews indexOfObject:tableView] == 2) {
  181. return 1;
  182. }
  183. return [super tableView:tableView numberOfRowsInSection:section];
  184. }
  185. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  186. if ([_tableViews indexOfObject:tableView] == 1) {
  187. return 44;
  188. }
  189. if ([_tableViews indexOfObject:tableView] == 2) {
  190. return kSize.height-kNavOffSet-JOb_DETAIL_SEGBAR_HEIGHT-SafeAreaBottomHeight;
  191. }
  192. return [super tableView:tableView heightForRowAtIndexPath:indexPath];
  193. }
  194. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  195. {
  196. if ([_tableViews indexOfObject:tableView] == 1) {
  197. LockCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"];
  198. if (!cell) {
  199. cell = [[[NSBundle mainBundle] loadNibNamed:@"LockCell" owner:nil options:nil]lastObject];
  200. }
  201. [cell upDataWithDic:_dataArr[indexPath.row]];
  202. return cell;
  203. }
  204. if ([_tableViews indexOfObject:tableView] == 2) {
  205. UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"];
  206. if (!cell) {
  207. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cellId"];
  208. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  209. }
  210. if (cell.contentView.subviews.count != 0) {
  211. [[cell.contentView.subviews lastObject] removeFromSuperview];
  212. }
  213. if (self.dataSource[@"TCO_ID"] == nil) {
  214. return cell;
  215. }
  216. UploadCarCredentials *uploadVC = [[UploadCarCredentials alloc] init];
  217. uploadVC.isPermission = isPermission;
  218. uploadVC.carID = [NSString stringWithFormat:@"%@",self.dataSource[@"TCO_ID"]];
  219. NSMutableArray *array = [NSMutableArray arrayWithCapacity:4];
  220. NSString *path = @"";
  221. if (self.dataSource[@"TCO_PHOTO_PATH"]) {
  222. path = self.dataSource[@"TCO_PHOTO_PATH"];
  223. }
  224. [array addObject:path];
  225. path = @"";
  226. if (self.dataSource[@"TCO_FILE_INFO"]) {
  227. path = self.dataSource[@"TCO_FILE_INFO"];
  228. }
  229. [array addObject:path];
  230. path = @"";
  231. if (self.dataSource[@"TCO_FILE_INFO2"]) {
  232. path = self.dataSource[@"TCO_FILE_INFO2"];
  233. }
  234. [array addObject:path];
  235. path = @"";
  236. if (self.dataSource[@"TCO_FILE_INFO3"]) {
  237. path = self.dataSource[@"TCO_FILE_INFO3"];
  238. }
  239. [array addObject:path];
  240. uploadVC.imgPathArray = array;
  241. uploadVC.view.height -= 64 + JOb_DETAIL_SEGBAR_HEIGHT;
  242. [self addChildViewController:uploadVC];
  243. [cell.contentView addSubview:uploadVC.view];
  244. return cell;
  245. }
  246. return [super tableView:tableView cellForRowAtIndexPath:indexPath];
  247. }
  248. - (void)didReceiveMemoryWarning {
  249. [super didReceiveMemoryWarning];
  250. // Dispose of any resources that can be recreated.
  251. }
  252. /*
  253. #pragma mark - Navigation
  254. // In a storyboard-based application, you will often want to do a little preparation before navigation
  255. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  256. // Get the new view controller using [segue destinationViewController].
  257. // Pass the selected object to the new view controller.
  258. }
  259. */
  260. @end