YOUPAILZBackpackVC.m 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. //
  2. // YOUPAILZBackpackVC.m
  3. // VQU
  4. //
  5. // Created by 肖浩然的mac on 2021/8/23.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAILZBackpackVC.h"
  9. #import "YOUPAILZBackpackModel.h"
  10. #import "LZAlertWindow.h"
  11. #import "UIViewController+TFPresent.h"
  12. @interface YOUPAILZBackpackVC ()<UITableViewDelegate,UITableViewDataSource>
  13. /* tableView */
  14. @property (strong, nonatomic) UITableView *youpaiptableView;
  15. /* 数据源 */
  16. @property (strong, nonatomic) NSArray *youpaipdataArr;
  17. @end
  18. @implementation YOUPAILZBackpackVC
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. [self youpaifinitUI];
  22. [self youpaifinitData];
  23. }
  24. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  25. YOUPAILZBackpackModel *model = self.youpaipdataArr[indexPath.row];
  26. if ([self.youpaiptype isEqualToString:@"noble_experience_card"] ) {
  27. @weakify(self);
  28. LZAlertAction *cancelAction = [LZAlertAction actionWithTitle:@"取消" handler:^(LZAlertAction *action) {
  29. }];
  30. cancelAction.cornerRadius = 24.0f;
  31. cancelAction.color = LZ273145Color;
  32. cancelAction.bgColor = HexColorFromRGB(0x9F9DA5);
  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. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  82. return 99;
  83. }
  84. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  85. return self.youpaipdataArr.count;
  86. }
  87. -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  88. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LZBackpackCell"];
  89. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"LZBackpackCell"];
  90. YOUPAILZBackpackModel *model = self.youpaipdataArr[indexPath.row];
  91. cell.backgroundColor = [UIColor whiteColor];
  92. //image
  93. UIImageView *bgImageView1 = [UIImageView new];
  94. [cell.contentView addSubview:bgImageView1];
  95. [bgImageView1 mas_makeConstraints:^(MASConstraintMaker *make) {
  96. make.left.mas_equalTo(14);
  97. make.width.mas_equalTo(ScaleSize(89));
  98. make.top.mas_equalTo(0);
  99. make.height.mas_equalTo(80);
  100. }];
  101. // bgImageView.image = [UIImage imageNamed:@"vqu_images_P_test_backpack"];;
  102. [bgImageView1 sd_setImageWithURL:[LCTools getImageUrlWithAddress:model.youpaipimg] placeholderImage:nil];
  103. bgImageView1.contentMode = UIViewContentModeScaleAspectFill;
  104. bgImageView1.clipsToBounds = YES;
  105. //折扣
  106. // UILabel *expireLabel = [UILabel new];
  107. // [bgImageView1 addSubview:expireLabel];
  108. // [expireLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  109. // make.left.mas_equalTo(14);
  110. // make.centerY.mas_equalTo(0);
  111. // }];
  112. // NSString *str = model.dis;
  113. //
  114. // expireLabel.attributedText = [LCTools setRichTextWithTitle:[NSString stringWithFormat:@"%@",[str substringToIndex:1]] subTitle:[str substringFromIndex:1] titleColor:[UIColor whiteColor] subTitleColor:[UIColor whiteColor] titleFontSize:40 subTitleFontSize:25];;
  115. UIImageView *bgImageView2 = [UIImageView new];
  116. [cell.contentView addSubview:bgImageView2];
  117. [bgImageView2 mas_makeConstraints:^(MASConstraintMaker *make) {
  118. make.left.mas_equalTo(bgImageView1.mas_right);
  119. make.width.mas_equalTo(ScaleSize(258));
  120. make.top.mas_equalTo(0);
  121. make.height.mas_equalTo(80);
  122. }];
  123. // bgImageView.image = [UIImage imageNamed:@"vqu_images_P_test_backpack"];;
  124. [bgImageView2 sd_setImageWithURL:[LCTools getImageUrlWithAddress:model.youpaipbg_img] placeholderImage:nil];
  125. bgImageView2.contentMode = UIViewContentModeScaleAspectFill;
  126. bgImageView2.clipsToBounds = YES;
  127. //title
  128. UILabel *titleLabel = [UILabel new];
  129. [bgImageView2 addSubview:titleLabel];
  130. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  131. make.left.mas_equalTo(0);
  132. make.top.mas_equalTo(15);
  133. make.height.mas_equalTo(14);
  134. }];
  135. titleLabel.text = model.youpaipname;
  136. titleLabel.font = LCBoldFont(14);
  137. titleLabel.textColor = [UIColor whiteColor];
  138. //详情
  139. UILabel *detailLabel = [UILabel new];
  140. [bgImageView2 addSubview:detailLabel];
  141. [detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  142. make.left.mas_equalTo(titleLabel);
  143. make.top.mas_equalTo(titleLabel.mas_bottom).offset(6);
  144. make.height.mas_equalTo(10);
  145. }];
  146. detailLabel.text = [NSString stringWithFormat:@"%@",model.youpaipdiscount];
  147. detailLabel.font = [UIFont systemFontOfSize:10];
  148. detailLabel.textColor = [UIColor whiteColor];
  149. //时间
  150. UILabel *timeLabel = [UILabel new];
  151. [bgImageView2 addSubview:timeLabel];
  152. [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  153. make.left.mas_equalTo(detailLabel);
  154. make.top.mas_equalTo(detailLabel.mas_bottom).offset(11);
  155. }];
  156. timeLabel.text = model.youpaipexpire;
  157. timeLabel.textColor = [UIColor whiteColor];
  158. timeLabel.font = [UIFont systemFontOfSize:9];
  159. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  160. return cell;
  161. }
  162. -(void)youpaifinitData{
  163. @weakify(self);
  164. [LCHttpHelper requestWithURLString:SetMineGetPackage parameters:@{@"type":self.youpaiptype} needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  165. @strongify(self);
  166. NSDictionary* dict = (NSDictionary*)responseObject;
  167. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  168. if (code == 0) {
  169. self.youpaipdataArr = [YOUPAILZBackpackModel mj_objectArrayWithKeyValuesArray:[dict objectForKey:@"data"]];
  170. [self.youpaiptableView reloadData];
  171. if (self.youpaipdataArr.count != 0) {
  172. [self.youpaiptableView lz_hideEmptyView];
  173. }else{
  174. [self.youpaiptableView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_home_data"] content:@"暂无优惠券"];
  175. }
  176. }else{
  177. [ZCHUDHelper showTitle:[dict objectForKey:@"message"]];
  178. }
  179. } failure:^(NSError *error) {
  180. [ZCHUDHelper showTitle:error.localizedDescription];
  181. }];
  182. }
  183. #pragma mark - JXCategoryListContainerView
  184. - (UIView *)listView{
  185. return self.view;
  186. }
  187. @end