123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- //
- // EvaluationListVC.m
- // LNManager
- //
- // Created by EchoShacolee on 2017/5/31.
- // Copyright © 2017年 lee. All rights reserved.
- //
- #import "EvaluationListVC.h"
- #import "MJRefresh.h"
- #import "EvaListCell.h"
- #import "NSString+ex.h"
- #import "NSArray+ex.h"
- #import "MengBanView.h"
- @interface EvaluationListVC ()
- {
- //记录页书
- NSInteger _currentPageNum;
- //加载数据的类型
- MyGetDataType _getDataType;
-
- //缓存cell高度
- NSMutableArray *_heightArr;
- MengBanView *_mengBanView;
- NSString * _status;
-
- UISegmentedControl *_seg;
-
- //权限
- BOOL _permissonSch;
- BOOL _permissonCoa;
- NSString *_failureStrSch;
- NSString *_failureStrCoa;
- }
- @end
- @implementation EvaluationListVC
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- // [self customRightBtn];
-
- //@lee 2018/2/9 处理下啦刷新显示问题
- if (iOS11) {
- }else {
- self.automaticallyAdjustsScrollViewInsets = NO;// Defaults to YES
- }
- self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
-
- _currentPageNum = 0;
- _getDataType = MyGetDataTypeNomal;
- _status = @"1";
- _permissonSch = NO;
- _permissonCoa = NO;
- _failureStrSch = @"";
- _failureStrCoa = @"";
-
- //
- _seg = [[UISegmentedControl alloc]initWithItems:@[@"机构评价",@"教练评价"]];
- _seg.frame = CGRectMake(10, kNavOffSet, kSize.width-20, 40);
- _seg.backgroundColor = [UIColor whiteColor];
- _seg.selectedSegmentIndex = 0;
- _seg.tintColor = COLOR_THEME;
- [_seg addTarget:self action:@selector(change:) forControlEvents:UIControlEventValueChanged];
- [self.view addSubview:_seg];
-
- self.tableView.frame = CGRectMake(0, kNavOffSet+40, kSize.width, kSize.height-kNavOffSet-40-SafeAreaBottomHeight);
-
- [self setRefreshAction];//设置刷新
- [self getPermisson];
-
- __weak typeof(self) weakSelf = self;
- self.block = ^{
- _currentPageNum = 0;
- [weakSelf getData];
- };
- }
- -(void)change:(UISegmentedControl *)seg{
-
- _status = [NSString stringWithFormat:@"%ld",seg.selectedSegmentIndex+1];
- [_heightArr removeAllObjects];
- [self.dataurce removeAllObjects];
- [self.tableView reloadData];
- [self headerRefresh];
- }
- -(void)customRightBtn{
- UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithTitle:@"筛选" style:UIBarButtonItemStylePlain target:self action:@selector(setMengbanView)];
- item.tintColor = COLOR_THEME;
- self.navigationItem.rightBarButtonItem = item;
- }
- -(void)setMengbanView{
-
- if (_mengBanView) {
- [_mengBanView showView];
- return;
- }
-
- NSArray * btnarr = @[@"机构评价",@"教练评价"];
- _mengBanView = [[MengBanView alloc]initWithTitileStr:nil buttonsArray:@[btnarr] block:^(NSArray *array) {
-
- if ([array[0] isEqualToString:@"机构评价"]) {
- _status = @"1";
- }else if ([array[0] isEqualToString:@"教练评价"]){
- _status = @"2";
- }
- [_heightArr removeAllObjects];
- [self.tableView setContentOffset:CGPointMake(0, -kNavOffSet) animated:NO];
- [self headerRefresh];
- }];
- [_mengBanView showView];
- }
- #pragma mark - 下拉刷新,上拉加载 -
- -(void)setRefreshAction{
- // 下拉加载更多
- __weak typeof(self) weakSelf = self;
- MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
- [weakSelf headerRefresh];
- }];
- self.tableView.mj_header = header;
-
- MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
- [weakSelf footerRefresh];
- }];
-
- self.tableView.mj_footer = footer;
-
- }
- -(void)headerRefresh{
-
- //设置获取数据的方式
- _getDataType=MyGetDataTypeHeaderRefresh;
- //加载数据
- [self getData];
- [self.tableView.mj_header endRefreshing];
- }
- -(void)footerRefresh{
- //设置获取数据的方式
- _getDataType=MyGetDataTypeFooterRefresh;
- //加载数据
- [self getData];
- [self.tableView.mj_footer endRefreshing];
- }
- #pragma mark - 网络加载
- -(void)getPermisson{
- //驾校
- [Tools permissionValidationWithID:@"700" result:^(BOOL isCan, NSString *failureStr) {
- if (!isCan) {
- if (failureStr) {
- [self showMsgByMBWithString:failureStr];
- _failureStrSch = failureStr;
- }
- return;
- }
-
- _permissonSch = YES;
- [self getData];
- }];
- //教练
- [Tools permissionValidationWithID:@"26" result:^(BOOL isCan, NSString *failureStr) {
- if (!isCan) {
- if (failureStr) {
- // [self showMsgByMBWithString:failureStr];
- _failureStrCoa = failureStr;
- }
- return;
- }
-
- _permissonCoa = YES;
- }];
- }
- -(void)getData{
-
- BOOL permisson = [_status integerValue]==1?_permissonSch:_permissonCoa;
- if (!permisson) {
- NSString *str = [_status integerValue]==1?_failureStrSch:_failureStrCoa;
- if (str.length != 0) {
- [self showMsgByAlertVCWithString:str];
- }
- return;
- }
-
- //判断当前是否正在加载数据。如果正在加载数据,直接return。
- if (_IS_LOADING) {
- return;
- }
- _IS_LOADING=YES;
- //获取第一页数据
- NSInteger needLoadPage;
- needLoadPage=_currentPageNum+1;
- if (_getDataType==MyGetDataTypeHeaderRefresh) {
- needLoadPage=1;
- }
-
- NSMutableDictionary * mDic = [NSMutableDictionary new];
- [mDic setObject:_status forKey:@"type"];//1机构2教练
- [mDic setObject:MYAPPDELEGATE.userDic[@"dqbh"] forKey:@"dqbh"];
- [mDic setObject:MYAPPDELEGATE.userDic[@"qxbh"] forKey:@"qxbh"];
- [mDic setObject:@"1" forKey:@"isPage"];
- [mDic setObject:@"10" forKey:@"pageSize"];
- [mDic setObject:[NSString stringWithFormat:@"%ld",(long)needLoadPage] forKey:@"currentPage"];
- __weak typeof(self) weakSelf = self;
-
- [self getDataWithDic:mDic method:@"getEvals" block:^(NSDictionary *successDic) {
-
- //处理数据
- //如果获取到了数据,而且是下拉刷新,清空数组。
- if (_getDataType==MyGetDataTypeHeaderRefresh){
- [weakSelf.dataurce removeAllObjects];
- }
- //追加数据
- [weakSelf.dataurce addObjectsFromArray:successDic[@"body"]];
- if (weakSelf.dataurce.count != 0) {
- weakSelf.holderV.hidden = YES;
- }
- //计数器+1
- _currentPageNum=needLoadPage;
- //刷新界面
- [weakSelf.tableView reloadData];
-
- //恢复初始状态。
- _getDataType=MyGetDataTypeNomal;
- }];
- }
- #pragma mark tableView代理方法
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
-
- return self.dataurce.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
-
- EvaListCell * cell = [EvaListCell cellForTabelView:tableView];
- [cell updateWithDic:self.dataurce[indexPath.row]];
- return cell;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
-
- //缓存高度
- NSNumber *cellHeight = [_heightArr h_safeObjectAtIndex:indexPath.row];
-
- if (cellHeight) {
-
- return [cellHeight floatValue];
-
- }else{
-
- NSDictionary * dic = self.dataurce[indexPath.row];
- CGFloat h1 = [dic[@"SRVMANNER"] length] ? 17 : 0;
- CGFloat h2 = [self getHeightWithString:dic[@"TEACHLEVEL"]];
- CGFloat h3 = [self getHeightWithString:dic[@"COACHNAME"]];
-
- CGFloat H = 74+h1+h2+h3;//74为其它固定高度
- [_heightArr addObject:@(H)];
- return H;
- }
-
- }
- #pragma mark 计算高度
- -(CGFloat)getHeightWithString:(NSString *)str{
-
- if (str.length == 0) {
- return 0;
- }
-
- NSString * newStr = [NSString stringWithFormat:@"评价管理 :%@",str];
- CGFloat w = self.tableView.frame.size.width-40;
- CGFloat h1 = [newStr heightForWid:w Font:14];
- return h1+5;//5是间隔
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- @end
|