YOUPAILZCommonGiftVC.m 21 KB

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