// // 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" @interface ScanOrderModelListViewController () @end @implementation ScanOrderModelListViewController - (void)viewDidLoad { [super viewDidLoad]; self.edit_check = true; // Do any additional setup after loading the view. } - (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 136.0f; } - (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; 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