ScanHistoryViewController.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //
  2. // ScanHistoryViewController.m
  3. // HMLG Scan Order
  4. //
  5. // Created by Rui Zhang on 3/29/22.
  6. // Copyright © 2022 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "ScanHistoryViewController.h"
  9. #import "ScanListCell.h"
  10. #import "RASingleton.h"
  11. #import "RADataProvider.h"
  12. @interface ScanHistoryViewController ()
  13. @end
  14. @implementation ScanHistoryViewController
  15. - (void)viewDidLoad {
  16. [super viewDidLoad];
  17. // 购物车更新后刷新高亮
  18. [[NSNotificationCenter defaultCenter] addObserver:self
  19. selector:@selector(onCartUpdatedRefreshHighlight)
  20. name:@"ScanListShouldRefreshHighlight"
  21. object:nil];
  22. }
  23. - (void)dealloc {
  24. [[NSNotificationCenter defaultCenter] removeObserver:self];
  25. }
  26. - (IBAction)onUpdateStock:(id)sender {
  27. [RADataProvider updateStock:self];
  28. }
  29. - (void)viewWillAppear:(BOOL)animated {
  30. [super viewWillAppear:animated];
  31. self.labelStock.text = [RADataProvider queryStockUpdateTime];
  32. }
  33. - (void)refreshStock {
  34. self.labelStock.text = [RADataProvider queryStockUpdateTime];
  35. [self.tableview reloadData];
  36. }
  37. #pragma mark - UITableViewDataSource
  38. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  39. return RASingleton.sharedInstance.scan_list.count;
  40. }
  41. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  42. NSMutableArray *arr = RASingleton.sharedInstance.scan_list;
  43. NSMutableDictionary *model = arr[indexPath.row];
  44. // 计算 description 多行文字高度
  45. UILabel *label = [UILabel new];
  46. label.frame = CGRectMake(0, 0, tableView.frame.size.width - 32, 0);
  47. label.text = model[@"description"];
  48. label.font = [UIFont systemFontOfSize:15];
  49. label.numberOfLines = 0;
  50. label.lineBreakMode = NSLineBreakByWordWrapping;
  51. [label sizeToFit];
  52. // 布局高度拆解:
  53. // 顶部区域(model/button 行):top(13) + button高度(41) + desc top间距(4) = 58
  54. // description:动态高度
  55. // scrollView上间距:8
  56. // scrollView高度:48(header行24 + data行24)
  57. // scrollView下间距:8
  58. // bottomLine:2
  59. // 合计固定部分:58 + 8 + 48 + 8 + 2 = 124,再加底部留白约 4 = 128
  60. // 注:此处用 label.frame.size.height 取 description 实际高度
  61. return label.frame.size.height + 128;
  62. }
  63. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  64. ScanListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ScanListCell"];
  65. if (!cell) {
  66. cell = [[ScanListCell alloc] initWithStyle:UITableViewCellStyleDefault
  67. reuseIdentifier:@"ScanListCell"];
  68. }
  69. NSMutableArray *arr = RASingleton.sharedInstance.scan_list;
  70. [cell setModelJson:arr[indexPath.row]];
  71. // labelModel 和 labelStock 均保留为 outlet,赋值逻辑不变
  72. cell.labelStock.text = [RADataProvider queryStock:cell.labelModel.text];
  73. return cell;
  74. }
  75. #pragma mark - RA_NOTIFICATION
  76. - (void)onCartUpdatedRefreshHighlight {
  77. [self.tableview reloadData];
  78. }
  79. - (void)refresh_ui {
  80. [self.tableview reloadData];
  81. }
  82. - (void)reload_data {
  83. [self.tableview reloadData];
  84. }
  85. @end