Explorar el Código

设置价格数据解析并显示。

Pen Li hace 9 años
padre
commit
8ae6c793f3

BIN
RedAnt ERP Mobile/RedAnt ERP Mobile.xcworkspace/xcuserdata/macmini1.xcuserdatad/UserInterfaceState.xcuserstate


+ 3 - 3
RedAnt ERP Mobile/iSales-NPD/CUL.storyboard

@@ -108,12 +108,12 @@
                                         <rect key="frame" x="0.0" y="28" width="1024" height="47"/>
                                         <rect key="frame" x="0.0" y="28" width="1024" height="47"/>
                                         <autoresizingMask key="autoresizingMask"/>
                                         <autoresizingMask key="autoresizingMask"/>
                                         <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="rnb-EK-8yY" id="WGZ-Bw-E4C">
                                         <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="rnb-EK-8yY" id="WGZ-Bw-E4C">
-                                            <frame key="frameInset" width="1024" height="46"/>
+                                            <frame key="frameInset" width="1024" height="46.5"/>
                                             <autoresizingMask key="autoresizingMask"/>
                                             <autoresizingMask key="autoresizingMask"/>
                                             <subviews>
                                             <subviews>
-                                                <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Dinning" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="3fh-vo-1qn">
+                                                <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Dinning" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="3fh-vo-1qn">
                                                     <constraints>
                                                     <constraints>
-                                                        <constraint firstAttribute="width" constant="100" id="jtE-Em-isT"/>
+                                                        <constraint firstAttribute="width" constant="200" id="jtE-Em-isT"/>
                                                     </constraints>
                                                     </constraints>
                                                     <fontDescription key="fontDescription" type="system" pointSize="17"/>
                                                     <fontDescription key="fontDescription" type="system" pointSize="17"/>
                                                     <nil key="textColor"/>
                                                     <nil key="textColor"/>

+ 35 - 2
RedAnt ERP Mobile/iSales-NPD/CategoryPriceCell.m

@@ -7,6 +7,7 @@
 //
 //
 
 
 #import "CategoryPriceCell.h"
 #import "CategoryPriceCell.h"
+#import "SetCategoryPriceController.h"
 
 
 @interface CategoryPriceCell ()
 @interface CategoryPriceCell ()
 
 
@@ -32,8 +33,40 @@
 - (void)setCategoryPrice:(NSDictionary *)categoryPrice {
 - (void)setCategoryPrice:(NSDictionary *)categoryPrice {
     _categoryPrice = categoryPrice;
     _categoryPrice = categoryPrice;
     
     
-    self.categoryLabel.text = @"LIVING";
-    self.priceLabel.text = [NSString stringWithFormat:@"base price:1000 + $50.11"];
+    NSString *basePrice = [categoryPrice objectForKey:@"base_price"];
+    NSString *discount = [categoryPrice objectForKey:@"price_discount"];
+    NSString *price = @"";
+    switch (basePrice.integerValue) {
+        case 0:{
+            basePrice = ab_lager;
+        }
+            break;
+        case 1:{
+            basePrice = flat_price;
+        }
+            
+        default:
+            break;
+    }
+    
+    if ([discount hasPrefix:@"-"]) {
+        
+        discount = [discount substringFromIndex:1];
+        price = [NSString stringWithFormat:@"%@ - %@",basePrice,discount];
+        
+    } else if ([discount hasSuffix:@"%"]) {
+        
+        price = [NSString stringWithFormat:@"%@ x %@",basePrice,discount];
+        
+    } else {
+        
+        price = [NSString stringWithFormat:@"%@ + %@",basePrice,discount];
+        
+    }
+    
+    self.categoryLabel.text = [self.categoryPrice objectForKey:@"title"];
+    
+    self.priceLabel.text = price;
 }
 }
 
 
 @end
 @end

+ 2 - 0
RedAnt ERP Mobile/iSales-NPD/CategoryPriceViewController.h

@@ -12,4 +12,6 @@
 
 
 @interface CategoryPriceViewController : UIViewController
 @interface CategoryPriceViewController : UIViewController
 
 
+@property (nonatomic,strong) NSMutableDictionary *categoryGivenPrice;
+
 @end
 @end

+ 42 - 4
RedAnt ERP Mobile/iSales-NPD/CategoryPriceViewController.m

@@ -9,6 +9,7 @@
 #import "CategoryPriceViewController.h"
 #import "CategoryPriceViewController.h"
 #import "const.h"
 #import "const.h"
 #import "CategoryPriceCell.h"
 #import "CategoryPriceCell.h"
