Files
yinmeng-ios-store/yinmeng-ios/DingDangApp/V2Versions/Mine/装饰商城/DDShoppingVC.m
2023-12-13 15:59:04 +08:00

387 lines
15 KiB
Objective-C

//
// DDShoppingVC.m
// DingDangApp
//
// Created by apple on 2023/6/29.
//
#import "DDShoppingVC.h"
#import "DDShoppingHeaderView.h"
#import "DDShoppingCell.h"
#import "DDShoppingModel.h"
#import "DDShoppingShowView.h"
#import "DDBuySuccessShowView.h"
#import "DDMyRechargeVC.h"
#import "DDWebViewController.h"
#import "DDShoppingListVC.h"
#import "DDDecoratePVC.h"
#import "Api+DDMineApi.h"
@interface DDShoppingVC () <UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
@property (nonatomic, strong) NSMutableArray *listArr;
@property (nonatomic, strong) DDShoppingHeaderView *headerView;
@property (nonatomic, strong) UICollectionView *hotCollectionView;
@property (nonatomic,strong) UICollectionViewFlowLayout *flowLayout;
@property (nonatomic, strong) NSMutableArray *dataArr;
@property (nonatomic, strong) UIButton *knapsackPageBtn;
@property (nonatomic, strong) UIButton *moreBtn;
@property (nonatomic, assign) NSInteger pageNum;
@end
@implementation DDShoppingVC
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.listArr = [[NSMutableArray alloc] init];
self.dataArr = [[NSMutableArray alloc] init];
[self defaultNavTitle:@"商城" hideLine:YES];
[self initWithSubView];
[self initRequest];
self.pageNum = 1;
[self initHotMall];
}
//分类
- (void)initRequest {
WeakSelf(ws);
[Api requestDressUpShopList:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
if(code == 200){
if (ws.listArr.count>0) {
[ws.listArr removeAllObjects];
}
NSArray *list = [DDCategoryModel DD_ModelsWithArray:data.data];
[ws.listArr addObjectsFromArray:list];
ws.headerView.dataArray = ws.listArr;
}
} dressType:@"1"];
return;
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
[NetworkRequest requestPOST:@"/goods/getGoodsClass" parameters:params block:^(BaseResponse * _Nonnull response) {
if (response.isSuccess) {
if ([ToolsObject IsNullWithObject:response.data]) {
return;
}
if (ws.listArr.count>0) {
[ws.listArr removeAllObjects];
}
ws.listArr = [NSArray yy_modelArrayWithClass:DDCategoryModel.class json:response.data[@"list"]].mutableCopy;
ws.headerView.dataArray = ws.listArr;
} else {
[ToolsObject addPopVieToText:response.msg];
}
}];
}
- (void)initHotMall {
WeakSelf(ws);
[Api requestDressUpShopList:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
[ws.hotCollectionView.mj_header endRefreshing];
[ws.hotCollectionView.mj_footer endRefreshing];
if(code == 200){
if (ws.pageNum == 1) {
[ws.dataArr removeAllObjects];
}
NSArray *list = [DDShoppingModel DD_ModelsWithArray:data.data];
[ws.dataArr addObjectsFromArray:list];
[ws.hotCollectionView reloadData];
}
} dressType:@"0"];
return;
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
[dic setObject:@(20) forKey:@"current_page"];
[dic setObject:@(self.pageNum) forKey:@"page_number"];
[NetworkRequest requestPOST:@"/goods/getHotGoods" parameters:dic block:^(BaseResponse * _Nonnull response) {
[ws.hotCollectionView.mj_header endRefreshing];
[ws.hotCollectionView.mj_footer endRefreshing];
if (response.isSuccess) {
if ([ToolsObject IsNullWithObject:response.data]) {
return;
}
if (ws.pageNum == 1) {
[ws.dataArr removeAllObjects];
}
[ws.dataArr addObjectsFromArray:[NSArray yy_modelArrayWithClass:DDShoppingModel.class json:response.data[@"hotGoodsList"]]];
[ws.hotCollectionView reloadData];
} else {
[ToolsObject addPopVieToText:response.msg];
}
}];
}
//背包
- (void)knapsackPageBtnClick {
DDDecoratePVC *VC = [[DDDecoratePVC alloc] init];
[self.navigationController pushViewController:VC animated:YES];
}
//商城说明
- (void)moreBtnClick {
DDWebViewController * webVC = [DDWebViewController webControlerWithUrlStr:[NSString stringWithFormat:@"%@/#/publicpage?position=1017",KWebURL] isShowNavBar:YES navTitle:@"商城说明"];
[self.navigationController pushViewController:webVC animated:NO];
}
- (void)initWithSubView {
[self.customNavBar addSubview:self.moreBtn];
[self.moreBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(-15);
make.centerY.equalTo(self.customNavBar.leftButton);
make.width.height.mas_equalTo(24);
}];
self.moreBtn.hidden = YES;
self.knapsackPageBtn.hidden = YES;
[self.customNavBar addSubview:self.knapsackPageBtn];
[self.knapsackPageBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.moreBtn.mas_left).offset(-10);
make.centerY.equalTo(self.customNavBar.leftButton);
make.width.mas_equalTo(76);
make.height.mas_equalTo(24);
}];
self.view.backgroundColor= DDHEXColor(0xF6F6F6);
[self.view addSubview:self.headerView];
[self.headerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.view);
make.top.equalTo(self.customNavBar.mas_bottom);
make.height.mas_equalTo(185+36);
}];
[self.view addSubview:self.hotCollectionView];
[self.hotCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.headerView.mas_bottom);
make.bottom.equalTo(self.view);
make.left.right.mas_equalTo(0);
}];
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.dataArr.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
DDShoppingCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"DDShoppingCell" forIndexPath:indexPath];
cell.model = self.dataArr[indexPath.row];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
return;
if (indexPath.item < self.dataArr.count) {
DDShoppingModel *goodModel = self.dataArr[indexPath.row];
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
[dic setObject:goodModel.goods_id forKey:@"goods_id"];
WeakSelf(ws);
[NetworkRequest requestPOST:@"/goods/getGoodsDetail" parameters:dic block:^(BaseResponse * _Nonnull response) {
if (response.isSuccess) {
if (![ToolsObject IsNullWithObject:response.data]) {
DDShoppingDetailsModel *model = [DDShoppingDetailsModel yy_modelWithJSON:response.data];
DDShoppingShowView *alertView = [[DDShoppingShowView alloc] initGoodsDetailAlertViewWithModel:model WithType:model.type];
alertView.didTopUpBlock = ^{
//跳转充值页面
DDMyRechargeVC *vc = [[DDMyRechargeVC alloc] init];
vc.walletType = 1;
[[ToolsObject getCurrentViewController].navigationController pushViewController:vc animated:YES];
};
__block DDShoppingShowView *blockView = alertView;
alertView.didBtnAcBlock = ^(NSString * _Nonnull goods_id, DDDetailsModelListModel * _Nonnull spModel, NSString * _Nonnull type, NSString * _Nonnull num) {
if (!spModel) {
return;
}
if ([ToolsObject getUserModel].diamond < [spModel.sell_price integerValue]) {
[self alertStarRechargeView];
[blockView hide];
return;
}
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
[dic setObject:goods_id forKey:@"goods_id"];
[dic setObject:spModel.goods_specifite_id forKey:@"goods_specifite_id"];
[dic setObject:type forKey:@"type"];
[dic setObject:num forKey:@"num"];
[ws payGoods:dic];
};
}
} else {
[ToolsObject addPopVieToText:response.msg];
}
}];
}
}
- (void)alertStarRechargeView{
DDCustomAlertView *alertView = [[DDCustomAlertView alloc]init:@[@"取消",@"去充值"] title:@"您的钻石余额不足,\n是否立即去充值钻石?" content:@"" alertType:0];
alertView.alertViewClickBlock = ^(NSInteger index, NSString * _Nonnull title) {
if ([title isEqualToString:@"去充值"]) {
//跳转充值页面
DDMyRechargeVC *vc = [[DDMyRechargeVC alloc] init];
vc.walletType = 1;
[[ToolsObject getCurrentViewController].navigationController pushViewController:vc animated:YES];
}
};
[alertView showAlertView];
}
//购买
- (void)payGoods:(NSMutableDictionary *)dic {
WeakSelf(ws)
[NetworkRequest requestPOST:@"/goods/placeOrder" parameters:dic block:^(BaseResponse * _Nonnull response) {
if (response.isSuccess) {
[ws getDiamond];
DDBuySuccessShowView *view = [[DDBuySuccessShowView alloc] initAlertView];
view.didUseGoodsBlock = ^(BOOL isUse, BOOL isHidden) {
if (isUse) {
//使用
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
[dic setObject:response.data[@"type"] forKey:@"type"];
[dic setObject:response.data[@"knapsack_id"] forKey:@"knapsack_id"];
[dic setObject:@"1" forKey:@"set_type"];
[self userGoods:dic];
}
};
[ToolsObject addPopVieToText:@"购买成功"];
} else {
[ToolsObject addPopVieToText:response.msg];
}
}];
}
//穿戴
- (void)userGoods:(NSMutableDictionary *)dic {
WeakSelf(ws);
[NetworkRequest requestPOST:@"/Knapsack/setWear" parameters:dic block:^(BaseResponse * _Nonnull response) {
if (response.isSuccess) {
[ToolsObject addPopVieToText:@"穿戴成功"];
[ws reloadUserInfo];
} else {
[ToolsObject addPopVieToText:response.msg];
}
}];
}
-(void)reloadUserInfo {
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
[NetworkRequest requestPOST:@"/user/info" parameters:dict block:^(BaseResponse * _Nonnull response) {
if (response.code == 200) {
if ([ToolsObject IsNullWithObject:response.data]) {
return;
}
AppUserModel *model = [AppUserModel yy_modelWithJSON:response.data];
AppUserModel * myModel = [ToolsObject getUserModel];
NSString * token = myModel.token;
myModel = model;
myModel.token = token;
[ToolsObject saveUserModel:myModel];
}
}];
}
- (void)getDiamond {
[NetworkRequest requestPOST:@"/finance/diamond" parameters:@{} block:^(BaseResponse * _Nonnull response) {
if (response.isSuccess) {
double diamod = [response.data[@"diamond"] doubleValue];
AppUserModel * myModel = [ToolsObject getUserModel];
myModel.diamond = diamod;
[ToolsObject saveUserModel:myModel];
} else {
[ToolsObject addPopVieToText:response.msg];
}
}];
}
#pragma mark ------ 懒加载 ------
- (UIButton *)knapsackPageBtn {
if (!_knapsackPageBtn) {
_knapsackPageBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
[_knapsackPageBtn setImage:[UIImage imageNamed:@"mine_bg_icon_38"] forState:(UIControlStateNormal)];
[_knapsackPageBtn addTarget:self action:@selector(knapsackPageBtnClick) forControlEvents:UIControlEventTouchUpInside];
} return _knapsackPageBtn;
}
- (UIButton *)moreBtn {
if (!_moreBtn) {
_moreBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
[_moreBtn setImage:[UIImage imageNamed:@"mine_bg_icon_39"] forState:(UIControlStateNormal)];
[_moreBtn addTarget:self action:@selector(moreBtnClick) forControlEvents:UIControlEventTouchUpInside];
} return _moreBtn;
}
-(DDShoppingHeaderView *)headerView
{
if (!_headerView) {
_headerView = [[DDShoppingHeaderView alloc]init];
WeakSelf(ws)
_headerView.didSelectBlockBlock = ^(id _Nonnull model) {
if ([model isKindOfClass:DDCategoryModel.class]) {
// DDCategoryModel *cateModel = model;
// DDShoppingListVC *vc = [[DDShoppingListVC alloc]init];
// vc.cateModel = cateModel;
// [ws.navigationController pushViewController:vc animated:YES];
}
};
}
return _headerView;
}
- (UICollectionViewFlowLayout *)flowLayout {
if (!_flowLayout) {
_flowLayout = [[UICollectionViewFlowLayout alloc]init];
CGFloat itemWidth = 0;
itemWidth = (kWidth-45)/3;
_flowLayout.itemSize = CGSizeMake(itemWidth, itemWidth*1.32);
_flowLayout.sectionInset = UIEdgeInsetsMake(10,15,10,15);
_flowLayout.minimumLineSpacing = 10;
_flowLayout.minimumInteritemSpacing = 7;
_flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
}return _flowLayout;
}
- (UICollectionView *)hotCollectionView {
if (!_hotCollectionView) {
_hotCollectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:self.flowLayout];
_hotCollectionView.delegate = self;
_hotCollectionView.dataSource = self;
_hotCollectionView.showsHorizontalScrollIndicator = NO;
_hotCollectionView.alwaysBounceVertical= YES;
_hotCollectionView.backgroundColor = [UIColor clearColor];
[_hotCollectionView registerClass:[DDShoppingCell class] forCellWithReuseIdentifier:@"DDShoppingCell"];
WeakSelf(ws)
_hotCollectionView.mj_footer =
_hotCollectionView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
ws.pageNum ++;
[ws initHotMall];
}];
} return _hotCollectionView;
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end