RegionsDetail.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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. NSString *str = sender.tag == 100 ? @"确定不通过审核" : @"确定通过审核";
  93. UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:@"审核" message:str preferredStyle:UIAlertControllerStyleAlert];
  94. [alertFind addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  95. }]];
  96. [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  97. if (sender.tag == 100) {
  98. [self auditRegionWithStatus:@"2"];
  99. }else if (sender.tag == 101){
  100. [self auditRegionWithStatus:@"1"];
  101. }
  102. }]];
  103. [self presentViewController:alertFind animated:true completion:nil];
  104. }
  105. #pragma mark 重写代理方法
  106. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  107. if ([_tableViews indexOfObject:tableView] != 0) {
  108. return 1;
  109. }
  110. return [_keysArr count];
  111. }
  112. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  113. if ([_tableViews indexOfObject:tableView] != 0) {
  114. return tableView.height;
  115. }
  116. return [super tableView:tableView heightForRowAtIndexPath:indexPath];
  117. }
  118. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  119. {
  120. UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"];
  121. if (!cell) {
  122. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cellId"];
  123. }
  124. if ([_tableViews indexOfObject:tableView] == 1) {
  125. [cell.contentView addSubview:_mapView];
  126. return cell;
  127. }else if ([_tableViews indexOfObject:tableView] == 2){
  128. if (cell.contentView.subviews.count != 0) {
  129. [[cell.contentView.subviews lastObject] removeFromSuperview];
  130. }
  131. TileViewController *vc = [[TileViewController alloc]initWithImageNames:_dataImgs];
  132. [self addChildViewController:vc];
  133. [cell.contentView addSubview:vc.view];
  134. return cell;
  135. }
  136. if ([_statusArr[indexPath.row] isEqualToNumber:@1]) {
  137. cell.detailTextLabel.numberOfLines = 0;
  138. cell.detailTextLabel.textAlignment = NSTextAlignmentLeft;
  139. }else{
  140. cell.detailTextLabel.numberOfLines = 1;
  141. cell.detailTextLabel.textAlignment = NSTextAlignmentRight;
  142. }
  143. NSString * key = _keysArr[indexPath.row][1];
  144. cell.textLabel.text = _keysArr[indexPath.row][0];
  145. if ([key isEqualToString:@"RI_TYPE"]) {
  146. NSString *sex = [NSString stringWithFormat:@"%@",self.dataSource[key]];
  147. cell.detailTextLabel.text = [sex isEqualToString:@"1"] ? @"第二部分" : @"第三部分" ;
  148. }else if ([key isEqualToString:@"RI_RECORD_STATUS"]){
  149. NSString *status = [NSString stringWithFormat:@"%@",self.dataSource[key]];
  150. cell.detailTextLabel.text = [status isEqualToString:@"1"] ? @"已备案" : @"未备案" ;
  151. }else if ([key isEqualToString:@"RI_NOTIFY_STATUS"]){
  152. NSString *status = [NSString stringWithFormat:@"%@",self.dataSource[key]];
  153. switch ([status integerValue]) {
  154. case 0:
  155. cell.detailTextLabel.text = @"未通知";
  156. break;
  157. case 1:
  158. cell.detailTextLabel.text = @"已通知";
  159. break;
  160. case 2:
  161. cell.detailTextLabel.text = @"通知失败";
  162. break;
  163. default:
  164. break;
  165. }
  166. }else if ([key isEqualToString:@"RI_AUDIT_STATUS"]){
  167. NSString *status = [NSString stringWithFormat:@"%@",self.dataSource[key]];
  168. switch ([status integerValue]) {
  169. case 0:
  170. cell.detailTextLabel.text = @"待审核";
  171. break;
  172. case 1:
  173. cell.detailTextLabel.text = @"审核通过";
  174. break;
  175. case 2:
  176. cell.detailTextLabel.text = @"审核不通过";
  177. break;
  178. default:
  179. break;
  180. }
  181. }else{
  182. cell.detailTextLabel.text = [NSString stringWithFormat:@"%@",self.dataSource[key]];
  183. }
  184. return cell;
  185. }
  186. #pragma mark 电子围栏相关
  187. -(void)creatDZWL{
  188. _mapView = [[BMKMapView alloc]initWithFrame:CGRectMake(0, 0, kSize.width,kSize.height-kNavOffSet)];
  189. //设置地图缩放级别
  190. [_mapView setZoomLevel:16];
  191. _mapView.mapType = BMKMapTypeStandard;
  192. _mapView.delegate = self;
  193. NSString * str = self.dataSource[@"RI_POLYGON"];
  194. NSArray * arr = [str componentsSeparatedByString:@";"];
  195. NSInteger k = arr.count-1;//最后一个为空
  196. CLLocationCoordinate2D * coords = malloc(k*sizeof(CLLocationCoordinate2D));
  197. for (int i = 0; i < k; i++) {
  198. NSArray * locationArr = [arr[i] componentsSeparatedByString:@","];
  199. coords[i].latitude = [locationArr[1] floatValue];
  200. coords[i].longitude = [locationArr[0] floatValue];
  201. if (i==1) {
  202. _mapView.centerCoordinate = coords[i];
  203. }
  204. }
  205. _polygo = [BMKPolygon polygonWithCoordinates:coords count:k];
  206. [_mapView addOverlay:_polygo];
  207. }
  208. //根据overlay生成对应的View
  209. - (BMKOverlayView *)mapView:(BMKMapView *)mapView viewForOverlay:(id <BMKOverlay>)overlay{
  210. BMKPolygonView* polygonView = [[BMKPolygonView alloc] initWithOverlay:overlay];
  211. polygonView.strokeColor = [[UIColor alloc] initWithRed:0.0 green:0 blue:0.5 alpha:1];
  212. polygonView.fillColor = [[UIColor alloc] initWithRed:0 green:1 blue:1 alpha:0.2];
  213. polygonView.lineWidth =2.0;
  214. polygonView.lineDash = (overlay == _polygo);
  215. return polygonView;
  216. }
  217. -(void)viewWillAppear:(BOOL)animated {
  218. [super viewWillAppear:animated];
  219. [_mapView viewWillAppear];
  220. _mapView.delegate = self; // 此处记得不用的时候需要置nil,否则影响内存的释放
  221. }
  222. -(void)viewWillDisappear:(BOOL)animated {
  223. [super viewWillDisappear:animated];
  224. [_mapView viewWillDisappear];
  225. _mapView.delegate = nil; // 不用时,置nil
  226. }
  227. - (void)didReceiveMemoryWarning {
  228. [super didReceiveMemoryWarning];
  229. // Dispose of any resources that can be recreated.
  230. }
  231. -(void)scrollViewDidScroll:(UIScrollView *)scrollView
  232. {
  233. if (scrollView.contentOffset.x >= kSize.width) {
  234. _mainScroolView.scrollEnabled = NO;
  235. UITableView * v = _tableViews[1];
  236. v.scrollEnabled = NO;
  237. }
  238. else {
  239. _mainScroolView.scrollEnabled = YES;
  240. }
  241. }
  242. #pragma mark 网络请求
  243. -(void)auditRegionWithStatus:(NSString *)status{
  244. NSMutableDictionary * mDic = [[NSMutableDictionary alloc]init];
  245. [mDic setObject:self.dataSource[@"RI_ID"] forKey:@"id"];
  246. [mDic setObject:status forKey:@"status"];
  247. [self getDataWithDic:mDic method:@"auditRegion" block:^(NSDictionary *successDic) {
  248. [self showMsgByMBWithString:@"审核成功!"];
  249. //审核完移除审核按钮
  250. // [_btn1 removeFromSuperview];
  251. // [_btn2 removeFromSuperview];
  252. //刷新待审核list
  253. if (self.block) {
  254. self.block();
  255. }
  256. [self.navigationController popViewControllerAnimated:YES];
  257. }];
  258. }
  259. -(void)getAreaImgs{
  260. //判断网络是否连接
  261. if (![NetworkManager connectedToNetWork]) {
  262. [self showMsgByAlertVCWithString:@"网络连接异常"];
  263. return;
  264. }
  265. NSMutableDictionary * mDic = [[NSMutableDictionary alloc]init];
  266. [mDic setObject:self.dataSource[@"RI_INSCODE"] forKey:@"inscode"];
  267. [mDic setObject:self.dataSource[@"RI_SEQ"] forKey:@"seq"];
  268. [MBProgressHUD hideHUDForView:self.view animated:NO];
  269. [MBProgressHUD showHUDAddedTo:self.view animated:NO];
  270. [NetworkManager requestWithMethod:@"getSchoolRegionImg" parameters:mDic type:0 handler:^(NSDictionary *successDic, NSString *failureStr) {
  271. _holderV.hidden = NO;
  272. [MBProgressHUD hideHUDForView:self.view animated:YES];
  273. if (failureStr) {
  274. [self showMsgByAlertVCWithString:failureStr];
  275. return;
  276. }
  277. if ([successDic[@"code"] isEqualToString:@"1"]) {
  278. [self showMsgByAlertVCWithString:successDic[@"msg"]];
  279. return;
  280. }
  281. [_dataImgs removeAllObjects];
  282. _dataImgs = successDic[@"body"];
  283. if (_dataImgs.count > 0) {
  284. _holderV.hidden = YES;
  285. }
  286. [_tableViews[2] reloadData];
  287. }];
  288. }
  289. @end