Files
yuyin_ios/SweetParty/主类/Mine/装扮&商城/SPShopMallVC.m
2025-08-08 11:05:33 +08:00

216 lines
8.2 KiB
Objective-C
Executable File

//
// SPShopMallVC.m
// romantic
//
// Created by bj_szd on 2022/7/29.
// Copyright © 2022 romantic. All rights reserved.
//
#import "SPShopMallVC.h"
#import "SPShopMallCell.h"
#import "SPMineDressVC.h"
#import "DressUpToBuyView.h"
#import "JXCategoryTitleBackgroundView.h"
@interface SPShopMallVC () <UICollectionViewDelegateFlowLayout, UICollectionViewDataSource, JXCategoryViewDelegate>
@property (weak, nonatomic) IBOutlet UIImageView *kuangImgV;
@property (weak, nonatomic) IBOutlet UIImageView *avatarImgV;
@property (weak, nonatomic) IBOutlet UILabel *nicknameLab;
@property (weak, nonatomic) IBOutlet UIImageView *gxImgV;
@property (weak, nonatomic) IBOutlet UIImageView *mlImgV;
@property (weak, nonatomic) IBOutlet UIView *bottomBgView;
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (weak, nonatomic) IBOutlet UIButton *buyBtn;
@property (weak, nonatomic) IBOutlet UILabel *priceLab;
@property (weak, nonatomic) IBOutlet UILabel *IDLab;
@property (nonatomic, strong) NSArray *titles;
@property (nonatomic, strong) JXCategoryTitleBackgroundView *categoryView;
@property (nonatomic, strong) JXCategoryIndicatorImageView *lineView;
@property (nonatomic, strong) NSArray *dataArray;
@property (nonatomic, assign) NSInteger currentIndex;
@property (nonatomic, assign) NSInteger pickIndex;
@end
@implementation SPShopMallVC
- (void)viewDidLoad {
[super viewDidLoad];
[self showNaviBarWithTitle:@"装扮商城"];
self.titles = @[@"头像框", @"坐骑", @"资料展示" ,@"气泡", @"个人靓号", @"房间靓号"];
self.pickIndex = -1;
[self createUI];
[self fetchData];
}
-(void)fetchData {
NSDictionary *params = @{@"page":@(1), @"page_limit":@(1000), @"type":@(self.currentIndex+1)};
[[AFNetworkRequset shared] postRequestWithParams:params Path:@"/api/Decorate/get_decorate_list" Loading:NO Hud:NO Success:^(id _Nonnull responseDic) {
NSArray *arr = [SPShopMallModel mj_objectArrayWithKeyValuesArray:responseDic[@"data"]];
self.dataArray = arr;
[self.collectionView reloadData];
} Failure:^(id _Nonnull errorData) {
}];
}
- (IBAction)onBuy:(id)sender {
if (self.pickIndex == -1) {
[HelpPageDefine showMessage:@"请选择装扮"];
return;
}
SPShopMallModel *model = self.dataArray[self.pickIndex];
if (0 == self.currentIndex) {
[self.kuangImgV sd_setImageWithURL:[NSURL URLWithString:model.base_image]];
}
NSString *did = minStr(model.did);
[AFNetworkRequset.shared postRequestWithParams:@{@"did":did} Path:@"api/decorate/get_decorate_info" Loading:NO Hud:NO Success:^(id _Nonnull responseDic) {
SPShopMallModel *detailModel = [SPShopMallModel mj_objectWithKeyValues:responseDic[@"data"]];
DressUpToBuyView *view = LoadNib(@"DressUpToBuyView");
[self.view addSubview:view];
if (self.currentIndex>3) {
[view configWithModel:detailModel title:self.titles[self.currentIndex-1]];
}else{
[view configWithModel:detailModel title:self.titles[self.currentIndex]];
}
[UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionTransitionCurlUp animations:^{
view.frame = CGRectMake(0, 0, APPW, APPH);
} completion:^(BOOL finished) {
}];
} Failure:^(id _Nonnull errorData) {
}];
}
- (void)createUI {
[self.bottomBgView addSubview:self.categoryView];
self.categoryView.frame = CGRectMake(10, 10, ScreenWidth-20, 40);
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
CGFloat itemW = (ScreenWidth-10*2-20*3)/4;
layout.itemSize = CGSizeMake(itemW, itemW+60);
layout.minimumInteritemSpacing = 20;
layout.minimumLineSpacing = 0;
layout.sectionInset = UIEdgeInsetsMake(0, 10, 0, 10);
_collectionView.collectionViewLayout = layout;
_collectionView.delegate = self;
_collectionView.dataSource = self;
[_collectionView registerNib:[UINib nibWithNibName:@"SPShopMallCell" bundle:nil] forCellWithReuseIdentifier:@"SPShopMallCell"];
[self.avatarImgV sd_setImageWithURL:[NSURL URLWithString:self.model.head_pic] placeholderImage:kDefaultUserIcon];
self.nicknameLab.text = self.model.nick_name;
self.IDLab.text = [NSString stringWithFormat:@"%@", self.model.uid];
[self.gxImgV sd_setImageWithURL:[NSURL URLWithString:self.model.contribution_level_image]];
[self.mlImgV sd_setImageWithURL:[NSURL URLWithString:self.model.charm_level_image]];
[ControlCreator createButton:self.view rect:CGRectMake(ScreenWidth-60-12, yb_StatusBar_H+7, 60, 30) text:@"我的装扮" font:YBMediumFont(12) color:HEXCOLOR(0x333333) backguoundColor:nil imageName:nil target:self action:@selector(onMineDress)];
[self.buyBtn setJianBianWithCGSize:CGSizeMake(ScreenWidth-15*2, 45)];
}
- (void)onMineDress {
SPMineDressVC *vc = [[SPMineDressVC alloc] init];
vc.model = self.model;
[self.navigationController pushViewController:vc animated:YES];
}
#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 {
SPShopMallCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"SPShopMallCell" forIndexPath:indexPath];
SPShopMallModel *model = self.dataArray[indexPath.row];
cell.model = model;
if (self.pickIndex == indexPath.row) {
cell.bgImgV.image = ImageNamed(@"mall_bg_sel");
}else {
cell.bgImgV.image = ImageNamed(@"mall_bg_nor");
}
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
self.pickIndex = indexPath.row;
[self.collectionView reloadData];
if (0 == self.currentIndex) {
SPShopMallModel *model = self.dataArray[self.pickIndex];
// [self.kuangImgV sd_setImageWithURL:[NSURL URLWithString:model.base_image]];
}
// SPShopMallModel *model = self.dataArray[self.pickIndex];
// self.priceLab.text = model.price;
//
// UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"确定购买该装扮吗?" message:nil preferredStyle:UIAlertControllerStyleAlert];
// [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
// [self onBuy:nil];
// }]];
// [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
// [self presentViewController:alert animated:YES completion:nil];
}
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
if (index < 3){
self.currentIndex = index;
}else{
self.currentIndex = index+1;
}
self.pickIndex = -1;
self.priceLab.text = @"";
[self fetchData];
if (index == 2){
_lineView.horizontalMargin = 52;
}else if (index == 5 || index == 4){
_lineView.horizontalMargin = 40;
}else if (index == 0){
_lineView.horizontalMargin = 30;
}else{
_lineView.horizontalMargin = 22;
}
}
- (JXCategoryTitleBackgroundView *)categoryView {
if (!_categoryView) {
_categoryView = [[JXCategoryTitleBackgroundView alloc] init];
_categoryView.delegate = self;
_categoryView.titleFont = YBMediumFont(14);
_categoryView.titleSelectedFont = YBBoldFont(15);
_categoryView.titleColor = HEXCOLOR(0xFFFFFF);
_categoryView.titleSelectedColor = HEXCOLOR(0x333333);
_categoryView.selectedBackgroundColor = kClearColor;
_categoryView.cellWidth = 90;
_categoryView.cellSpacing = 10;
_categoryView.titles = self.titles;
_categoryView.contentEdgeInsetLeft = 0;
_categoryView.contentEdgeInsetRight = 0;
_categoryView.normalImageName = @"dress_title_nor";
_categoryView.selectedImageName = @"dress_title_sel";
}
return _categoryView;
}
@end