// // YOUPAILZBackpackVC.m // VQU // // Created by 肖浩然的mac on 2021/8/23. // Copyright © 2021 MS. All rights reserved. // #import "YOUPAILZBackpackVC.h" #import "YOUPAILZBackpackModel.h" #import "LZAlertWindow.h" #import "UIViewController+TFPresent.h" @interface YOUPAILZBackpackVC () /* tableView */ @property (strong, nonatomic) UITableView *youpaiptableView; /* 数据源 */ @property (strong, nonatomic) NSArray *youpaipdataArr; @end @implementation YOUPAILZBackpackVC - (void)viewDidLoad { [super viewDidLoad]; [self youpaifinitUI]; [self youpaifinitData]; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ YOUPAILZBackpackModel *model = self.youpaipdataArr[indexPath.row]; if ([self.youpaiptype isEqualToString:@"noble_experience_card"] ) { @weakify(self); LZAlertAction *cancelAction = [LZAlertAction actionWithTitle:@"取消" handler:^(LZAlertAction *action) { }]; cancelAction.cornerRadius = 24.0f; cancelAction.color = LZ273145Color; cancelAction.bgColor = HexColorFromRGB(0x9F9DA5); LZAlertAction *confimAction = [LZAlertAction actionWithTitle:@"确定" handler:^(LZAlertAction *action) { @strongify(self); [self youpaifdidUseCard:[NSString stringWithFormat:@"%ld",model.youpaipid]]; }]; confimAction.cornerRadius = 24.0f; confimAction.color = [UIColor whiteColor]; confimAction.bgColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake((KScreenWidth - 105.0f) / 2.0f, 48.0f) FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:GradientLeftToRight]]; LZAlertWindow *alert = [LZAlertWindow alertWithTitle:@"提示" content:@"是否使用优惠券" action:@[cancelAction,confimAction]]; alert.contentTextAlignment = NSTextAlignmentCenter; [self TFPresentVC:alert completion:^{}]; } } -(void)youpaifdidUseCard:(NSString*)ID{ @weakify(self); [LCHttpHelper requestWithURLString:UseNobleCard parameters:@{@"p_id":ID} needToken:YES type:HttpRequestTypePost success:^(id responseObject) { @strongify(self); NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) { [ZCHUDHelper showTitle:[dict objectForKey:@"message"]]; [self youpaifinitData]; }else{ [ZCHUDHelper showTitle:[dict objectForKey:@"message"]]; } } failure:^(NSError *error) { [ZCHUDHelper showTitle:error.localizedDescription]; }]; } - (void)youpaifinitUI{ self.youpaiptableView = [[UITableView alloc] initWithFrame:CGRectZero style:(UITableViewStylePlain)]; self.youpaiptableView.delegate = self; self.youpaiptableView.dataSource = self; [self.youpaiptableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"LZBackpackCell"]; self.youpaiptableView.backgroundColor = [UIColor whiteColor]; [self.youpaiptableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)]; self.youpaiptableView.tableFooterView = [UIView new]; [self.view addSubview:self.youpaiptableView]; self.youpaiptableView.backgroundColor = [UIColor whiteColor]; if (@available(iOS 15.0, *)) { self.youpaiptableView.sectionHeaderTopPadding = 0; } [self.youpaiptableView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.offset(0); make.left.offset(0); make.right.offset(0); make.bottom.offset(0); }]; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 99; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.youpaipdataArr.count; } -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LZBackpackCell"]; cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"LZBackpackCell"]; YOUPAILZBackpackModel *model = self.youpaipdataArr[indexPath.row]; cell.backgroundColor = [UIColor whiteColor]; //image UIImageView *bgImageView1 = [UIImageView new]; [cell.contentView addSubview:bgImageView1]; [bgImageView1 mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(14); make.width.mas_equalTo(ScaleSize(89)); make.top.mas_equalTo(0); make.height.mas_equalTo(80); }]; // bgImageView.image = [UIImage imageNamed:@"vqu_images_P_test_backpack"];; [bgImageView1 sd_setImageWithURL:[LCTools getImageUrlWithAddress:model.youpaipimg] placeholderImage:nil]; bgImageView1.contentMode = UIViewContentModeScaleAspectFill; bgImageView1.clipsToBounds = YES; //折扣 // UILabel *expireLabel = [UILabel new]; // [bgImageView1 addSubview:expireLabel]; // [expireLabel mas_makeConstraints:^(MASConstraintMaker *make) { // make.left.mas_equalTo(14); // make.centerY.mas_equalTo(0); // }]; // NSString *str = model.dis; // // expireLabel.attributedText = [LCTools setRichTextWithTitle:[NSString stringWithFormat:@"%@",[str substringToIndex:1]] subTitle:[str substringFromIndex:1] titleColor:[UIColor whiteColor] subTitleColor:[UIColor whiteColor] titleFontSize:40 subTitleFontSize:25];; UIImageView *bgImageView2 = [UIImageView new]; [cell.contentView addSubview:bgImageView2]; [bgImageView2 mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(bgImageView1.mas_right); make.width.mas_equalTo(ScaleSize(258)); make.top.mas_equalTo(0); make.height.mas_equalTo(80); }]; // bgImageView.image = [UIImage imageNamed:@"vqu_images_P_test_backpack"];; [bgImageView2 sd_setImageWithURL:[LCTools getImageUrlWithAddress:model.youpaipbg_img] placeholderImage:nil]; bgImageView2.contentMode = UIViewContentModeScaleAspectFill; bgImageView2.clipsToBounds = YES; //title UILabel *titleLabel = [UILabel new]; [bgImageView2 addSubview:titleLabel]; [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.top.mas_equalTo(15); make.height.mas_equalTo(14); }]; titleLabel.text = model.youpaipname; titleLabel.font = LCBoldFont(14); titleLabel.textColor = [UIColor whiteColor]; //详情 UILabel *detailLabel = [UILabel new]; [bgImageView2 addSubview:detailLabel]; [detailLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(titleLabel); make.top.mas_equalTo(titleLabel.mas_bottom).offset(6); make.height.mas_equalTo(10); }]; detailLabel.text = [NSString stringWithFormat:@"%@",model.youpaipdiscount]; detailLabel.font = [UIFont systemFontOfSize:10]; detailLabel.textColor = [UIColor whiteColor]; //时间 UILabel *timeLabel = [UILabel new]; [bgImageView2 addSubview:timeLabel]; [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(detailLabel); make.top.mas_equalTo(detailLabel.mas_bottom).offset(11); }]; timeLabel.text = model.youpaipexpire; timeLabel.textColor = [UIColor whiteColor]; timeLabel.font = [UIFont systemFontOfSize:9]; [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; return cell; } -(void)youpaifinitData{ @weakify(self); [LCHttpHelper requestWithURLString:SetMineGetPackage parameters:@{@"type":self.youpaiptype} needToken:YES type:HttpRequestTypePost success:^(id responseObject) { @strongify(self); NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) { self.youpaipdataArr = [YOUPAILZBackpackModel mj_objectArrayWithKeyValuesArray:[dict objectForKey:@"data"]]; [self.youpaiptableView reloadData]; if (self.youpaipdataArr.count != 0) { [self.youpaiptableView lz_hideEmptyView]; }else{ [self.youpaiptableView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_home_data"] content:@"暂无优惠券"]; } }else{ [ZCHUDHelper showTitle:[dict objectForKey:@"message"]]; } } failure:^(NSError *error) { [ZCHUDHelper showTitle:error.localizedDescription]; }]; } #pragma mark - JXCategoryListContainerView - (UIView *)listView{ return self.view; } @end