SLiveReportView.m 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. //
  2. // SLiveReportView.m
  3. // BuguLive
  4. //
  5. // Created by 丁凯 on 2017/7/14.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import "SLiveReportView.h"
  9. #import "reportModel.h"
  10. #import "SReportViewCell.h"
  11. @implementation SLiveReportView
  12. - (instancetype)initWithFrame:(CGRect)frame
  13. {
  14. self = [super initWithFrame:frame];
  15. if (self)
  16. {
  17. [self makeMYUI];
  18. [self loadData];
  19. }
  20. return self;
  21. }
  22. - (void)makeMYUI
  23. {
  24. self.dataArray = [[NSMutableArray alloc]init];
  25. self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.5];
  26. self.paymentTag = -1;
  27. self.userInteractionEnabled = NO;
  28. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];
  29. tap.delegate = self;
  30. [self addGestureRecognizer:tap];
  31. CGFloat leftMargin = kRealValue(40);
  32. //底部白色的view
  33. self.bottomView = [[UIView alloc]initWithFrame:CGRectMake(leftMargin, (kScreenH - kRealValue(300)) / 2, kScreenW - leftMargin * 2, kRealValue(300))];
  34. self.bottomView.backgroundColor = kBackGroundColor;
  35. self.bottomView.layer.cornerRadius = 5;
  36. self.bottomView.layer.masksToBounds = YES;
  37. [self addSubview:self.bottomView];
  38. //举报类型
  39. self.reportType = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.bottomView.width, kRealValue(40))];
  40. self.reportType.textColor = kAppGrayColor1;
  41. self.reportType.backgroundColor = kBackGroundColor;
  42. self.reportType.text = ASLocalizedString(@"举报类型");
  43. self.reportType.font = [UIFont systemFontOfSize:16];
  44. self.reportType.textAlignment = NSTextAlignmentCenter;
  45. [self.bottomView addSubview:self.reportType];
  46. //UITableView
  47. self.reportTableView = [[UITableView alloc]initWithFrame:CGRectMake(kRealValue(15), self.reportType.bottom, self.bottomView.width - kRealValue(15 + 10), kRealValue(30 * 7))];
  48. self.reportTableView.dataSource = self;
  49. self.reportTableView.delegate = self;
  50. self.reportTableView.backgroundColor = kBackGroundColor;
  51. self.reportTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  52. [self.reportTableView registerNib:[UINib nibWithNibName:@"SReportViewCell" bundle:nil] forCellReuseIdentifier:@"SReportViewCell"];
  53. [self.bottomView addSubview:self.reportTableView];
  54. [BGMJRefreshManager refresh:self.reportTableView target:self headerRereshAction:@selector(loadData) footerRereshAction:nil];
  55. //lineView2
  56. self.lineView2 = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.reportTableView.frame), self.bottomView.width, 1)];
  57. self.lineView2.backgroundColor = kAppSpaceColor4;
  58. [self.bottomView addSubview:self.lineView2];
  59. //取消
  60. self.cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
  61. self.cancelButton.frame = CGRectMake(0, self.lineView2.bottom, (self.bottomView.width-1)/2, kRealValue(40));
  62. // self.cancelButton.frame = CGRectMake(20*kScaleWidth, CGRectGetMaxY(self.lineView2.frame)+10*kScaleHeight, (self.bottomView.width-60*kScaleWidth)/2, 40*kScaleHeight);
  63. [self.cancelButton setTitle:ASLocalizedString(@"取消")forState:UIControlStateNormal];
  64. [self.cancelButton setTitleColor:kAppGrayColor1 forState:UIControlStateNormal];
  65. self.cancelButton.titleLabel.font = [UIFont systemFontOfSize:16];
  66. self.cancelButton.tag = 0;
  67. [self.cancelButton addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  68. [self.bottomView addSubview:self.cancelButton];
  69. self.VLineView = [[UIView alloc]initWithFrame:CGRectMake(self.cancelButton.left, self.lineView2.bottom, 1, kRealValue(40))];
  70. self.VLineView.backgroundColor = kAppSpaceColor4;
  71. [self.bottomView addSubview:self.VLineView];
  72. //确认
  73. self.confirmButton = [UIButton buttonWithType:UIButtonTypeCustom];
  74. self.confirmButton.frame = CGRectMake(self.cancelButton.right ,self.lineView2.bottom,(self.bottomView.width-1)/2, kRealValue(40));
  75. [self.confirmButton setTitle:ASLocalizedString(@"确认")forState:UIControlStateNormal];
  76. [self.confirmButton setTitleColor:kAppGrayColor1 forState:UIControlStateNormal];
  77. self.confirmButton.titleLabel.font = [UIFont systemFontOfSize:16];
  78. self.confirmButton.tag = 1;
  79. [self.confirmButton addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  80. [self.bottomView addSubview:self.confirmButton];
  81. }
  82. - (void)loadData
  83. {
  84. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  85. [parmDict setObject:@"app" forKey:@"ctl"];
  86. [parmDict setObject:@"tipoff_type" forKey:@"act"];
  87. FWWeakify(self)
  88. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson)
  89. {
  90. FWStrongify(self)
  91. [_dataArray removeAllObjects];
  92. self.userInteractionEnabled = YES;
  93. if ([responseJson toInt:@"status"] == 1)
  94. {
  95. NSArray *array = [responseJson objectForKey:@"list"];
  96. if (array.count > 0)
  97. {
  98. for (NSDictionary *dict in array)
  99. {
  100. reportModel *model = [[reportModel alloc]init];
  101. model.ID = [dict toInt:@"id"];
  102. model.name = [dict toString:@"name"];
  103. [self.dataArray addObject:model];
  104. }
  105. [self.reportTableView reloadData];
  106. }
  107. }else
  108. {
  109. [FanweMessage alertHUD:[responseJson toString:@"error"]];
  110. }
  111. [BGMJRefreshManager endRefresh:self.reportTableView];
  112. } FailureBlock:^(NSError *error)
  113. {
  114. FWStrongify(self)
  115. self.userInteractionEnabled = YES;
  116. [BGMJRefreshManager endRefresh:self.reportTableView];
  117. }];
  118. }
  119. //返回行数
  120. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  121. {
  122. if (self.dataArray.count > 0)
  123. {
  124. return self.dataArray.count;
  125. }else
  126. {
  127. return 0;
  128. }
  129. }
  130. //返回单元格
  131. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  132. {
  133. SReportViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SReportViewCell" forIndexPath:indexPath];
  134. reportModel *model = [self.dataArray objectAtIndex:indexPath.row];
  135. if (model.name.length > 0)
  136. {
  137. cell.leftNameLabel.text = model.name;
  138. }else
  139. {
  140. cell.leftNameLabel.text = ASLocalizedString(@"其他原因");
  141. }
  142. if (indexPath.row == self.paymentTag)
  143. {
  144. cell.selectImgView.image = [UIImage imageNamed:@"com_radio_selected_3"];
  145. }else
  146. {
  147. cell.selectImgView.image = [UIImage imageNamed:@"com_radio_normal_3"];
  148. }
  149. return cell;
  150. }
  151. #pragma mark 用来解决跟tableview等的手势冲突问题
  152. - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
  153. {
  154. if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableViewCellContentView"] || [NSStringFromClass([touch.view class]) isEqualToString:@"UIImageView"] || [touch.view isDescendantOfView:self.reportTableView] ||[touch.view isDescendantOfView:self.reportType] ||[touch.view isDescendantOfView:self.bottomView])
  155. {
  156. return NO;
  157. }else
  158. {
  159. return YES;
  160. }
  161. }
  162. - (void)tap:(UITapGestureRecognizer *)sender
  163. {
  164. if (self.reportDelegate)
  165. {
  166. if ([self.reportDelegate respondsToSelector:@selector(clickWithReportId: andBtnIndex: andView:)])
  167. {
  168. [self.reportDelegate clickWithReportId:self.reportId andBtnIndex:2 andView:self];
  169. }
  170. }
  171. }
  172. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  173. {
  174. return 44;
  175. }
  176. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  177. {
  178. self.paymentTag = indexPath.row;
  179. reportModel *model = _dataArray[indexPath.row];
  180. self.reportId = [NSString stringWithFormat:@"%d",model.ID];
  181. [self.reportTableView reloadData];
  182. }
  183. #pragma mark 0取消 1确认
  184. - (IBAction)btnClick:(UIButton *)sender
  185. {
  186. if (self.reportDelegate)
  187. {
  188. if ([self.reportDelegate respondsToSelector:@selector(clickWithReportId: andBtnIndex: andView:)])
  189. {
  190. [self.reportDelegate clickWithReportId:self.reportId andBtnIndex:(int)sender.tag andView:self];
  191. }
  192. }
  193. }
  194. @end