// // ScanOrderModelListViewController.m // HMLG Scan Order // // Created by Rui Zhang on 3/17/22. // Copyright © 2022 United Software Applications, Inc. All rights reserved. // #import "ScanOrderModelListViewController.h" #import "ScanModelListCell.h" #define NUMBERS @"0123456789\n" #import "RASingleton.h" #import "ActiveViewController.h" #import "RAUtils.h" #import "RAConvertor.h" #import "RADataProvider.h" #import "ScanRefreshStock.h" @interface ScanOrderModelListViewController () @end @implementation ScanOrderModelListViewController - (void)viewDidLoad { [super viewDidLoad]; self.edit_check = true; // [self refreshStock]; // Do any additional setup after loading the view. } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; self.labelStock.text = [RADataProvider queryStockUpdateTime]; } - (IBAction)onUpdateStock:(id)sender { [RADataProvider updateStock:self]; } -(void) refreshStock { // NSDictionary *addressDic1 = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanStock"]; // if (addressDic1) { // NSString* updatetime=addressDic1[@"updatetime"]; // self.labelStock.text = updatetime; // } self.labelStock.text = [RADataProvider queryStockUpdateTime]; [self.tableView reloadData]; } - (IBAction)stepChange:(id)sender { UIStepper * stepper = (UIStepper *) sender; UITableViewCell *cell = (UITableViewCell *) stepper.superview.superview; NSIndexPath * indexPath = [self.tableView indexPathForCell:cell]; ScanModelListCell * scancell = (ScanModelListCell*)cell; NSMutableDictionary* item= self.modellist[indexPath.row]; int qty = (int)((UIStepper*)sender).value; scancell.editQTY.text = [NSString stringWithFormat:@"%d",qty ]; item[@"count"] = @(qty); item[@"subtotal_price"] = @(qty*[item[@"unit_price"] doubleValue]); self.modellist[indexPath.row] = item; } - (void)setScan_val:(id)scan_val { [super setScan_val:scan_val]; AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; NSDictionary* price_group = [RADataProvider get_price_group:appDelegate.price_group]; self.modellist = [NSMutableArray new]; NSArray* arr = (NSArray*) self.scan_val; bool iscollection=false; if(arr.count>1) iscollection = true; for(int i=0;i=200) [RASingleton.sharedInstance.scan_list removeLastObject]; [RASingleton.sharedInstance.scan_list insertObject:jitem atIndex:0]; [ActiveViewController Notify:@"ScanHistoryViewController" Message:RA_NOTIFICATION_RELOAD_DATA]; // int idx = [RASingleton.sharedInstance.scan_list indexOfObject:jitem]; // if(idx>=0) // { // //如果存在,移动到最前。 // // // } } [self.tableView reloadData]; } #pragma mark - TableView DataSource - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { NSMutableArray* arr = (NSMutableArray*) self.scan_val; return arr.count; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { // return 166.0f; UILabel * label = [UILabel new]; NSMutableArray* arr = self.modellist; NSMutableDictionary* model = arr[indexPath.row]; label.frame = CGRectMake(0, 0, tableView.frame.size.width-32-30, 0); label.text = model[@"description"]; label.font = [UIFont systemFontOfSize:15]; label.numberOfLines=0; label.lineBreakMode = NSLineBreakByWordWrapping; double s = label.font.pointSize; // NSLog(label.text); // CGSize s=[label sizeThatFits:CGSizeMake(tableView.frame.size.width-32, 0)]; [label sizeToFit]; return label.frame.size.height+107.5; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { ScanModelListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ScanModelListCell"]; if (!cell) { cell = [[ScanModelListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ScanModelListCell"]; } NSMutableArray* arr = (NSMutableArray*) self.modellist; [cell setModelJson:arr[indexPath.row]]; cell.editQTY.delegate = self; cell.labelStock.text = [RADataProvider queryStock:cell.labelModel.text]; return cell; } //#pragma mark - TableView Delegate /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ - (IBAction)onScanNext:(id)sender { [self dismissViewControllerAnimated:true completion:^{ if(self.returnValue) self.returnValue(nil); }]; } - (IBAction)onAddToCart:(id)sender { // [self.lastedit endEditing:true]; if(self.lastedit) [self textFieldDidEndEditing:self.lastedit]; if(self.edit_check) { NSMutableArray* arrname = [NSMutableArray new]; for(int j=0;j