| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- //
- // ScanHistoryViewController.m
- // HMLG Scan Order
- //
- // Created by Rui Zhang on 3/29/22.
- // Copyright © 2022 United Software Applications, Inc. All rights reserved.
- //
- #import "ScanHistoryViewController.h"
- #import "ScanListCell.h"
- #import "RASingleton.h"
- #import "RADataProvider.h"
- @interface ScanHistoryViewController ()
- @end
- @implementation ScanHistoryViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // 购物车更新后刷新高亮
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(onCartUpdatedRefreshHighlight)
- name:@"ScanListShouldRefreshHighlight"
- object:nil];
- }
- - (void)dealloc {
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- - (IBAction)onUpdateStock:(id)sender {
- [RADataProvider updateStock:self];
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- self.labelStock.text = [RADataProvider queryStockUpdateTime];
- }
- - (void)refreshStock {
- self.labelStock.text = [RADataProvider queryStockUpdateTime];
- [self.tableview reloadData];
- }
- #pragma mark - UITableViewDataSource
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return RASingleton.sharedInstance.scan_list.count;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- NSMutableArray *arr = RASingleton.sharedInstance.scan_list;
- NSMutableDictionary *model = arr[indexPath.row];
- // 计算 description 多行文字高度
- UILabel *label = [UILabel new];
- label.frame = CGRectMake(0, 0, tableView.frame.size.width - 32, 0);
- label.text = model[@"description"];
- label.font = [UIFont systemFontOfSize:15];
- label.numberOfLines = 0;
- label.lineBreakMode = NSLineBreakByWordWrapping;
- [label sizeToFit];
- // 布局高度拆解:
- // 顶部区域(model/button 行):top(13) + button高度(41) + desc top间距(4) = 58
- // description:动态高度
- // scrollView上间距:8
- // scrollView高度:48(header行24 + data行24)
- // scrollView下间距:8
- // bottomLine:2
- // 合计固定部分:58 + 8 + 48 + 8 + 2 = 124,再加底部留白约 4 = 128
- // 注:此处用 label.frame.size.height 取 description 实际高度
- return label.frame.size.height + 128;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- ScanListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ScanListCell"];
- if (!cell) {
- cell = [[ScanListCell alloc] initWithStyle:UITableViewCellStyleDefault
- reuseIdentifier:@"ScanListCell"];
- }
- NSMutableArray *arr = RASingleton.sharedInstance.scan_list;
- [cell setModelJson:arr[indexPath.row]];
- // labelModel 和 labelStock 均保留为 outlet,赋值逻辑不变
- cell.labelStock.text = [RADataProvider queryStock:cell.labelModel.text];
- return cell;
- }
- #pragma mark - RA_NOTIFICATION
- - (void)onCartUpdatedRefreshHighlight {
- [self.tableview reloadData];
- }
- - (void)refresh_ui {
- [self.tableview reloadData];
- }
- - (void)reload_data {
- [self.tableview reloadData];
- }
- @end
|