// // WalletViewController.m // TreeHole // // Created by 谢培艺 on 2022/6/19. // #import "WalletViewController.h" #import "WalletInfo.h" #import "WalletRecordCell.h" #import "WXApi.h" @interface WalletViewController () @property (nonatomic, strong) WalletInfo *info; @end @implementation WalletViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self startLoading]; [PYHTTPManager postWithPath:@"mywallet" params:nil callback:^(id _Nullable rsp, NSError * _Nullable error) { [self endLoading:error]; self.info = [WalletInfo mj_objectWithKeyValues:rsp]; [self setupUI]; [self.tableView reloadData]; }]; } - (BOOL)refreshEnable { return NO; } - (BOOL)loadMoreEnable { return NO; } - (void)setupUI { self.title = @"钱包"; UIButton *okButton = [UIButton buttonWithType:UIButtonTypeSystem]; [okButton setTitle:@"去提现" forState:UIControlStateNormal]; okButton.titleLabel.font = MT_FONT_REGULAR_SIZE(15); WeakSelf(self); [okButton addTouchUpInsideWithAction:^(UIButton * _Nullable button) { [MTAlertView showWithSetupBlcok:^(MTAlertViewConfig *config) { config.title = @"提现"; config.message = weakself.info.can_reward ? weakself.info.can_reward_des : weakself.info.cannot_reward_des; if (weakself.info.can_reward) { config.cancelTitle = @"取消"; config.otherTitle = @"前往微信"; config.otherHandler = ^(MTAlertButton *button) { if (![WXApi openWXApp]) { [SVProgressHUD showErrorWithStatus:@"唤起微信失败,请手动唤起"]; } }; } else { config.otherTitle = @"知道了"; } }]; }]; [okButton setTitleColor:THEME_COLOR forState:UIControlStateNormal]; okButton.width = FIX_SIZE(50); if (self.info.can_reward) { okButton.hidden = NO; }else{ okButton.hidden = YES; } self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:okButton]; UIView *headerView = [[UIView alloc] init]; headerView.width = SCREEN_WIDTH; PYImageView *bannerView = [[PYImageView alloc] init]; bannerView.width = SCREEN_WIDTH; bannerView.height = self.info.banner.banner_img.length > 0 ? bannerView.width * 50.0 / 375.0 : 0.0; bannerView.imageUrl = self.info.banner.banner_img; [bannerView addTapWithAction:^{ [PYAppService openWebVCWithTitle:@"" url:self.info.banner.banner_url]; }]; [headerView addSubview:bannerView]; UIImageView *cardView = [[UIImageView alloc] init]; cardView.image = ImageNamed(@"TH_wallet_card_bg"); cardView.layer.cornerRadius = cardView.x = FIX_SIZE(15); cardView.y = FIX_SIZE(15) + bannerView.bottom; cardView.width = SCREEN_WIDTH - cardView.x * 2; cardView.height = cardView.width * 130.0 / 345.0; UIView *containerView = [[UIView alloc] init]; containerView.x = FIX_SIZE(16); containerView.width = cardView.width - containerView.x * 2; containerView.height = FIX_SIZE(70); UILabel *cardTitleLabel = [[UILabel alloc] init]; cardTitleLabel.text = @"我的资产(元)"; cardTitleLabel.font = MT_FONT_REGULAR_SIZE(14); cardTitleLabel.textColor = COLOR_WITH_RGB(0xC5CBF4); cardTitleLabel.width = containerView.width; cardTitleLabel.height = FIX_SIZE(20); [containerView addSubview:cardTitleLabel]; UILabel *cardContentLabel = [[UILabel alloc] init]; cardContentLabel.text = self.info.can_reward_rmb; cardContentLabel.font = MT_FONT_MEDIUM_SIZE(34); cardContentLabel.textColor = COLOR_WITH_RGB(0xF1F3FC); [cardContentLabel sizeToFit]; cardContentLabel.y = cardTitleLabel.bottom; [containerView addSubview:cardContentLabel]; UILabel *willRewardLabel = [[UILabel alloc] init]; willRewardLabel.text = self.info.will_reward_rmb; willRewardLabel.font = MT_FONT_MEDIUM_SIZE(14); willRewardLabel.textColor = COLOR_WITH_RGB(0xF1F3FC); [willRewardLabel sizeToFit]; willRewardLabel.centerY = cardContentLabel.centerY+ FIX_SIZE(4); willRewardLabel.left = cardContentLabel.right + FIX_SIZE(6); [containerView addSubview:willRewardLabel]; containerView.height = cardContentLabel.bottom + FIX_SIZE(8); [cardView addSubview:containerView]; containerView.centerY = cardView.height * 0.5; [headerView addSubview:cardView]; headerView.height = cardView.bottom; self.tableView.tableHeaderView = headerView; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.info.deal_flows.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { WalletRecordCell *cell = [WalletRecordCell cellWithTableView:tableView]; cell.record = self.info.deal_flows[indexPath.row]; return cell; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return FIX_SIZE(WalletRecordCellHeight); } @end