MOSendRedPacketView.m 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806
  1. //
  2. // MOSendRedPacketView.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2024/6/12.
  6. //
  7. #import "MOSendRedPacketView.h"
  8. #import "MOSendRedPackeCell.h"
  9. #import "MOOpenCountdownView.h"
  10. #import "MORedPacketRuleView.h"
  11. #import "MORedPacketHistoryView.h"
  12. #import "MOTopUpVC.h"
  13. #import "MORedCellShowView.h"
  14. #import "MORedPackeQuantityView.h"
  15. #import "MORedPacketCustomView.h"
  16. #define kBgViewHeight kScaleWidth(583)
  17. @interface MOSendRedPacketView ()<JXCategoryViewDelegate>
  18. @property (nonatomic, strong) UIView *backgroundView;
  19. @property (nonatomic, strong) UIView *contentView;
  20. @property (nonatomic, strong) UIImageView *bgImgView;
  21. @property (nonatomic, strong) UIButton *ruleButton;
  22. @property (nonatomic, strong) UIButton *historyButton;
  23. @property (nonatomic, strong) UILabel *tipTagLab;
  24. @property (nonatomic, strong) UIButton *sendBtn;
  25. @property (nonatomic, strong) NSArray *dataArr;
  26. @property (nonatomic, strong) MORedPacketRuleView *ruleView;
  27. @property (nonatomic, strong) MORedPacketHistoryView *historyView;
  28. @property (nonatomic, strong) MORedConfigData *configData;
  29. @property (nonatomic, strong) MOOpenCountdownView *bottomView;
  30. @property (nonatomic, assign) BOOL isKeyboardVisible;
  31. @property (nonatomic, assign) BOOL isAlreadySend;
  32. @property (nonatomic, strong) JXCategoryTitleView *titleCategoryView;//区分普通红包 / 全服红包
  33. @property (nonatomic, strong) UIImageView *centerContainerView;
  34. @property (nonatomic, strong) UILabel *amountLabel;
  35. @property (nonatomic, strong) MORedCellShowView *collectionShowView;
  36. @property (nonatomic, strong) UILabel *quantityLabel;
  37. @property (nonatomic, strong) MORedPackeQuantityView *quantityView;
  38. @property (nonatomic, strong) UILabel *timeLabel;
  39. @property (nonatomic, strong) NSMutableArray *scope1Array;//普通红包
  40. @property (nonatomic, strong) NSMutableArray *scope2Array;;//全服红包
  41. @property (nonatomic, strong) UIView *bottomContentView;
  42. @property (nonatomic, strong) UIImageView *diamondIconView;
  43. @property (nonatomic, strong) UILabel *diamondLabel;
  44. @property (nonatomic, strong) UILabel *rechargeLab;
  45. @property (nonatomic, strong) UIImageView *arrowImageView;
  46. @property (nonatomic, strong) MORedSendConfigs *currentSelectedConfig;//当前选中的红包金额配置
  47. @property (nonatomic, assign) NSInteger selectedQuantityIdx;//当前选中红包数量位置
  48. @property (nonatomic, assign) CGFloat bottomSpacing;//底部显示间距差,全面屏和非全面屏的值不一样
  49. //请求参数
  50. /** 当前范围 1 普通 2全服 */
  51. @property (nonatomic, assign) NSInteger currentScope;
  52. /** 1默认 2自定义 */
  53. @property (nonatomic, assign) NSInteger type;
  54. /** 倒计时 分钟 */
  55. @property (nonatomic, assign) NSInteger countdownNum;
  56. /** 红包数量 */
  57. @property (nonatomic, assign) NSInteger quantityNum;
  58. /** 钻石数量 */
  59. @property (nonatomic, assign) NSInteger zuanNum;
  60. /** 红包编号 */
  61. @property (nonatomic, assign) double redCode;
  62. @end
  63. @implementation MOSendRedPacketView
  64. + (instancetype)moSendRedPacketView{
  65. MOSendRedPacketView *view = [[MOSendRedPacketView alloc] initWithFrame:CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGHT)];
  66. return view;
  67. }
  68. - (instancetype)initWithFrame:(CGRect)frame {
  69. if (self = [super initWithFrame:frame]) {
  70. [self initData];
  71. [self setupUI];
  72. }
  73. return self;
  74. }
  75. - (void)initData {
  76. self.currentScope = 1;
  77. self.type = 1;
  78. self.zuanNum = 0;
  79. self.quantityNum = 0;
  80. self.countdownNum = 0;
  81. self.isKeyboardVisible = NO;
  82. self.isAlreadySend = NO;
  83. self.bottomSpacing = kBottomSafeAreaInset > 0 ? 15.0 : 50.0;
  84. }
  85. - (void)setupUI {
  86. [self addSubview:self.backgroundView];
  87. [self.backgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
  88. make.edges.mas_equalTo(0);
  89. }];
  90. [self addSubview:self.contentView];
  91. [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
  92. make.left.right.mas_equalTo(0);
  93. make.top.mas_equalTo(SCREENHEIGHT);
  94. make.height.mas_equalTo(kScaleWidth(583));
  95. }];
  96. [self.contentView addSubview:self.bgImgView];
  97. [self.bgImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  98. make.edges.mas_equalTo(0);
  99. }];
  100. [self.contentView addSubview:self.ruleButton];
  101. [self.ruleButton mas_makeConstraints:^(MASConstraintMaker *make) {
  102. make.top.mas_equalTo(kScaleWidth(74));
  103. make.left.mas_equalTo(15);
  104. make.size.mas_equalTo(CGSizeMake(21, 21));
  105. }];
  106. [self.contentView addSubview:self.historyButton];
  107. [self.historyButton mas_makeConstraints:^(MASConstraintMaker *make) {
  108. make.centerY.equalTo(self.ruleButton);
  109. make.right.mas_equalTo(-15);
  110. make.size.mas_equalTo(CGSizeMake(21, 21));
  111. }];
  112. self.titleCategoryView.titles = @[NSLocalString(@"mimo_red_packet_normal_title"),NSLocalString(@"mimo_red_packet_all_title")];
  113. CGFloat totalItemWidth = 283.0;
  114. self.titleCategoryView.layer.cornerRadius = 30.0 / 2.0;
  115. self.titleCategoryView.layer.masksToBounds = YES;
  116. self.titleCategoryView.cellSpacing = 0;
  117. self.titleCategoryView.cellWidth = totalItemWidth / self.titleCategoryView.titles.count;
  118. self.titleCategoryView.titleColor = [MOTools colorWithHexString:@"#FFFFFF" alpha:1.0];
  119. self.titleCategoryView.titleSelectedColor = [MOTools colorWithHexString:@"#6B2800" alpha:1.0];
  120. self.titleCategoryView.titleFont = [MOTextTools getTheFontWithSize:13.0 AndFontName:kNormalContentFontStr];
  121. self.titleCategoryView.titleSelectedFont = [MOTextTools getTheFontWithSize:13.0 AndFontName:kNormalContentBlodFontStr];
  122. self.titleCategoryView.backgroundColor = [MOTools colorWithHexString:@"#000000" alpha:0.2];
  123. self.titleCategoryView.layer.borderColor = [MOTools colorWithHexString:@"#FFBB95"].CGColor;
  124. self.titleCategoryView.layer.borderWidth = 1;
  125. JXCategoryIndicatorBackgroundView *backgroundTwoView = [[JXCategoryIndicatorBackgroundView alloc] init];
  126. backgroundTwoView.indicatorHeight = 30.0;
  127. backgroundTwoView.indicatorWidthIncrement = 0;
  128. backgroundTwoView.indicatorColor = [MOTools colorWithHexString:@"#FFEC85" alpha:1.0];
  129. NSArray *colorTwoArr = @[[MOTools colorWithHexString:@"#FAEFA7"],[MOTools colorWithHexString:@"#FFB54C"]];
  130. UIImage *imageTwo = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, 142.0, 30.0) Colors:colorTwoArr GradientType:0];
  131. UIImageView *imgTwoBgView = [[UIImageView alloc] init];
  132. imgTwoBgView.contentMode = UIViewContentModeScaleToFill;
  133. [imgTwoBgView setImage:imageTwo];
  134. [backgroundTwoView addSubview:imgTwoBgView];
  135. [imgTwoBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  136. make.edges.equalTo(backgroundTwoView);
  137. }];
  138. imgTwoBgView.layer.cornerRadius = 15;
  139. imgTwoBgView.layer.masksToBounds = YES;
  140. imgTwoBgView.layer.borderColor = [MOTools colorWithHexString:@"#FFBB95"].CGColor;
  141. imgTwoBgView.layer.borderWidth = 1;
  142. self.titleCategoryView.indicators = @[backgroundTwoView];
  143. [self.contentView addSubview:self.titleCategoryView];
  144. [self.titleCategoryView mas_makeConstraints:^(MASConstraintMaker *make) {
  145. make.top.mas_equalTo(kScaleWidth(114));
  146. make.width.mas_equalTo(283);
  147. make.centerX.mas_equalTo(0);
  148. make.height.mas_equalTo(30);
  149. }];
  150. [self.contentView addSubview:self.centerContainerView];
  151. [self.centerContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
  152. make.top.equalTo(self.titleCategoryView.mas_bottom).offset(kScaleWidth(15));
  153. make.centerX.mas_equalTo(0);
  154. make.width.mas_equalTo(kScaleWidth(345));
  155. make.height.mas_equalTo(kScaleWidth(320));
  156. }];
  157. [self.centerContainerView addSubview:self.amountLabel];
  158. [self.amountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  159. make.top.left.mas_equalTo(kScaleWidth(15));
  160. }];
  161. [self.centerContainerView addSubview:self.collectionShowView];
  162. [self.collectionShowView mas_makeConstraints:^(MASConstraintMaker *make) {
  163. make.top.equalTo(self.amountLabel.mas_bottom).offset(kScaleWidth(10));
  164. make.left.right.mas_equalTo(0);
  165. make.height.mas_equalTo(kScaleWidth(80));
  166. }];
  167. [self.centerContainerView addSubview:self.quantityLabel];
  168. [self.quantityLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  169. make.top.equalTo(self.collectionShowView.mas_bottom).offset(kScaleWidth(15));
  170. make.left.mas_equalTo(kScaleWidth(15));
  171. }];
  172. [self.centerContainerView addSubview:self.quantityView];
  173. [self.quantityView mas_makeConstraints:^(MASConstraintMaker *make) {
  174. make.top.equalTo(self.quantityLabel.mas_bottom).offset(kScaleWidth(10));
  175. make.left.right.mas_equalTo(0);
  176. make.height.mas_equalTo(kScaleWidth(32));
  177. }];
  178. [self.centerContainerView addSubview:self.timeLabel];
  179. [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  180. make.top.equalTo(self.quantityView.mas_bottom).offset(kScaleWidth(15));
  181. make.left.mas_equalTo(kScaleWidth(15));
  182. }];
  183. [self.centerContainerView addSubview:self.bottomView];
  184. [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
  185. make.top.equalTo(self.timeLabel.mas_bottom).offset(kScaleWidth(10));
  186. make.left.right.mas_equalTo(0);
  187. make.height.mas_equalTo(kScaleWidth(32));
  188. }];
  189. [self.centerContainerView addSubview:self.tipTagLab];
  190. [self.tipTagLab mas_makeConstraints:^(MASConstraintMaker *make) {
  191. make.centerX.mas_equalTo(0);
  192. make.bottom.mas_equalTo(-35);
  193. }];
  194. [self.contentView addSubview:self.sendBtn];
  195. [self.sendBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  196. make.centerX.mas_equalTo(0);
  197. make.centerY.equalTo(self.centerContainerView.mas_bottom);
  198. make.size.mas_equalTo(CGSizeMake(kScaleWidth(244), kScaleWidth(59)));
  199. }];
  200. [self.contentView addSubview:self.bottomContentView];
  201. [self.bottomContentView mas_makeConstraints:^(MASConstraintMaker *make) {
  202. make.top.equalTo(self.sendBtn.mas_bottom).offset(5);
  203. make.left.right.bottom.mas_equalTo(0);
  204. }];
  205. [self.bottomContentView addSubview:self.diamondIconView];
  206. [self.diamondIconView mas_makeConstraints:^(MASConstraintMaker *make) {
  207. make.top.mas_equalTo(10);
  208. make.left.mas_equalTo(15);
  209. make.size.mas_equalTo(CGSizeMake(16, 12));
  210. }];
  211. [self.bottomContentView addSubview:self.diamondLabel];
  212. [self.diamondLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  213. make.left.equalTo(self.diamondIconView.mas_right).offset(5);
  214. make.centerY.equalTo(self.diamondIconView);
  215. }];
  216. [self.bottomContentView addSubview:self.arrowImageView];
  217. [self.arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  218. make.centerY.equalTo(self.diamondIconView);
  219. make.right.mas_equalTo(-15);
  220. make.size.mas_equalTo(CGSizeMake(6, 11));
  221. }];
  222. [self.bottomContentView addSubview:self.rechargeLab];
  223. [self.rechargeLab mas_makeConstraints:^(MASConstraintMaker *make) {
  224. make.centerY.equalTo(self.diamondIconView);
  225. make.right.equalTo(self.arrowImageView.mas_left).offset(-5);
  226. }];
  227. }
  228. - (void)ruleBtnClick {
  229. [self addSubview:self.ruleView];
  230. [self.ruleView mas_makeConstraints:^(MASConstraintMaker *make) {
  231. make.left.equalTo(self).offset(0);
  232. make.width.mas_equalTo(@(SCREENWIDTH));
  233. make.height.mas_equalTo(kBgViewHeight - self.bottomSpacing);
  234. make.top.equalTo(self.mas_bottom);
  235. }];
  236. [self setNeedsLayout];
  237. [self layoutIfNeeded];
  238. [self.ruleView showRedPacketRuleView];
  239. }
  240. - (void)historyBtnClick {
  241. [self addSubview:self.historyView];
  242. [self.historyView mas_makeConstraints:^(MASConstraintMaker *make) {
  243. make.left.equalTo(self).offset(0);
  244. make.width.mas_equalTo(SCREENWIDTH);
  245. make.height.mas_equalTo(kBgViewHeight - self.bottomSpacing);
  246. make.top.equalTo(self.mas_bottom);
  247. }];
  248. [self setNeedsLayout];
  249. [self layoutIfNeeded];
  250. [self.historyView showRedPacketHistoryView];
  251. }
  252. - (void)rechargeClick {
  253. WEAKSELF
  254. UIViewController *currentVC = [MOTools currentViewController];
  255. MOTopUpVC *vc = [[MOTopUpVC alloc] init];
  256. vc.topUpSuccesssBlock = ^(MOMeDataInfo * _Nonnull model) {
  257. weakSelf.diamondLabel.text = [NSString stringWithFormat:@"%.f",model.userWallet.diamond];
  258. };
  259. [currentVC.navigationController pushViewController:vc animated:YES];
  260. }
  261. //发红包
  262. - (void)sendRedPackedBtnClick {
  263. if(self.dataArr.count == 0){
  264. return;
  265. }
  266. if(self.type == 2){
  267. MORedSendConfigs *model = self.dataArr.firstObject;
  268. if(self.quantityNum < model.minNum){
  269. [MBProgressHUD showTipMessageInWindow:NSLocalString(@"mimo_red_packet_min_red_num_tip")];
  270. return;
  271. }
  272. if(self.quantityNum > model.maxNum){
  273. [MBProgressHUD showTipMessageInWindow:NSLocalString(@"mimo_red_packet_max_red_num_tip")];
  274. return;
  275. }
  276. if(self.zuanNum < model.minAmount){
  277. [MBProgressHUD showTipMessageInWindow:NSLocalString(@"mimo_red_packet_min_red_diamond_num_tip")];
  278. return;
  279. }
  280. }
  281. if(self.roomId.length == 0){
  282. return;
  283. }
  284. if(self.isAlreadySend == YES){
  285. return;
  286. }
  287. self.isAlreadySend = YES;
  288. WEAKSELF
  289. NSDictionary *dict = @{@"roomId":self.roomId,
  290. @"configCode":@(self.redCode),
  291. @"num":@(self.quantityNum),
  292. @"amount":@(self.zuanNum),
  293. @"delayMinutes":@(self.countdownNum)};
  294. [kHttpManager toSendTheRedEnvelopeConfigWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  295. if(kCode_Success){
  296. // MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
  297. [weakSelf dismissSendRedPacketView];
  298. NSDictionary *backDict = data[@"data"];
  299. NSInteger currentDiamond = [[MODataManager objectOrNilForKey:@"walletDiamonds" fromDictionary:backDict] integerValue];
  300. weakSelf.diamondLabel.text = [NSString stringWithFormat:@"%zd",currentDiamond];
  301. MOMeDataInfo *userInfoData = (MOMeDataInfo *)[[MODataCache sharedYYCache] objectForKey:kMineUserInfo];
  302. userInfoData.userWallet.diamond = currentDiamond;
  303. [[MODataCache sharedYYCache] setObject:userInfoData forKey:kMineUserInfo];
  304. }
  305. else{
  306. self.isAlreadySend = NO;
  307. MOLogV(@"toSendTheRedEnvelopeConfigWithParams 接口报错了");
  308. NSInteger code = [data[@"code"] integerValue];
  309. if(code != 30001){
  310. //没钱, 提示充值
  311. kShowNetError(data)
  312. }
  313. }
  314. }];
  315. }
  316. - (void)showSendRedPacketView{
  317. [UIView animateWithDuration:0.3 animations:^ {
  318. self.contentView.transform = CGAffineTransformMakeTranslation(0, -kBgViewHeight + self.bottomSpacing);
  319. }];
  320. //不能滑动
  321. SendNotification(@"MOShowLivePagesVCCannotScroll")
  322. [self toGetTheRedPacketConfig];
  323. }
  324. - (void)dismissSendRedPacketView{
  325. //完成下移动画
  326. [UIView animateWithDuration:0.3 animations:^ {
  327. self.contentView.transform = CGAffineTransformIdentity;
  328. } completion:^(BOOL finished) {
  329. [self removeFromSuperview];
  330. }];
  331. //可以滑动
  332. SendNotification(@"MOShowLivePagesVCCanScroll")
  333. if (self.dismissBlock) {
  334. self.dismissBlock();
  335. }
  336. }
  337. - (void)toGetTheRedPacketConfig{
  338. WEAKSELF
  339. [kHttpManager toGetTheRedEnvelopeConfigWithParams:nil andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  340. if(kCode_Success){
  341. MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
  342. weakSelf.configData = [MORedConfigData modelObjectWithDictionary:data[@"data"]];
  343. [weakSelf handleData];
  344. }
  345. else{
  346. MOLogV(@"toGetTheRedPacketConfig 接口报错了");
  347. kShowNetError(data)
  348. }
  349. }];
  350. }
  351. - (void)handleData {
  352. [self.configData.redSendConfigs enumerateObjectsUsingBlock:^(MORedSendConfigs *_Nonnull object, NSUInteger idx, BOOL * _Nonnull stop) {
  353. if (object.scope == 1) {//普通红包
  354. [self.scope1Array addObject:object];
  355. } else if (object.scope == 2) {//全服红包
  356. [self.scope2Array addObject:object];
  357. }
  358. }];
  359. [self updataAllUIWithProperty];
  360. }
  361. - (void)updataAllUIWithProperty{
  362. NSMutableArray *tempArr = [NSMutableArray array];
  363. self.currentSelectedConfig.customAmountValue = 0;
  364. self.currentSelectedConfig.customQuantityValue = 0;
  365. if(self.currentScope == 1){//普通红包
  366. //普通红包
  367. [self.scope1Array enumerateObjectsUsingBlock:^(MORedSendConfigs * _Nonnull object, NSUInteger idx, BOOL * _Nonnull stop) {
  368. object.isSelect = NO;
  369. if (object.type == 1) {//默认红包
  370. object.iconName = [NSString stringWithFormat:@"icon_diamone_%zd", idx];
  371. } else {//自定义
  372. object.isCustom = YES;
  373. object.customAmountValue = 0;
  374. object.iconName = @"icon_red_packet_edit_big";
  375. }
  376. [tempArr addObject:object];
  377. }];
  378. } else {//全服红包
  379. [self.scope2Array enumerateObjectsUsingBlock:^(MORedSendConfigs * _Nonnull object, NSUInteger idx, BOOL * _Nonnull stop) {
  380. object.isSelect = NO;
  381. if (object.type == 1) {//默认红包
  382. object.iconName = [NSString stringWithFormat:@"icon_diamone_%zd", idx];
  383. } else {//自定义
  384. object.isCustom = YES;
  385. object.iconName = @"icon_red_packet_edit_big";
  386. }
  387. [tempArr addObject:object];
  388. }];
  389. }
  390. self.tipTagLab.text = [NSString stringWithFormat:NSLocalString(@"mimo_red_packet_tip_tag_title"),self.configData.refundMinutes];
  391. if(tempArr.count > 0){
  392. MORedSendConfigs *firstObject = tempArr.firstObject;
  393. firstObject.isSelect = YES;
  394. self.currentSelectedConfig = firstObject;
  395. self.redCode = firstObject.code;
  396. NSArray *optionNumArray = (NSArray *)firstObject.optionalNum;
  397. self.quantityNum = [optionNumArray.firstObject integerValue];
  398. self.zuanNum = firstObject.minAmount;
  399. if(self.type == 2){
  400. self.quantityNum = 0;
  401. self.zuanNum = 0;
  402. }
  403. self.quantityView.configModel = firstObject;
  404. }
  405. self.bottomView.startDelayMinutes = self.configData.startDelayMinutes;
  406. if(self.configData.startDelayMinutes.count > 0){
  407. NSNumber *object = self.configData.startDelayMinutes.firstObject;
  408. NSInteger num = [object integerValue];
  409. self.countdownNum = num;
  410. }
  411. self.dataArr = [tempArr copy];
  412. self.collectionShowView.dataArr = [tempArr copy];
  413. }
  414. // 点击选中或者滚动选中都会调用该方法。适用于只关心选中事件,不关心具体是点击还是滚动选中的。
  415. - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index{
  416. MOLogV(@"变换了");
  417. if(categoryView == self.titleCategoryView){
  418. if(index == 0){
  419. self.currentScope = 1;
  420. }
  421. else{
  422. self.currentScope = 2;
  423. }
  424. }
  425. if(self.configData){
  426. [self updataAllUIWithProperty];
  427. }
  428. }
  429. #pragma mark - Lazy
  430. - (UIView *)backgroundView {
  431. if (!_backgroundView) {
  432. _backgroundView = [[UIView alloc] init];
  433. _backgroundView.backgroundColor = [MOTools colorWithHexString:@"#000000" alpha:0.5];
  434. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissSendRedPacketView)];
  435. [_backgroundView addGestureRecognizer:tap];
  436. }
  437. return _backgroundView;
  438. }
  439. - (UIView *)contentView {
  440. if (!_contentView) {
  441. _contentView = [[UIView alloc] init];
  442. }
  443. return _contentView;
  444. }
  445. - (UIImageView *)bgImgView {
  446. if (!_bgImgView) {
  447. _bgImgView = [[UIImageView alloc] init];
  448. _bgImgView.image = [UIImage imageNamed:@"icon_red_envelope_bg"];
  449. }
  450. return _bgImgView;
  451. }
  452. - (UIButton *)ruleButton {
  453. if (!_ruleButton) {
  454. _ruleButton = [[UIButton alloc] init];
  455. [_ruleButton addTarget:self action:@selector(ruleBtnClick) forControlEvents:UIControlEventTouchUpInside];
  456. [_ruleButton setImage:[UIImage imageNamed:@"icon_rule_yellow"] forState:UIControlStateNormal];
  457. }
  458. return _ruleButton;
  459. }
  460. - (UIButton *)historyButton {
  461. if (!_historyButton) {
  462. _historyButton = [[UIButton alloc] init];
  463. [_historyButton addTarget:self action:@selector(historyBtnClick) forControlEvents:UIControlEventTouchUpInside];
  464. [_historyButton setImage:[UIImage imageNamed:@"icon_history_yellow"] forState:UIControlStateNormal];
  465. }
  466. return _historyButton;
  467. }
  468. - (MORedPacketRuleView *)ruleView{
  469. if(!_ruleView){
  470. _ruleView = [MORedPacketRuleView moRedPacketRuleView];
  471. }
  472. return _ruleView;
  473. }
  474. - (MORedPacketHistoryView *)historyView{
  475. if(!_historyView){
  476. _historyView = [MORedPacketHistoryView moRedPacketHistoryView];
  477. }
  478. return _historyView;
  479. }
  480. - (MOOpenCountdownView *)bottomView{
  481. if(!_bottomView){
  482. _bottomView = [MOOpenCountdownView moOpenCountdownView];
  483. WEAKSELF
  484. _bottomView.countdownClickBlock = ^(NSInteger mins) {
  485. weakSelf.countdownNum = mins;
  486. };
  487. }
  488. return _bottomView;
  489. }
  490. - (JXCategoryTitleView *)titleCategoryView{
  491. if(!_titleCategoryView){
  492. _titleCategoryView = [[JXCategoryTitleView alloc] init];
  493. _titleCategoryView.delegate = self;
  494. }
  495. return _titleCategoryView;
  496. }
  497. - (UIImageView *)centerContainerView {
  498. if (!_centerContainerView) {
  499. _centerContainerView = [[UIImageView alloc] init];
  500. NSArray *colorArr = @[[MOTools colorWithHexString:@"#FFFFFF"],[MOTools colorWithHexString:@"#FFF1E7"]];
  501. UIImage *bgImage = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, kScaleWidth(345), kScaleWidth(331)) Colors:colorArr GradientType:1];
  502. _centerContainerView.image = bgImage;
  503. _centerContainerView.layer.masksToBounds = YES;
  504. _centerContainerView.layer.cornerRadius = 16;
  505. _centerContainerView.layer.borderColor = [MOTools colorWithHexString:@"#FFFFFF"].CGColor;
  506. _centerContainerView.layer.borderWidth = 2;
  507. _centerContainerView.userInteractionEnabled = YES;
  508. }
  509. return _centerContainerView;
  510. }
  511. - (UILabel *)amountLabel {
  512. if (!_amountLabel) {
  513. _amountLabel = [[UILabel alloc] init];
  514. _amountLabel.textColor = [MOTools colorWithHexString:@"#75360E"];
  515. _amountLabel.font = [MOTextTools getTheFontWithSize:13.0 AndFontName:kNormalContentBlodFontStr];
  516. _amountLabel.text = NSLocalString(@"mimo_send_red_envelope_amount_title");
  517. }
  518. return _amountLabel;
  519. }
  520. - (MORedCellShowView *)collectionShowView{
  521. if(!_collectionShowView){
  522. _collectionShowView = [[MORedCellShowView alloc] initTheView];
  523. WEAKSELF
  524. _collectionShowView.didSelectItemAtIndexPath = ^(MORedSendConfigs * _Nonnull cellModel) {
  525. if (self.currentSelectedConfig == cellModel && !cellModel.isCustom) {//选中的不是自定义选项并且和之前是同一个,不做处理
  526. return;
  527. }
  528. //刷新数量UI
  529. // weakSelf.quantityView.configModel.customQuantityValue = 0;
  530. // weakSelf.quantityView.configModel = cellModel;
  531. // weakSelf.quantityNum = cellModel.minNum;
  532. if (cellModel.isCustom) {//自定义红包金额
  533. MORedPacketCustomView *customView = [[MORedPacketCustomView alloc] init];
  534. customView.confirmBlock = ^(NSInteger result) {
  535. cellModel.iconName = @"icon_diamone_2";
  536. cellModel.customAmountValue = result;
  537. cellModel.isSelect = YES;
  538. weakSelf.currentSelectedConfig = cellModel;
  539. [weakSelf.collectionShowView reloadView];
  540. weakSelf.zuanNum = result;
  541. weakSelf.redCode = cellModel.code;
  542. };
  543. customView.cancelBlock = ^{
  544. cellModel.isSelect = NO;
  545. weakSelf.currentSelectedConfig.isSelect = YES;
  546. [weakSelf.collectionShowView reloadView];
  547. };
  548. customView.type = CustomRedPacketTypeAmount;
  549. customView.config = cellModel;
  550. [customView show];
  551. } else {//选中默认的红包金额
  552. weakSelf.currentSelectedConfig = cellModel;
  553. weakSelf.redCode = cellModel.code;
  554. weakSelf.zuanNum = cellModel.minAmount;
  555. }
  556. };
  557. }
  558. return _collectionShowView;
  559. }
  560. - (UILabel *)quantityLabel {
  561. if (!_quantityLabel) {
  562. _quantityLabel = [[UILabel alloc] init];
  563. _quantityLabel.textColor = [MOTools colorWithHexString:@"#75360E"];
  564. _quantityLabel.font = [MOTextTools getTheFontWithSize:13.0 AndFontName:kNormalContentBlodFontStr];
  565. _quantityLabel.text = NSLocalString(@"mimo_send_red_envelope_quantity_title");
  566. }
  567. return _quantityLabel;
  568. }
  569. - (MORedPackeQuantityView *)quantityView {
  570. if (!_quantityView) {
  571. _quantityView = [[MORedPackeQuantityView alloc] init];
  572. WEAKSELF
  573. _quantityView.didSelectItemAtIndexPath = ^(NSInteger quantity, NSInteger index) {
  574. if (quantity == -1) {//自定义数量
  575. MORedPacketCustomView *customView = [[MORedPacketCustomView alloc] init];
  576. customView.type = CustomRedPacketTypeQuantity;
  577. customView.config = weakSelf.currentSelectedConfig;
  578. customView.confirmBlock = ^(NSInteger result) {
  579. weakSelf.quantityNum = result;
  580. weakSelf.quantityView.configModel.customQuantityValue = result;
  581. [weakSelf.quantityView reloadView];
  582. };
  583. customView.cancelBlock = ^{
  584. weakSelf.quantityView.selectedIdx = weakSelf.selectedQuantityIdx;
  585. [weakSelf.quantityView reloadView];
  586. };
  587. [customView show];
  588. } else {
  589. weakSelf.quantityNum = quantity;
  590. weakSelf.selectedQuantityIdx = index;
  591. }
  592. };
  593. }
  594. return _quantityView;
  595. }
  596. - (UILabel *)timeLabel {
  597. if (!_timeLabel) {
  598. _timeLabel = [[UILabel alloc] init];
  599. _timeLabel.textColor = [MOTools colorWithHexString:@"#75360E"];
  600. _timeLabel.font = [MOTextTools getTheFontWithSize:13.0 AndFontName:kNormalContentBlodFontStr];
  601. _timeLabel.text = NSLocalString(@"mimo_send_red_envelope_open_title");
  602. }
  603. return _timeLabel;
  604. }
  605. - (NSMutableArray *)scope1Array {
  606. if (!_scope1Array) {
  607. _scope1Array = [NSMutableArray array];
  608. }
  609. return _scope1Array;
  610. }
  611. - (NSMutableArray *)scope2Array {
  612. if (!_scope2Array) {
  613. _scope2Array = [NSMutableArray array];
  614. }
  615. return _scope2Array;
  616. }
  617. - (UILabel *)tipTagLab {
  618. if (!_tipTagLab) {
  619. _tipTagLab = [[UILabel alloc] init];
  620. [_tipTagLab setFont:[MOTextTools getTheFontWithSize:11.0 AndFontName:kNormalContentFontStr]];
  621. _tipTagLab.textColor = [MOTools colorWithHexString:@"#75360E"];
  622. }
  623. return _tipTagLab;
  624. }
  625. - (UIButton *)sendBtn {
  626. if (!_sendBtn) {
  627. _sendBtn = [[UIButton alloc] init];
  628. [_sendBtn setFont:[MOTextTools getTheFontWithSize:15.0 AndFontName:kNormalContentBlodFontStr]];
  629. [_sendBtn setTitleColor:[MOTools colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
  630. [_sendBtn setBackgroundImage:[UIImage imageNamed:@"icon_send_red_packet_bg"] forState:UIControlStateNormal];
  631. [_sendBtn setTitle:NSLocalString(@"mimo_red_packet_send_btn_title") forState:UIControlStateNormal];
  632. [_sendBtn addTarget:self action:@selector(sendRedPackedBtnClick) forControlEvents:UIControlEventTouchUpInside];
  633. }
  634. return _sendBtn;
  635. }
  636. - (UIView *)bottomContentView {
  637. if (!_bottomContentView) {
  638. _bottomContentView = [[UIView alloc] init];
  639. _bottomContentView.backgroundColor = [MOTools colorWithHexString:@"#000000" alpha:0.3];
  640. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(rechargeClick)];
  641. [_bottomContentView addGestureRecognizer:tap];
  642. }
  643. return _bottomContentView;
  644. }
  645. - (UIImageView *)diamondIconView {
  646. if (!_diamondIconView) {
  647. _diamondIconView = [[UIImageView alloc] init];
  648. _diamondIconView.image = [UIImage imageNamed:@"icon_red_list_diamond"];
  649. }
  650. return _diamondIconView;
  651. }
  652. - (UILabel *)diamondLabel {
  653. if (!_diamondLabel) {
  654. _diamondLabel = [[UILabel alloc] init];
  655. _diamondLabel.font = [MOTextTools getTheFontWithSize:14.0 AndFontName:kNormalContentFontStr];
  656. _diamondLabel.textColor = [MOTools colorWithHexString:@"#FFCC00"];
  657. MOMeDataInfo *userInfoData = (MOMeDataInfo *)[[MODataCache sharedYYCache] objectForKey:kMineUserInfo];
  658. _diamondLabel.text = [MOTextTools formatNumberDecimalValue:userInfoData.userWallet.diamond];
  659. }
  660. return _diamondLabel;
  661. }
  662. - (UILabel *)rechargeLab {
  663. if (!_rechargeLab) {
  664. _rechargeLab = [[UILabel alloc] init];
  665. _rechargeLab.font = [MOTextTools getTheFontWithSize:14.0 AndFontName:kNormalContentFontStr];
  666. _rechargeLab.textColor = [MOTools colorWithHexString:@"#FFCC00"];
  667. _rechargeLab.text = NSLocalString(@"mimo_red_packet_rechange_title");
  668. }
  669. return _rechargeLab;
  670. }
  671. - (UIImageView *)arrowImageView {
  672. if (!_arrowImageView) {
  673. _arrowImageView = [[UIImageView alloc] init];
  674. _arrowImageView.image = [UIImage imageNamed:@"icon_arrow_yellow"];
  675. }
  676. return _arrowImageView;
  677. }
  678. @end