YOUPAIHRChatRoomSubGiftVC.m 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. //
  2. // YOUPAILZCommonGiftVC.m
  3. // VQU
  4. //
  5. // Created by 肖浩然的mac on 2021/8/20.
  6. // Copyright © 2021 leo. All rights reserved.
  7. //
  8. #import "YOUPAIHRChatRoomSubGiftVC.h"
  9. #import "YOUPAIWZHorizontalPageFlowlayout.h"
  10. #import "YOUPAIHRHorizontalPageCell.h"
  11. #import "YOUPAILZLiveBtn.h"
  12. #import "YOUPAIHRHorizontalPageCell.h"
  13. #import "YBPopupMenu.h"
  14. #import "YOUPAIHRChatRoomGiftModel.h"
  15. static NSString * const identifier = @"HorizontalPageCell";
  16. @interface YOUPAIHRChatRoomSubGiftVC ()<UICollectionViewDataSource,UICollectionViewDelegate,YBPopupMenuDelegate>
  17. @property (nonatomic,strong)UIView *youpaipmenuView;
  18. @property (nonatomic,strong)UICollectionView *youpaipcollectionView;
  19. @property (nonatomic,strong)NSMutableArray *youpaipgiftArray;
  20. @property (nonatomic,strong)UIPageControl *youpaippageView;
  21. @property (nonatomic,assign)NSInteger youpaipcoinsTotal;//总虾币
  22. @property (nonatomic,strong)NSIndexPath *youpaipselectIndex;
  23. @property (nonatomic,strong)NSMutableArray* youpaipcellArray;
  24. @property (nonatomic,strong)UILabel *youpaipcountL;
  25. /* youpaipisSendGift */
  26. @property (assign, nonatomic) BOOL youpaipisSendGift;
  27. /* sendgiftL */
  28. @property (strong, nonatomic) UILabel *youpaipsendgiftL;
  29. /* sendGiftBtn */
  30. @property (strong, nonatomic) UIButton *youpaipsendGiftBtn;
  31. /* youpaipcoinL */
  32. @property (strong, nonatomic) UILabel *youpaipcoinL;
  33. @property (nonatomic, strong) YBPopupMenu *youpaippopupMenu;
  34. @property(nonatomic,strong)UIButton *youpaipaddCountBtn;
  35. @property(nonatomic,strong)NSArray *youpaipgiftCountArr;
  36. @end
  37. @implementation YOUPAIHRChatRoomSubGiftVC
  38. - (void)viewDidLoad {
  39. [super viewDidLoad];
  40. self.youpaipgiftArray = [NSMutableArray array];
  41. [self youpaifsetupUI];
  42. [self youpaifinitData];
  43. self.youpaipisSendGift = NO;
  44. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifliveQuietlySendGift:) name:@"LZLiveQuietlySendGift" object:nil];
  45. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifreloadBalance) name:@"VQUChatRoomRefreshBalance" object:nil];
  46. }
  47. - (void)youpaifliveQuietlySendGift:(NSNotification *)notification{
  48. self.youpaipsendGiftBtn.selected = [notification.object boolValue];
  49. }
  50. - (void)youpaifreloadBalance{
  51. // @weakify(self);
  52. // [LCHttpHelper requestWithURLString:LivegetGiftDet parameters:@{@"gift_type":self.youpaipID} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  53. // @strongify(self);
  54. // NSDictionary* dict = (NSDictionary*)responseObject;
  55. // NSInteger code = [[dict objectForKey:@"code"] integerValue];
  56. // if (code==0) {//成功
  57. // self.youpaipcoinsTotal = [[[dict objectForKey:@"data"]objectForKey:@"coin"]integerValue];
  58. // self.youpaipcoinL.text = [NSString stringWithFormat:@"%zd",self.youpaipcoinsTotal];
  59. // }
  60. // } failure:^(NSError *error) {
  61. //
  62. // }];
  63. [self youpaifinitData];
  64. }
  65. - (void)youpaifinitData{
  66. @weakify(self);
  67. [LCHttpHelper requestWithURLString:LivegetGiftDet parameters:@{@"gift_type":self.youpaipID} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  68. @strongify(self);
  69. NSDictionary* dict = (NSDictionary*)responseObject;
  70. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  71. if (code==0) {//成功
  72. self.youpaipcoinsTotal = [[[dict objectForKey:@"data"]objectForKey:@"coin"]integerValue];
  73. YOUPAILCGiftModel *gModel = nil;
  74. for (YOUPAILCGiftModel *giftModel in self.youpaipgiftArray) {
  75. if (giftModel.youpaipselected) {
  76. gModel = giftModel;
  77. break;
  78. }
  79. }
  80. self.youpaipgiftArray = [YOUPAILCGiftModel mj_objectArrayWithKeyValuesArray:[[dict objectForKey:@"data"]objectForKey:@"gift_list"]];
  81. if (gModel != nil) {
  82. for (YOUPAILCGiftModel *giftModel in self.youpaipgiftArray) {
  83. if ([giftModel.youpaipid isEqual:gModel.youpaipid]) {
  84. giftModel.youpaipselected = gModel.youpaipselected;
  85. break;
  86. }
  87. }
  88. }else{
  89. self.youpaipselectIndex = nil;
  90. }
  91. self.youpaipcoinL.text = [NSString stringWithFormat:@"%zd",self.youpaipcoinsTotal];
  92. NSInteger sendtype = [[[dict objectForKey:@"data"]objectForKey:@"send_gift_hide"] intValue];
  93. if (sendtype == 1){
  94. self.youpaipsendGiftBtn.hidden = NO;
  95. self.youpaipsendgiftL.hidden = NO;
  96. self.youpaipsendGiftBtn.selected = YES;
  97. }else if (sendtype == 2){
  98. self.youpaipsendGiftBtn.hidden = NO;
  99. self.youpaipsendgiftL.hidden = NO;
  100. self.youpaipsendGiftBtn.selected = NO;
  101. }
  102. if (self.youpaipisAnchor == NO) {
  103. self.youpaipsendGiftBtn.hidden = YES;
  104. self.youpaipsendgiftL.hidden = YES;
  105. }
  106. [self.youpaipcollectionView reloadData];
  107. if (self.youpaipgiftArray.count != 0) {
  108. [self.youpaipcollectionView lz_hideEmptyView];
  109. }else{
  110. [self.youpaipcollectionView lz_showEmptyViewWithImageSizeWUWU:[UIImage imageNamed:@"vqu_images_IM_sendgift_NoData"] content:@"分类下暂无礼物哦~"];
  111. }
  112. NSInteger totalRecord = self.youpaipgiftArray.count;
  113. NSInteger maxResult = 8;
  114. NSInteger totalPage = totalRecord % maxResult == 0 ? totalRecord / maxResult : totalRecord / maxResult + 1 ;
  115. self.youpaippageView.numberOfPages = totalPage;
  116. NSLog(@"GiftConfig == %@",dict);
  117. NSMutableArray *youpaipgiftArray = [NSMutableArray array];
  118. youpaipgiftArray = [YOUPAILCGiftModel mj_objectArrayWithKeyValuesArray:[[dict objectForKey:@"data"]objectForKey:@"gift_list"]];
  119. for (int i = 0; i< youpaipgiftArray.count; i++) {
  120. YOUPAILCGiftModel *model = youpaipgiftArray[i];
  121. if (model.youpaipsvga.length> 0 ) {
  122. [LCTools giftSVGAWithSvgaUrlStr:model.youpaipsvga];
  123. }
  124. }
  125. }
  126. } failure:^(NSError *error) {
  127. }];
  128. }
  129. -(void)youpaifsetupUI{
  130. self.youpaipcellArray = [NSMutableArray array];
  131. UIView* youpaipmenuView = [[UIView alloc]initWithFrame:self.view.bounds];
  132. youpaipmenuView.backgroundColor = LCBkgColor;
  133. self.youpaipmenuView = youpaipmenuView;
  134. [self.view addSubview:youpaipmenuView];
  135. YOUPAIWZHorizontalPageFlowlayout *layout = [[YOUPAIWZHorizontalPageFlowlayout alloc] initWithRowCount:2 itemCountPerRow:4];
  136. // layout.columnSpacing = 25.0f;
  137. layout.youpaiprowSpacing = 12.0f;
  138. layout.itemSize = CGSizeMake((KScreenWidth - 30.0f - 3*25.0f)/ 4.0f, (192+15-12.0f) / 2.0f);
  139. // layout.edgeInsets = UIEdgeInsetsMake(10.0f, 15.0f, 0.0f, 15.0f);
  140. // [layout setColumnSpacing:20 rowSpacing:10 edgeInsets:UIEdgeInsetsMake(10, 105, 0, 0)];
  141. /** 注意,此处设置的item的尺寸是理论值,实际是由行列间距、collectionView的内边距和宽高决定 */
  142. // layout.itemSize = CGSizeMake((KScreenWidth - 30.0f-30.0f) / 4.0f, (192 - 10.0f-10.0f) / 2.0f);
  143. // layout.minimumInteritemSpacing = 20;
  144. // layout.minimumLineSpacing = 10;
  145. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  146. _youpaipcollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(15.0f, 0, KScreenWidth-30 , 192+15) collectionViewLayout:layout];
  147. _youpaipcollectionView.backgroundColor = [UIColor clearColor];
  148. _youpaipcollectionView.bounces = YES;
  149. _youpaipcollectionView.pagingEnabled = YES;
  150. _youpaipcollectionView.dataSource = self;
  151. _youpaipcollectionView.delegate = self;
  152. _youpaipcollectionView.showsHorizontalScrollIndicator=NO;
  153. _youpaipcollectionView.showsVerticalScrollIndicator=NO;
  154. [_youpaipcollectionView registerClass:[YOUPAIHRHorizontalPageCell class] forCellWithReuseIdentifier:identifier];
  155. [youpaipmenuView addSubview:self.youpaipcollectionView];
  156. NSInteger totalRecord = self.youpaipgiftArray.count;
  157. NSInteger maxResult = 8;
  158. NSInteger totalPage = totalRecord % maxResult == 0 ? totalRecord / maxResult : totalRecord / maxResult + 1 ;
  159. UIPageControl *youpaippageView = [[UIPageControl alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_youpaipcollectionView.frame), KScreenWidth, 20)];
  160. youpaippageView.numberOfPages = totalPage;
  161. youpaippageView.currentPage = 1;
  162. youpaippageView.pageIndicatorTintColor = HexColorFromRGBA(0xffffff,0.5);
  163. youpaippageView.currentPageIndicatorTintColor = HexColorFromRGBA(0xffffff,1.0);
  164. youpaippageView.userInteractionEnabled = NO;
  165. youpaippageView.hidesForSinglePage = YES;
  166. self.youpaippageView = youpaippageView;
  167. [youpaipmenuView addSubview:youpaippageView];
  168. UIView* bottomView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(youpaippageView.frame), KScreenWidth, 47.0f)];
  169. [youpaipmenuView addSubview:bottomView];
  170. UIImageView *zuanshiImgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"vqu_images_ic_user_show_zuanshi"]];
  171. [bottomView addSubview:zuanshiImgV];
  172. [zuanshiImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  173. make.centerY.equalTo(bottomView);
  174. make.left.offset(10.0f);
  175. make.size.mas_offset(CGSizeMake(19.0f, 19.0f));
  176. }];
  177. UILabel *youpaipcoinL = [[UILabel alloc] init];
  178. self.youpaipcoinL = youpaipcoinL;
  179. youpaipcoinL.font = LCFont14;
  180. youpaipcoinL.textColor = [UIColor whiteColor];
  181. [bottomView addSubview:youpaipcoinL];
  182. [youpaipcoinL mas_makeConstraints:^(MASConstraintMaker *make) {
  183. make.centerY.equalTo(bottomView);
  184. make.left.equalTo(zuanshiImgV.mas_right).offset(5.0f);
  185. }];
  186. //下划线
  187. UIView *lineView = [UIView new];
  188. [bottomView addSubview:lineView];
  189. [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
  190. make.left.mas_equalTo(youpaipcoinL.mas_right).offset(12);
  191. make.centerY.mas_equalTo(youpaipcoinL);
  192. make.size.mas_equalTo(CGSizeMake(1, 14));
  193. }];
  194. lineView.backgroundColor = HexColorFromRGBA(0xFFFFFF, 0.2);
  195. UIButton *rechargeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  196. rechargeBtn.titleLabel.font = LCFont14;
  197. [rechargeBtn setTitle:@"充值" forState:UIControlStateNormal];
  198. [rechargeBtn setTitleColor:HexColorFromRGB(0xF4003F) forState:UIControlStateNormal];
  199. [rechargeBtn addTarget:self action:@selector(rechargeClick) forControlEvents:(UIControlEventTouchUpInside)];
  200. [bottomView addSubview:rechargeBtn];
  201. [rechargeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  202. make.centerY.equalTo(bottomView);
  203. make.left.equalTo(lineView.mas_right).offset(12.0f);
  204. }];
  205. UIView *sendBgView = [UIView new];
  206. [bottomView addSubview:sendBgView];
  207. [sendBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  208. make.right.offset(-14.0f);
  209. make.top.offset(5.0f);
  210. make.size.mas_offset(CGSizeMake(124.0f, 33.0f));
  211. }];
  212. UIImageView *sendGiftBgV = [[UIImageView alloc] init];
  213. sendGiftBgV.userInteractionEnabled = YES;
  214. sendGiftBgV.layer.cornerRadius = 16.5f;
  215. sendGiftBgV.clipsToBounds = YES;
  216. sendGiftBgV.image = [LCTools ColorImage:CGSizeMake(124.0f, 33.0f) FromColors:@[HexColorFromRGB(0xFF0084),HexColorFromRGB(0xFF3A00)] ByGradientType:GradientLeftToRight];
  217. [sendBgView addSubview:sendGiftBgV];
  218. [sendGiftBgV mas_makeConstraints:^(MASConstraintMaker *make) {
  219. make.right.offset(0.0f);
  220. make.top.offset(5.0f);
  221. make.size.mas_offset(CGSizeMake(124.0f, 33.0f));
  222. }];
  223. UIButton *sendBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  224. [sendBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(62, 33) FromColors:@[ZYGradientOneColor,ZYGradientTwoColor] ByGradientType:GradientLeftToRight] forState:(UIControlStateNormal)];
  225. [sendBtn setTitle:@"赠送" forState:(UIControlStateNormal)];
  226. [sendBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
  227. sendBtn.titleLabel.font = [UIFont systemFontOfSize:12];
  228. [sendBtn addTarget:self action:@selector(youpaifsendClick) forControlEvents:(UIControlEventTouchUpInside)];
  229. [sendGiftBgV addSubview:sendBtn];
  230. [sendBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  231. make.right.top.bottom.offset(0.0f);
  232. make.width.offset(62.0f);
  233. }];
  234. UIView *countBgV = [[UIView alloc] initWithFrame:CGRectMake(0.5f, 0.5f, 62.0f, 32.0f)];
  235. countBgV.backgroundColor = LCBkgColor;
  236. [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerBottomLeft View:countBgV size:CGSizeMake(17.0f, 17.0f)];
  237. [sendGiftBgV addSubview:countBgV];
  238. //选择更多
  239. UIImageView *addCountImgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"vqu_images_gift_more"]];
  240. [countBgV addSubview:addCountImgV];
  241. [addCountImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  242. make.right.offset(-4.0f);
  243. make.centerY.equalTo(countBgV);
  244. make.size.mas_offset(CGSizeMake(12.0f, 12.0f));
  245. }];
  246. UILabel *youpaipcountL = [[UILabel alloc] init];
  247. youpaipcountL.font = LCFont14;
  248. youpaipcountL.textColor = [UIColor whiteColor];
  249. youpaipcountL.text = @"1";
  250. youpaipcountL.textAlignment = NSTextAlignmentCenter;
  251. [countBgV addSubview:youpaipcountL];
  252. self.youpaipcountL = youpaipcountL;
  253. [youpaipcountL mas_makeConstraints:^(MASConstraintMaker *make) {
  254. make.top.bottom.offset(0.0f);
  255. make.left.equalTo(4);
  256. make.right.equalTo(addCountImgV.mas_left).offset(0.0f);
  257. }];
  258. UIButton *youpaipaddCountBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  259. self.youpaipaddCountBtn = youpaipaddCountBtn;
  260. [youpaipaddCountBtn addTarget:self action:@selector(youpaifaddCountBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  261. [countBgV addSubview:youpaipaddCountBtn];
  262. [youpaipaddCountBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  263. make.right.top.bottom.left.offset(0.0f);
  264. }];
  265. //悄悄送礼
  266. UIButton *sendGiftBtn = [UIButton new];
  267. self.youpaipsendGiftBtn = sendGiftBtn;
  268. [bottomView addSubview:sendGiftBtn];
  269. [sendGiftBtn makeConstraints:^(MASConstraintMaker *make) {
  270. make.right.equalTo(countBgV.mas_left).offset(-10);
  271. make.top.mas_equalTo(sendBtn);
  272. make.size.mas_equalTo(CGSizeMake(27, 16));
  273. }];
  274. [sendGiftBtn setImage:[UIImage imageNamed:@"vqu_images_D_mine_set_Notic_Open"] forState:UIControlStateSelected];
  275. [sendGiftBtn setImage:[UIImage imageNamed:@"vqu_images_D_mine_set_Notic_Close"] forState:UIControlStateNormal];
  276. [sendGiftBtn addTarget:self action:@selector(youpaifsendGiftBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  277. //
  278. UILabel *sendgiftL = [[UILabel alloc] init];
  279. [bottomView addSubview:sendgiftL];
  280. self.youpaipsendgiftL = sendgiftL;
  281. [sendgiftL mas_makeConstraints:^(MASConstraintMaker *make) {
  282. make.top.mas_equalTo(sendGiftBtn.mas_bottom).offset(5);
  283. make.centerX.mas_equalTo(sendGiftBtn);
  284. make.width.mas_equalTo(52);
  285. }];
  286. sendgiftL.font = LCFont12;
  287. sendgiftL.textColor = [UIColor whiteColor];
  288. sendgiftL.text = @"悄悄送礼";
  289. // 是否悄悄送礼 0不显示 1是 2否
  290. if (self.youpaipsend_gift_hide == 1){
  291. sendGiftBtn.hidden = NO;
  292. sendgiftL.hidden = NO;
  293. sendGiftBtn.selected = YES;
  294. }else if (self.youpaipsend_gift_hide == 2){
  295. sendGiftBtn.hidden = NO;
  296. sendgiftL.hidden = NO;
  297. sendGiftBtn.selected = NO;
  298. }else{
  299. sendGiftBtn.hidden = YES;
  300. sendgiftL.hidden = YES;
  301. }
  302. if (self.youpaipisAnchor == NO) {
  303. sendGiftBtn.hidden = YES;
  304. sendgiftL.hidden = YES;
  305. }
  306. }
  307. #pragma mark-悄悄送礼按钮
  308. -(void)youpaifsendGiftBtnClick:(UIButton*)sender{
  309. sender.selected = !sender.selected;
  310. NSString *switchType = sender.selected ? @"1" : @"2";
  311. [[NSNotificationCenter defaultCenter] postNotificationName:@"LZLiveQuietlySendGift" object:@(sender.selected) userInfo:nil];
  312. [LCHttpHelper requestWithURLString:NobleSetting parameters:@{@"send_gift_hide":switchType} needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  313. if (responseObject) {
  314. if ([responseObject[@"code"] intValue]== 0) {
  315. }
  316. [ZCHUDHelper showTitle:responseObject[@"message"]];
  317. }
  318. } failure:^(NSError *error) {
  319. [ZCHUDHelper showTitle:error.localizedDescription];
  320. }];
  321. }
  322. - (void)youpaifaddCountBtnClick:(UIButton*)sender{
  323. // NSInteger count = [self.youpaipcountL.text integerValue] + 1;
  324. // self.youpaipcountL.text = [NSString stringWithFormat:@"%@",@(count >= 99 ? 99 : count)];
  325. self.youpaipgiftCountArr = @[@"520",@"99",@"66",@"10",@"1"];
  326. @weakify(self);
  327. self.youpaippopupMenu = [YBPopupMenu showRelyOnView:self.youpaipaddCountBtn titles:self.youpaipgiftCountArr icons:@[@"",@""] menuWidth:96 otherSettings:^(YBPopupMenu *youpaippopupMenu) {
  328. @strongify(self)
  329. youpaippopupMenu.delegate = self;
  330. youpaippopupMenu.itemHeight = 30;
  331. youpaippopupMenu.selectTextColor = YES;
  332. youpaippopupMenu.isCenter = YES;
  333. youpaippopupMenu.borderWidth = 0.5f;
  334. youpaippopupMenu.borderColor = HexColorFromRGB(0x4F4B5B);
  335. youpaippopupMenu.backColor = [UIColor blackColor];
  336. youpaippopupMenu.textColor = HexColorFromRGB(0xffffff);
  337. }];
  338. }
  339. #pragma mark - YBPopupMenuDelegate
  340. - (void)ybPopupMenu:(YBPopupMenu *)ybPopupMenu didSelectedAtIndex:(NSInteger)index{
  341. self.youpaipcountL.text = self.youpaipgiftCountArr[index];
  342. }
  343. - (void)rechargeClick{
  344. [UMengRecordTool umengEventCountWithId:RechargeClickMessage];
  345. if (!self.youpaipisAnchor) {
  346. [self dismissViewControllerAnimated:NO completion:^{
  347. if (self.youpaipjumToWalletBlock) {
  348. self.youpaipjumToWalletBlock();
  349. }
  350. }];
  351. }else{
  352. [ZCHUDHelper showTitle:@"你在直播中,不可以离开哦"];
  353. }
  354. }
  355. - (void)youpaifsendClick{
  356. if (self.youpaipselectIndex && self.youpaipisSendGift == NO) {
  357. self.youpaipisSendGift = YES;
  358. YOUPAIHRHorizontalPageCell * cell = (YOUPAIHRHorizontalPageCell *)[self.youpaipcollectionView cellForItemAtIndexPath:self.youpaipselectIndex];
  359. // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  360. if (!cell.youpaipmodel.youpaipselected) {
  361. self.youpaipisSendGift = NO;
  362. return;
  363. }
  364. if (self.Giftdelegate &&[self.Giftdelegate respondsToSelector:@selector(youpaifDidSenderGiftWith:Count:CategoryID:)]) {
  365. self.youpaipisSendGift = NO;
  366. [self.Giftdelegate youpaifDidSenderGiftWith:cell.youpaipmodel Count:self.youpaipcountL.text.integerValue CategoryID:self.youpaipID];
  367. // [self.collectionView reloadData];
  368. }
  369. // });
  370. }
  371. }
  372. #pragma mark - UICollectionViewDataSource
  373. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  374. {
  375. return 1;
  376. }
  377. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  378. {
  379. return self.youpaipgiftArray.count;
  380. }
  381. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  382. {
  383. YOUPAIHRHorizontalPageCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
  384. YOUPAILCGiftModel *model = self.youpaipgiftArray[indexPath.row];
  385. cell.youpaipmodel = model;
  386. // cell.backgroundColor = [UIColor yellowColor];
  387. return cell;
  388. }
  389. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  390. if (self.youpaipselectIndex.item <= self.youpaipgiftArray.count - 1) {
  391. YOUPAILCGiftModel *model = self.youpaipgiftArray[self.youpaipselectIndex.item];
  392. model.youpaipselected = NO;
  393. }
  394. YOUPAILCGiftModel *model = self.youpaipgiftArray[indexPath.row];
  395. model.youpaipselected = YES;
  396. self.youpaipselectIndex = indexPath;
  397. self.youpaipcountL.text = @"1";
  398. [collectionView reloadData];
  399. }
  400. -(void)scrollViewDidScroll:(UIScrollView *)scrollView{
  401. // 当前的索引
  402. NSInteger index = scrollView.contentOffset.x / _youpaipcollectionView.mj_w;
  403. self.youpaippageView.currentPage = index;
  404. }
  405. - (void)dealloc{
  406. [[NSNotificationCenter defaultCenter]removeObserver:self];;
  407. }
  408. #pragma mark - JXCategoryListContainerView
  409. - (UIView *)listView{
  410. return self.view;
  411. }
  412. @end