YRDocuVC.m 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. //
  2. // YRDocuVC.m
  3. // UU_Ent
  4. //
  5. // Created by liujl on 2019/7/4.
  6. // Copyright © 2019 UAS. All rights reserved.
  7. //
  8. #import "YRDocuVC.h"
  9. #import "YRDocuCell.h"
  10. @interface YRDocuVC()<UITableViewDelegate,UITableViewDataSource>
  11. @property(strong,nonatomic)YRTableView *tableView;
  12. @property(strong,nonatomic)NSMutableArray<NSMutableArray<YRDocuModel *> *> *dataArr;
  13. @end
  14. @implementation YRDocuVC
  15. -(void)viewDidLoad{
  16. [super viewDidLoad];
  17. }
  18. -(void)setUpUI{
  19. [self.view addSubview:self.tableView];
  20. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  21. make.edges.equalTo(self.view);
  22. }];
  23. [self loadDataFromServerWith:self.caller];
  24. [self.tableView reloadData];
  25. @weakify(self)
  26. self.tableView.emptyDidClicked = ^{
  27. @strongify(self)
  28. [self.tableView reloadData];
  29. };
  30. }
  31. -(void)loadDataFromServerWith:(NSString *)caller{
  32. NSString *url = [NSString stringWithFormat:@"http://erp.yitoa.com:8888/ERP/mobile/common/getformandgriddetail.action?caller=FeePlease!CCSQ!new&condition=1=1&sessionId=4AA6E9E6F286E19211C32E1B8D5FC7A9&id=0"];
  33. url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  34. YRNetworkManager *manager = [YRNetworkManager shareManager];
  35. [manager request:url method:POST parameters:nil progress:nil success:^(NSURLSessionDataTask *task, NSDictionary *responseObject) {
  36. } failure:^(NSURLSessionDataTask *task, NSError *error) {
  37. }];
  38. }
  39. #pragma mark - delegate && dataSource
  40. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  41. return self.dataArr.count;
  42. }
  43. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  44. return self.dataArr[section].count;
  45. }
  46. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  47. YRDocuCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YRDocuCellReid"];
  48. if (!cell) {
  49. cell = [[YRDocuCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"YRDocuCellReid"];
  50. }
  51. cell.indexPath = indexPath;
  52. @weakify(self)
  53. cell.didClicked = ^(YRDocuModel * _Nonnull model,NSIndexPath *indexPath) {
  54. model.value = [NSString stringWithFormat:@"%d",arc4random()];
  55. [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
  56. };
  57. cell.model = self.dataArr[indexPath.section][indexPath.row];
  58. return cell;
  59. }
  60. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  61. return self.dataArr[indexPath.section][indexPath.row].height;
  62. }
  63. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  64. [self.dataArr removeAllObjects];
  65. [tableView reloadData];
  66. self.dataArr = nil;
  67. }
  68. -(void)viewWillDisappear:(BOOL)animated{
  69. [super viewWillDisappear:animated];
  70. }
  71. -(YRTableView *)tableView{
  72. if (!_tableView) {
  73. _tableView = [[YRTableView alloc]initWithFrame:self.view.frame];
  74. _tableView.delegate = self;
  75. _tableView.dataSource = self;
  76. _tableView.tableHeaderView = [UIView new];
  77. _tableView.tableFooterView = [UIView new];
  78. }
  79. return _tableView;
  80. }
  81. -(NSMutableArray *)dataArr{
  82. if (!_dataArr) {
  83. _dataArr = [[NSMutableArray alloc]init];
  84. NSMutableArray *arrOne = [[NSMutableArray alloc]init];
  85. for (int i=0; i<30; i++) {
  86. YRDocuModel *model = [YRDocuModel new];
  87. model.key = @"单据";
  88. model.value = @"";
  89. if (i%3==0) {
  90. model.value = @"这里是";
  91. model.type = @"FF";
  92. }
  93. [arrOne addObject:model];
  94. }
  95. [_dataArr addObject:arrOne];
  96. }
  97. return _dataArr;
  98. }
  99. @end