// // PushManage_VC.m // Haishenghai-master // // Created by GG on 2019/1/4. // Copyright © 2019年 Haishenghai intelligence network technology. All rights reserved. // #import "PushManage_VC.h" #import "Header.h" #import "PushManageCell.h" @interface PushManage_VC () { NSMutableArray *siteIDArr; UIImageView *selectImage; NSString *mesStr; NSString *telStr; NSMutableArray *mesArr; NSMutableArray *telArr; } @end @implementation PushManage_VC - (void)viewDidLoad { [super viewDidLoad]; mesStr= @"0"; telStr= @"0"; self.navigationItem.title = @"推送设置"; self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:60/255.0 green:114/255.0 blue:255/255.0 alpha:1]; [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:18],NSForegroundColorAttributeName:[UIColor whiteColor]}]; UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [backBtn setImage:[UIImage imageNamed:@"hsh_return"] forState:UIControlStateNormal]; backBtn.frame = CGRectMake(0, 0, 44, 44); [backBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside]; backBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backBtn]; [self setupUI]; //集成下拉刷新控件 [self setupDownRefresh]; } -(void)backClick{ [self.navigationController popViewControllerAnimated:YES]; } -(void)setupUI{ _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, HEIGHT) style:UITableViewStylePlain]; // _tableView.backgroundColor = [UIColor grayColor]; _tableView.delegate = self; _tableView.dataSource = self; _tableView.userInteractionEnabled = YES; _tableView.showsHorizontalScrollIndicator=NO; _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; [self.view addSubview:_tableView]; } /** * 集成下拉刷新控件 */ - (void)setupDownRefresh { // 设置回调(一旦进入刷新状态,就调用target的action,也就是调用self的loadNewData方法) self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewDatas)]; //马上进入刷新状态 [self.tableView.mj_header beginRefreshing]; } -(void)loadNewDatas{ [self.dataArray removeAllObjects]; //请求数据 [DataSourceManager getSiteWithUrlPagesize:100 Page:1 completionBlock:^(NSMutableArray *array) { _dataArray = array; [_tableView reloadData]; //结束刷新 [self.tableView.mj_header endRefreshing]; mesArr = [[NSMutableArray alloc] init]; telArr = [[NSMutableArray alloc] init]; siteIDArr = [NSMutableArray array]; for (int i = 0; i<_dataArray.count; i++) { PlaceModel *model = _dataArray[i]; [telArr addObject:model.isTel]; [mesArr addObject:model.isMsg]; [siteIDArr addObject:model.Id]; } NSLog(@"telArr~~~~~%@",telArr); }]; [self.tableView.mj_header endRefreshing]; } #pragma mark-- tableviewDelegate -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return _dataArray.count; } -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 70; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *cellId = @"cell"; PushManageCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId]; if (!cell) { cell = [[PushManageCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellId]; } cell.selectionStyle = UITableViewCellSelectionStyleNone; PlaceModel *model = self.dataArray[indexPath.row]; cell.model = model; NSLog(@"--------site%@",model.Id); NSLog(@"model===%@",model.isTel); cell.titleLabel.text = model.deployment; // if ([model.isTel isEqualToString:@"1"]) { // [cell.selectTelBtn setImage:[UIImage imageNamed:@"hsh_news_choice_transforma"] forState:UIControlStateNormal]; // // }else if([model.isTel isEqualToString:@"0"]){ // [cell.selectTelBtn setImage:[UIImage imageNamed:@"hsh_news_choice"] forState:UIControlStateNormal]; // } // // if ([model.isMsg isEqualToString:@"1"]) { // [cell.selectMsgBtn setImage:[UIImage imageNamed:@"hsh_news_choice_transforma"] forState:UIControlStateNormal]; // // }else if([model.isMsg isEqualToString:@"0"]){ // [cell.selectMsgBtn setImage:[UIImage imageNamed:@"hsh_news_choice"] forState:UIControlStateNormal]; // // } cell.comitBtn.tag =indexPath.row; cell.selectMsgBtn.tag = 2000+indexPath.row; cell.selectTelBtn.tag = 1000+indexPath.row; [cell.comitBtn addTarget:self action:@selector(comitBtnClick:) forControlEvents:UIControlEventTouchUpInside]; [cell.selectTelBtn addTarget:self action:@selector(selectTelBtnClick:) forControlEvents:UIControlEventTouchUpInside]; [cell.selectMsgBtn addTarget:self action:@selector(selectMsgBtnClick:) forControlEvents:UIControlEventTouchUpInside]; return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath{ PlaceModel *model = [self.dataArray objectAtIndex:indexPath.section]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(void)selectTelBtnClick:(UIButton *)selectBtn{ if (selectBtn.selected) { NSString *telsStr = telArr[selectBtn.tag-1000]; NSLog(@"~~~~~~%@ %ld",telsStr,(long)selectBtn.tag); if ([telsStr isEqualToString:@"1"]) { [telArr replaceObjectAtIndex:selectBtn.tag-1000 withObject:@"0"]; }else{ [telArr replaceObjectAtIndex:selectBtn.tag-1000 withObject:@"1"]; } }else{ NSString *telsStr = telArr[selectBtn.tag-1000]; NSLog(@"~~~~~~%@ %ld",telsStr,(long)selectBtn.tag); if ([telsStr isEqualToString:@"1"]) { [telArr replaceObjectAtIndex:selectBtn.tag-1000 withObject:@"0"]; }else{ [telArr replaceObjectAtIndex:selectBtn.tag-1000 withObject:@"1"]; } } NSLog(@"telArr %@",telArr); selectBtn.selected = !selectBtn.selected; // if (selectBtn.selected ==YES) { //// telStr = @"1"; // [selectBtn setImage:[UIImage imageNamed:@"hsh_news_choice_transforma"] forState:UIControlStateNormal]; // // // }else{ //// telStr = @"0"; // [selectBtn setImage:[UIImage imageNamed:@"hsh_news_choice"] forState:UIControlStateSelected]; // // } } -(void)selectMsgBtnClick:(UIButton *)selectBtn{ if (selectBtn.selected) { NSString *messStr = mesArr[selectBtn.tag-2000]; NSLog(@"~~~~~~%@ %ld",messStr,(long)selectBtn.tag); if ([messStr isEqualToString:@"1"]) { [mesArr replaceObjectAtIndex:selectBtn.tag-2000 withObject:@"0"]; }else{ [mesArr replaceObjectAtIndex:selectBtn.tag-2000 withObject:@"1"]; } }else{ NSString *messStr = mesArr[selectBtn.tag-2000]; NSLog(@"~~~~~~%@ %ld",messStr,(long)selectBtn.tag); if ([messStr isEqualToString:@"1"]) { [mesArr replaceObjectAtIndex:selectBtn.tag-2000 withObject:@"0"]; }else{ [mesArr replaceObjectAtIndex:selectBtn.tag-2000 withObject:@"1"]; } } selectBtn.selected = !selectBtn.selected; } -(void)comitBtnClick:(UIButton *)comitBtn{ //在这里处理提交的逻辑,暂时未实现 telStr =telArr[comitBtn.tag]; mesStr =mesArr[comitBtn.tag]; NSLog(@"~~~~~~~%@",telStr); NSString *siteId = siteIDArr[comitBtn.tag]; [DataSourceManager updatePhonePushWithURlSiteID:siteId ISTel:telStr ISMsg:mesStr completionBlock:^(NSDictionary *dic) { [self loadNewDatas]; [self.tableView reloadData]; }]; } /* #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