RegionsDetail.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  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. #import <TZImageManager.h>
  12. #import <TZImagePickerController.h>
  13. @interface RegionsDetail ()<BMKMapViewDelegate,TZImagePickerControllerDelegate>
  14. {
  15. //审核button
  16. UIButton *_btn1;
  17. UIButton *_btn2;
  18. //电子围栏
  19. BMKMapView * _mapView;
  20. BMKPolygon * _polygo;
  21. HolderView * _holderV;
  22. NSMutableArray *_dataImgs;
  23. /**从照片库挑选的所有照片
  24. */
  25. NSMutableArray *imageArray;
  26. BOOL isPermission;
  27. }
  28. @end
  29. @implementation RegionsDetail
  30. - (void)viewDidLoad {
  31. [super viewDidLoad];
  32. self.navigationItem.title = @"教学区域详情";
  33. _dataImgs = [[NSMutableArray alloc]init];
  34. imageArray = [NSMutableArray array];
  35. [Tools permissionValidationWithID:@"47" view:self.view result:^(BOOL isCan, NSString *failureStr) {
  36. isPermission = isCan;
  37. if (isCan) {
  38. [self setSegmentControllWithTitles:@[@"基本信息",@"电子围栏",@"纸质图片"] isBttomBar:YES];
  39. [self createBottomBarWithtoolTitles:@[@"上传纸质图片"]];
  40. }else{
  41. [self setSegmentControllWithTitles:@[@"基本信息",@"电子围栏",@"纸质图片"] isBttomBar:NO];
  42. }
  43. [self creatDZWL];
  44. [self getAreaImgs];
  45. UITableView *tableV = _tableViews[2];
  46. _holderV = [[HolderView alloc]initWithFrame:tableV.frame];
  47. [_holderV freshBlock:^{
  48. [self getAreaImgs];
  49. }];
  50. [_mainScroolView addSubview:_holderV];
  51. }];
  52. }
  53. -(void)setData{
  54. _keysArr = @[
  55. @[@"场地名称",@"RI_NAME"],
  56. @[@"类型",@"RI_TYPE"],
  57. @[@"地址",@"RI_ADDRESS"],
  58. @[@"场地编号",@"RI_SEQ"],
  59. @[@"场地面积(单位m2)",@"RI_AREA"],
  60. @[@"地址",@"RI_ADDRESS"],
  61. @[@"可容纳车辆",@"RI_TOTALVEHNUM"],
  62. @[@"已投放车辆数",@"RI_CURVEHNUM"],
  63. @[@"培训车型",@"RI_VEHICLETYPE"],
  64. @[@"备注",@"RI_REMARK"],
  65. // @[@"备案状态",@"RI_LOGOUT"],
  66. @[@"备案/解除备案时间",@"RI_RECORD_DATE"],
  67. @[@"启用状态",@"RI_IS_LOCK"],
  68. @[@"审核状态",@"RI_AUDIT_STATUS"],
  69. @[@"审核时间",@"RI_AUDIT_TIME"],
  70. @[@"审核意见",@"RI_AUDIT_INFO"],
  71. @[@"是否通过",@"RI_IS_THROUGH"],
  72. ];
  73. [super setData];
  74. }
  75. #pragma mark 创建BottomBarButton
  76. -(void)createBottomBarWithtoolTitles:(NSArray *)toolTitles{
  77. float widthBtn = (kSize.width-1*toolTitles.count+1)/toolTitles.count;
  78. float HeightBth = JOb_DETAIL_BOTTOMBAR_HEIGHT;
  79. for (int i=0; i<toolTitles.count; i++) {
  80. UIButton * button = [UIButton buttonWithType:UIButtonTypeSystem];
  81. button.frame = CGRectMake(i*(widthBtn+1), kSize.height-HeightBth-kNavOffSet-SafeAreaBottomHeight, widthBtn, HeightBth);
  82. [button setTitle:toolTitles[i] forState:UIControlStateNormal];
  83. UIColor * color = defGreen;
  84. button.backgroundColor = color;
  85. [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  86. [button addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  87. button.tag = 100+i;
  88. if (i==0) {
  89. _btn1 = button;
  90. }else if (i==1){
  91. _btn2 = button;
  92. }
  93. [self.view addSubview:button];
  94. }
  95. }
  96. -(void)btnClick:(UIButton *)sender{
  97. //选择图片
  98. [self upDatePhotos];
  99. }
  100. #pragma mark 网络请求
  101. -(void)uploadAreas{
  102. NSMutableString *mStr = [NSMutableString new];
  103. for (UIImage *updataImg in imageArray) {
  104. NSData *imgData = UIImageJPEGRepresentation(updataImg,0.5);
  105. if (imgData.length > 24*1024) {
  106. //如果图片大于24kb 就使劲压缩
  107. imgData = UIImageJPEGRepresentation(updataImg,0.1);
  108. }
  109. NSString *imgContent = [imgData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
  110. [mStr appendString:[NSString stringWithFormat:@",%@",imgContent]];
  111. }
  112. NSMutableDictionary * mDic = [[NSMutableDictionary alloc]init];
  113. [mDic setObject:[mStr substringFromIndex:1] forKey:@"content"];
  114. [mDic setObject:self.dataSource[@"RI_ID"] forKey:@"id"];
  115. [NetManager requestAnythingWithURL:@"uploadAreas" dictionary:mDic dataArray:nil completion:^(NSDictionary *root) {
  116. [MBProgressHUD hideHUDForView:self.view];
  117. if (!root) {
  118. [self showMsgByAlertVCWithString:@"文件过大,请尝试取消选择原图,重新上传"];
  119. return;
  120. }
  121. ShowMsg(root[@"msg"]);
  122. if ([root[@"code"] integerValue] == 1) {
  123. return;
  124. }
  125. // [self getAreaImgs];
  126. [_dataImgs removeAllObjects];
  127. _dataImgs = [NSMutableArray arrayWithArray:[root[@"body"] componentsSeparatedByString:@","]];
  128. //我就是要判断一下
  129. if (_dataImgs.count > 0) {
  130. _holderV.hidden = YES;
  131. [_dataImgs removeObject:@""];
  132. }else{
  133. [self getAreaImgs];
  134. }
  135. [_tableViews[2] reloadData];
  136. self.currentIndex = 2;
  137. }];
  138. }
  139. -(void)getAreaImgs{
  140. //判断网络是否连接
  141. if (![NetManager connectedToNetWork]) {
  142. showMsgUnconnect();
  143. return;
  144. }
  145. NSMutableDictionary * mdic = [NSMutableDictionary new];
  146. [mdic setValue:self.dataSource[@"RI_ID"] forKey:@"regionId"];
  147. [mdic setValue:self.dataSource[@"RI_SCHOOL_ID"] forKey:@"schoolId"];
  148. [MBProgressHUD showLoadToView:self.view];
  149. [NetManager requestAnythingWithURL:@"getAreaImgs" dictionary:mdic dataArray:nil completion:^(NSDictionary *root) {
  150. [MBProgressHUD hideHUDForView:self.view];
  151. _holderV.hidden = NO;
  152. if (!root) {
  153. ShowMsg(@"数据请求失败,请重试");
  154. return;
  155. }
  156. if ([root[@"code"] integerValue] == 1) {
  157. ShowMsg(root[@"msg"]);
  158. return;
  159. }
  160. if ([root[@"body"] length] == 0) {
  161. return;
  162. }
  163. [_dataImgs removeAllObjects];
  164. _dataImgs = [NSMutableArray arrayWithArray:[root[@"body"] componentsSeparatedByString:@","]];
  165. if (_dataImgs.count > 0) {
  166. _holderV.hidden = YES;
  167. }
  168. [_tableViews[2] reloadData];
  169. }];
  170. }
  171. #pragma mark 调用系统相册
  172. -(void)upDatePhotos
  173. {
  174. [imageArray removeAllObjects];
  175. TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:9 delegate:self];
  176. // 通过block(或者代理),来得到用户选择的照片.
  177. [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets,BOOL isSelectOriginalPhoto) {
  178. [MBProgressHUD showLoadToView:self.view];//不会太突兀
  179. if (isSelectOriginalPhoto) {
  180. for (int i=0; i<assets.count; i++) {
  181. [[TZImageManager manager] getOriginalPhotoDataWithAsset:assets[i] completion:^(NSData *data, NSDictionary *info, BOOL isDegraded) {
  182. //始终返回isDegraded == no 不参与判断
  183. [imageArray addObject:[UIImage imageWithData:data]];
  184. if (i == assets.count-1) {
  185. [self uploadAreas];
  186. }
  187. }];
  188. }
  189. }else{
  190. imageArray = [NSMutableArray arrayWithArray:photos];
  191. [self uploadAreas];
  192. }
  193. }];
  194. [self presentViewController:imagePickerVc animated:YES completion:nil];
  195. }
  196. #pragma mark 重写代理方法
  197. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  198. if ([_tableViews indexOfObject:tableView] != 0) {
  199. return 1;
  200. }
  201. return [_keysArr count];
  202. }
  203. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  204. if ([_tableViews indexOfObject:tableView] != 0) {
  205. return kSize.height-kNavOffSet-JOb_DETAIL_SEGBAR_HEIGHT-SafeAreaBottomHeight - (isPermission?JOb_DETAIL_BOTTOMBAR_HEIGHT:0);
  206. }
  207. return [super tableView:tableView heightForRowAtIndexPath:indexPath];
  208. }
  209. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  210. {
  211. UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"];
  212. if (!cell) {
  213. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cellId"];
  214. }
  215. if ([_tableViews indexOfObject:tableView] == 1) {
  216. [cell.contentView addSubview:_mapView];
  217. return cell;
  218. }else if ([_tableViews indexOfObject:tableView] == 2){
  219. if (cell.contentView.subviews.count != 0) {
  220. [[cell.contentView.subviews lastObject] removeFromSuperview];
  221. }
  222. TileViewController *vc = [[TileViewController alloc]initWithImageNames:_dataImgs];
  223. CGFloat height = kNavOffSet+JOb_DETAIL_SEGBAR_HEIGHT;
  224. height += isPermission ? JOb_DETAIL_BOTTOMBAR_HEIGHT + SafeAreaBottomHeight: 0;
  225. vc.view.height -= height;
  226. [self addChildViewController:vc];
  227. [cell.contentView addSubview:vc.view];
  228. return cell;
  229. }
  230. NSString * key = _keysArr[indexPath.row][1];
  231. cell.textLabel.text = _keysArr[indexPath.row][0];
  232. if ([_statusArr[indexPath.row] isEqualToNumber:@1]) {
  233. cell.detailTextLabel.numberOfLines = 0;
  234. cell.detailTextLabel.textAlignment = NSTextAlignmentLeft;
  235. }else{
  236. cell.detailTextLabel.numberOfLines = 1;
  237. cell.detailTextLabel.textAlignment = NSTextAlignmentRight;
  238. }
  239. if ([key isEqualToString:@"RI_TYPE"]) {
  240. NSString *sex = [NSString stringWithFormat:@"%@",self.dataSource[key]];
  241. cell.detailTextLabel.text = [sex isEqualToString:@"1"] ? @"第二部分" : @"第三部分" ;
  242. }else if ([key isEqualToString:@"RI_IS_LOCK"]){//启用状态 0启用 1锁定
  243. NSString *status = [NSString stringWithFormat:@"%@",self.dataSource[key]];
  244. cell.detailTextLabel.text = [status isEqualToString:@"1"] ? @"锁定" : @"启用" ;
  245. }else if ([key isEqualToString:@"RI_LOGOUT"]){//状态,0正常,1注销
  246. NSString *status = [NSString stringWithFormat:@"%@",self.dataSource[key]];
  247. cell.detailTextLabel.text = [status isEqualToString:@"0"] ? @"正常" : @"注销" ;
  248. }else if ([key isEqualToString:@"RI_IS_THROUGH"]){
  249. NSString *status = [NSString stringWithFormat:@"%@",self.dataSource[key]];
  250. switch ([status integerValue]) {//是否通过: 0未通过; 1通过
  251. case 0:
  252. cell.detailTextLabel.text = @"未通过";
  253. break;
  254. case 1:
  255. cell.detailTextLabel.text = @"通过";
  256. break;
  257. default:
  258. break;
  259. }
  260. }else if ([key isEqualToString:@"RI_AUDIT_STATUS"]){
  261. NSString *status = [NSString stringWithFormat:@"%@",self.dataSource[key]];
  262. switch ([status integerValue]) {//审核状态: 0未申请; 1审核中; 2已审核;
  263. case 0:
  264. cell.detailTextLabel.text = @"未申请";
  265. break;
  266. case 1:
  267. cell.detailTextLabel.text = @"审核中";
  268. break;
  269. case 2:
  270. cell.detailTextLabel.text = @"已审核";
  271. break;
  272. default:
  273. break;
  274. }
  275. }else{
  276. cell.detailTextLabel.text = [NSString stringWithFormat:@"%@",self.dataSource[_keysArr[indexPath.row][1]]];
  277. }
  278. return cell;
  279. }
  280. #pragma mark 电子围栏相关
  281. -(void)creatDZWL{
  282. CGFloat height = kSize.height-kNavOffSet-JOb_DETAIL_SEGBAR_HEIGHT;
  283. height -= isPermission ? JOb_DETAIL_BOTTOMBAR_HEIGHT + SafeAreaBottomHeight : 0;
  284. _mapView = [[BMKMapView alloc]initWithFrame:CGRectMake(0, 0, kSize.width,height)];
  285. //设置地图缩放级别
  286. [_mapView setZoomLevel:16];
  287. _mapView.mapType = BMKMapTypeStandard;
  288. _mapView.delegate = self;
  289. NSString * str = self.dataSource[@"RI_DZWL"];
  290. NSString *newStr = [str stringByReplacingOccurrencesOfString:@"#" withString:@"\""];
  291. NSData *data = [newStr dataUsingEncoding:NSUTF8StringEncoding];
  292. if (!data) {
  293. ShowMsg(@"数据异常,解析失败");
  294. }
  295. NSArray * arr = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
  296. CLLocationCoordinate2D * coords = malloc(arr.count*sizeof(CLLocationCoordinate2D));
  297. for (int i = 0; i < arr.count; i++) {
  298. NSDictionary * locationDic = arr[i];
  299. coords[i].latitude = [locationDic[@"lat"] floatValue];
  300. coords[i].longitude = [locationDic[@"lng"] floatValue];
  301. if (i==1) {
  302. _mapView.centerCoordinate = coords[i];
  303. }
  304. }
  305. _polygo = [BMKPolygon polygonWithCoordinates:coords count:arr.count];
  306. [_mapView addOverlay:_polygo];
  307. }
  308. //根据overlay生成对应的View
  309. - (BMKOverlayView *)mapView:(BMKMapView *)mapView viewForOverlay:(id <BMKOverlay>)overlay{
  310. BMKPolygonView* polygonView = [[BMKPolygonView alloc] initWithOverlay:overlay];
  311. polygonView.strokeColor = [[UIColor alloc] initWithRed:0.0 green:0 blue:0.5 alpha:1];
  312. polygonView.fillColor = [[UIColor alloc] initWithRed:0 green:1 blue:1 alpha:0.2];
  313. polygonView.lineWidth =2.0;
  314. polygonView.lineDash = (overlay == _polygo);
  315. return polygonView;
  316. }
  317. -(void)viewWillAppear:(BOOL)animated {
  318. [super viewWillAppear:animated];
  319. [_mapView viewWillAppear];
  320. _mapView.delegate = self; // 此处记得不用的时候需要置nil,否则影响内存的释放
  321. }
  322. -(void)viewWillDisappear:(BOOL)animated {
  323. [super viewWillDisappear:animated];
  324. [_mapView viewWillDisappear];
  325. _mapView.delegate = nil; // 不用时,置nil
  326. }
  327. - (void)didReceiveMemoryWarning {
  328. [super didReceiveMemoryWarning];
  329. // Dispose of any resources that can be recreated.
  330. }
  331. -(void)scrollViewDidScroll:(UIScrollView *)scrollView
  332. {
  333. if (scrollView.contentOffset.x >= kSize.width) {
  334. _mainScroolView.scrollEnabled = NO;
  335. UITableView * v = _tableViews[1];
  336. v.scrollEnabled = NO;
  337. }
  338. else {
  339. _mainScroolView.scrollEnabled = YES;
  340. }
  341. }
  342. /*
  343. #pragma mark - Navigation
  344. // In a storyboard-based application, you will often want to do a little preparation before navigation
  345. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  346. // Get the new view controller using [segue destinationViewController].
  347. // Pass the selected object to the new view controller.
  348. }
  349. */
  350. @end