|
@@ -7,22 +7,14 @@
|
|
|
//
|
|
|
|
|
|
#import "NYComplaintListViewController.h"
|
|
|
-#import "NYComplaintPageViewController.h"
|
|
|
#import "NYComplaintListViewCell.h"
|
|
|
-#import "ComplaintDataModel.h"
|
|
|
+#import "NYComplaintListViewModel.h"
|
|
|
|
|
|
@interface NYComplaintListViewController ()<UITableViewDataSource,UITableViewDelegate>
|
|
|
|
|
|
-
|
|
|
@property (weak, nonatomic) IBOutlet UIButton *addcomp_button;
|
|
|
|
|
|
-@property (weak, nonatomic) IBOutlet UITableView *tableView;
|
|
|
-
|
|
|
-@property (nonatomic,assign) int currentPage;
|
|
|
-
|
|
|
-@property (nonatomic,strong) ComplaintDataModel *complaintDataModel;
|
|
|
-
|
|
|
-@property (nonatomic,strong) NSMutableArray *complaintList;
|
|
|
+@property (nonatomic,strong) NYComplaintListViewModel *complaintListViewModel;
|
|
|
|
|
|
@end
|
|
|
|
|
@@ -32,12 +24,13 @@
|
|
|
[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 getComplaintList];
|
|
|
+ [self.complaintListViewModel getComplaintList];
|
|
|
}
|
|
|
|
|
|
- (void)dealloc {
|
|
@@ -46,56 +39,36 @@
|
|
|
}
|
|
|
|
|
|
#pragma mark - PublicMethods
|
|
|
-
|
|
|
-- (void)getComplaintList{
|
|
|
- _currentPage = 1;
|
|
|
- NSMutableArray *arr = [NSMutableArray array];
|
|
|
- [arr addPro:@"stunum" Value:RQ_USER_MANAGER.currentUser.outId];///学员编号
|
|
|
- [arr addPro:@"currentPage" Value:@(_currentPage)];///当前页
|
|
|
- [arr addPro:@"pageSize" Value:@10];
|
|
|
- [arr addPro:@"dqbh" Value:RQ_USER_MANAGER.currentUser.city];///地区编号
|
|
|
- NSString *method = @"getComplaintList";
|
|
|
+//绑定vm
|
|
|
+- (void)bindViewModel{
|
|
|
@weakify(self)
|
|
|
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
|
|
|
- NSLog(@"%@",dict);
|
|
|
- int code = [dict[@"code"] intValue];
|
|
|
- if(code == 0 ){
|
|
|
- self.complaintDataModel = [ComplaintDataModel yy_modelWithDictionary:dict[@"body"]];
|
|
|
- if(self.complaintDataModel.list.count>0&&self.complaintList.count!=self.complaintDataModel.list.count){
|
|
|
- [self.complaintList removeAllObjects];
|
|
|
- [self.complaintList addObjectsFromArray:self.complaintDataModel.list];
|
|
|
- [self.tableView reloadData];
|
|
|
- }
|
|
|
- }
|
|
|
+ // 使用 RAC 建立按钮点击事件与视图模型中的命令的绑定
|
|
|
+ [[self.addcomp_button rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
|
|
|
+ @strongify(self);
|
|
|
+ [self.complaintListViewModel.addCommand execute:nil];
|
|
|
}];
|
|
|
-}
|
|
|
-
|
|
|
-//更多下一页
|
|
|
-- (void)getComplaintListMore {
|
|
|
|
|
|
- int total = 10* (_currentPage+1);
|
|
|
- if(self.complaintDataModel.total > total){
|
|
|
- _currentPage +=1;
|
|
|
- NSMutableArray *arr = [NSMutableArray array];
|
|
|
- [arr addPro:@"stunum" Value:RQ_USER_MANAGER.currentUser.outId];///学员编号
|
|
|
- [arr addPro:@"currentPage" Value:@(_currentPage)];///当前页
|
|
|
- [arr addPro:@"pageSize" Value:@10];
|
|
|
- [arr addPro:@"dqbh" Value:RQ_USER_MANAGER.currentUser.city];///地区编号
|
|
|
- NSString *method = @"getComplaintList";
|
|
|
- @weakify(self)
|
|
|
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
|
|
|
- NSLog(@"%@",dict);
|
|
|
- int code = [dict[@"code"] intValue];
|
|
|
- if(code == 0 ){
|
|
|
- self.complaintDataModel = [ComplaintDataModel yy_modelWithDictionary:dict[@"body"]];
|
|
|
- if(self.complaintDataModel.list.count>0&&self.complaintList.count!=self.complaintDataModel.list.count){
|
|
|
- [self.complaintList addObjectsFromArray:self.complaintDataModel.list];
|
|
|
- [self.tableView reloadData];
|
|
|
- }
|
|
|
- }
|
|
|
- }];
|
|
|
- }
|
|
|
+ /// 上拉加载
|
|
|
+ [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
|
|
@@ -112,44 +85,44 @@
|
|
|
|
|
|
}
|
|
|
|
|
|
-#pragma mark - 事件
|
|
|
-
|
|
|
-- (IBAction)pushAddCompdo:(UIButton *)sender {
|
|
|
- NYComplaintPageViewController *complaintPageViewController = [[NYComplaintPageViewController alloc] init];
|
|
|
- [RQControllerHelper.currentViewController.navigationController qmui_pushViewController:complaintPageViewController animated:YES completion:nil];
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
#pragma mark - UITableViewDataSource
|
|
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
|
|
{
|
|
|
- return self.complaintList.count;
|
|
|
+ return self.complaintListViewModel.complaintList.count;
|
|
|
}
|
|
|
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
|
|
|
{
|
|
|
- return 260;
|
|
|
+ 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.complaintList[indexPath.row]];
|
|
|
+ [cell setComplaintInfoModel:self.complaintListViewModel.complaintList[indexPath.row]];
|
|
|
+ cell.cancelCommand = self.complaintListViewModel.cancelCommand;
|
|
|
return cell;
|
|
|
}
|
|
|
|
|
|
#pragma mark - UITableViewDelegate
|
|
|
|
|
|
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
|
|
+{
|
|
|
+ [tableView deselectRowAtIndexPath:indexPath animated:true];
|
|
|
+
|
|
|
+}
|
|
|
|
|
|
#pragma mark - Lazy
|
|
|
|
|
|
-- (NSMutableArray *)complaintList
|
|
|
+- (NYComplaintListViewModel *)complaintListViewModel
|
|
|
{
|
|
|
- if(!_complaintList){
|
|
|
- _complaintList = [NSMutableArray array];
|
|
|
+ if(!_complaintListViewModel){
|
|
|
+ _complaintListViewModel = [[NYComplaintListViewModel alloc] init];
|
|
|
+ _complaintListViewModel.vc = self;
|
|
|
}
|
|
|
- return _complaintList;
|
|
|
+ return _complaintListViewModel;
|
|
|
}
|
|
|
|
|
|
@end
|