// // NYComplaintListViewController.m // jiaPei // // Created by Ning.ge on 2023/7/2. // Copyright © 2023 JCZ. All rights reserved. // #import "NYComplaintListViewController.h" #import "NYComplaintListViewCell.h" #import "NYComplaintListViewModel.h" @interface NYComplaintListViewController () @property (weak, nonatomic) IBOutlet UIButton *addcomp_button; @property (nonatomic,strong) NYComplaintListViewModel *complaintListViewModel; @end @implementation NYComplaintListViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. [self setupUI]; [self bindViewModel]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.complaintListViewModel getComplaintList]; } - (void)dealloc { NSLog(@"投诉建议列表-NYComplaintListViewController"); } #pragma mark - PublicMethods //绑定vm - (void)bindViewModel{ @weakify(self) // 使用 RAC 建立按钮点击事件与视图模型中的命令的绑定 [[self.addcomp_button rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) { @strongify(self); [self.complaintListViewModel.addCommand execute:nil]; }]; /// 上拉加载 [self.tableView rq_addFooterRefresh:^(MJRefreshAutoNormalFooter *footer) { /// 加载上拉刷新的数据 @strongify(self); [self.complaintListViewModel getComplaintListMore]; }]; /// 隐藏footer or 无更多数据 RAC(self.tableView.mj_footer, hidden) = [[RACObserve(self.complaintListViewModel, dataSource) deliverOnMainThread] map:^(NSArray *dataSource) { @strongify(self) NSUInteger count = dataSource.count; /// 无数据,默认隐藏mj_footer if (count == 0) return @1; /// 无更多数据,隐藏mj_footer if (count == self.complaintListViewModel.complaintDataModel.total) return @1; /// because of return (count % self.complaintListViewModel.currentPage)?@1:@0; }]; } #pragma mark - PrivateMethods - (void)setupUI { self.title = @"投诉建议列表"; [self configureUI]; } - (void)configureUI { self.tableView.backgroundColor = UIColorMakeWithRGBA(242, 243, 245, 1); self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; [self.tableView registerNib:[UINib nibWithNibName:@"NYComplaintListViewCell" bundle:nil] forCellReuseIdentifier:@"NYComplaintListViewCell"]; } #pragma mark - UITableViewDataSource - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.complaintListViewModel.complaintList.count; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { ComplaintInfoModel *info =self.complaintListViewModel.complaintList[indexPath.row]; return info.cellHeight; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NYComplaintListViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"NYComplaintListViewCell"]; [cell setComplaintInfoModel:self.complaintListViewModel.complaintList[indexPath.row]]; cell.cancelCommand = self.complaintListViewModel.cancelCommand; cell.imagesCommand = self.complaintListViewModel.imagesCommand; return cell; } #pragma mark - UITableViewDelegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:true]; } #pragma mark - Lazy - (NYComplaintListViewModel *)complaintListViewModel { if(!_complaintListViewModel){ _complaintListViewModel = [[NYComplaintListViewModel alloc] init]; _complaintListViewModel.vc = self; } return _complaintListViewModel; } @end