// // RegionsDetail.m // LNManager // // Created by EchoShacolee on 2017/4/18. // Copyright © 2017年 lee. All rights reserved. // #import "RegionsDetail.h" #import #import "TZImageManager.h" #import "TZImagePickerController.h" #import "TileViewController.h" @interface RegionsDetail () { //审核button UIButton *_btn1; UIButton *_btn2; //电子围栏 BMKMapView * _mapView; BMKPolygon * _polygo; HolderView * _holderV; NSMutableArray *_dataImgs; /**从照片库挑选的所有照片 */ NSMutableArray *imageArray; } @end @implementation RegionsDetail - (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.title = @"教学区域详情"; _dataImgs = [[NSMutableArray alloc]init]; imageArray = [NSMutableArray array]; [self setSegmentControllWithTitles:@[@"基本信息",@"电子围栏",@"纸质图片"] isBttomBar:YES]; [self createBottomBarWithtoolTitles:@[@"上传纸质图片"]]; [self creatDZWL]; [self getAreaImgs]; UITableView *tableV = _tableViews[2]; _holderV = [[HolderView alloc]initWithFrame:tableV.frame]; [_holderV freshBlock:^{ [self getAreaImgs]; }]; [_mainScroolView addSubview:_holderV]; } -(void)setData{ _keysArr = @[ @[@"场地名称",@"RI_NAME"], @[@"类型",@"RI_TYPE"], @[@"地址",@"RI_ADDRESS"], @[@"场地编号",@"RI_SEQ"], @[@"场地面积(单位m2)",@"RI_AREA"], @[@"地址",@"RI_ADDRESS"], @[@"可容纳车辆",@"RI_TOTALVEHNUM"], @[@"已投放车辆数",@"RI_CURVEHNUM"], @[@"培训车型",@"RI_VEHICLETYPE"], @[@"备注",@"RI_REMARK"], // @[@"备案状态",@"RI_LOGOUT"], @[@"备案/解除备案时间",@"RI_RECORD_DATE"], @[@"启用状态",@"RI_IS_LOCK"], @[@"审核状态",@"RI_AUDIT_STATUS"], @[@"审核时间",@"RI_AUDIT_TIME"], @[@"审核意见",@"RI_AUDIT_INFO"], @[@"是否通过",@"RI_IS_THROUGH"], ]; [super setData]; } #pragma mark 创建BottomBarButton -(void)createBottomBarWithtoolTitles:(NSArray *)toolTitles{ float widthBtn = (kSize.width-1*toolTitles.count+1)/toolTitles.count; float HeightBth = JOb_DETAIL_BOTTOMBAR_HEIGHT; for (int i=0; i 24*1024) { //如果图片大于24kb 就使劲压缩 imgData = UIImageJPEGRepresentation(updataImg,0.1); } NSString *imgContent = [imgData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength]; [mStr appendString:[NSString stringWithFormat:@",%@",imgContent]]; } NSMutableDictionary * mDic = [[NSMutableDictionary alloc]init]; [mDic setObject:[mStr substringFromIndex:1] forKey:@"content"]; [mDic setObject:self.dataSource[@"RI_ID"] forKey:@"id"]; [NetManager requestAnythingWithURL:@"uploadAreas" dictionary:mDic dataArray:nil completion:^(NSDictionary *root) { if (!root) { [self showMsgByAlertVCWithString:@"文件过大,请尝试取消选择原图,重新上传"]; return; } if ([root[@"code"] integerValue] == 1) { ShowMsg(root[@"msg"]); return; } // [self getAreaImgs]; [_dataImgs removeAllObjects]; _dataImgs = [NSMutableArray arrayWithArray:[root[@"body"] componentsSeparatedByString:@","]]; //我就是要判断一下你咬我 if (_dataImgs.count > 0) { _holderV.hidden = YES; [_dataImgs removeObject:@""]; }else{ [self getAreaImgs]; } [_tableViews[2] reloadData]; }]; } -(void)getAreaImgs{ //判断网络是否连接 if (![NetManager connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableDictionary * mdic = [NSMutableDictionary new]; [mdic setValue:self.dataSource[@"RI_ID"] forKey:@"regionId"]; [mdic setValue:self.dataSource[@"RI_SCHOOL_ID"] forKey:@"schoolId"]; [NetManager requestAnythingWithURL:@"getAreaImgs" dictionary:mdic dataArray:nil completion:^(NSDictionary *root) { _holderV.hidden = NO; if (!root) { ShowMsg(@"数据请求失败,请重试"); return; } if ([root[@"code"] integerValue] == 1) { ShowMsg(root[@"msg"]); return; } if ([root[@"body"] length] == 0) { return; } [_dataImgs removeAllObjects]; _dataImgs = [NSMutableArray arrayWithArray:[root[@"body"] componentsSeparatedByString:@","]]; if (_dataImgs.count > 0) { _holderV.hidden = YES; } [_tableViews[2] reloadData]; }]; } #pragma mark 调用系统相册 -(void)upDatePhotos { [RQ_SHARE_FUNCTION getPhotosWithGetPhotosWay:GetPhotosWay_Album size:CGSizeMake(500, 500) maxLength:100 maxImagesCount:9 photosBlock:^(NSArray * _Nonnull imagesArr, NSArray * _Nonnull imagesDataStrArr) { ShowHUD();//不会太突兀 imageArray = [NSMutableArray arrayWithArray:imagesArr]; [self uploadAreas]; }]; } #pragma mark 重写代理方法 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ if ([_tableViews indexOfObject:tableView] != 0) { return 1; } return [_keysArr count]; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ if ([_tableViews indexOfObject:tableView] != 0) { return kSize.height-kNavOffSet-JOb_DETAIL_BOTTOMBAR_HEIGHT-JOb_DETAIL_SEGBAR_HEIGHT-kSafeAreaBottomHeight; } return [super tableView:tableView heightForRowAtIndexPath:indexPath]; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cellId"]; } if ([_tableViews indexOfObject:tableView] == 1) { [cell.contentView addSubview:_mapView]; return cell; }else if ([_tableViews indexOfObject:tableView] == 2){ if (cell.contentView.subviews.count != 0) { [[cell.contentView.subviews lastObject] removeFromSuperview]; } TileViewController *vc = [[TileViewController alloc]initWithImageNames:_dataImgs]; vc.view.height -= kNavOffSet+JOb_DETAIL_SEGBAR_HEIGHT+JOb_DETAIL_BOTTOMBAR_HEIGHT+kSafeAreaBottomHeight; [self addChildViewController:vc]; [cell.contentView addSubview:vc.view]; return cell; } NSString * key = _keysArr[indexPath.row][1]; cell.textLabel.text = _keysArr[indexPath.row][0]; if ([_statusArr[indexPath.row] isEqualToNumber:@1]) { cell.detailTextLabel.numberOfLines = 0; cell.detailTextLabel.textAlignment = NSTextAlignmentLeft; }else{ cell.detailTextLabel.numberOfLines = 1; cell.detailTextLabel.textAlignment = NSTextAlignmentRight; } if ([key isEqualToString:@"RI_TYPE"]) { NSString *sex = [NSString stringWithFormat:@"%@",self.dataSource[key]]; cell.detailTextLabel.text = [sex isEqualToString:@"1"] ? @"第二部分" : @"第三部分" ; }else if ([key isEqualToString:@"RI_IS_LOCK"]){//启用状态 0启用 1锁定 NSString *status = [NSString stringWithFormat:@"%@",self.dataSource[key]]; cell.detailTextLabel.text = [status isEqualToString:@"1"] ? @"锁定" : @"启用" ; }else if ([key isEqualToString:@"RI_LOGOUT"]){//状态,0正常,1注销 NSString *status = [NSString stringWithFormat:@"%@",self.dataSource[key]]; cell.detailTextLabel.text = [status isEqualToString:@"0"] ? @"正常" : @"注销" ; }else if ([key isEqualToString:@"RI_IS_THROUGH"]){ NSString *status = [NSString stringWithFormat:@"%@",self.dataSource[key]]; switch ([status integerValue]) {//是否通过: 0未通过; 1通过 case 0: cell.detailTextLabel.text = @"未通过"; break; case 1: cell.detailTextLabel.text = @"通过"; break; default: break; } }else if ([key isEqualToString:@"RI_AUDIT_STATUS"]){ NSString *status = [NSString stringWithFormat:@"%@",self.dataSource[key]]; switch ([status integerValue]) {//审核状态: 0未申请; 1审核中; 2已审核; case 0: cell.detailTextLabel.text = @"未申请"; break; case 1: cell.detailTextLabel.text = @"审核中"; break; case 2: cell.detailTextLabel.text = @"已审核"; break; default: break; } }else{ cell.detailTextLabel.text = [NSString stringWithFormat:@"%@",self.dataSource[_keysArr[indexPath.row][1]]]; } return cell; } #pragma mark 电子围栏相关 -(void)creatDZWL{ _mapView = [[BMKMapView alloc]initWithFrame:CGRectMake(0, 0, kSize.width,kSize.height-kNavOffSet-JOb_DETAIL_SEGBAR_HEIGHT-JOb_DETAIL_BOTTOMBAR_HEIGHT-kSafeAreaBottomHeight)]; //设置地图缩放级别 [_mapView setZoomLevel:16]; _mapView.mapType = BMKMapTypeStandard; _mapView.delegate = self; NSString * str = self.dataSource[@"RI_DZWL"]; NSString *newStr = [str stringByReplacingOccurrencesOfString:@"#" withString:@"\""]; NSData *data = [newStr dataUsingEncoding:NSUTF8StringEncoding]; if (!data) { ShowMsg(@"数据异常,解析失败"); } NSArray * arr = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; CLLocationCoordinate2D * coords = malloc(arr.count*sizeof(CLLocationCoordinate2D)); for (int i = 0; i < arr.count; i++) { NSDictionary * locationDic = arr[i]; coords[i].latitude = [locationDic[@"lat"] floatValue]; coords[i].longitude = [locationDic[@"lng"] floatValue]; if (i==1) { _mapView.centerCoordinate = coords[i]; } } _polygo = [BMKPolygon polygonWithCoordinates:coords count:arr.count]; [_mapView addOverlay:_polygo]; } //根据overlay生成对应的View - (BMKOverlayView *)mapView:(BMKMapView *)mapView viewForOverlay:(id )overlay{ BMKPolygonView* polygonView = [[BMKPolygonView alloc] initWithOverlay:overlay]; polygonView.strokeColor = [[UIColor alloc] initWithRed:0.0 green:0 blue:0.5 alpha:1]; polygonView.fillColor = [[UIColor alloc] initWithRed:0 green:1 blue:1 alpha:0.2]; polygonView.lineWidth =2.0; polygonView.lineDash = (overlay == _polygo); return polygonView; } -(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [_mapView viewWillAppear]; _mapView.delegate = self; // 此处记得不用的时候需要置nil,否则影响内存的释放 } -(void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [_mapView viewWillDisappear]; _mapView.delegate = nil; // 不用时,置nil } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(void)scrollViewDidScroll:(UIScrollView *)scrollView { if (scrollView.contentOffset.x >= kSize.width) { _mainScroolView.scrollEnabled = NO; UITableView * v = _tableViews[1]; v.scrollEnabled = NO; } else { _mainScroolView.scrollEnabled = YES; } } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end