RegionsDetail.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. //
  2. // RegionsDetail.m
  3. // LNManager
  4. //
  5. // Created by EchoShacolee on 2017/4/18.
  6. // Copyright © 2017年 lee. All rights reserved.
  7. //
  8. #import "RegionsDetail.h"
  9. #import <BaiduMapAPI_Map/BMKMapComponent.h>
  10. #import "TileViewController.h"
  11. @interface RegionsDetail ()<BMKMapViewDelegate>
  12. {
  13. //审核button
  14. UIButton *_btn1;
  15. UIButton *_btn2;
  16. //电子围栏
  17. BMKMapView* _mapView;
  18. BMKPolygon * _polygo;
  19. HolderView *_holderV;
  20. NSMutableArray *_dataImgs;
  21. }
  22. @end
  23. @implementation RegionsDetail
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. self.navigationItem.title = @"教学区域详情";
  27. _dataImgs = [[NSMutableArray alloc]init];
  28. [self setSegmentControllWithTitles:@[@"基本信息",@"电子围栏",@"纸质图片"]];
  29. if ([[NSString stringWithFormat:@"%@",self.dataSource[@"RI_AUDIT_STATUS"]] integerValue] == 0) {
  30. [self createBottomBarWithtoolTitles:@[@"不通过审核",@"通过审核"]];
  31. }
  32. [self creatDZWL];
  33. [self getAreaImgs];
  34. UITableView *tableV = _tableViews[2];
  35. _holderV = [[HolderView alloc]initWithFrame:tableV.frame];
  36. [_holderV freshBlock:^{
  37. [self getAreaImgs];
  38. }];
  39. [_mainScroolView addSubview:_holderV];
  40. }
  41. -(void)setData{
  42. _keysArr = @[
  43. @[@"教学区域名称",@"RI_NAME"],
  44. @[@"教学区域类型",@"RI_TYPE"],
  45. @[@"教学区域地址",@"RI_ADDRESS"],
  46. @[@"教学区域编号",@"RI_SEQ"],
  47. @[@"教学区域面积(单位m2)",@"RI_AREA"],
  48. @[@"可容纳车辆",@"RI_TOTALVEHNUM"],
  49. @[@"已投放车辆数",@"RI_CURVEHNUM"],
  50. @[@"培训车型",@"RI_VEHICLETYPE"],
  51. @[@"培训机构编码",@"RI_INSCODE"],
  52. @[@"启用标识",@"RI_FLAG"],
  53. @[@"原因(不同意启用的原因)",@"RI_REASON"],
  54. @[@"审核状态",@"RI_AUDIT_STATUS"],
  55. @[@"审核操作时间",@"RI_AUDIT_TIME"],
  56. @[@"通知状态",@"RI_NOTIFY_STATUS"],
  57. @[@"通知时间",@"RI_NOTIFY_TIME"],
  58. @[@"备案状态",@"RI_RECORD_STATUS"],
  59. @[@"备案/解除备案时间",@"RI_RECORD_TIME"]
  60. ];
  61. [super setData];
  62. }
  63. #pragma mark 创建BottomBarButton
  64. -(void)createBottomBarWithtoolTitles:(NSArray *)toolTitles{
  65. CGRect newFrame = CGRectMake(0, kNavOffSet+JOb_DETAIL_SEGBAR_HEIGHT, kSize.width, kSize.height-kNavOffSet-JOb_DETAIL_SEGBAR_HEIGHT-JOb_DETAIL_BOTTOMBAR_HEIGHT-SafeAreaBottomHeight);
  66. _mainScroolView.frame = newFrame;
  67. int i=0;
  68. for (UIView *view in _mainScroolView.subviews) {
  69. CGRect newFrame = CGRectMake(kSize.width*i++, 0, kSize.width, kSize.height-kNavOffSet-JOb_DETAIL_SEGBAR_HEIGHT-JOb_DETAIL_BOTTOMBAR_HEIGHT-SafeAreaBottomHeight);
  70. view.frame = newFrame;
  71. }
  72. float widthBtn = (kSize.width-1*toolTitles.count+1)/toolTitles.count;
  73. float HeightBth = JOb_DETAIL_BOTTOMBAR_HEIGHT;
  74. for (int i=0; i<toolTitles.count; i++) {
  75. UIButton * button = [UIButton buttonWithType:UIButtonTypeSystem];
  76. button.frame = CGRectMake(i*(widthBtn+1), kSize.height-HeightBth-SafeAreaBottomHeight, widthBtn, HeightBth);
  77. [button setTitle:toolTitles[i] forState:UIControlStateNormal];
  78. UIColor * color = COLOR_THEME;
  79. button.backgroundColor = color;
  80. [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  81. [button addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  82. button.tag = 100+i;
  83. if (i==0) {
  84. _btn1 = button;
  85. }else if (i==1){
  86. _btn2 = button;
  87. }
  88. [self.view addSubview:button];
  89. }
  90. }
  91. -(void)btnClick:(UIButton *)sender{
  92. if (sender.tag == 100) {
  93. [self auditRegionWithStatus:@"2"];
  94. }else if (sender.tag == 101){
  95. [self auditRegionWithStatus:@"1"];
  96. }
  97. }
  98. #pragma mark 重写代理方法
  99. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  100. if ([_tableViews indexOfObject:tableView] != 0) {
  101. return 1;
  102. }
  103. return [_keysArr count];
  104. }
  105. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  106. if ([_tableViews indexOfObject:tableView] != 0) {
  107. return kSize.height-64-40;
  108. }
  109. return [super tableView:tableView heightForRowAtIndexPath:indexPath];
  110. }
  111. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  112. {
  113. UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"];
  114. if (!cell) {
  115. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cellId"];
  116. }
  117. if ([_tableViews indexOfObject:tableView] == 1) {
  118. [cell.contentView addSubview:_mapView];
  119. return cell;
  120. }else if ([_tableViews indexOfObject:tableView] == 2){
  121. if (cell.contentView.subviews.count != 0) {
  122. [[cell.contentView.subviews lastObject] removeFromSuperview];
  123. }
  124. TileViewController *vc = [[TileViewController alloc]initWithImageNames:_dataImgs];
  125. [self addChildViewController:vc];
  126. [cell.contentView addSubview:vc.view];
  127. return cell;
  128. }
  129. if ([_statusArr[indexPath.row] isEqualToNumber:@1]) {
  130. cell.detailTextLabel.numberOfLines = 0;
  131. cell.detailTextLabel.textAlignment = NSTextAlignmentLeft;
  132. }else{
  133. cell.detailTextLabel.numberOfLines = 1;
  134. cell.detailTextLabel.textAlignment = NSTextAlignmentRight;
  135. }
  136. NSString * key = _keysArr[indexPath.row][1];
  137. cell.textLabel.text = _keysArr[indexPath.row][0];
  138. if ([key isEqualToString:@"RI_TYPE"]) {
  139. NSString *sex = [NSString stringWithFormat:@"%@",self.dataSource[key]];
  140. cell.detailTextLabel.text = [sex isEqualToString:@"1"] ? @"第二部分" : @"第三部分" ;
  141. }else if ([key isEqualToString:@"RI_RECORD_STATUS"]){
  142. NSString *status = [NSString stringWithFormat:@"%@",self.dataSource[key]];
  143. cell.detailTextLabel.text = [status isEqualToString:@"1"] ? @"已备案" : @"未备案" ;
  144. }else if ([key isEqualToString:@"RI_NOTIFY_STATUS"]){
  145. NSString *status = [NSString stringWithFormat:@"%@",self.dataSource[key]];
  146. switch ([status integerValue]) {
  147. case 1:
  148. cell.detailTextLabel.text = @"未通知";
  149. break;
  150. case 2:
  151. cell.detailTextLabel.text = @"已通知";
  152. break;
  153. case 3:
  154. cell.detailTextLabel.text = @"通知失败";
  155. break;
  156. default:
  157. break;
  158. }
  159. }else if ([key isEqualToString:@"RI_AUDIT_STATUS"]){
  160. NSString *status = [NSString stringWithFormat:@"%@",self.dataSource[key]];
  161. switch ([status integerValue]) {
  162. case 1:
  163. cell.detailTextLabel.text = @"待审核";
  164. break;
  165. case 2:
  166. cell.detailTextLabel.text = @"审核通过";
  167. break;
  168. case 3:
  169. cell.detailTextLabel.text = @"审核不通过";
  170. break;
  171. default:
  172. break;
  173. }
  174. }else{
  175. cell.detailTextLabel.text = [NSString stringWithFormat:@"%@",self.dataSource[key]];
  176. }
  177. return cell;
  178. }
  179. #pragma mark 电子围栏相关
  180. -(void)creatDZWL{
  181. _mapView = [[BMKMapView alloc]initWithFrame:CGRectMake(0, 0, kSize.width,kSize.height-64)];
  182. //设置地图缩放级别
  183. [_mapView setZoomLevel:16];
  184. _mapView.mapType = BMKMapTypeStandard;
  185. _mapView.delegate = self;
  186. NSString * str = self.dataSource[@"RI_POLYGON"];
  187. NSArray * arr = [str componentsSeparatedByString:@";"];
  188. NSInteger k = arr.count-1;//最后一个为空
  189. CLLocationCoordinate2D * coords = malloc(k*sizeof(CLLocationCoordinate2D));
  190. for (int i = 0; i < k; i++) {
  191. NSArray * locationArr = [arr[i] componentsSeparatedByString:@","];
  192. coords[i].latitude = [locationArr[1] floatValue];
  193. coords[i].longitude = [locationArr[0] floatValue];
  194. if (i==1) {
  195. _mapView.centerCoordinate = coords[i];
  196. }
  197. }
  198. _polygo = [BMKPolygon polygonWithCoordinates:coords count:k];
  199. [_mapView addOverlay:_polygo];
  200. }
  201. //根据overlay生成对应的View
  202. - (BMKOverlayView *)mapView:(BMKMapView *)mapView viewForOverlay:(id <BMKOverlay>)overlay{
  203. BMKPolygonView* polygonView = [[BMKPolygonView alloc] initWithOverlay:overlay];
  204. polygonView.strokeColor = [[UIColor alloc] initWithRed:0.0 green:0 blue:0.5 alpha:1];
  205. polygonView.fillColor = [[UIColor alloc] initWithRed:0 green:1 blue:1 alpha:0.2];
  206. polygonView.lineWidth =2.0;
  207. polygonView.lineDash = (overlay == _polygo);
  208. return polygonView;
  209. }
  210. -(void)viewWillAppear:(BOOL)animated {
  211. [super viewWillAppear:animated];
  212. [_mapView viewWillAppear];
  213. _mapView.delegate = self; // 此处记得不用的时候需要置nil,否则影响内存的释放
  214. }
  215. -(void)viewWillDisappear:(BOOL)animated {
  216. [super viewWillDisappear:animated];
  217. [_mapView viewWillDisappear];
  218. _mapView.delegate = nil; // 不用时,置nil
  219. }
  220. - (void)didReceiveMemoryWarning {
  221. [super didReceiveMemoryWarning];
  222. // Dispose of any resources that can be recreated.
  223. }
  224. -(void)scrollViewDidScroll:(UIScrollView *)scrollView
  225. {
  226. if (scrollView.contentOffset.x >= kSize.width) {
  227. _mainScroolView.scrollEnabled = NO;
  228. UITableView * v = _tableViews[1];
  229. v.scrollEnabled = NO;
  230. }
  231. else {
  232. _mainScroolView.scrollEnabled = YES;
  233. }
  234. }
  235. #pragma mark 网络请求
  236. -(void)auditRegionWithStatus:(NSString *)status{
  237. NSMutableDictionary * mDic = [[NSMutableDictionary alloc]init];
  238. [mDic setObject:self.dataSource[@"RI_ID"] forKey:@"id"];
  239. [mDic setObject:status forKey:@"status"];
  240. [self getDataWithDic:mDic method:@"auditRegion" block:^(NSDictionary *successDic) {
  241. [self showMsgByMBWithString:@"审核成功!"];
  242. //审核完移除审核按钮
  243. // [_btn1 removeFromSuperview];
  244. // [_btn2 removeFromSuperview];
  245. //刷新待审核list
  246. if (self.block) {
  247. self.block();
  248. }
  249. [self.navigationController popViewControllerAnimated:YES];
  250. }];
  251. }
  252. -(void)getAreaImgs{
  253. //判断网络是否连接
  254. if (![NetworkManager connectedToNetWork]) {
  255. [self showMsgByAlertVCWithString:@"网络连接异常"];
  256. return;
  257. }
  258. NSMutableDictionary * mDic = [[NSMutableDictionary alloc]init];
  259. [mDic setObject:self.dataSource[@"RI_INSCODE"] forKey:@"inscode"];
  260. [mDic setObject:self.dataSource[@"RI_SEQ"] forKey:@"seq"];
  261. [MBProgressHUD hideHUDForView:self.view animated:NO];//强行先掉一次@lee
  262. [MBProgressHUD showHUDAddedTo:self.view animated:NO];
  263. [NetworkManager requestWithMethod:@"getSchoolRegionImg" parameters:mDic type:0 handler:^(NSDictionary *successDic, NSString *failureStr) {
  264. _holderV.hidden = NO;
  265. [MBProgressHUD hideHUDForView:self.view animated:YES];
  266. if (failureStr) {
  267. [self showMsgByAlertVCWithString:failureStr];
  268. return;
  269. }
  270. if ([successDic[@"code"] isEqualToString:@"1"]) {
  271. [self showMsgByAlertVCWithString:successDic[@"msg"]];
  272. return;
  273. }
  274. [_dataImgs removeAllObjects];
  275. _dataImgs = successDic[@"body"];
  276. if (_dataImgs.count > 0) {
  277. _holderV.hidden = YES;
  278. }
  279. [_tableViews[2] reloadData];
  280. }];
  281. }
  282. @end