YOUPAILZBackPackVipVC.m 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. //
  2. // YOUPAILZBackPackVipVC.m
  3. // VQU
  4. //
  5. // Created by 肖浩然的mac on 2021/9/1.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAILZBackPackVipVC.h"
  9. #import "YOUPAILZBackpackModel.h"
  10. #import "LZAlertWindow.h"
  11. #import "UIViewController+TFPresent.h"
  12. @interface YOUPAILZBackPackVipVC ()<UITableViewDelegate,UITableViewDataSource>
  13. /* tableView */
  14. @property (strong, nonatomic) UITableView *youpaiptableView;
  15. /* 数据源 */
  16. @property (strong, nonatomic) NSArray *youpaipdataArr;
  17. @end
  18. @implementation YOUPAILZBackPackVipVC
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. [self youpaifinitUI];
  22. [self youpaifinitData];
  23. }
  24. #pragma mark-UITableViewDelegate
  25. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  26. YOUPAILZBackpackModel *model = self.youpaipdataArr[indexPath.row];
  27. @weakify(self);
  28. LZAlertAction *cancelAction = [LZAlertAction actionWithTitle:@"取消" handler:^(LZAlertAction *action) {
  29. }];
  30. cancelAction.cornerRadius = 24.0f;
  31. cancelAction.color = LZ273145Color;
  32. cancelAction.bgColor = LZF5F4F7Color;
  33. LZAlertAction *confimAction = [LZAlertAction actionWithTitle:@"确定" handler:^(LZAlertAction *action) {
  34. @strongify(self);
  35. [self youpaifdidUseCard:[NSString stringWithFormat:@"%ld",model.youpaipid]];
  36. }];
  37. confimAction.cornerRadius = 24.0f;
  38. confimAction.color = [UIColor whiteColor];
  39. confimAction.bgColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake((KScreenWidth - 105.0f) / 2.0f, 48.0f) FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:GradientLeftToRight]];
  40. LZAlertWindow *alert = [LZAlertWindow alertWithTitle:@"提示" content:@"是否使用优惠券" action:@[cancelAction,confimAction]];
  41. alert.contentTextAlignment = NSTextAlignmentCenter;
  42. [self TFPresentVC:alert completion:^{}];
  43. }
  44. //点击使用优惠券
  45. -(void)youpaifdidUseCard:(NSString*)ID{
  46. @weakify(self);
  47. [LCHttpHelper requestWithURLString:UseNobleCard parameters:@{@"p_id":ID} needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  48. @strongify(self);
  49. NSDictionary* dict = (NSDictionary*)responseObject;
  50. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  51. if (code == 0) {
  52. [ZCHUDHelper showTitle:[dict objectForKey:@"message"]];
  53. [self youpaifinitData];
  54. }else{
  55. [ZCHUDHelper showTitle:[dict objectForKey:@"message"]];
  56. }
  57. } failure:^(NSError *error) {
  58. [ZCHUDHelper showTitle:error.localizedDescription];
  59. }];
  60. }
  61. - (void)youpaifinitUI{
  62. self.youpaiptableView = [[UITableView alloc] initWithFrame:CGRectZero style:(UITableViewStylePlain)];
  63. self.youpaiptableView.delegate = self;
  64. self.youpaiptableView.dataSource = self;
  65. [self.youpaiptableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"LZBackpackCell"];
  66. self.youpaiptableView.backgroundColor = [UIColor whiteColor];
  67. [self.youpaiptableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
  68. self.youpaiptableView.tableFooterView = [UIView new];
  69. [self.view addSubview:self.youpaiptableView];
  70. self.youpaiptableView.backgroundColor = [UIColor whiteColor];
  71. if (@available(iOS 15.0, *)) {
  72. self.youpaiptableView.sectionHeaderTopPadding = 0;
  73. }
  74. [self.youpaiptableView mas_makeConstraints:^(MASConstraintMaker *make) {
  75. make.top.offset(0);
  76. make.left.offset(0);
  77. make.right.offset(0);
  78. make.bottom.offset(0);
  79. }];
  80. }
  81. #pragma mark-UITableViewDataSource
  82. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  83. return 99;
  84. }
  85. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  86. return self.youpaipdataArr.count;
  87. }
  88. -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  89. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LZBackpackCell"];
  90. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"LZBackpackCell"];
  91. YOUPAILZBackpackModel *model = self.youpaipdataArr[indexPath.row];
  92. cell.backgroundColor = [UIColor whiteColor];
  93. //image
  94. UIImageView *bgImageView1 = [UIImageView new];
  95. [cell.contentView addSubview:bgImageView1];
  96. [bgImageView1 mas_makeConstraints:^(MASConstraintMaker *make) {
  97. make.left.mas_equalTo(14);
  98. make.width.mas_equalTo(KScreenWidth-28);
  99. make.top.mas_equalTo(0);
  100. make.height.mas_equalTo(80);
  101. }];
  102. // bgImageView.image = [UIImage imageNamed:@"vqu_images_P_test_backpack"];;
  103. [bgImageView1 sd_setImageWithURL:[LCTools getImageUrlWithAddress:model.youpaipbg_img] placeholderImage:nil];
  104. bgImageView1.contentMode = UIViewContentModeScaleAspectFill;
  105. bgImageView1.clipsToBounds = YES;
  106. bgImageView1.layer.cornerRadius = 10.0f;
  107. UIImageView *bgImageView2 = [UIImageView new];
  108. [bgImageView1 addSubview:bgImageView2];
  109. [bgImageView2 mas_makeConstraints:^(MASConstraintMaker *make) {
  110. make.left.mas_equalTo(0);
  111. make.width.mas_equalTo(ScaleSize(119));
  112. make.top.mas_equalTo(0);
  113. make.height.mas_equalTo(80);
  114. }];
  115. [bgImageView2 sd_setImageWithURL:[LCTools getImageUrlWithAddress:model.youpaipimg] placeholderImage:nil];
  116. bgImageView2.contentMode = UIViewContentModeScaleAspectFill;
  117. bgImageView2.clipsToBounds = YES;
  118. //title
  119. UILabel *titleLabel = [UILabel new];
  120. [bgImageView1 addSubview:titleLabel];
  121. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  122. make.left.mas_equalTo(bgImageView2.mas_right).offset(16);
  123. make.top.mas_equalTo(15);
  124. make.height.mas_equalTo(14);
  125. }];
  126. titleLabel.text = model.youpaipname;
  127. titleLabel.font = LCBoldFont(14);
  128. titleLabel.textColor = [UIColor whiteColor];
  129. //详情
  130. UILabel *detailLabel = [UILabel new];
  131. [bgImageView1 addSubview:detailLabel];
  132. [detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  133. make.left.mas_equalTo(titleLabel);
  134. make.top.mas_equalTo(titleLabel.mas_bottom).offset(6);
  135. make.height.mas_equalTo(10);
  136. }];
  137. detailLabel.text = [NSString stringWithFormat:@"%@",model.youpaipdiscount];
  138. detailLabel.font = [UIFont systemFontOfSize:10];
  139. detailLabel.textColor = [UIColor whiteColor];
  140. //时间
  141. UILabel *timeLabel = [UILabel new];
  142. [bgImageView1 addSubview:timeLabel];
  143. [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  144. make.left.mas_equalTo(detailLabel);
  145. make.top.mas_equalTo(detailLabel.mas_bottom).offset(11);
  146. }];
  147. timeLabel.text = model.youpaipexpire;
  148. timeLabel.textColor = [UIColor whiteColor];
  149. timeLabel.font = [UIFont systemFontOfSize:9];
  150. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  151. return cell;
  152. }
  153. -(void)youpaifinitData{
  154. @weakify(self);
  155. [LCHttpHelper requestWithURLString:SetMineGetPackage parameters:@{@"type":self.youpaiptype} needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  156. @strongify(self);
  157. NSDictionary* dict = (NSDictionary*)responseObject;
  158. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  159. if (code == 0) {
  160. self.youpaipdataArr = [YOUPAILZBackpackModel mj_objectArrayWithKeyValuesArray:[dict objectForKey:@"data"]];
  161. [self.youpaiptableView reloadData];
  162. if (self.youpaipdataArr.count != 0) {
  163. [self.youpaiptableView lz_hideEmptyView];
  164. }else{
  165. [self.youpaiptableView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_home_data"] content:@"暂无体验卡"];
  166. }
  167. }else{
  168. [ZCHUDHelper showTitle:[dict objectForKey:@"message"]];
  169. }
  170. } failure:^(NSError *error) {
  171. [ZCHUDHelper showTitle:error.localizedDescription];
  172. }];
  173. }
  174. #pragma mark - JXCategoryListContainerView
  175. - (UIView *)listView{
  176. return self.view;
  177. }
  178. @end