PushManage_VC.m 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. //
  2. // PushManage_VC.m
  3. // Haishenghai-master
  4. //
  5. // Created by GG on 2019/1/4.
  6. // Copyright © 2019年 Haishenghai intelligence network technology. All rights reserved.
  7. //
  8. #import "PushManage_VC.h"
  9. #import "Header.h"
  10. #import "PushManageCell.h"
  11. @interface PushManage_VC ()<UITableViewDelegate,UITableViewDataSource,UIGestureRecognizerDelegate>
  12. {
  13. NSMutableArray *siteIDArr;
  14. UIImageView *selectImage;
  15. NSString *mesStr;
  16. NSString *telStr;
  17. NSMutableArray *mesArr;
  18. NSMutableArray *telArr;
  19. }
  20. @end
  21. @implementation PushManage_VC
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. mesStr= @"0";
  25. telStr= @"0";
  26. self.navigationItem.title = @"推送设置";
  27. self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:60/255.0 green:114/255.0 blue:255/255.0 alpha:1];
  28. [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:18],NSForegroundColorAttributeName:[UIColor whiteColor]}];
  29. UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  30. [backBtn setImage:[UIImage imageNamed:@"hsh_return"] forState:UIControlStateNormal];
  31. backBtn.frame = CGRectMake(0, 0, 44, 44);
  32. [backBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
  33. backBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  34. self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backBtn];
  35. [self setupUI];
  36. //集成下拉刷新控件
  37. [self setupDownRefresh];
  38. }
  39. -(void)backClick{
  40. [self.navigationController popViewControllerAnimated:YES];
  41. }
  42. -(void)setupUI{
  43. _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, HEIGHT) style:UITableViewStylePlain];
  44. // _tableView.backgroundColor = [UIColor grayColor];
  45. _tableView.delegate = self;
  46. _tableView.dataSource = self;
  47. _tableView.userInteractionEnabled = YES;
  48. _tableView.showsHorizontalScrollIndicator=NO;
  49. _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  50. [self.view addSubview:_tableView];
  51. }
  52. /**
  53. * 集成下拉刷新控件
  54. */
  55. - (void)setupDownRefresh
  56. {
  57. // 设置回调(一旦进入刷新状态,就调用target的action,也就是调用self的loadNewData方法)
  58. self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewDatas)];
  59. //马上进入刷新状态
  60. [self.tableView.mj_header beginRefreshing];
  61. }
  62. -(void)loadNewDatas{
  63. [self.dataArray removeAllObjects];
  64. //请求数据
  65. [DataSourceManager getSiteWithUrlPagesize:100 Page:1 completionBlock:^(NSMutableArray *array) {
  66. _dataArray = array;
  67. [_tableView reloadData];
  68. //结束刷新
  69. [self.tableView.mj_header endRefreshing];
  70. mesArr = [[NSMutableArray alloc] init];
  71. telArr = [[NSMutableArray alloc] init];
  72. siteIDArr = [NSMutableArray array];
  73. for (int i = 0; i<_dataArray.count; i++) {
  74. PlaceModel *model = _dataArray[i];
  75. [telArr addObject:model.isTel];
  76. [mesArr addObject:model.isMsg];
  77. [siteIDArr addObject:model.Id];
  78. }
  79. NSLog(@"telArr~~~~~%@",telArr);
  80. }];
  81. [self.tableView.mj_header endRefreshing];
  82. }
  83. #pragma mark-- tableviewDelegate
  84. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  85. return _dataArray.count;
  86. }
  87. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  88. return 1;
  89. }
  90. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  91. return 70;
  92. }
  93. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  94. static NSString *cellId = @"cell";
  95. PushManageCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
  96. if (!cell) {
  97. cell = [[PushManageCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellId];
  98. }
  99. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  100. PlaceModel *model = self.dataArray[indexPath.row];
  101. cell.model = model;
  102. NSLog(@"--------site%@",model.Id);
  103. NSLog(@"model===%@",model.isTel);
  104. cell.titleLabel.text = model.deployment;
  105. // if ([model.isTel isEqualToString:@"1"]) {
  106. // [cell.selectTelBtn setImage:[UIImage imageNamed:@"hsh_news_choice_transforma"] forState:UIControlStateNormal];
  107. //
  108. // }else if([model.isTel isEqualToString:@"0"]){
  109. // [cell.selectTelBtn setImage:[UIImage imageNamed:@"hsh_news_choice"] forState:UIControlStateNormal];
  110. // }
  111. //
  112. // if ([model.isMsg isEqualToString:@"1"]) {
  113. // [cell.selectMsgBtn setImage:[UIImage imageNamed:@"hsh_news_choice_transforma"] forState:UIControlStateNormal];
  114. //
  115. // }else if([model.isMsg isEqualToString:@"0"]){
  116. // [cell.selectMsgBtn setImage:[UIImage imageNamed:@"hsh_news_choice"] forState:UIControlStateNormal];
  117. //
  118. // }
  119. cell.comitBtn.tag =indexPath.row;
  120. cell.selectMsgBtn.tag = 2000+indexPath.row;
  121. cell.selectTelBtn.tag = 1000+indexPath.row;
  122. [cell.comitBtn addTarget:self action:@selector(comitBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  123. [cell.selectTelBtn addTarget:self action:@selector(selectTelBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  124. [cell.selectMsgBtn addTarget:self action:@selector(selectMsgBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  125. return cell;
  126. }
  127. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath{
  128. PlaceModel *model = [self.dataArray objectAtIndex:indexPath.section];
  129. }
  130. - (void)didReceiveMemoryWarning {
  131. [super didReceiveMemoryWarning];
  132. // Dispose of any resources that can be recreated.
  133. }
  134. -(void)selectTelBtnClick:(UIButton *)selectBtn{
  135. if (selectBtn.selected) {
  136. NSString *telsStr = telArr[selectBtn.tag-1000];
  137. NSLog(@"~~~~~~%@ %ld",telsStr,(long)selectBtn.tag);
  138. if ([telsStr isEqualToString:@"1"]) {
  139. [telArr replaceObjectAtIndex:selectBtn.tag-1000 withObject:@"0"];
  140. }else{
  141. [telArr replaceObjectAtIndex:selectBtn.tag-1000 withObject:@"1"];
  142. }
  143. }else{
  144. NSString *telsStr = telArr[selectBtn.tag-1000];
  145. NSLog(@"~~~~~~%@ %ld",telsStr,(long)selectBtn.tag);
  146. if ([telsStr isEqualToString:@"1"]) {
  147. [telArr replaceObjectAtIndex:selectBtn.tag-1000 withObject:@"0"];
  148. }else{
  149. [telArr replaceObjectAtIndex:selectBtn.tag-1000 withObject:@"1"];
  150. }
  151. }
  152. NSLog(@"telArr %@",telArr);
  153. selectBtn.selected = !selectBtn.selected;
  154. // if (selectBtn.selected ==YES) {
  155. //// telStr = @"1";
  156. // [selectBtn setImage:[UIImage imageNamed:@"hsh_news_choice_transforma"] forState:UIControlStateNormal];
  157. //
  158. //
  159. // }else{
  160. //// telStr = @"0";
  161. // [selectBtn setImage:[UIImage imageNamed:@"hsh_news_choice"] forState:UIControlStateSelected];
  162. //
  163. // }
  164. }
  165. -(void)selectMsgBtnClick:(UIButton *)selectBtn{
  166. if (selectBtn.selected) {
  167. NSString *messStr = mesArr[selectBtn.tag-2000];
  168. NSLog(@"~~~~~~%@ %ld",messStr,(long)selectBtn.tag);
  169. if ([messStr isEqualToString:@"1"]) {
  170. [mesArr replaceObjectAtIndex:selectBtn.tag-2000 withObject:@"0"];
  171. }else{
  172. [mesArr replaceObjectAtIndex:selectBtn.tag-2000 withObject:@"1"];
  173. }
  174. }else{
  175. NSString *messStr = mesArr[selectBtn.tag-2000];
  176. NSLog(@"~~~~~~%@ %ld",messStr,(long)selectBtn.tag);
  177. if ([messStr isEqualToString:@"1"]) {
  178. [mesArr replaceObjectAtIndex:selectBtn.tag-2000 withObject:@"0"];
  179. }else{
  180. [mesArr replaceObjectAtIndex:selectBtn.tag-2000 withObject:@"1"];
  181. }
  182. }
  183. selectBtn.selected = !selectBtn.selected;
  184. }
  185. -(void)comitBtnClick:(UIButton *)comitBtn{
  186. //在这里处理提交的逻辑,暂时未实现
  187. telStr =telArr[comitBtn.tag];
  188. mesStr =mesArr[comitBtn.tag];
  189. NSLog(@"~~~~~~~%@",telStr);
  190. NSString *siteId = siteIDArr[comitBtn.tag];
  191. [DataSourceManager updatePhonePushWithURlSiteID:siteId ISTel:telStr ISMsg:mesStr completionBlock:^(NSDictionary *dic) {
  192. [self loadNewDatas];
  193. [self.tableView reloadData];
  194. }];
  195. }
  196. /*
  197. #pragma mark - Navigation
  198. // In a storyboard-based application, you will often want to do a little preparation before navigation
  199. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  200. // Get the new view controller using [segue destinationViewController].
  201. // Pass the selected object to the new view controller.
  202. }
  203. */
  204. @end