RegionsDetail.m 13 KB

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