+#import "UIColor+JK_HEX.h"
 
 
 @interface CategoryPriceViewController ()<UITableViewDelegate,UITableViewDataSource>
 @interface CategoryPriceViewController ()<UITableViewDelegate,UITableViewDataSource>
 
 
@@ -52,18 +53,25 @@
 #pragma mark - data source
 #pragma mark - data source
 
 
 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
-    return 1;
+    return [[self.categoryGivenPrice objectForKey:@"count"] integerValue];
 }
 }
 
 
 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
-    return 100;
+    NSString *sectionKey = [NSString stringWithFormat:@"category_%d",section];
+    return [[[self.categoryGivenPrice objectForKey:sectionKey] objectForKey:@"count"] integerValue];
 }
 }
 
 
 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
     
     
     CategoryPriceCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CategoryPriceCell"];
     CategoryPriceCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CategoryPriceCell"];
     
     
-    cell.categoryPrice = nil;
+    // 解析数据
+    NSInteger section = indexPath.section;
+    NSInteger row = indexPath.row;
+    NSDictionary *categorySection = [self.categoryGivenPrice objectForKey:[NSString stringWithFormat:@"category_%d",section]];
+    NSDictionary *categoryRow = [categorySection objectForKey:[NSString stringWithFormat:@"category_%d",row]];
+
+    cell.categoryPrice = categoryRow;
     
     
     return cell;
     return cell;
 }
 }
@@ -80,13 +88,16 @@
 
 
 - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
 - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
     
     
+    NSString *sectionKey = [NSString stringWithFormat:@"category_%d",section];
+    
     UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(tableView.bounds), 40)];
     UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(tableView.bounds), 40)];
+    headerView.backgroundColor = [UIColor colorWithHEX:0xEFEAE5];
     
     
     UILabel *categoryLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 10, 100, 20)];
     UILabel *categoryLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 10, 100, 20)];
     categoryLabel.textColor = [UIColor blackColor];
     categoryLabel.textColor = [UIColor blackColor];
     categoryLabel.font = [UIFont systemFontOfSize:17.0f];
     categoryLabel.font = [UIFont systemFontOfSize:17.0f];
     categoryLabel.textAlignment = NSTextAlignmentLeft;
     categoryLabel.textAlignment = NSTextAlignmentLeft;
-    categoryLabel.text = @"Dinning";
+    categoryLabel.text = [[self.categoryGivenPrice objectForKey:sectionKey] objectForKey:@"title"];
     
     
     [headerView addSubview:categoryLabel];
     [headerView addSubview:categoryLabel];
     
     
@@ -95,8 +106,35 @@
 
 
 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
     
     
+    CategoryPriceCell *cell = [tableView cellForRowAtIndexPath:indexPath];
+    
     SetCategoryPriceController *setPriceVC =[ [UIStoryboard storyboardWithName:@"CUL" bundle:nil] instantiateViewControllerWithIdentifier:@"SetCategoryPriceController"];
     SetCategoryPriceController *setPriceVC =[ [UIStoryboard storyboardWithName:@"CUL" bundle:nil] instantiateViewControllerWithIdentifier:@"SetCategoryPriceController"];
     
     
+    __weak typeof(self) weakself = self;
+    setPriceVC.returnBlock = ^(NSDictionary *result){
+        
+        
+        if (weakself) {
+            __strong typeof(weakself) strongself = weakself;
+            
+            NSInteger section = indexPath.section;
+            NSInteger row = indexPath.row;
+            NSDictionary *categorySection = [[self.categoryGivenPrice objectForKey:[NSString stringWithFormat:@"category_%d",section]] mutableCopy];
+            [categorySection setValue:result forKey:[NSString stringWithFormat:@"category_%d",row]];
+            
+            [strongself.categoryGivenPrice setObject:categorySection forKey:[NSString stringWithFormat:@"category_%d",section]];
+            
+            dispatch_async(dispatch_get_main_queue(), ^{
+                [strongself.categoryTable reloadData];
+            });
+            
+        }
+        
+        
+    };
+    setPriceVC.categoryID = [[cell.categoryPrice objectForKey:@"cid"] integerValue];
+    setPriceVC.categoryPrice = cell.categoryPrice.mutableCopy;
+    
     [self.navigationController pushViewController:setPriceVC animated:YES];
     [self.navigationController pushViewController:setPriceVC animated:YES];
     
     
 }
 }

