| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- //
- // ScanCartItemCell.m
- // HMLG Scan Order
- //
- // Created by Rui Zhang on 3/21/22.
- // Copyright © 2022 United Software Applications, Inc. All rights reserved.
- //
- #import "ScanCartItemCell.h"
- #import "AppDelegate.h"
- #import "RANetwork.h"
- #import "CartViewController.h"
- #define NUMBERS @"0123456789\n"
- @implementation ScanCartItemCell
- - (void)awakeFromNib {
- [super awakeFromNib];
- // Initialization code
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- // Configure the view for the selected state
- }
- -(void) init_Stepper:(int) step max:(int) max min:(int)min value:(int)value
- {
-
- // [self.stepper becomeFirstResponder];
- if(self.setpperQTY!=nil)
- {
- if(min<=0)
- min=1;
- if(step<=0)
- step=1;
- self.setpperQTY.minimumValue= min;
-
-
-
- self.setpperQTY.stepValue= step;
-
- self.setpperQTY.value= value;
-
- self.pre_val = value;
-
- [self.setpperQTY addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
- // self.totalchange=0;
-
- }
- }
- - (void)valueChanged:(UIStepper *)sender {
-
-
-
- self.editQTY.text = [NSString stringWithFormat:@"%d",(int)sender.value ];
-
- [self set_Count:(int)sender.value ];
-
-
- //
- // [celldelegate stepClicked:(int)sender.value];
- // -(void) stepClicked:(int) value;
- }
- - (IBAction)setpperChanged:(UIStepper *)sender {
-
- DebugLog(@"setpperChanged");
-
-
-
- [self cancel_setQTY];
- [self performSelector:@selector(delayRun) withObject:nil afterDelay:0.8];
-
- }
- -(void) cancel_setQTY
- {
- [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(delayRun) object:nil];
- }
- -(void) delayRun
- {
- // NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(calculate) object:nil];
- // // 启动
- // [thread start];
-
- [RANetwork request_update_cartqty:self.cart_id value:self.setpperQTY.value completionHandler:^(NSMutableDictionary *result) {
- NSDictionary* cart_json =result;
-
- if([[cart_json valueForKey:@"result"] intValue]==2)
- {
- if(self.onReturnQTY)
- self.onReturnQTY(self.setpperQTY.value,cart_json);
- // if (self.delegate && [self.delegate respondsToSelector:@selector(returnQTY:)]) {
- // [self.delegate returnQTY:sender.value ];
- // }
- }
- else
- {
- UIViewController* vc=[RAUtils getViewController :self];
- [((CartViewController *)vc).itemListTable reloadData];
- // [RAUtils message_box:[cart_json valueForKey:@"err_msg"] message:[cart_json valueForKey:@"err_msg"] completion:nil] ;
- [RAUtils message_box:@"Change Model Count" message:cart_json[@"err_msg"] completion:nil];
- }
-
-
-
- }];
-
-
- }
- -(void) set_Count:(int) count
- {
-
- self.setpperQTY.value=count;
-
- // double dprice=0;
- // self.labelUnitPrice.text =[NSString stringWithFormat:@"%.2f",self.unit_price];
-
-
-
-
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- // NSString* price = [NSString stringWithFormat:@"%.2f",self.unit_price*count*(1-self.discount/100.0) ];
- // if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
- // {
- //
- // }
- // else
- // {
- // price=nil;
- // }
-
- if(self.noprice&&self.unit_price==0.0)
- self.labelSubtotal.text =@"No Price";
- else
- self.labelSubtotal.text =[RAConvertor currencyNumber:self.unit_price*count*(1-self.discount/100.0)];//price;
-
- self.editQTY.text =[NSString stringWithFormat:@"%d",count];
- }
- #pragma mark textField delegate
- - (BOOL)textFieldShouldReturn:(UITextField *)textField {
- [textField resignFirstResponder];
- return NO;
- }
- -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
-
-
- DebugLog(@"text:%@",textField.text);
-
-
-
- NSCharacterSet *cs;
- cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERS]invertedSet];
-
- NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs]componentsJoinedByString:@""];
-
- BOOL canChange = [string isEqualToString:filtered];
-
-
-
-
- return canChange;
- }
- - (void)textFieldDidEndEditing:(UITextField *)textField
- {
-
-
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- int qty = [textField.text intValue];
-
- if(qty==0)
- qty=self.setpperQTY.minimumValue;
-
-
-
-
- // NSMutableDictionary* item= self.modellist[indexPath.row];
- // int qty = [textField.text intValue];
- //
- int c=qty;
-
- int mpack= self.setpperQTY.stepValue;
-
- int m=c%mpack;
- if(m!=0)
-
- {
- [RAUtils message_box:@"Warrning" message:[NSString stringWithFormat:@"QTY must be a multiple of %d",mpack] completion:nil];
- textField.text = [NSString stringWithFormat:@"%d",self.pre_val];
- return;
- }
-
- // int c=qty;
-
- // int m=c%(int)(self.setpperQTY.stepValue);
- // if(m!=0&&appDelegate.alert_sold_in_quantities)
- //
- else
- {
- [self set_Count:qty];
-
- [RANetwork request_update_cartqty:self.cart_id value:qty completionHandler:^(NSMutableDictionary *result) {
- NSDictionary* cart_json =result;
- if([[cart_json valueForKey:@"result"] intValue]==2)
- {
- // if (self.delegate && [self.delegate respondsToSelector:@selector(returnQTY:)]) {
- // [self.delegate returnQTY:qty];
- // }
-
- if(self.onReturnQTY)
- self.onReturnQTY(qty,cart_json);
- }
- else
- {
- UIViewController* vc=[RAUtils getViewController :self];
- [((CartViewController *)vc).itemListTable reloadData];
- // [RAUtils message_box:[cart_json valueForKey:@"err_msg"] message:[cart_json valueForKey:@"err_msg"] completion:nil] ;
- [RAUtils message_box:@"Change Model Count" message:cart_json[@"err_msg"] completion:nil];
- }
-
-
-
- }];
-
- }
-
-
-
-
-
-
-
- }
- - (void)textFieldDidBeginEditing:(UITextField *)textField
- {
- NSString* text = textField.text;
- if(text.length==0)
- text=@"0";
- self.pre_val = [textField.text intValue];
-
- // self.last_edit = textField.text;
- }
- @end
|