SLiveRedBagView.m 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. //
  2. // SLiveRedBagView.m
  3. // BuguLive
  4. //
  5. // Created by 丁凯 on 2017/7/15.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import "SLiveRedBagView.h"
  9. #import "CustomMessageModel.h"
  10. #import "SRedBagViewCell.h"
  11. @implementation SLiveRedBagView
  12. - (void)awakeFromNib
  13. {
  14. [super awakeFromNib];
  15. self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.5];
  16. self.smallHeadViewSpaceH.constant = 25 *kScreenH/480;
  17. self.nameLabelSpaceH.constant = self.nameLabelSpaceH.constant *kScreenH/480;
  18. self.messageLabel2SpaceH.constant = self.messageLabel2SpaceH.constant *kScreenH/480;
  19. self.messageLabelSpaceH.constant = self.messageLabelSpaceH.constant *kScreenH/480;
  20. self.lineViewSpaceH.constant = self.lineViewSpaceH.constant *kScreenH/480;
  21. // self.redButtonSpaceH.constant = self.redButtonSpaceH.constant *kScreenH/480;
  22. self.rebbagBigView.layer.cornerRadius = 6*kScreenH/480;
  23. self.rebbagBigView.layer.masksToBounds = YES;
  24. self.clipsToBounds = YES;
  25. self.dataArray = [[NSMutableArray alloc]init];
  26. self.myTableView.delegate = self;
  27. self.myTableView.dataSource = self;
  28. self.lineView.hidden = YES;
  29. self.luckNewButton.hidden = YES;
  30. self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  31. self.myTableView.backgroundColor = kClearColor;
  32. self.myTableView.tableHeaderView = [[UIView alloc]initWithFrame:CGRectZero];
  33. [self.myTableView registerNib:[UINib nibWithNibName:@"SRedBagViewCell" bundle:nil] forCellReuseIdentifier:@"SRedBagViewCell"];
  34. [BGMJRefreshManager refresh:self.myTableView target:self headerRereshAction:@selector(loadRedBagNet) shouldHeaderBeginRefresh:NO footerRereshAction:nil];
  35. self.headImgView.layer.cornerRadius = 45 / 2;
  36. self.headImgView.layer.masksToBounds = YES;
  37. self.headImgView3.layer.cornerRadius = 68 / 2;
  38. self.headImgView3.layer.masksToBounds = YES;
  39. self.headImgView3.hidden = YES;
  40. self.smallHeadView.layer.cornerRadius = 27*kScreenW/320;
  41. self.smallHeadView.layer.masksToBounds = YES;
  42. self.redButton.userInteractionEnabled = YES;
  43. self.redButton.layer.cornerRadius = 30*kScreenW/320;
  44. self.redButton.layer.masksToBounds = YES;
  45. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(buttonClick:)];
  46. self.luckImgView.userInteractionEnabled = YES;
  47. [self.luckImgView addGestureRecognizer:tap];
  48. self.lineView.backgroundColor = kAppSpaceColor2;
  49. self.redButtonSpaceH.constant= 95*kScreenH/480;
  50. // UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap)];
  51. // [self addGestureRecognizer:tap1];
  52. [self.headBackBroundView setImage:[UIImage imageNamedL:@"bg_room_red_BigHead"]];
  53. [self.luckNewButton setLocalizedString];
  54. [self.messageLabel setLocalizedString];
  55. }
  56. - (void)tap
  57. {
  58. // [self removeFromSuperview];
  59. }
  60. - (void)creatRedWithModel:(CustomMessageModel *)model
  61. {
  62. self.customMessageModel = model;
  63. [self.headImgView sd_setImageWithURL:[NSURL URLWithString:model.sender.head_image]];
  64. [self.headImgView3 sd_setImageWithURL:[NSURL URLWithString:model.sender.head_image]];
  65. self.nameLabel.text = model.sender.nick_name;
  66. _user_prop_id = model.user_prop_id;
  67. //抢完红包后的界面
  68. [self.smallHeadView sd_setImageWithURL:[NSURL URLWithString:model.sender.head_image]];
  69. self.nameLabel2.text = [NSString stringWithFormat:ASLocalizedString(@"%@的红包"),model.sender.nick_name];
  70. self.nameLabel3.text = [NSString stringWithFormat:ASLocalizedString(@"%@的红包"),model.sender.nick_name];
  71. }
  72. - (void)changeRedPackageView{
  73. // self.rebbagBigView.backgroundColor = kWhiteColor;
  74. // self.headBackBroundView.hidden = YES;
  75. [self.headBackBroundView setImage:[UIImage imageNamed:@"bg_room_red_packet_head"]];
  76. self.headImgView.hidden = YES;
  77. self.nameLabel.hidden = YES;
  78. self.messageLabel.hidden = YES;
  79. self.redButton.hidden = YES;
  80. self.headImgWidthConstraint.constant = 278;
  81. self.headImgHeightConstraint.constant = 404;
  82. self.nameLabel2.hidden = NO;
  83. self.luckButton.hidden = YES;//旧的隐藏掉
  84. self.smallHeadBackBroundView.hidden = NO;
  85. self.smallHeadView.hidden = NO;
  86. self.nameLabel2.hidden = NO;
  87. self.messageLabel2.hidden = NO;
  88. self.luckNewButton.hidden = NO;
  89. self.luckImgView.hidden = NO;
  90. self.headImgView.hidden = YES;
  91. if (self.customMessageModel.redPackageTip && [self.customMessageModel.redPackageTip isKindOfClass:[NSString class]])
  92. {
  93. if (self.customMessageModel.redPackageTip.length)
  94. {
  95. _messageLabel2.text = self.customMessageModel.redPackageTip;
  96. }
  97. }
  98. }
  99. - (IBAction)redButtonClick:(UIButton *)sender
  100. {
  101. self.redButton.userInteractionEnabled = NO;
  102. NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
  103. [dict setObject:@"surprise" forKey:@"ctl"];
  104. [dict setObject:@"requestGetSurprise" forKey:@"act"];
  105. [dict setObject:_user_prop_id forKey:@"user_prop_id"];
  106. [dict setObject:self.customMessageModel.dicData[@"surprise_id"] forKey:@"surprise_id"];
  107. [dict setObject:self.video_id forKey:@"video_id"];
  108. FWWeakify(self)
  109. [self.httpsManager POSTWithParameters:dict SuccessBlock:^(NSDictionary *responseJson){
  110. FWStrongify(self)
  111. self.customMessageModel.redPackageTip = [responseJson toString:@"error"];
  112. _messageLabel2.text = [responseJson toString:@"error"];
  113. _currentDiamonds = [[IMAPlatform sharedInstance].host getDiamonds];
  114. _currentDiamonds += [responseJson toInt:@"diamonds"];
  115. [[IMAPlatform sharedInstance].host setDiamonds:[NSString stringWithFormat:@"%ld",(long)_currentDiamonds]];
  116. if (self.BuguLive.appModel.open_diamond_game_module == 1)
  117. {
  118. //更新游戏的余额
  119. [[NSNotificationCenter defaultCenter]postNotificationName:@"updateCoin" object:nil];
  120. }
  121. [self changeRedPackageView];
  122. self.customMessageModel.isRedPackageTaked = YES;
  123. if (_rebBagDelegate && [_rebBagDelegate respondsToSelector:@selector(openRedbag:)])
  124. {
  125. [_rebBagDelegate openRedbag:self];
  126. }
  127. } FailureBlock:^(NSError *error)
  128. {
  129. }];
  130. }
  131. - (IBAction)deleteButtonClick:(id)sender
  132. {
  133. }
  134. - (IBAction)buttonClick:(id)sender
  135. {
  136. self.luckButton.hidden = YES;
  137. self.luckImgView.hidden = YES;
  138. CGRect rect = self.frame;
  139. self.frame = rect;
  140. self.myTableView.hidden = NO;
  141. [self.headBackBroundView setImage:[UIImage imageNamed:@"bg_room_red_shouqi"]];
  142. self.messageLabel2.hidden = YES;
  143. self.messageLabel.hidden = YES;
  144. self.nameLabel2.hidden = YES;
  145. self.luckNewButton.hidden = YES;
  146. self.headImgHeightConstraint.constant = 408;
  147. self.headImgWidthConstraint.constant = 279;
  148. self.headImgView3.hidden = NO;
  149. self.nameLabel3.hidden = NO;
  150. self.headImgView.hidden = YES;
  151. [self loadRedBagNet];
  152. }
  153. - (IBAction)clickClose:(UIButton *)sender {
  154. [self removeFromSuperview];
  155. }
  156. - (void)loadRedBagNet
  157. {
  158. NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
  159. [dict setObject:@"deal" forKey:@"ctl"];
  160. [dict setObject:@"user_red_envelope" forKey:@"act"];
  161. [dict setObject:_user_prop_id forKey:@"user_prop_id"];
  162. FWWeakify(self)
  163. [self.httpsManager POSTWithParameters:dict SuccessBlock:^(NSDictionary *responseJson)
  164. {
  165. FWStrongify(self)
  166. [_dataArray removeAllObjects];
  167. NSArray *array = [responseJson objectForKey:@"list"];
  168. if (array.count > 0)
  169. {
  170. for (NSDictionary *dict in array)
  171. {
  172. CustomMessageModel *model = [CustomMessageModel mj_objectWithKeyValues:dict];
  173. [_dataArray addObject:model];
  174. }
  175. }
  176. [BGMJRefreshManager endRefresh:_myTableView];
  177. [self.myTableView reloadData];
  178. } FailureBlock:^(NSError *error)
  179. {
  180. FWStrongify(self)
  181. [BGMJRefreshManager endRefresh:self.myTableView];
  182. }];
  183. }
  184. #pragma UItableViewDataDelegate
  185. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  186. {
  187. if (_dataArray.count > 0)
  188. {
  189. return _dataArray.count;
  190. }else
  191. {
  192. return 1;
  193. }
  194. }
  195. //返回行数
  196. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  197. {
  198. return 1;
  199. }
  200. //返回单元格
  201. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  202. {
  203. SRedBagViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SRedBagViewCell"];
  204. if (self.dataArray.count > 0)
  205. {
  206. CustomMessageModel *model = self.dataArray[indexPath.section];
  207. [cell creatCellWithModel:model andRow:(int)indexPath.section];
  208. }
  209. return cell;
  210. }
  211. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  212. {
  213. return 50;
  214. }
  215. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  216. {
  217. // if (section == 0)
  218. // {
  219. // return 35;
  220. // }else
  221. // {
  222. return 0;
  223. // }
  224. }
  225. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  226. {
  227. // if (section == 0)
  228. // {
  229. // UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW*0.8, 35)];
  230. // view.backgroundColor = kClearColor;
  231. // UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, kScreenW*0.8, 35)];
  232. // label.text = @"TOP50";
  233. // label.textColor = kWhiteColor;
  234. // label.textAlignment = NSTextAlignmentLeft;
  235. // [view addSubview:label];
  236. // return view;
  237. // }else
  238. // {
  239. return nil;
  240. // }
  241. }
  242. @end