123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- //
- // XYWishCenterViewController.m
- // Timi
- //
- // Created by 翟玉磊 on 2021/10/19.
- //
- #import "XYWishCenterViewController.h"
- #import "XYWishCenterViewModel.h"
- #import "XYWishCenterTableViewCell.h"
- #import "XYWishGiftModel.h"
- #import "XYWishRecordListViewController.h"
- @interface XYWishCenterViewController ()<XYWishCenterTableViewCellDelegate>
- @property (nonatomic, strong) XYWishCenterViewModel *viewModel;
- @property (nonatomic, strong) UILabel *topTipLabel;
- @end
- @implementation XYWishCenterViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
-
- self.title = @"许愿中心";
-
- [self setupUI];
- }
- #pragma mark - Override
- - (UIEdgeInsets)contentInset {
- return UIEdgeInsetsMake(NAVGATION_HEIGHT + 36.0f, 0, 0, 0);
- }
- - (void)bindViewModel {
- self.viewModel = XYWishCenterViewModel.new;
- }
- - (void)tableViewDidTriggerHeaderRefresh {
- self.viewModel.pullDown = YES;
- [self.viewModel loadData:^(id _Nullable responseModel) {
-
- [self tableViewDidFinishTriggerHeader:YES reload:YES];
- [self.tableView zyl_configEmptyViewWithType:ZYLEmptyDataViewTypeDefault emptyInfo:@"" errorInfo:@"" offsetTop:DefaultOffsetTop hasData:self.viewModel.dataSource.count > 0 hasError:NO reloadBlock:nil];
- } failure:^(ZYLNetworkError * _Nullable error) {
- [self tableViewDidFinishTriggerHeader:YES reload:NO];
- [self.tableView zyl_configEmptyViewWithType:ZYLEmptyDataViewTypeDefault emptyInfo:error.domain errorInfo:error.domain offsetTop:DefaultOffsetTop hasData:self.viewModel.dataSource.count > 0 hasError:error != nil reloadBlock:nil];
- }];
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- return 92.0f;
- }
- /// dequeueReusableCell <复用cell> 子类需重写,无须调用 [super xxx]
- - (UITableViewCell *)tableView:(UITableView *)tableView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath {
- return [XYWishCenterTableViewCell cellWithTableView:tableView];
- }
- /// configure cell with data <为cell配置模型 , 等效于 cell.model = object> 子类需重写,无须调用 [super configureCell:atIndexPath:withObject:]
- - (void)configureCell:(XYWishCenterTableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object {
- [cell configureModel:object];
- [cell setIndexPath:indexPath rowsInSection:self.viewModel.dataSource.count];
- cell.delegate = self;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
- }
- #pragma mark - XYWishCenterTableViewCellDelegate
- - (void)wishCenterGiftSwitchValueChangeAtIndexPath:(NSIndexPath *)indexPath {
- XYWishGiftModel *model = self.viewModel.dataSource[indexPath.row];
- [SVProgressHUD show];
- [self.viewModel setupWishGiftSwitchStatusWithModel:model successBlock:^(NSInteger oldIndex, NSInteger index) {
- XYWishGiftModel *currentModel = [self.viewModel.dataSource objectAtIndex:index];
- if (currentModel.status == 1) {
- [SVProgressHUD showSuccessWithStatus:[NSString stringWithFormat:@"%@开启成功", currentModel.giftName]];
- }else if (currentModel.status == 0) {
- [SVProgressHUD showSuccessWithStatus:[NSString stringWithFormat:@"关闭成功,进度次日重置"]];
- }
- if (oldIndex >= 0) {
- [self.tableView reloadRowsAtIndexPaths:@[indexPath, [NSIndexPath indexPathForRow:oldIndex inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
- }else {
- [self.tableView reloadRowAtIndexPath:indexPath withRowAnimation:UITableViewRowAnimationNone];
- }
- } failureBlock:^(ZYLNetworkError * _Nullable error) {
- [SVProgressHUD showInfoWithStatus:error.domain];
- [self.tableView reloadRowAtIndexPath:indexPath withRowAnimation:UITableViewRowAnimationNone];
- }];
- }
- #pragma mark - UI
- - (void)setupUI {
- [self customNavigationItem];
-
- [self topTipLabel];
- }
- - (void)customNavigationItem {
-
- self.navigationItem.rightBarButtonItem = [UIBarButtonItem systemItemWithTitle:@"记录" titleColor:Color_TextFont imageName:nil target:self selector:@selector(recordListAction:) textType:YES];
- }
- #pragma mark - Action
- // 查看心愿记录列表
- - (void)recordListAction:(id)sender {
- [self.navigationController pushViewController:XYWishRecordListViewController.new animated:YES];
- }
- - (UILabel *)topTipLabel {
- if (_topTipLabel == nil) {
- _topTipLabel = [UILabel createLabelTextColor:ColorFromHexString(@"#FF6010") fount:Font(12)];
- _topTipLabel.backgroundColor = ColorFromHexString(@"#FFF9ED");
- _topTipLabel.text = @"~ 许愿任务展示到个人名片,启用一个许愿,次日0点重置 ~";
- _topTipLabel.textAlignment = NSTextAlignmentCenter;
- [self.view addSubview:_topTipLabel];
- [_topTipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.view).offset(NAVGATION_HEIGHT);
- make.left.right.equalTo(self.view);
- make.height.equalTo(@36.0f);
- }];
- [_topTipLabel layoutIfNeeded];
- }
- return _topTipLabel;
- }
- /*
- #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
|