PerformanceRankListVc.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. //
  2. // PerformanceRankListVc.m
  3. // IBOSS
  4. //
  5. // Created by guan hong hou on 2018/6/4.
  6. // Copyright © 2018年 elongtian. All rights reserved.
  7. //
  8. #import "PerformanceRankListVc.h"
  9. @interface PerformanceRankListVc (){
  10. NSMutableDictionary *_cellHeight;
  11. }
  12. @end
  13. @implementation PerformanceRankListVc
  14. - (void)viewDidLoad {
  15. [super viewDidLoad];
  16. _cellHeight = [[NSMutableDictionary alloc] init];
  17. _dataList=[[NSMutableArray alloc]init];
  18. NSString *currentDate=[DateFormat getCurrentDate];
  19. NSArray *dateArray = [currentDate componentsSeparatedByString:@"-"];
  20. _currentYear= [dateArray objectAtIndex:0];
  21. _currentMonth=[dateArray objectAtIndex:1];
  22. [self loadNavStyle];
  23. [self initHeaderView];
  24. [self initUI];
  25. [self loadData];
  26. }
  27. /**
  28. 安全区视图发生变化
  29. */
  30. -(void)viewSafeAreaInsetsDidChange{
  31. _tableView.frame = self.view.safeAreaLayoutGuide.layoutFrame;;
  32. [super viewSafeAreaInsetsDidChange];
  33. }
  34. /**
  35. 导航按钮样式
  36. */
  37. - (void)loadNavStyle {
  38. self.navigationItem.title = @"本月业绩排行";
  39. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  40. [button setImage:[UIImage imageNamed:@"icon_back"] forState:UIControlStateNormal];
  41. [button addTarget:self action:@selector(goBack)
  42. forControlEvents:UIControlEventTouchUpInside];
  43. button.frame = CGRectMake(0, 0,45,22);
  44. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  45. self.navigationItem.leftBarButtonItem = menuButton;
  46. }
  47. -(void)loadData{
  48. [self startLoading];
  49. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  50. [dict setObject:@"SalesmanTaskCompleteStatisticsIphone" forKey:@"Action"];
  51. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  52. [dict setObject:kkUserCode forKey:@"UserCode"];
  53. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  54. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  55. [dict setObject:_currentYear forKey:@"TaskAnnual"];
  56. [dict setObject:_currentMonth forKey:@"TaskMonth"];
  57. [dict setObject:@"" forKey:@"StaffIDList"];
  58. [dict setObject:@"1" forKey:@"Granularity"];
  59. [dict setObject:@"1" forKey:@"ShowAllFlag"];
  60. _mDownManager = [[ASIDownManager alloc] init];
  61. _mDownManager.delegate = self;
  62. _mDownManager.onRequestSuccess = @selector(onStaffPerformanceLoadFinish:);
  63. _mDownManager.onRequestFail = @selector(onStaffPerformanceLoadFail:);
  64. [_mDownManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
  65. }
  66. -(void)initUI{
  67. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
  68. _tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
  69. _tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
  70. _tableView.dataSource=self;
  71. _tableView.delegate = self;
  72. [self.view addSubview:_tableView];
  73. }
  74. /**
  75. 加载数据成功回调
  76. @param sender <#sender description#>
  77. */
  78. - (void)onStaffPerformanceLoadFinish:(ASIDownManager *)sender {
  79. // 服务器返回数据
  80. RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
  81. // 服务器返回数据状态值
  82. int iStatus = resultModel.status;
  83. [self stopLoading];
  84. // 服务器返回数据消息
  85. NSString *message = resultModel.message;
  86. // 服务器返回数据状态值正确
  87. if (iStatus == 0) {
  88. NSDictionary * infoDic = (NSDictionary *)resultModel.result;
  89. NSArray *infoArray=[infoDic objectForKey:@"Table"];
  90. if(infoArray!=nil&&infoArray.count>0){
  91. for(int i=0;i<infoArray.count;i++){
  92. NSDictionary *dic=[infoArray objectAtIndex:i];
  93. PerformanceRankListModel *performanceListModel=[ PerformanceRankListModel dk_modelWithDictionary:dic];
  94. performanceListModel.rankNo=[NSString stringWithFormat:@"%d",i+1];
  95. [_dataList addObject:performanceListModel];
  96. }
  97. if(_staffList.count==0||_staffList.count>1){
  98. _tableView.tableHeaderView=nil;
  99. }
  100. else{
  101. StaffModel *staffModel=[_staffList objectAtIndex:0];
  102. PerformanceRankListModel *myPerformanceModel;
  103. for(int i=0;i<_dataList.count;i++){
  104. PerformanceRankListModel *performanceListModel=[_dataList objectAtIndex:i];
  105. if([staffModel.staffId integerValue]==[performanceListModel.staffId integerValue]){
  106. myPerformanceModel=performanceListModel;
  107. break;
  108. }
  109. }
  110. if(myPerformanceModel!=nil){
  111. _tableView.tableHeaderView=_performanceRankHeaderView;
  112. _lblRankNumberOneName.text=[NSString stringWithFormat:@"%@(%@)(第%@名)",@"我",myPerformanceModel.staffName,myPerformanceModel.rankNo];
  113. _lblSalesAmount.text=[NSString stringWithFormat:@"¥%@",myPerformanceModel.salesAmount];
  114. _lblCurrentMonthTask.text=[NSString stringWithFormat:@"¥%@",myPerformanceModel.currentMonthTaskAmount];
  115. _lblCompletePercent.text=[NSString stringWithFormat:@"%@%@",myPerformanceModel.currentMonthTaskAmount,@"%"];
  116. }
  117. }
  118. [_tableView reloadData];
  119. }
  120. else{
  121. // 无数据的view
  122. UIView *noDataView = [self noDataViewByFrame:_tableView.bounds];
  123. _tableView.backgroundView=noDataView;
  124. [self showAlertViewText:@"未找到匹配结果"];
  125. return;
  126. }
  127. }
  128. // 服务器返回数据状态值异常
  129. else if(iStatus == ActionResultStatusAuthError
  130. ||iStatus == ActionResultStatusNoLogin
  131. ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){
  132. [self showReLoginDialog:message];
  133. }
  134. else {
  135. [self showAlertViewText:message];
  136. }
  137. }
  138. /**
  139. 数据加载失败回调
  140. @param sender <#sender description#>
  141. */
  142. - (void)onStaffPerformanceLoadFail:(ASIDownManager *)sender {
  143. [self showAlertViewText:@"网络异常"];
  144. }
  145. -(void)initHeaderView{
  146. CGFloat heightRow = 40;
  147. CGFloat lblx = 20;
  148. CGFloat lbly = 8;
  149. CGFloat lblwidth = 70;
  150. CGFloat lblheight = 25;
  151. CGFloat valuey = 8;
  152. CGFloat valueheight = 25;
  153. _performanceRankHeaderView= [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_Width, heightRow)];
  154. [_performanceRankHeaderView setBackgroundColor:[UIColor whiteColor]];
  155. UIView *vRankNo = [UIView new];
  156. vRankNo.frame=CGRectMake(0,20, Screen_Width, heightRow);
  157. [_performanceRankHeaderView addSubview:vRankNo];
  158. _lblRankNumberOneName = [UILabel new];
  159. _lblRankNumberOneName.textColor=[UIColor blackColor];
  160. _lblRankNumberOneName.frame=CGRectMake(lblx, valuey,Screen_Width-108, valueheight);
  161. _lblRankNumberOneName.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  162. [vRankNo addSubview:_lblRankNumberOneName];
  163. _lblSalesAmount = [UILabel new];
  164. _lblSalesAmount.frame=CGRectMake(Screen_Width-108 ,valuey,100, valueheight);
  165. _lblSalesAmount.textAlignment = NSTextAlignmentRight;
  166. _lblSalesAmount.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  167. _lblSalesAmount.textColor=[UIColor redColor];
  168. [vRankNo addSubview:_lblSalesAmount];
  169. UIView *vCurrentMonthTask = [UIView new];
  170. vCurrentMonthTask.frame=CGRectMake(0, CGRectGetMaxY(vRankNo.frame), Screen_Width/2, heightRow);
  171. [_performanceRankHeaderView addSubview:vCurrentMonthTask];
  172. UILabel *lblCurrentTaskTitle=[UILabel new];
  173. lblCurrentTaskTitle.frame=CGRectMake(lblx, lbly, lblwidth, lblheight);
  174. lblCurrentTaskTitle.text=@"本月任务:";
  175. lblCurrentTaskTitle.textColor =LabelGrayTextColor;
  176. lblCurrentTaskTitle.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  177. [vCurrentMonthTask addSubview:lblCurrentTaskTitle];
  178. _lblCurrentMonthTask= [UILabel new];
  179. _lblCurrentMonthTask.frame=CGRectMake(CGRectGetMaxX(lblCurrentTaskTitle.frame), valuey, Screen_Width/2-CGRectGetMaxX(lblCurrentTaskTitle.frame)-3 , valueheight);
  180. _lblCurrentMonthTask.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  181. [vCurrentMonthTask addSubview:_lblCurrentMonthTask];
  182. UIView *vCompletePercent = [UIView new];
  183. vCompletePercent.frame=CGRectMake(Screen_Width/2, CGRectGetMaxY(vRankNo.frame), Screen_Width/2, heightRow);
  184. [_performanceRankHeaderView addSubview: vCompletePercent];
  185. UILabel *lblCompletePercentTitle=[UILabel new];
  186. lblCompletePercentTitle.frame=CGRectMake(5, lbly,110, lblheight);
  187. lblCompletePercentTitle.text=@"完成百分比:";
  188. lblCompletePercentTitle.textColor = LabelGrayTextColor;
  189. lblCompletePercentTitle.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  190. [vCompletePercent addSubview:lblCompletePercentTitle];
  191. _lblCompletePercent= [UILabel new];
  192. _lblCompletePercent.frame=CGRectMake(CGRectGetMaxX(lblCompletePercentTitle.frame), valuey, Screen_Width/2-lblwidth-5 , valueheight);
  193. _lblCompletePercent.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  194. [vCompletePercent addSubview:_lblCompletePercent];
  195. //分割线
  196. UIView *bottomSeparator= [UIView new];
  197. bottomSeparator.backgroundColor=LineBackgroundColor;
  198. bottomSeparator.frame = CGRectMake(0, CGRectGetMaxY(vCurrentMonthTask.frame), Screen_Width, 10);
  199. [_performanceRankHeaderView addSubview:bottomSeparator];
  200. _performanceRankHeaderView.frame=CGRectMake(0, 0, Screen_Width, CGRectGetMaxY(bottomSeparator.frame));
  201. }
  202. /**
  203. tableview的行数
  204. @param tableView <#tableView description#>
  205. @param section <#section description#>
  206. @return <#return value description#>
  207. */
  208. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  209. {
  210. return _dataList.count;
  211. }
  212. /**
  213. tableview的分区数
  214. @param tableView <#tableView description#>
  215. @return <#return value description#>
  216. */
  217. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  218. return 1;
  219. }
  220. /**
  221. 获取tableview cell
  222. @param tableView <#tableView description#>
  223. @param indexPath <#indexPath description#>
  224. @return <#return value description#>
  225. */
  226. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  227. {
  228. static NSString *cellIdentifier = @"PerformanceCellId";
  229. PerformanceRankListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
  230. if (cell == nil) {
  231. cell = [[PerformanceRankListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
  232. cell.selectionStyle=UITableViewCellSelectionStyleNone;
  233. }
  234. else
  235. //当页面拉动的时候 当cell存在并且最后一个存在 把它进行删除就出来一个独特的cell我们在进行数据配置即可避免
  236. {
  237. while ([cell.contentView.subviews lastObject] != nil) {
  238. [(UIView *)[cell.contentView.subviews lastObject] removeFromSuperview];
  239. }
  240. }
  241. NSUInteger row = [indexPath row];
  242. PerformanceRankListModel *rankListModel = [_dataList objectAtIndex:row];
  243. [cell setPerformanceRankListFrame:rankListModel];
  244. _cellHeight[@(indexPath.row)] = @(cell.cellHeight);
  245. return cell;
  246. }
  247. /**
  248. 预防高度
  249. @param tableView <#tableView description#>
  250. @param indexPath <#indexPath description#>
  251. @return <#return value description#>
  252. */
  253. -(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
  254. return 250;
  255. }
  256. /**
  257. tableview的高度
  258. @param tableView <#tableView description#>
  259. @param indexPath <#indexPath description#>
  260. @return <#return value description#>
  261. */
  262. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  263. return [_cellHeight[@(indexPath.row)] floatValue];
  264. }
  265. - (void)didReceiveMemoryWarning {
  266. [super didReceiveMemoryWarning];
  267. }
  268. @end