2
This commit is contained in:
@@ -272,7 +272,7 @@
|
||||
- (UILabel *)amountLabel {
|
||||
if (!_amountLabel) {
|
||||
_amountLabel = [UILabel new];
|
||||
_amountLabel.text = @"88.00";
|
||||
_amountLabel.text = @"00.00";
|
||||
_amountLabel.textColor = [UIColor colorWithHex:KBColorValue];
|
||||
_amountLabel.font = [KBFont bold:40];
|
||||
_amountLabel.adjustsFontSizeToFitWidth = YES;
|
||||
|
||||
@@ -70,6 +70,7 @@ static const CGFloat JXheightForHeaderInSection = 50;
|
||||
}];
|
||||
|
||||
[self fetchShopStylesWithHUD:YES];
|
||||
[self fetchWalletBalanceWithHUD:NO];
|
||||
}
|
||||
|
||||
// 系统导航栏显隐由 Base 统一管理(全局隐藏),该 VC 不再手动切换,避免闪烁。
|
||||
@@ -137,6 +138,7 @@ static const CGFloat JXheightForHeaderInSection = 50;
|
||||
__weak typeof(self)weakSelf = self;
|
||||
self.pagerView.mainTableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
|
||||
[weakSelf fetchShopStylesWithHUD:NO];
|
||||
[weakSelf fetchWalletBalanceWithHUD:NO];
|
||||
}];
|
||||
|
||||
self.pagerView.pinSectionHeaderVerticalOffset = KB_NAV_TOTAL_HEIGHT;
|
||||
@@ -272,6 +274,28 @@ static const CGFloat JXheightForHeaderInSection = 50;
|
||||
return _shopVM;
|
||||
}
|
||||
|
||||
- (void)fetchWalletBalanceWithHUD:(BOOL)showHUD {
|
||||
if (showHUD) {
|
||||
[KBHUD show];
|
||||
}
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[self.shopVM fetchWalletBalanceWithCompletion:^(NSNumber * _Nullable balance, NSError * _Nullable error) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (showHUD) {
|
||||
[KBHUD dismiss];
|
||||
}
|
||||
if (error) {
|
||||
NSString *msg = error.localizedDescription ?: KBLocalized(@"Network error");
|
||||
[KBHUD showInfo:msg];
|
||||
return;
|
||||
}
|
||||
double amountValue = balance.doubleValue;
|
||||
NSString *amountString = [NSString stringWithFormat:@"%.2f", amountValue];
|
||||
[weakSelf.userHeaderView updatePoints:amountString];
|
||||
});
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)fetchShopStylesWithHUD:(BOOL)showHUD {
|
||||
if (showHUD) {
|
||||
[KBHUD show];
|
||||
|
||||
@@ -18,6 +18,8 @@ typedef void(^KBShopStylesCompletion)(NSArray<KBShopStyleModel *> *_Nullable sty
|
||||
NSError *_Nullable error);
|
||||
typedef void(^KBShopThemesCompletion)(NSArray<KBShopThemeModel *> *_Nullable themes,
|
||||
NSError *_Nullable error);
|
||||
typedef void(^KBShopBalanceCompletion)(NSNumber *_Nullable balance,
|
||||
NSError *_Nullable error);
|
||||
|
||||
@interface KBShopVM : NSObject
|
||||
@property (nonatomic, copy, readonly, nullable) NSArray<KBShopStyleModel *> *styles;
|
||||
@@ -29,6 +31,9 @@ typedef void(^KBShopThemesCompletion)(NSArray<KBShopThemeModel *> *_Nullable the
|
||||
- (void)fetchThemesForStyleId:(nullable NSString *)styleId
|
||||
completion:(KBShopThemesCompletion)completion;
|
||||
|
||||
/// 查询钱包余额
|
||||
- (void)fetchWalletBalanceWithCompletion:(KBShopBalanceCompletion)completion;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
@@ -82,4 +82,35 @@
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)fetchWalletBalanceWithCompletion:(KBShopBalanceCompletion)completion {
|
||||
[[KBNetworkManager shared] GET:API_WALLET_BALANCE
|
||||
parameters:nil
|
||||
headers:nil
|
||||
autoShowBusinessError:NO
|
||||
completion:^(NSDictionary * _Nullable json,
|
||||
NSURLResponse * _Nullable response,
|
||||
NSError * _Nullable error) {
|
||||
if (error) {
|
||||
if (completion) completion(nil, error);
|
||||
return;
|
||||
}
|
||||
id dataObj = json[KBData] ?: json[@"data"];
|
||||
if (![dataObj isKindOfClass:[NSDictionary class]]) {
|
||||
if (completion) completion(nil, [self kb_invalidResponseError]);
|
||||
return;
|
||||
}
|
||||
id balanceValue = dataObj[@"balance"];
|
||||
NSNumber *balanceNumber = nil;
|
||||
if ([balanceValue isKindOfClass:[NSNumber class]]) {
|
||||
balanceNumber = balanceValue;
|
||||
} else if ([balanceValue isKindOfClass:[NSString class]]) {
|
||||
balanceNumber = @([(NSString *)balanceValue doubleValue]);
|
||||
}
|
||||
if (!balanceNumber) {
|
||||
balanceNumber = @(0);
|
||||
}
|
||||
if (completion) completion(balanceNumber, nil);
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user