| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336 |
- //
- // PerformanceRankListVc.m
- // IBOSS
- //
- // Created by guan hong hou on 2018/6/4.
- // Copyright © 2018年 elongtian. All rights reserved.
- //
- #import "PerformanceRankListVc.h"
- @interface PerformanceRankListVc (){
- NSMutableDictionary *_cellHeight;
- }
- @end
- @implementation PerformanceRankListVc
- - (void)viewDidLoad {
- [super viewDidLoad];
- _cellHeight = [[NSMutableDictionary alloc] init];
- _dataList=[[NSMutableArray alloc]init];
- NSString *currentDate=[DateFormat getCurrentDate];
- NSArray *dateArray = [currentDate componentsSeparatedByString:@"-"];
- _currentYear= [dateArray objectAtIndex:0];
- _currentMonth=[dateArray objectAtIndex:1];
-
- [self loadNavStyle];
- [self initHeaderView];
- [self initUI];
- [self loadData];
-
- }
- /**
- 安全区视图发生变化
- */
- -(void)viewSafeAreaInsetsDidChange{
- _tableView.frame = self.view.safeAreaLayoutGuide.layoutFrame;;
- [super viewSafeAreaInsetsDidChange];
- }
- /**
- 导航按钮样式
- */
- - (void)loadNavStyle {
- self.navigationItem.title = @"本月业绩排行";
- UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
- [button setImage:[UIImage imageNamed:@"icon_back"] forState:UIControlStateNormal];
- [button addTarget:self action:@selector(goBack)
- forControlEvents:UIControlEventTouchUpInside];
- button.frame = CGRectMake(0, 0,45,22);
-
- UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
- self.navigationItem.leftBarButtonItem = menuButton;
-
-
- }
- -(void)loadData{
- [self startLoading];
- NSMutableDictionary *dict = [NSMutableDictionary dictionary];
- [dict setObject:@"SalesmanTaskCompleteStatisticsIphone" forKey:@"Action"];
- [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
- [dict setObject:kkUserCode forKey:@"UserCode"];
- [dict setObject:kkUserPwd forKey:@"UserPassword"];
- [dict setObject:kkSessionKey forKey:@"SessionKey"];
-
- [dict setObject:_currentYear forKey:@"TaskAnnual"];
- [dict setObject:_currentMonth forKey:@"TaskMonth"];
- [dict setObject:@"" forKey:@"StaffIDList"];
- [dict setObject:@"1" forKey:@"Granularity"];
- [dict setObject:@"1" forKey:@"ShowAllFlag"];
- _mDownManager = [[ASIDownManager alloc] init];
- _mDownManager.delegate = self;
- _mDownManager.onRequestSuccess = @selector(onStaffPerformanceLoadFinish:);
- _mDownManager.onRequestFail = @selector(onStaffPerformanceLoadFail:);
- [_mDownManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
- }
- -(void)initUI{
-
- _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
- _tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
- _tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
- _tableView.dataSource=self;
- _tableView.delegate = self;
- [self.view addSubview:_tableView];
- }
- /**
- 加载数据成功回调
-
- @param sender <#sender description#>
- */
- - (void)onStaffPerformanceLoadFinish:(ASIDownManager *)sender {
-
- // 服务器返回数据
- RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
- // 服务器返回数据状态值
- int iStatus = resultModel.status;
- [self stopLoading];
-
- // 服务器返回数据消息
- NSString *message = resultModel.message;
- // 服务器返回数据状态值正确
- if (iStatus == 0) {
- NSDictionary * infoDic = (NSDictionary *)resultModel.result;
- NSArray *infoArray=[infoDic objectForKey:@"Table"];
- if(infoArray!=nil&&infoArray.count>0){
-
- for(int i=0;i<infoArray.count;i++){
- NSDictionary *dic=[infoArray objectAtIndex:i];
- PerformanceRankListModel *performanceListModel=[ PerformanceRankListModel dk_modelWithDictionary:dic];
- performanceListModel.rankNo=[NSString stringWithFormat:@"%d",i+1];
- [_dataList addObject:performanceListModel];
- }
- if(_staffList.count==0||_staffList.count>1){
- _tableView.tableHeaderView=nil;
- }
- else{
-
- StaffModel *staffModel=[_staffList objectAtIndex:0];
- PerformanceRankListModel *myPerformanceModel;
- for(int i=0;i<_dataList.count;i++){
- PerformanceRankListModel *performanceListModel=[_dataList objectAtIndex:i];
- if([staffModel.staffId integerValue]==[performanceListModel.staffId integerValue]){
- myPerformanceModel=performanceListModel;
- break;
- }
-
-
- }
- if(myPerformanceModel!=nil){
- _tableView.tableHeaderView=_performanceRankHeaderView;
- _lblRankNumberOneName.text=[NSString stringWithFormat:@"%@(%@)(第%@名)",@"我",myPerformanceModel.staffName,myPerformanceModel.rankNo];
- _lblSalesAmount.text=[NSString stringWithFormat:@"¥%@",myPerformanceModel.salesAmount];
- _lblCurrentMonthTask.text=[NSString stringWithFormat:@"¥%@",myPerformanceModel.currentMonthTaskAmount];
-
- _lblCompletePercent.text=[NSString stringWithFormat:@"%@%@",myPerformanceModel.currentMonthTaskAmount,@"%"];
- }
- }
-
- [_tableView reloadData];
- }
- else{
- // 无数据的view
- UIView *noDataView = [self noDataViewByFrame:_tableView.bounds];
- _tableView.backgroundView=noDataView;
- [self showAlertViewText:@"未找到匹配结果"];
- return;
- }
- }
-
- // 服务器返回数据状态值异常
- else if(iStatus == ActionResultStatusAuthError
- ||iStatus == ActionResultStatusNoLogin
- ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){
- [self showReLoginDialog:message];
- }
- else {
-
- [self showAlertViewText:message];
- }
- }
- /**
- 数据加载失败回调
- @param sender <#sender description#>
- */
- - (void)onStaffPerformanceLoadFail:(ASIDownManager *)sender {
- [self showAlertViewText:@"网络异常"];
- }
- -(void)initHeaderView{
- CGFloat heightRow = 40;
- CGFloat lblx = 20;
- CGFloat lbly = 8;
- CGFloat lblwidth = 70;
- CGFloat lblheight = 25;
- CGFloat valuey = 8;
- CGFloat valueheight = 25;
-
- _performanceRankHeaderView= [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_Width, heightRow)];
- [_performanceRankHeaderView setBackgroundColor:[UIColor whiteColor]];
-
- UIView *vRankNo = [UIView new];
- vRankNo.frame=CGRectMake(0,20, Screen_Width, heightRow);
- [_performanceRankHeaderView addSubview:vRankNo];
- _lblRankNumberOneName = [UILabel new];
- _lblRankNumberOneName.textColor=[UIColor blackColor];
- _lblRankNumberOneName.frame=CGRectMake(lblx, valuey,Screen_Width-108, valueheight);
- _lblRankNumberOneName.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
- [vRankNo addSubview:_lblRankNumberOneName];
-
- _lblSalesAmount = [UILabel new];
- _lblSalesAmount.frame=CGRectMake(Screen_Width-108 ,valuey,100, valueheight);
- _lblSalesAmount.textAlignment = NSTextAlignmentRight;
- _lblSalesAmount.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
- _lblSalesAmount.textColor=[UIColor redColor];
- [vRankNo addSubview:_lblSalesAmount];
-
-
- UIView *vCurrentMonthTask = [UIView new];
- vCurrentMonthTask.frame=CGRectMake(0, CGRectGetMaxY(vRankNo.frame), Screen_Width/2, heightRow);
- [_performanceRankHeaderView addSubview:vCurrentMonthTask];
- UILabel *lblCurrentTaskTitle=[UILabel new];
- lblCurrentTaskTitle.frame=CGRectMake(lblx, lbly, lblwidth, lblheight);
- lblCurrentTaskTitle.text=@"本月任务:";
- lblCurrentTaskTitle.textColor =LabelGrayTextColor;
- lblCurrentTaskTitle.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
- [vCurrentMonthTask addSubview:lblCurrentTaskTitle];
-
- _lblCurrentMonthTask= [UILabel new];
- _lblCurrentMonthTask.frame=CGRectMake(CGRectGetMaxX(lblCurrentTaskTitle.frame), valuey, Screen_Width/2-CGRectGetMaxX(lblCurrentTaskTitle.frame)-3 , valueheight);
- _lblCurrentMonthTask.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
- [vCurrentMonthTask addSubview:_lblCurrentMonthTask];
-
-
- UIView *vCompletePercent = [UIView new];
- vCompletePercent.frame=CGRectMake(Screen_Width/2, CGRectGetMaxY(vRankNo.frame), Screen_Width/2, heightRow);
- [_performanceRankHeaderView addSubview: vCompletePercent];
- UILabel *lblCompletePercentTitle=[UILabel new];
- lblCompletePercentTitle.frame=CGRectMake(5, lbly,110, lblheight);
- lblCompletePercentTitle.text=@"完成百分比:";
- lblCompletePercentTitle.textColor = LabelGrayTextColor;
- lblCompletePercentTitle.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
- [vCompletePercent addSubview:lblCompletePercentTitle];
-
- _lblCompletePercent= [UILabel new];
- _lblCompletePercent.frame=CGRectMake(CGRectGetMaxX(lblCompletePercentTitle.frame), valuey, Screen_Width/2-lblwidth-5 , valueheight);
- _lblCompletePercent.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
- [vCompletePercent addSubview:_lblCompletePercent];
-
- //分割线
- UIView *bottomSeparator= [UIView new];
- bottomSeparator.backgroundColor=LineBackgroundColor;
- bottomSeparator.frame = CGRectMake(0, CGRectGetMaxY(vCurrentMonthTask.frame), Screen_Width, 10);
-
- [_performanceRankHeaderView addSubview:bottomSeparator];
- _performanceRankHeaderView.frame=CGRectMake(0, 0, Screen_Width, CGRectGetMaxY(bottomSeparator.frame));
-
- }
- /**
- tableview的行数
- @param tableView <#tableView description#>
- @param section <#section description#>
- @return <#return value description#>
- */
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return _dataList.count;
- }
- /**
- tableview的分区数
- @param tableView <#tableView description#>
- @return <#return value description#>
- */
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
- return 1;
- }
- /**
- 获取tableview cell
- @param tableView <#tableView description#>
- @param indexPath <#indexPath description#>
- @return <#return value description#>
- */
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *cellIdentifier = @"PerformanceCellId";
- PerformanceRankListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
- if (cell == nil) {
- cell = [[PerformanceRankListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
- cell.selectionStyle=UITableViewCellSelectionStyleNone;
- }
- else
- //当页面拉动的时候 当cell存在并且最后一个存在 把它进行删除就出来一个独特的cell我们在进行数据配置即可避免
- {
- while ([cell.contentView.subviews lastObject] != nil) {
- [(UIView *)[cell.contentView.subviews lastObject] removeFromSuperview];
- }
- }
-
- NSUInteger row = [indexPath row];
- PerformanceRankListModel *rankListModel = [_dataList objectAtIndex:row];
-
- [cell setPerformanceRankListFrame:rankListModel];
- _cellHeight[@(indexPath.row)] = @(cell.cellHeight);
-
- return cell;
-
- }
- /**
- 预防高度
-
- @param tableView <#tableView description#>
- @param indexPath <#indexPath description#>
- @return <#return value description#>
- */
- -(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
- return 250;
- }
- /**
- tableview的高度
- @param tableView <#tableView description#>
- @param indexPath <#indexPath description#>
- @return <#return value description#>
- */
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- return [_cellHeight[@(indexPath.row)] floatValue];
-
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
-
- }
- @end
|