NYComplaintListViewController.m 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //
  2. // NYComplaintListViewController.m
  3. // jiaPei
  4. //
  5. // Created by Ning.ge on 2023/7/2.
  6. // Copyright © 2023 JCZ. All rights reserved.
  7. //
  8. #import "NYComplaintListViewController.h"
  9. #import "NYComplaintListViewCell.h"
  10. #import "NYComplaintListViewModel.h"
  11. @interface NYComplaintListViewController ()<UITableViewDataSource,UITableViewDelegate>
  12. @property (weak, nonatomic) IBOutlet UIButton *addcomp_button;
  13. @property (nonatomic,strong) NYComplaintListViewModel *complaintListViewModel;
  14. @end
  15. @implementation NYComplaintListViewController
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. // Do any additional setup after loading the view from its nib.
  19. [self setupUI];
  20. [self bindViewModel];
  21. }
  22. - (void)viewWillAppear:(BOOL)animated
  23. {
  24. [super viewWillAppear:animated];
  25. [self.complaintListViewModel getComplaintList];
  26. }
  27. - (void)dealloc {
  28. NSLog(@"投诉建议列表-NYComplaintListViewController");
  29. }
  30. #pragma mark - PublicMethods
  31. //绑定vm
  32. - (void)bindViewModel{
  33. @weakify(self)
  34. // 使用 RAC 建立按钮点击事件与视图模型中的命令的绑定
  35. [[self.addcomp_button rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
  36. @strongify(self);
  37. [self.complaintListViewModel.addCommand execute:nil];
  38. }];
  39. /// 上拉加载
  40. [self.tableView rq_addFooterRefresh:^(MJRefreshAutoNormalFooter *footer) {
  41. /// 加载上拉刷新的数据
  42. @strongify(self);
  43. [self.complaintListViewModel getComplaintListMore];
  44. }];
  45. /// 隐藏footer or 无更多数据
  46. RAC(self.tableView.mj_footer, hidden) = [[RACObserve(self.complaintListViewModel, dataSource)
  47. deliverOnMainThread]
  48. map:^(NSArray *dataSource) {
  49. @strongify(self)
  50. NSUInteger count = dataSource.count;
  51. /// 无数据,默认隐藏mj_footer
  52. if (count == 0) return @1;
  53. /// 无更多数据,隐藏mj_footer
  54. if (count == self.complaintListViewModel.complaintDataModel.total) return @1;
  55. /// because of
  56. return (count % self.complaintListViewModel.currentPage)?@1:@0;
  57. }];
  58. }
  59. #pragma mark - PrivateMethods
  60. - (void)setupUI {
  61. self.title = @"投诉建议列表";
  62. [self configureUI];
  63. }
  64. - (void)configureUI {
  65. self.tableView.backgroundColor = UIColorMakeWithRGBA(242, 243, 245, 1);
  66. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  67. [self.tableView registerNib:[UINib nibWithNibName:@"NYComplaintListViewCell" bundle:nil] forCellReuseIdentifier:@"NYComplaintListViewCell"];
  68. }
  69. #pragma mark - UITableViewDataSource
  70. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  71. {
  72. return self.complaintListViewModel.complaintList.count;
  73. }
  74. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  75. {
  76. ComplaintInfoModel *info =self.complaintListViewModel.complaintList[indexPath.row];
  77. return info.cellHeight;
  78. }
  79. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  80. {
  81. NYComplaintListViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"NYComplaintListViewCell"];
  82. [cell setComplaintInfoModel:self.complaintListViewModel.complaintList[indexPath.row]];
  83. cell.cancelCommand = self.complaintListViewModel.cancelCommand;
  84. cell.imagesCommand = self.complaintListViewModel.imagesCommand;
  85. return cell;
  86. }
  87. #pragma mark - UITableViewDelegate
  88. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  89. {
  90. [tableView deselectRowAtIndexPath:indexPath animated:true];
  91. }
  92. #pragma mark - Lazy
  93. - (NYComplaintListViewModel *)complaintListViewModel
  94. {
  95. if(!_complaintListViewModel){
  96. _complaintListViewModel = [[NYComplaintListViewModel alloc] init];
  97. _complaintListViewModel.vc = self;
  98. }
  99. return _complaintListViewModel;
  100. }
  101. @end