WaringVC.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. //
  2. // WaringVC.m
  3. // LN_School
  4. //
  5. // Created by EchoShacolee on 2017/8/11.
  6. // Copyright © 2017年 Danson. All rights reserved.
  7. //
  8. #import "WaringVC.h"
  9. #import "WillDoCell.h"
  10. #import "MengBanView.h"
  11. #import "WaringDetailList.h"
  12. @interface WaringVC ()<UITableViewDelegate,UITableViewDataSource>
  13. {
  14. NSArray *_titleArray;
  15. NSMutableArray *_dataArray;
  16. UITableView *_tableView;
  17. MengBanView *_mengBanView;
  18. //条件参数
  19. NSString *_status;
  20. NSString *_start;
  21. NSString *_end;
  22. UIButton *_cancleWaring;//解除警报
  23. BOOL haveRequestPermission;
  24. }
  25. @end
  26. /*
  27. ydqj 遇到抢劫
  28. jtsg 交通事故
  29. clgz 车辆故障
  30. chaosu 超速报警
  31. gnssOpen 卫星定位
  32. gnssCut 天线状态
  33. powerOff 电源断电
  34. overStop 超时停车
  35. overBound 围栏越界
  36. collision 碰撞报警
  37. rollover 侧翻报警
  38. openDoor 非法开门报警
  39. */
  40. @implementation WaringVC
  41. - (void)viewDidLoad {
  42. [super viewDidLoad];
  43. self.navigationItem.title = @"车辆报警";
  44. self.navigationController.navigationBar.translucent = NO;
  45. [self customRightBtn];
  46. // [self createBottomBarWithtoolTitles:@[@"解除报警"]];
  47. if (_isNotification == NO)
  48. {
  49. //正常状态
  50. [self goBackByNavigation];
  51. }
  52. else
  53. {
  54. //推送状态 要将根视图变回去
  55. UIBarButtonItem* backBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back.png"] style:UIBarButtonItemStylePlain target:self action:@selector(dismissNavgation)];
  56. [backBtn setTintColor:defGreen];
  57. [self.navigationItem setLeftBarButtonItem:backBtn];
  58. }
  59. _status = @"1";
  60. _start = @"";
  61. _end = @"";
  62. _titleArray = @[@"遇到抢劫",@"交通事故",@"车辆故障",@"超速报警",@"卫星定位",@"天线状态",@"电源断电",@"超时停车",@"围栏越界",@"碰撞报警",@"侧翻报警",@"非法开门报警"];
  63. _dataArray = [NSMutableArray new];
  64. [Tools permissionValidationWithID:@"1265" view:self.view result:^(BOOL isCan, NSString *failureStr) {
  65. [self myInitWithPermission:isCan];
  66. [self getMacWarning];
  67. haveRequestPermission = YES;
  68. }];
  69. }
  70. -(void)dismissNavgation
  71. {
  72. [myDelegate initHomeVC];
  73. }
  74. -(void)viewWillAppear:(BOOL)animated{
  75. [super viewWillAppear:animated];
  76. if (haveRequestPermission) {
  77. [self getMacWarning];
  78. }
  79. }
  80. -(void)myInitWithPermission:(BOOL)permission{
  81. CGFloat bottomBtn_H = permission ? 50 : 0;
  82. UIButton *bottomBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  83. bottomBtn.backgroundColor = defGreen;
  84. bottomBtn.frame = CGRectMake(0, kFrame.size.height - kNavOffSet - bottomBtn_H-SafeAreaBottomHeight, kSize.width, bottomBtn_H);
  85. [bottomBtn setTitle:@"解除报警" textColor:[UIColor whiteColor] font:Font18 fotState:UIControlStateNormal];
  86. [bottomBtn target:self Tag:1];
  87. [self.view addSubview:bottomBtn];
  88. _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kFrame.size.width, kFrame.size.height - kNavOffSet-SafeAreaBottomHeight - bottomBtn_H) style:UITableViewStylePlain];
  89. _tableView.backgroundColor = KBackGroundColor;
  90. _tableView.showsVerticalScrollIndicator = NO;
  91. _tableView.rowHeight = 50.0f;
  92. _tableView.delegate = self;
  93. _tableView.dataSource = self;
  94. _tableView.tableFooterView = [UIView new];
  95. [self.view addSubview:_tableView];
  96. [_tableView registerNib:[UINib nibWithNibName:@"WillDoCell" bundle:nil] forCellReuseIdentifier:@"WillDoCellId"];
  97. UIView *view = [UIView new];
  98. _tableView.tableFooterView = view;
  99. }
  100. -(void)btnClick:(UIButton *)sender{
  101. UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:@"解除报警" message:@"您确定要解除所有报警信息吗?" preferredStyle:UIAlertControllerStyleAlert];
  102. [alertFind addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  103. }]];
  104. [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  105. [self removeMacWarning];
  106. }]];
  107. [self presentViewController:alertFind animated:true completion:nil];
  108. }
  109. -(void)customRightBtn{
  110. UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
  111. btn.frame = CGRectMake(0, 0, 43, 44);
  112. btn.titleLabel.font = [UIFont systemFontOfSize:17];
  113. [btn setTitle:@"筛选" forState:UIControlStateNormal];
  114. [btn setTitleColor:defGreen forState:UIControlStateNormal];
  115. [btn addTarget:self action:@selector(setMengbanView) forControlEvents:UIControlEventTouchUpInside];
  116. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
  117. }
  118. -(void)setMengbanView{
  119. if (_mengBanView) {
  120. [_mengBanView showView];
  121. return;
  122. }
  123. NSArray * btnarr = @[@"未解除",@"已解除"];
  124. NSString *start = @"开始时间";
  125. NSString *end = @"结束时间";
  126. NSArray * buttonsArray = @[@[@"1",btnarr],@[@"2",start],@[@"2",end]];
  127. _mengBanView = [[MengBanView alloc]initWithTitileStr:nil buttonsArray:buttonsArray isAllbtn:NO block:^(NSArray *array) {
  128. //确认解除报警 0 已解除 1 未解除(默认查未解除)
  129. if ([array[0] isEqualToString:@"已解除"]) {
  130. _status = @"0";
  131. }else if ([array[0] isEqualToString:@"未解除"]){
  132. _status = @"1";
  133. }
  134. if (![array[1] isEqualToString:@"开始时间"]) {
  135. _start = array[1];
  136. }
  137. if (![array[2] isEqualToString:@"结束时间"]) {
  138. _end = array[2];
  139. }
  140. [self getMacWarning];
  141. }];
  142. [_mengBanView showView];
  143. }
  144. #pragma mark tableview代理方法
  145. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  146. return _titleArray.count;
  147. }
  148. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  149. WillDoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WillDoCellId" forIndexPath:indexPath];
  150. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  151. cell.titleLabel.text = _titleArray[indexPath.row];
  152. CGFloat colorR = 200.0/_titleArray.count*indexPath.row;
  153. CGFloat colorG = 200.0/_titleArray.count*(_titleArray.count-indexPath.row);
  154. CGFloat colorB = 200.0/_titleArray.count*indexPath.row;
  155. cell.smallView.backgroundColor = RGB_COLOR(colorR, colorG, colorB);
  156. if (_dataArray.count == _titleArray.count) {
  157. NSString * str = [NSString stringWithFormat:@"%@",_dataArray[indexPath.row]];
  158. if ([str floatValue] == 0) {
  159. cell.markNumLabel.hidden = YES;
  160. }else{
  161. cell.markNumLabel.hidden = NO;
  162. cell.markNumLabel.text = str;
  163. if([str integerValue] > 999){
  164. cell.markNumLabel.text = @"999+";
  165. }
  166. }
  167. }
  168. return cell;
  169. }
  170. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  171. WaringDetailList * vc = [[WaringDetailList alloc] init];
  172. vc.navigationItem.title = _titleArray[indexPath.row];
  173. vc.startDate = _start;
  174. vc.endDate = _end;
  175. vc.status = _status;
  176. vc.type =[NSString stringWithFormat:@"%ld",(long)indexPath.row+1];
  177. [self navPushHideTabbarToVC:vc];
  178. }
  179. #pragma mark 创建BottomBarButton
  180. //-(void)createBottomBarWithtoolTitles:(NSArray *)toolTitles{
  181. //
  182. // float widthBtn = (kSize.width-1*toolTitles.count+1)/toolTitles.count;
  183. // float HeightBth = 50;
  184. //
  185. // for (int i=0; i<toolTitles.count; i++) {
  186. //
  187. // UIButton * button = [UIButton buttonWithType:UIButtonTypeSystem];
  188. // button.frame = CGRectMake(i*(widthBtn+1), kSize.height-HeightBth-knavoffset, widthBtn, HeightBth);
  189. // if (i == 1) {
  190. // [button setTitle:@"解除报警" forState:UIControlStateNormal];
  191. // _cancleWaring = button;
  192. // }else{
  193. // [button setTitle:toolTitles[i] forState:UIControlStateNormal];
  194. // }
  195. //
  196. // UIColor * color = defGreen;
  197. // button.backgroundColor = color;
  198. // [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  199. // [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
  200. // button.tag = 100+i;
  201. //
  202. // [self.view addSubview:button];
  203. // }
  204. //}
  205. //
  206. //- (void)buttonClick:(UIButton *)sender{
  207. //
  208. // UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:nil message:@"您确定要解除所有报警吗" preferredStyle:UIAlertControllerStyleAlert];
  209. //
  210. // [alertFind addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
  211. // [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  212. //
  213. // [self removeMacWarning];
  214. //
  215. // }]];
  216. // [self presentViewController:alertFind animated:true completion:nil];
  217. //
  218. //}
  219. //
  220. #pragma mark 网络请求
  221. -(void)getMacWarning{
  222. if (![NetManager connectedToNetWork]) {
  223. showMsgUnconnect();
  224. return;
  225. }
  226. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  227. [dic setObject:defUser.userDict[@"school"] forKey:@"schoolId"];
  228. [dic setObject:_status forKey:@"status"];
  229. [dic setObject:_start forKey:@"startTime"];
  230. [dic setObject:_end forKey:@"endTime"];
  231. NSString *method = @"getMacWarning";
  232. [MBProgressHUD showLoadToView:self.view];
  233. [NetManager requestAnythingWithURL:method dictionary:dic dataArray:nil completion:^(NSDictionary *root) {
  234. [MBProgressHUD hideHUDForView:self.view];
  235. if (!root) {
  236. ShowMsg(@"数据请求失败,请重试");
  237. return;
  238. }
  239. if ([root[@"code"] integerValue] == 1) {
  240. ShowMsg(root[@"msg"]);
  241. NSLog(@"%@",root[@"msg"]);
  242. return;
  243. }
  244. [_dataArray removeAllObjects];
  245. NSArray * keys = @[@"YDQJ",
  246. @"JTSG",
  247. @"CLGZ",
  248. @"CHAOSU",
  249. @"GNSSOPEN",
  250. @"GNSSCUT",
  251. @"POWEROFF",
  252. @"OVERSTOP",
  253. @"OVERBOUND",
  254. @"COLLISION",
  255. @"ROLLOVER",
  256. @"OPENDOOR"];
  257. NSDictionary * dic = root[@"body"];
  258. for (int i=0; i<keys.count; i++) {
  259. [_dataArray addObject:dic[keys[i]]];
  260. }
  261. [_tableView reloadData];
  262. }];
  263. }
  264. -(void)removeMacWarning{
  265. if (![NetManager connectedToNetWork]) {
  266. showMsgUnconnect();
  267. return;
  268. }
  269. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  270. [dic setObject:defUser.userDict[@"school"] forKey:@"schoolId"];
  271. [dic setObject:@"" forKey:@"sim"];
  272. NSString *method = @"removeMacWarning";
  273. [MBProgressHUD showLoadToView:self.view];
  274. [NetManager requestAnythingWithURL:method dictionary:dic dataArray:nil completion:^(NSDictionary *root) {
  275. [MBProgressHUD hideHUDForView:self.view];
  276. if (!root) {
  277. ShowMsg(@"数据请求失败,请重试");
  278. return;
  279. }
  280. if ([root[@"code"] integerValue] == 1) {
  281. ShowMsg(root[@"msg"]);
  282. return;
  283. }
  284. ShowMsg(@"操作成功");
  285. [self getMacWarning];
  286. }];
  287. }
  288. - (void)didReceiveMemoryWarning {
  289. [super didReceiveMemoryWarning];
  290. // Dispose of any resources that can be recreated.
  291. }
  292. /*
  293. #pragma mark - Navigation
  294. // In a storyboard-based application, you will often want to do a little preparation before navigation
  295. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  296. // Get the new view controller using [segue destinationViewController].
  297. // Pass the selected object to the new view controller.
  298. }
  299. */
  300. @end