MGSignHomeSuccessView.m 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. //
  2. // MGSignHomeSuccessView.m
  3. // BuguLive
  4. //
  5. // Created by 宋晨光 on 2019/12/21.
  6. // Copyright © 2019 xfg. All rights reserved.
  7. //
  8. #import "MGSignHomeSuccessView.h"
  9. #import "MGSignCollectCell.h"
  10. #import "SignSuccessPopView.h"
  11. #import "MGSignHomeHeaderCollectReusView.h"
  12. #import "SignFooterCollectReusView.h"
  13. @interface MGSignHomeSuccessView ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
  14. @property(nonatomic, strong) UICollectionView *collectionView;
  15. @property(nonatomic, assign) BOOL alreadySign;
  16. @property(nonatomic, strong) BGSignModel *model;
  17. ////@property(nonatomic, strong) UIView *bgView;
  18. ////@property(nonatomic, strong) UIButton *tipButton;
  19. //@property(nonatomic, strong) UIImageView *bgImageView;
  20. //@property(nonatomic, strong) UILabel *titleLabel;
  21. //@property(nonatomic, strong) UILabel *giftLabel;
  22. //
  23. //@property(nonatomic, strong) UIImageView *successImageView;
  24. //@property(nonatomic, strong) UIButton *closeButton;
  25. //@property(nonatomic, strong) NSString *gift;
  26. @property(nonatomic, strong) dismissBlock block;
  27. @end
  28. static NSString *const image_name_bg = @"签到成功背景";
  29. static NSString *const image_name_success = @"签到成功";
  30. static NSString *const image_name_btn = @"签到成功按钮";
  31. @implementation MGSignHomeSuccessView
  32. +(void)showTodaySignSuccessViewGift:(NSString *)gift frame:(CGRect)frame WithComplete:(dismissBlock)complete{
  33. MGSignHomeSuccessView *view = [[MGSignHomeSuccessView alloc]initWithFrame:frame];
  34. view.block = complete;
  35. [view pop];
  36. }
  37. - (instancetype)initWithFrame:(CGRect)frame {
  38. self = [super initWithFrame:frame];
  39. if (self) {
  40. self.backgroundColor = kClearColor;
  41. [self addSubview:self.collectionView];
  42. [self requestData];
  43. [self requestDataToady];
  44. }
  45. return self;
  46. }
  47. - (void)requestData{
  48. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  49. [parmDict setObject:@"index" forKey:@"ctl"];
  50. [parmDict setObject:@"signin_list" forKey:@"act"];
  51. FWWeakify(self)
  52. [[NetHttpsManager manager] POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  53. FWStrongify(self)
  54. NSDictionary * dict = responseJson;
  55. BGSignModel *model =[BGSignModel mj_objectWithKeyValues:dict];
  56. self.model = model;
  57. // self.alreadySign = model.is_sign.intValue;
  58. [self.collectionView reloadData];
  59. [self requestDataToady];
  60. } FailureBlock:^(NSError *error) {
  61. }];
  62. }
  63. - (void)requestDataToady{
  64. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  65. [parmDict setObject:@"index" forKey:@"ctl"];
  66. [parmDict setObject:@"is_signin" forKey:@"act"];
  67. FWWeakify(self)
  68. [[NetHttpsManager manager] POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  69. FWStrongify(self)
  70. self.alreadySign = [responseJson toInt:@"today_signin"];
  71. [self.collectionView reloadData];
  72. } FailureBlock:^(NSError *error) {
  73. }];
  74. }
  75. - (void)signRequest{
  76. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  77. [parmDict setObject:@"index" forKey:@"ctl"];
  78. [parmDict setObject:@"user_signin" forKey:@"act"];
  79. FWWeakify(self)
  80. [[NetHttpsManager manager] POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  81. if ([responseJson toInt:@"status"] == 1) {
  82. //签到成功弹出成功
  83. //刷新头部 刷新列表
  84. //钻石后台返回
  85. FWStrongify(self)
  86. [self requestData];
  87. [SignSuccessPopView showSignSuccessViewGift:responseJson[@"reward"] WithComplete:^{
  88. }];
  89. }
  90. } FailureBlock:^(NSError *error) {
  91. }];
  92. }
  93. - (void)dismissAction{
  94. [self dismiss];
  95. !self.block?:self.block();
  96. }
  97. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
  98. UITouch *touch = [touches anyObject];
  99. if ([touch.view isEqual:self]) {
  100. [self dismiss];
  101. }
  102. }
  103. -(void)pop
  104. {
  105. UIWindow *keyWindow = [UIApplication sharedApplication].delegate.window;
  106. [keyWindow addSubview:self];
  107. // self.bgImageView.transform = CGAffineTransformMakeScale(0.1, 0.1);
  108. [UIView animateWithDuration:0.3 animations:^{
  109. // self.bgImageView.transform = CGAffineTransformIdentity;
  110. self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.7];
  111. }];
  112. }
  113. -(void)dismiss
  114. {
  115. [UIView animateWithDuration:0.3 animations:^{
  116. // self.bgImageView.transform = CGAffineTransformMakeScale(0.1, 0.1);
  117. } completion:^(BOOL finished) {
  118. [self removeFromSuperview];
  119. self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0];
  120. }];
  121. }
  122. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
  123. if (section==0) {
  124. return CGSizeMake(kRealValue(278), kRealValue(113));
  125. }
  126. return CGSizeZero;
  127. }
  128. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section{
  129. if (section==1) {
  130. return CGSizeMake(kRealValue(188), kRealValue(50));
  131. }
  132. return CGSizeZero;
  133. }
  134. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
  135. if (indexPath.section == 0) {
  136. MGSignHomeHeaderCollectReusView * headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:NSStringFromClass([MGSignHomeHeaderCollectReusView class]) forIndexPath:indexPath];
  137. headerView.backgroundColor = kClearColor;
  138. headerView.clickCloseBlock = ^(BOOL isClose) {
  139. [self dismiss];
  140. };
  141. // [headerView setDataWithsignin_continue:@"1" signin_count:self.model.signin_count];
  142. return headerView;
  143. }
  144. if (indexPath.section == 1) {
  145. SignFooterCollectReusView * footerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:NSStringFromClass([SignFooterCollectReusView class]) forIndexPath:indexPath];
  146. __weak __typeof(self)weakSelf = self;
  147. footerView.alreadySign = self.alreadySign;
  148. footerView.signBlock = ^{
  149. [weakSelf signRequest];
  150. };
  151. return footerView;
  152. }
  153. return nil;
  154. }
  155. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  156. return 2;
  157. }
  158. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  159. if (section == 0) {
  160. return self.model.list.count > 4 ? 4 : self.model.list.count;
  161. }
  162. return self.model.list.count > 4 ? self.model.list.count - 4 : 0;
  163. }
  164. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  165. MGSignCollectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([MGSignCollectCell class]) forIndexPath:indexPath];
  166. if (self.model.list) {
  167. if (indexPath.section == 0) {
  168. cell.model = self.model.list[indexPath.item];
  169. } else {
  170. cell.model = self.model.list[indexPath.item+4];
  171. }
  172. }
  173. return cell;
  174. }
  175. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
  176. return CGSizeMake((kRealValue(278) - kRealValue(13 * 2) - kRealValue(11 * 2) ) / 4, kRealValue(85));
  177. }
  178. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
  179. return 0;
  180. }
  181. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
  182. return 0;
  183. }
  184. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
  185. if (section == 0) {
  186. return UIEdgeInsetsMake(0, 14, 0, 14);
  187. }
  188. return UIEdgeInsetsMake(0, 45, 0, 45);
  189. }
  190. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  191. }
  192. #pragma mark - setter
  193. - (UICollectionView *)collectionView{
  194. if (!_collectionView) {
  195. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
  196. _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0,0, kRealValue(278) , kRealValue(348)) collectionViewLayout:layout];
  197. _collectionView.centerY = kScreenH / 2;
  198. _collectionView.centerX = kScreenW / 2;
  199. _collectionView.delegate = self;
  200. _collectionView.backgroundColor = kWhiteColor;
  201. _collectionView.dataSource = self;
  202. [_collectionView registerClass:[MGSignCollectCell class] forCellWithReuseIdentifier:NSStringFromClass([MGSignCollectCell class])];
  203. [_collectionView registerClass:[MGSignHomeHeaderCollectReusView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader
  204. withReuseIdentifier:NSStringFromClass([MGSignHomeHeaderCollectReusView class])];
  205. [_collectionView registerClass:[SignFooterCollectReusView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter
  206. withReuseIdentifier:NSStringFromClass([SignFooterCollectReusView class])];
  207. }
  208. return _collectionView;
  209. }
  210. @end