123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- //
- // ASProductListViewModel.m
- // Asteria
- //
- // Created by iOS on 2023/6/12.
- //
- #import "ASProductListViewModel.h"
- @implementation ASProductListViewModel
- - (NSArray<ASProductBaseModel *> *)productList {
- if (!_productList) {
- NSMutableArray *arr = [NSMutableArray array];
- _productList = arr;
- }
- return _productList;
- }
- - (NSMutableDictionary<NSString *,KWProductListFilterSubModel *> *)selectDic {
- if (!_selectDic) {
- NSMutableDictionary *tempDic = [NSMutableDictionary dictionary];
- _selectDic = tempDic;
- }
- return _selectDic;
- }
- -(NSMutableArray<KWProductListFilterModel *> *)showArr {
- NSMutableArray *arr = [NSMutableArray array];
- // [arr addObjectsFromArray:self.selectArr];
- [arr addObjectsFromArray:self.sourceArr];
- return arr;
- }
- - (NSArray<KWProductListFilterModel *> *)sourceArr {
- if (!_sourceArr) {
- NSMutableArray *arr = [NSMutableArray array];
- for (int i=0; i<(arc4random()%10+1);i++) {
- [arr addObject:[KWProductListFilterModel demoData]];
- }
- KWProductListFilterModel *priceM = [KWProductListFilterModel new];
- priceM.attribute_id = @"-100";
- priceM.attribute_name = @"PRICE RANGE";
- priceM.attribute_data = [NSMutableArray arrayWithObject:[KWProductListFilterSubModel demoData]];
- [arr addObject:priceM];
- _sourceArr = arr;
- }
- return _sourceArr;
- }
- - (void)getProductListData:(NSString *)catId page:(NSInteger)page orderBy:(NSInteger)orderBy dir:(NSString *)dir com:(void(^)(BOOL hasNext, NSString *msg))com {
- NSMutableDictionary *para = [NSMutableDictionary dictionary];
- para[@"currencyCode"] = ASCurrencyManager.shared.currentCur;
- para[@"page"] = @(page);
- para[@"size"] = @20;
- if (orderBy != 0) {
- NSArray *arr = @[@"position", @"price", @"sold_qty"];
- if (arr.count > orderBy && orderBy >= 0) {
- para[@"order"] = arr[orderBy];
- } else {
- para[@"order"] = @"sold_qty";
- }
- } else {
- para[@"order"] = @"sold_qty";
- }
- if (dir != nil && ![dir isEqualToString:@""]) {
- para[@"dir"] = dir;
- } else {
- para[@"dir"] = @"DESC";
- }
- NSString *url = [NSString stringWithFormat:getProductListUrl, catId];
- [ASNetTools.shared getWithPath:url param:para success:^(id _Nonnull json) {
- ASProductListCategoryModel *m = [ASProductListCategoryModel mj_objectWithKeyValues:json[@"category"]];
- self.cateModel = m;
- NSArray *arr = json[@"product"];
- NSMutableArray *products = [ASProductBaseModel mj_objectArrayWithKeyValuesArray:arr];
- if (products.count > 0) {
- if (page == 1) {
- self.productList = products;
- } else {
- self.productList = [self.productList arrayByAddingObjectsFromArray:products];
- }
- if (products.count < 20) {
- com(false, @"");
- } else {
- com(true, @"");
- }
- } else {
- com(false, @"");
- }
- } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
- com(false, msg);
- }];
-
-
- }
- - (void)getPoint:(NSString *)pointType com:(void(^)(BOOL isSuc, NSString *msg))com {
- [ASNetTools.shared postWithPath:postTakeExtraPoints param:@{@"type": pointType} success:^(id _Nonnull json) {
- com(true, @"");
- } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
- com(false,msg);
- }];
- }
- -(void)getTopLinkList:(btnClickBlock)success {
- __weak typeof(self) weakSelf = self;
- [ASNetTools.shared getWithPath:getHotList param:@{@"type":@"banner"} success:^(id _Nonnull json) {
- NSLog(@"------url:%@---json:%@------", getHotList, json);
- NSArray *arr = [KWSearchHotKeyModel mj_objectArrayWithKeyValuesArray:json];
- weakSelf.topLinks = arr;
- success();
- } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
- NSLog(@"------url:%@---code:%@---msg:%@---", getHotList, code, msg);
- weakSelf.topLinks = @[];
- success();
- }];
- }
- @end
|