// // DressUpToBuyView.m // YaYin // // Created by dlan on 2023/2/7. // Copyright © 2023 YaYin. All rights reserved. // #import "DressUpToBuyView.h" #import "SPWalletRechargeCell.h" @interface DressUpToBuyView () /** */ @property (weak, nonatomic) IBOutlet UIView *containerView; @property(nonatomic, strong) UICollectionView *collectView; @property (weak, nonatomic) IBOutlet UIView *mainbgView; @property (weak, nonatomic) IBOutlet UILabel *moneyLabel; @property(nonatomic, copy) NSArray *dataArray; /** */ @property(nonatomic, assign) NSInteger index; @end @implementation DressUpToBuyView - (void)awakeFromNib{ [super awakeFromNib]; [self.mainbgView addSubview:self.collectView]; [self.collectView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.mainbgView); }]; self.index = 0; self.containerView.backgroundColor = [UIColor bm_colorGradientChangeWithSize:CGSizeMake(APPW, 350) direction:FXGradientChangeDirectionVertical startColor:HEXCOLORA(0xDFFFF6, 1) endColor:HEXCOLORA(0xFFFFFF, 1)]; [self.confirmBtn setJianBianWithCGSize:CGSizeMake(80, 36)]; [self loadData]; } - (void)loadData { [RCMicHTTP postWithURLString:@"/api/user/get_user_money" parameters:@{} response:^(RCMicHTTPResult *result) { [SVProgressHUD dismiss]; if (result.success) { if (result.errorCode == 200 && [result.content isKindOfClass:NSDictionary.class]) { NSString *moneyText = [result.content safeStringForKey:@"integral"]; self.moneyLabel.text = NSStringFormat(@"%ld", [moneyText integerValue]); }else { [SVProgressHUD showInfoWithStatus:result.message]; } }else { [SVProgressHUD showInfoWithStatus:@"网络错误"]; } }]; } - (void)configWithModel:(SPShopMallModel *)model title:(NSString *)title{ _model = model; [_iconIMG sd_setImageWithURL:URL(model.base_image) placeholderImage:kDefaultUserIcon]; _titleLab.text = NSStringFormat(@"%@-%@",model.title,title); self.dataArray = model.decorate_price; [self.collectView reloadData]; NSDictionary *dic = self.dataArray.firstObject; _priceLab.text = NSStringFormat(@"%@金币/%@天",minStr([dic valueForKey:@"price"]),minStr([dic valueForKey:@"day"])); } #pragma mark -------- collectionView代理方法 ------ - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return self.dataArray.count; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { SPWalletRechargeCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"SPWalletRechargeCell" forIndexPath:indexPath]; // SPShopMallModel *model = self.dataArray[indexPath.row]; // cell.model = model; // NSDictionary *dic = self.dataArray[indexPath.row]; cell.coinLab.text = minStr([dic valueForKey:@"price"]); cell.priceLab.text = NSStringFormat(@"%@天",minStr([dic valueForKey:@"day"])); cell.coinLab.font = YBBoldFont(17); if (self.index == indexPath.row) { cell.bgImgV.image = ImageNamed(@"dress_bg_sel"); cell.coinLab.textColor = HEXCOLOR(0x333333); cell.priceLab.textColor = HEXCOLORA(0x333333, 1); }else { cell.bgImgV.image = ImageNamed(@"dress_bg_nor"); cell.coinLab.textColor = HEXCOLOR(0x333333); cell.priceLab.textColor = HEXCOLORA(0x333333, 1); } return cell; } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { self.index = indexPath.row; [self.collectView reloadData]; NSDictionary *dic = self.dataArray[indexPath.row]; _priceLab.text = NSStringFormat(@"%@金币/%@天",minStr([dic valueForKey:@"price"]),minStr([dic valueForKey:@"day"])); } - (IBAction)doneMethod:(id)sender { NSDictionary *dic = self.dataArray[self.index]; NSDictionary *params = @{@"day":minStr(dic[@"day"]), @"did":_model.did }; [AFNetworkRequset.shared postRequestWithParams:params Path:@"api/decorate/pay_decorate" Loading:YES Hud:YES Success:^(id _Nonnull responseDic) { [self closeMethod:nil]; } Failure:^(id _Nonnull errorData) { }]; } - (IBAction)closeMethod:(id)sender { [UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ [self removeFromSuperview]; [self layoutIfNeeded]; } completion:^(BOOL finished) { }]; } #pragma mark - 懒加载 - (UICollectionView *)collectView { if (!_collectView) { UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; CGFloat itemW = (ScreenWidth-15*2-15*2)/3; layout.itemSize = CGSizeMake(itemW, 80); layout.minimumInteritemSpacing = 0; layout.minimumLineSpacing = 12; layout.sectionInset = UIEdgeInsetsMake(0, 15, 0, 15); _collectView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout]; _collectView.delegate = self; _collectView.dataSource = self; _collectView.backgroundColor = kClearColor; [_collectView registerNib:[UINib nibWithNibName:@"SPWalletRechargeCell" bundle:nil] forCellWithReuseIdentifier:@"SPWalletRechargeCell"]; } return _collectView; } @end