123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- //
- // XYWalletListViewModel.m
- // Starbuds
- //
- // Created by 翟玉磊 on 2020/1/13.
- // Copyright © 2020 翟玉磊. All rights reserved.
- //
- #import "XYWalletListViewModel.h"
- #import "XYWalletListCellModel.h"
- @implementation XYWalletListViewModel
- - (instancetype)init {
- if (self = [super init]) {
-
- self.shouldPullDownToRefresh = YES;
- self.shouldBeginRefreshing = NO;
- }
- return self;
- }
- - (void)loadData:(SuccessHandler)success failure:(FailureHandler)failure {
- [[XYUserAPIManager new] getUserWalletSuccessHandler:^(ZYLResponseModel *responseModel) {
-
- if (responseModel.codeState) {
-
- [self.dataSource removeAllObjects];
-
- if (StringIsNotEmpty([XYAppConfigModel getUrlVirtualCoin])) {
- XYWalletListCellModel *model = [XYWalletListCellModel new];
- model.walletType = Wallet_Type_Star_Virtual;
- model.bgImageName = @"icon_wallet_virtual_bg";
- model.title = [NSString stringWithFormat:@"查看%@", App_CoinName(Wallet_Type_Star_Virtual)];
- model.cellHeight = SCREEN_WIDTH * (72.0f/375.0f);
- [self.dataSource addObject:model];
- }
-
- NSMutableArray *tempArray = [NSMutableArray array];
- for (NSDictionary *dict in responseModel.data[@"walletItems"]) {
- XYWalletListCellModel *model = [XYWalletListCellModel new];
- model.walletType = [dict[@"walletType"] integerValue];
- switch (model.walletType) {
- case Wallet_Type_Star_Diamond:
- {
- model.bgImageName = @"icon_wallet_pink_bg";
- model.coin = [BaseMethod toString:dict[@"balance"]];
- model.title = App_CoinName(Wallet_Type_Star_Diamond);
- model.operationStr = kLocalizedString(@"充值");
- model.introduceTitle = App_CoinName(Wallet_Type_Star_Diamond);
- model.introduce = kLocalizedString(@"可用来购买虚拟礼物等本平台上的产品或服务。");
- self.coinBalance = responseModel.data[@"coinBalance"];
-
- [tempArray addObject:model];
- }
- break;
- case Wallet_Type_Star_Yuan:
- {
- model.bgImageName = @"icon_wallet_blue_bg";
- model.coin = [BaseMethod toString:dict[@"balance"]];
- model.title = App_CoinName(Wallet_Type_Star_Yuan);
- if (StringIsNotEmpty([XYAppConfigModel getUrlCoinShop])) {
- model.operationStr = kLocalizedString(@"兑换");
- }
- model.introduceTitle = App_CoinName(Wallet_Type_Star_Yuan);
- model.introduce = [NSString stringWithFormat:kLocalizedString(@"%@:每充值100%@可获得1%@,可用来兑换【贵族】或在【%@商城】中兑换您喜欢的其他商品。"), App_CoinName(Wallet_Type_Star_Yuan), App_CoinName(Wallet_Type_Star_Diamond), App_CoinName(Wallet_Type_Star_Yuan), App_CoinName(Wallet_Type_Star_Yuan)];
- // [tempArray addObject:model];
- }
- break;
- case Wallet_Type_Star_Coin:
- {
- model.bgImageName = @"icon_wallet_yellow_bg";
- model.coin = [BaseMethod toString:dict[@"balance"]];
- model.title = App_CoinName(Wallet_Type_Star_Coin);
- model.operationStr = kLocalizedString(@"转出");
- // [tempArray addObject:model];
- }
- break;
- case Wallet_Type_Star_Dust:
- {
- model.bgImageName = @"icon_wallet_purple_bg";
- model.coin = [BaseMethod toString:dict[@"balance"]];
- model.title = App_CoinName(Wallet_Type_Star_Dust);
- model.operationStr = kLocalizedString(@"提现");
- model.introduceTitle = App_CoinName(Wallet_Type_Star_Dust);
- model.introduce = kLocalizedString(@"用户在平台上的收益,可以兑换钻石或提现。");
- if (!ApplicationDelegate.isVersionStatus) {
- [tempArray addObject:model];
- }
- }
- break;
- case Wallet_Type_Gold_Coin:
- {
- model.bgImageName = @"icon_wallet_gold_bg";
- model.coin = [BaseMethod toString:dict[@"balance"]];
- model.title = App_CoinName(Wallet_Type_Gold_Coin);
- model.operationStr = kLocalizedString(@"商城兑换");
- model.introduceTitle = App_CoinName(Wallet_Type_Gold_Coin);
- model.introduce = kLocalizedString(@"签到获得金币,金币可用于商城兑换");
- [tempArray addObject:model];
- }
- break;
- default:
- break;
- }
- }
- // 排序
- NSArray *sortedArray = [tempArray sortedArrayUsingComparator:^NSComparisonResult(XYWalletListCellModel *obj1, XYWalletListCellModel *obj2) {
- if (obj1.walletType < obj2.walletType) {
- return NSOrderedAscending;
- }else {
- return NSOrderedDescending;
- }
- }];
- [self.dataSource addObjectsFromArray:sortedArray];
- }
- !success?:success(responseModel);
- } failureHandler:^(NSError *error) {
- !failure?:failure(error);
- }];
- }
- @end
|