Просмотр исходного кода

feat:筛选价格根据美元汇率计算

“wangdongchao” 1 год назад
Родитель
Сommit
79f91e6688

+ 3 - 3
Asteria/Fuction/Category/vc/ASCategoryViewController.m

@@ -117,9 +117,9 @@
 // MARK: - actions
 - (void)toResult:(NSString *)key type:(NSString *)type keyWord:(NSString *)word {
    NSDictionary *para = @{
-       @"type":type,  //String
-       @"title":key,//String
-       @"searchKey":word,//String
+       @"type":AS_String_NotNull(type),  //String
+       @"title":AS_String_NotNull(key),//String
+       @"searchKey":AS_String_NotNull(word),//String
    };
    UIViewController *vc = [CTMediator.sharedInstance getProductListVc:para];
    

+ 5 - 2
Asteria/Fuction/Home/Views/productList/KWProductMenuFilterView.m

@@ -374,8 +374,8 @@
         cell.minTf.text = m.inputMin;
         cell.maxTf.text = m.inputMax;
         if (m.status <= 0) {
-            cell.minTf.placeholder = m.minPrice;
-            cell.maxTf.placeholder = m.maxPrice;
+            cell.minTf.placeholder = @"Min";
+            cell.maxTf.placeholder = @"Max";
         }
         
         return cell;
@@ -421,6 +421,9 @@
     if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
         KWProductMenuFilterItemHeaderView *v = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"KWProductMenuFilterItemHeaderView" forIndexPath:indexPath];
         NSString *ti = [NSString stringWithFormat:@"%@",self.vm.sourceArr[indexPath.section].attribute_name];
+        if ([ti isEqualToString:@"Price"]) {
+            ti = [NSString stringWithFormat:@"%@ (%@)", ti, ASCurrencyManager.shared.currentCur];
+        }
         v.titleLb.text = ti;
         return  v;
     }

+ 7 - 1
Asteria/Fuction/Home/vm/ASProductListViewModel.m

@@ -72,7 +72,12 @@
         for (KWProductListFilterSubModel *subM in subMs) {
             if ([key isEqualToString:@"price"]) {
                 if (subM.inputMax.length > 0 && subM.inputMin.length > 0) {
-                    valueStr = [NSMutableString stringWithFormat:@"%@-%@", subM.inputMin, subM.inputMax];
+                    
+                    //搜索价格根据当前币种汇率转换成美元
+                    float rateCount = [[[ASCurrencyManager shared] getCurrentCurrencyRate] floatValue];
+                    NSString *minStr = [NSString stringWithFormat:@"%lf", [subM.inputMin floatValue] / rateCount];
+                    NSString *maxStr = [NSString stringWithFormat:@"%lf", [subM.inputMax floatValue] / rateCount];
+                    valueStr = [NSMutableString stringWithFormat:@"%@-%@", minStr, maxStr];
                     para[key] = valueStr;
                 }
                 continue;
@@ -130,6 +135,7 @@
                 com(true, @"");
             }
         } else {
+            self.productList = @[];
             com(false, @"");
         }
     } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {

+ 5 - 0
Asteria/Fuction/Manager/UserManager/currency/ASCurrencyManager.h

@@ -17,11 +17,16 @@ NS_ASSUME_NONNULL_BEGIN
 
 @property (nonatomic, strong) NSArray<NSString *> *avaiCurencys;
 
+@property (nonatomic, strong) NSArray *exchange_rates;//汇率列表
+
 - (void)setSelectCurrency:(NSString *)sel;
 
 + (instancetype)shared;
 - (void)getAllCurrencyData;
 
+//获取当前汇率 (保留两位小数的字符串)
+- (NSString *)getCurrentCurrencyRate;
+
 
 
 @end

+ 17 - 0
Asteria/Fuction/Manager/UserManager/currency/ASCurrencyManager.m

@@ -46,12 +46,29 @@
     return localCur;
 }
 
+//获取当前汇率 (保留两位小数的字符串)
+- (NSString *)getCurrentCurrencyRate {
+    NSString *rateStr = @"1";
+    for (int i = 0; i < self.exchange_rates.count; i++) {
+        NSDictionary *rateDic = [self.exchange_rates objectAtIndex:i];
+        NSString *tempCurrency = rateDic[@"currency_to"];
+        
+        if ([self.currentCur isEqualToString:tempCurrency]) {
+            rateStr = rateDic[@"rate"];
+            break;
+        }
+    }
+    return rateStr;
+}
+
 
 - (void)getAllCurrencyData {
     __weak typeof(self) weakSelf = self;
     [ASNetTools.shared getWithPath:getAllCurrencyUrl param:@{} success:^(id _Nonnull json) {
         NSDictionary *dic = (NSDictionary *)json;
         weakSelf.avaiCurencys = dic[@"available_currency_codes"];
+        
+        weakSelf.exchange_rates = dic[@"exchange_rates"];
        
     } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {