XYWishCenterViewController.m 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. //
  2. // XYWishCenterViewController.m
  3. // Timi
  4. //
  5. // Created by 翟玉磊 on 2021/10/19.
  6. //
  7. #import "XYWishCenterViewController.h"
  8. #import "XYWishCenterViewModel.h"
  9. #import "XYWishCenterTableViewCell.h"
  10. #import "XYWishGiftModel.h"
  11. #import "XYWishRecordListViewController.h"
  12. @interface XYWishCenterViewController ()<XYWishCenterTableViewCellDelegate>
  13. @property (nonatomic, strong) XYWishCenterViewModel *viewModel;
  14. @property (nonatomic, strong) UILabel *topTipLabel;
  15. @end
  16. @implementation XYWishCenterViewController
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. // Do any additional setup after loading the view.
  20. self.title = @"许愿中心";
  21. [self setupUI];
  22. }
  23. #pragma mark - Override
  24. - (UIEdgeInsets)contentInset {
  25. return UIEdgeInsetsMake(NAVGATION_HEIGHT + 36.0f, 0, 0, 0);
  26. }
  27. - (void)bindViewModel {
  28. self.viewModel = XYWishCenterViewModel.new;
  29. }
  30. - (void)tableViewDidTriggerHeaderRefresh {
  31. self.viewModel.pullDown = YES;
  32. [self.viewModel loadData:^(id _Nullable responseModel) {
  33. [self tableViewDidFinishTriggerHeader:YES reload:YES];
  34. [self.tableView zyl_configEmptyViewWithType:ZYLEmptyDataViewTypeDefault emptyInfo:@"" errorInfo:@"" offsetTop:DefaultOffsetTop hasData:self.viewModel.dataSource.count > 0 hasError:NO reloadBlock:nil];
  35. } failure:^(ZYLNetworkError * _Nullable error) {
  36. [self tableViewDidFinishTriggerHeader:YES reload:NO];
  37. [self.tableView zyl_configEmptyViewWithType:ZYLEmptyDataViewTypeDefault emptyInfo:error.domain errorInfo:error.domain offsetTop:DefaultOffsetTop hasData:self.viewModel.dataSource.count > 0 hasError:error != nil reloadBlock:nil];
  38. }];
  39. }
  40. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  41. return 92.0f;
  42. }
  43. /// dequeueReusableCell <复用cell> 子类需重写,无须调用 [super xxx]
  44. - (UITableViewCell *)tableView:(UITableView *)tableView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath {
  45. return [XYWishCenterTableViewCell cellWithTableView:tableView];
  46. }
  47. /// configure cell with data <为cell配置模型 , 等效于 cell.model = object> 子类需重写,无须调用 [super configureCell:atIndexPath:withObject:]
  48. - (void)configureCell:(XYWishCenterTableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object {
  49. [cell configureModel:object];
  50. [cell setIndexPath:indexPath rowsInSection:self.viewModel.dataSource.count];
  51. cell.delegate = self;
  52. }
  53. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  54. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  55. }
  56. #pragma mark - XYWishCenterTableViewCellDelegate
  57. - (void)wishCenterGiftSwitchValueChangeAtIndexPath:(NSIndexPath *)indexPath {
  58. XYWishGiftModel *model = self.viewModel.dataSource[indexPath.row];
  59. [SVProgressHUD show];
  60. [self.viewModel setupWishGiftSwitchStatusWithModel:model successBlock:^(NSInteger oldIndex, NSInteger index) {
  61. XYWishGiftModel *currentModel = [self.viewModel.dataSource objectAtIndex:index];
  62. if (currentModel.status == 1) {
  63. [SVProgressHUD showSuccessWithStatus:[NSString stringWithFormat:@"%@开启成功", currentModel.giftName]];
  64. }else if (currentModel.status == 0) {
  65. [SVProgressHUD showSuccessWithStatus:[NSString stringWithFormat:@"关闭成功,进度次日重置"]];
  66. }
  67. if (oldIndex >= 0) {
  68. [self.tableView reloadRowsAtIndexPaths:@[indexPath, [NSIndexPath indexPathForRow:oldIndex inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
  69. }else {
  70. [self.tableView reloadRowAtIndexPath:indexPath withRowAnimation:UITableViewRowAnimationNone];
  71. }
  72. } failureBlock:^(ZYLNetworkError * _Nullable error) {
  73. [SVProgressHUD showInfoWithStatus:error.domain];
  74. [self.tableView reloadRowAtIndexPath:indexPath withRowAnimation:UITableViewRowAnimationNone];
  75. }];
  76. }
  77. #pragma mark - UI
  78. - (void)setupUI {
  79. [self customNavigationItem];
  80. [self topTipLabel];
  81. }
  82. - (void)customNavigationItem {
  83. self.navigationItem.rightBarButtonItem = [UIBarButtonItem systemItemWithTitle:@"记录" titleColor:Color_TextFont imageName:nil target:self selector:@selector(recordListAction:) textType:YES];
  84. }
  85. #pragma mark - Action
  86. // 查看心愿记录列表
  87. - (void)recordListAction:(id)sender {
  88. [self.navigationController pushViewController:XYWishRecordListViewController.new animated:YES];
  89. }
  90. - (UILabel *)topTipLabel {
  91. if (_topTipLabel == nil) {
  92. _topTipLabel = [UILabel createLabelTextColor:ColorFromHexString(@"#FF6010") fount:Font(12)];
  93. _topTipLabel.backgroundColor = ColorFromHexString(@"#FFF9ED");
  94. _topTipLabel.text = @"~ 许愿任务展示到个人名片,启用一个许愿,次日0点重置 ~";
  95. _topTipLabel.textAlignment = NSTextAlignmentCenter;
  96. [self.view addSubview:_topTipLabel];
  97. [_topTipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  98. make.top.equalTo(self.view).offset(NAVGATION_HEIGHT);
  99. make.left.right.equalTo(self.view);
  100. make.height.equalTo(@36.0f);
  101. }];
  102. [_topTipLabel layoutIfNeeded];
  103. }
  104. return _topTipLabel;
  105. }
  106. /*
  107. #pragma mark - Navigation
  108. // In a storyboard-based application, you will often want to do a little preparation before navigation
  109. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  110. // Get the new view controller using [segue destinationViewController].
  111. // Pass the selected object to the new view controller.
  112. }
  113. */
  114. @end