+ 14 - 2
RedAnt ERP Mobile/iSales-NPD/PriceSettingViewController.m

@@ -99,9 +99,20 @@
 
 
 - (IBAction)calculatePriceButtonClick:(UIButton *)sender {
 - (IBAction)calculatePriceButtonClick:(UIButton *)sender {
     
     
-    CategoryPriceViewController *categoryPriceVC =[ [UIStoryboard storyboardWithName:@"CUL" bundle:nil] instantiateViewControllerWithIdentifier:@"CategoryPriceViewController"];
     
     
-    [self.navigationController pushViewController:categoryPriceVC animated:YES];
+    NSString *url = @"http://192.168.0.126:8080/site/isales/getSeeGivenPrice.htm";
+    NSData *data = [iSalesNetwork get_json:url parameters:@{}.mutableCopy];
+    
+    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
+
+    if ([[dic objectForKey:@"result"] integerValue] == 2) {
+    
+        CategoryPriceViewController *categoryPriceVC =[ [UIStoryboard storyboardWithName:@"CUL" bundle:nil] instantiateViewControllerWithIdentifier:@"CategoryPriceViewController"];
+        
+        categoryPriceVC.categoryGivenPrice = dic.mutableCopy;
+        
+        [self.navigationController pushViewController:categoryPriceVC animated:YES];
+    }
 }
 }
 
 
 - (NSString *)checkPriceType:(NSInteger)priceType {
 - (NSString *)checkPriceType:(NSInteger)priceType {
@@ -175,6 +186,7 @@
         DebugLog(@"set price type failure");
         DebugLog(@"set price type failure");
     }
     }
     
     
+    [self dismissViewControllerAnimated:YES completion:nil];
 }
 }
 
 
 @end
 @end

+ 2 - 0
RedAnt ERP Mobile/iSales-NPD/SetCategoryPriceController.h

@@ -16,6 +16,8 @@ typedef void (^setCategoryPriceReturnBlock) (NSDictionary *categoryPrice);
 
 
 @interface SetCategoryPriceController : UIViewController
 @interface SetCategoryPriceController : UIViewController
 
 
+@property (nonatomic,assign) NSInteger categoryID;
+
 @property (nonatomic,strong) NSMutableDictionary *categoryPrice;
 @property (nonatomic,strong) NSMutableDictionary *categoryPrice;
 
 
 @property (nonatomic,copy) setCategoryPriceReturnBlock returnBlock;
 @property (nonatomic,copy) setCategoryPriceReturnBlock returnBlock;

+ 67 - 9
RedAnt ERP Mobile/iSales-NPD/SetCategoryPriceController.m

@@ -9,6 +9,7 @@
 #import "SetCategoryPriceController.h"
 #import "SetCategoryPriceController.h"
 #import "const.h"
 #import "const.h"
 #import "EnumSelectViewController.h"
 #import "EnumSelectViewController.h"
+#import "iSalesNetwork.h"
 
 
 #define Percent  100
 #define Percent  100
 #define Float    101
 #define Float    101
@@ -39,6 +40,7 @@
     
     
     self.changePrice = NoChange;
     self.changePrice = NoChange;
     [self configAppearance];
     [self configAppearance];
+    
 }
 }
 
 
 - (void)didReceiveMemoryWarning {
 - (void)didReceiveMemoryWarning {
@@ -53,6 +55,19 @@
                                                                   action:@selector( returnBackClick:)];
                                                                   action:@selector( returnBackClick:)];
     
     
     self.navigationItem.leftBarButtonItem = backButton;
     self.navigationItem.leftBarButtonItem = backButton;
