JXSheBenListVc.m 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. //
  2. // JXSheBenListVc.m
  3. // shiku_im
  4. //
  5. // Created by 123 on 2020/5/26.
  6. // Copyright © 2020 Reese. All rights reserved.
  7. //
  8. #import "JXSheBenListVc.h"
  9. #import "JXSheBeiCell.h"
  10. @interface JXSheBenListVc ()<UITableViewDelegate,UITableViewDataSource,UIAlertViewDelegate>
  11. @property (nonatomic,weak) UITableView *tableVIew;
  12. @property (nonatomic,strong) NSMutableArray *dataArr;
  13. @property (nonatomic,weak) UIView *titelView;
  14. @property (nonatomic,strong) MJRefreshHeaderView *header;
  15. @property (nonatomic,strong) NSIndexPath *RecordindexPath;
  16. @end
  17. @implementation JXSheBenListVc
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. // Do any additional setup after loading the view from its nib.
  21. [self defineNavBar:@"登陆设备管理" andRinghtBtnImg:@""];
  22. _dataArr=[NSMutableArray array];
  23. UIView *titelView=[[UIView alloc]initWithFrame:CGRectMake(0, JX_SCREEN_TOP, JX_SCREEN_WIDTH, JX_SCREEN_TOP+5)];
  24. titelView.backgroundColor=kRGBColor246;
  25. NSMutableAttributedString *hintString2=[[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"最近登录设备:你可以删除列表中的设备,删除后在该 设备登录微信需要进行身份验证"]];
  26. // NSRange range2=[[hintString2 string]rangeOfString:@"];
  27. // [hintString2 addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:range2];
  28. // [hintString2 addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12 weight:UIFontWeightSemibold] range:range2];
  29. UILabel *titleB=[[UILabel alloc]initWithFrame:CGRectMake(10, 8, JX_SCREEN_WIDTH-20, 60)];
  30. titleB.attributedText=hintString2;
  31. titleB.numberOfLines=0;
  32. [titelView addSubview:titleB];
  33. [self.view addSubview:titelView];
  34. self.titelView=titelView;
  35. _dataArr=[NSMutableArray array];
  36. [self createTableViewUI];
  37. // 加载最新数据
  38. long time = (long)[[NSDate date] timeIntervalSince1970];
  39. time = (time *1000 + g_server.timeDifference);
  40. NSString *salt = [NSString stringWithFormat:@"%ld", time];
  41. [SVProgressHUD show];
  42. [g_server getUserGetAllPhoneDeviceInformation:salt userID:g_server.myself.userId andToView:self];
  43. _header = [MJRefreshHeaderView header];
  44. _header.pullShowStr=@"刷新设备";
  45. _header.scrollView = self.tableVIew;
  46. __weak typeof(self) weakSelf = self;
  47. _header.beginRefreshingBlock = ^(MJRefreshBaseView *refreshView) {
  48. // 进入刷新状态就会回调这个Block
  49. long time = (long)[[NSDate date] timeIntervalSince1970];
  50. time = (time *1000 + g_server.timeDifference);
  51. NSString *salt = [NSString stringWithFormat:@"%ld", time];
  52. [SVProgressHUD show];
  53. [g_server getUserGetAllPhoneDeviceInformation:salt userID:g_server.myself.userId andToView:weakSelf];
  54. };
  55. _header.endStateChangeBlock = ^(MJRefreshBaseView *refreshView) {
  56. // 刷新完毕就会回调这个Block
  57. // NSLog(@"%@----刷新完毕", refreshView.class);
  58. };
  59. _header.refreshStateChangeBlock = ^(MJRefreshBaseView *refreshView, MJRefreshState state) {
  60. // 控件的刷新状态切换了就会调用这个block
  61. switch (state) {
  62. case MJRefreshStateNormal:
  63. // NSLog(@"%@----切换到:普通状态", refreshView.class);
  64. break;
  65. case MJRefreshStatePulling:
  66. // NSLog(@"%@----切换到:松开即可刷新的状态", refreshView.class);
  67. {
  68. }
  69. break;
  70. case MJRefreshStateRefreshing:
  71. // NSLog(@"%@----切换到:正在刷新状态", refreshView.class);
  72. break;
  73. default:
  74. break;
  75. }
  76. };
  77. }
  78. - (void)createTableViewUI{
  79. UITableView *tableVIew=[[UITableView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_titelView.frame), JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT-JX_SCREEN_TOP-JX_SCREEN_TOP-5)];
  80. tableVIew.delegate=self;
  81. tableVIew.dataSource=self;
  82. [self.view addSubview:tableVIew];
  83. self.tableVIew=tableVIew;
  84. //tableVIew.separatorStyle=UITableViewCellSeparatorStyleNone;
  85. tableVIew.tableFooterView=[UIView new];
  86. }
  87. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  88. return 74;
  89. }
  90. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  91. return _dataArr.count;
  92. }
  93. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  94. JXSheBeiCell *cell=[JXSheBeiCell cellWithTableView:tableView];
  95. shebeiModel *model=_dataArr[indexPath.row];
  96. cell.Model=model;
  97. cell.block = ^(UIButton *sender) {
  98. _RecordindexPath=indexPath;
  99. UIAlertView *aletShow=[[UIAlertView alloc]initWithTitle:@"提示" message:@"确认删除改设备?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
  100. [aletShow show];
  101. };
  102. return cell;
  103. }
  104. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
  105. shebeiModel *model=_dataArr[_RecordindexPath.row];
  106. long time = (long)[[NSDate date] timeIntervalSince1970];
  107. time = (time *1000 + g_server.timeDifference);
  108. NSString *salt = [NSString stringWithFormat:@"%ld", time];
  109. [g_server getUserDeleteAllPhoneDeviceInformation:salt userID:g_server.myself.userId deviceName:model.deviceIMSI andToView:self];
  110. [_dataArr removeObjectAtIndex:_RecordindexPath.row];
  111. //错误的写法:
  112. NSIndexPath* path =[NSIndexPath indexPathForRow:_RecordindexPath.row inSection:0];
  113. NSMutableArray* deleteArray=[NSMutableArray arrayWithObject:path];
  114. [_tableVIew deleteRowsAtIndexPaths:deleteArray withRowAnimation:UITableViewRowAnimationFade];
  115. }
  116. //- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
  117. //
  118. //
  119. //
  120. //// NSIndexPath *indexPathxx =[NSIndexPath indexPathForRow:indexPath.row inSection:0];
  121. //// [_dataArr removeObjectAtIndex:indexPath.row];
  122. //// [tableView deleteRowsAtIndexPaths:@[indexPathxx] withRowAnimation:UITableViewRowAnimationFade];
  123. ////
  124. //}
  125. #pragma mark --- 请求成功
  126. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  127. [SVProgressHUD dismiss];
  128. [_header endRefreshing];
  129. // NSLog(@"dict: %@ --- arry: %@",dict ,array1 );
  130. if([aDownload.action isEqualToString:act_userdeviceLogdeleteDeviceLog])
  131. {
  132. // _dataArr=[shebeiModel mj_objectArrayWithKeyValuesArray:array1];
  133. }
  134. else if([aDownload.action isEqualToString:act_userdeviceLogGetAllDeviceLog])
  135. {
  136. _dataArr=[shebeiModel mj_objectArrayWithKeyValuesArray:array1];
  137. [_tableVIew reloadData];
  138. }
  139. }
  140. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  141. [SVProgressHUD dismiss];
  142. [_header endRefreshing];
  143. NSString * errorCode = [NSString stringWithFormat:@"%@",[dict objectForKey:@"resultMsg"]];
  144. if([errorCode isEqualToString:@"权限验证失败"])
  145. {
  146. }
  147. return [errorCode intValue];
  148. }
  149. @end