+    
+    // base price
+    NSString *basePrice = [self.categoryPrice objectForKey:@"base_price"];
+    [self changePriceType:basePrice.integerValue];
+    
+    // discount
+    NSString *discount = [self.categoryPrice objectForKey:@"price_discount"];
+    if ([discount hasSuffix:@"%"]) {
+        self.percentageTextField.text = [discount substringToIndex:discount.length - 1];
+    } else {
+        self.floatTextField.text = discount;
+    }
+
 }
 }
 
 
 - (void)returnBackClick:(id)sender {
 - (void)returnBackClick:(id)sender {
@@ -138,6 +153,8 @@
 }
 }
 
 
 - (IBAction)percentageCheckButtonClick:(UIButton *)sender {
 - (IBAction)percentageCheckButtonClick:(UIButton *)sender {
+    
+    
     if (self.changePrice == NoChange || self.changePrice == Percent) {
     if (self.changePrice == NoChange || self.changePrice == Percent) {
         sender.selected = !sender.selected;
         sender.selected = !sender.selected;
         if (sender.selected) {
         if (sender.selected) {
@@ -145,31 +162,72 @@
         } else {
         } else {
             self.changePrice = NoChange;
             self.changePrice = NoChange;
         }
         }
-        self.percentageTextField.enabled = sender.selected;
+    } else if (self.changePrice == Float) {
+        sender.selected = YES;
+        self.changePrice = Percent;
+        self.floatCheckButton.selected = NO;
+        self.floatTextField.enabled = NO;
     }
     }
     
     
+    self.percentageTextField.enabled = sender.selected;
+    
 }
 }
 
 
 - (IBAction)floatCheckButtonClick:(UIButton *)sender {
 - (IBAction)floatCheckButtonClick:(UIButton *)sender {
+    
     if (self.changePrice == NoChange || self.changePrice == Float) {
     if (self.changePrice == NoChange || self.changePrice == Float) {
-        
         sender.selected = !sender.selected;
         sender.selected = !sender.selected;
         if (sender.selected) {
         if (sender.selected) {
             self.changePrice = Float;
             self.changePrice = Float;
         } else {
         } else {
             self.changePrice = NoChange;
             self.changePrice = NoChange;
         }
         }
-        self.floatTextField.enabled = sender.selected;
+        
+    } else if (self.changePrice == Percent) {
+        sender.selected = YES;
+        self.changePrice = Float;
+        self.percentageCheckButton.selected = NO;
+        self.percentageTextField.enabled = NO;
     }
     }
-    
+    self.floatTextField.enabled = sender.selected;
 }
 }
 - (IBAction)saveButtonClick:(UIButton *)sender {
 - (IBAction)saveButtonClick:(UIButton *)sender {
     
     
     // 向服务器提交数据
     // 向服务器提交数据
+    // http://192.168.0.126:8080/site/isales/setSeeGivenPrice.htm
     
     
-    // 将数据返回
-    if (self.returnBlock)
-        self.returnBlock(self.categoryPrice);
+    NSString *discount = @"";
+    switch (self.changePrice) {
+        case Float:{
+            discount = self.floatTextField.text;
+        }
+            break;
+        case Percent:{
+            discount = [self.percentageTextField.text stringByAppendingString:@"%"];
+        }
+            break;
+    
+        default:
+            break;
+    }
+    
+    NSString *url = @"http://192.168.0.126:8080/site/isales/setSeeGivenPrice.htm";
+    
+    NSData *data = [iSalesNetwork get_json:url parameters:@{@"base_price" : [NSString stringWithFormat:@"%d",self.priceType],@"discount" : discount,@"category_id" : @(self.categoryID)}.mutableCopy];
+    
+    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
+    
+    if ([[dic objectForKey:@"result"] integerValue] == 2) {
+        
+        [self.categoryPrice setObject:[NSString stringWithFormat:@"%d",self.priceType] forKey:@"base_price"];
+        [self.categoryPrice setObject:discount forKey:@"price_discount"];
+        
+        // 将数据返回
+        if (self.returnBlock)
+            self.returnBlock(self.categoryPrice);
+    }
+    
+    [self.navigationController popViewControllerAnimated:YES];
 }
 }
 
 
 #pragma mark - text field delegate
 #pragma mark - text field delegate
@@ -235,10 +293,10 @@
     
     
 
 
     // 正则表达式
     // 正则表达式
-    NSString *match = @"-[1-9]+(\\.[0-9]*)?|-0\\.[0-9]+|[1-9]+(\\.[0-9]*)?|0\\.[0-9]{0,}|0{1,1}|-{1,1}|-0{1,1}|-0\\.{1,1}";
+    NSString *match = @"-[1-9]{1,1}[0-9]*(\\.[0-9]*)?|-0\\.[0-9]+|[1-9]{1,1}[0-9]*(\\.[0-9]*)?|0\\.[0-9]{0,}|0{1,1}|-{1,1}|-0{1,1}|-0\\.{1,1}";
     
     
     if ([textField isEqual:self.percentageTextField])
     if ([textField isEqual:self.percentageTextField])
-        match = @"[1-9]+(\\.[0-9]*)?|0(\\.[0-9]*)?";
+        match = @"[1-9]{1,1}[0-9]*(\\.[0-9]*)?|0(\\.[0-9]*)?";
     
     
     NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",match];
     NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",match];