123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- //
- // FKCircleProductViewModel.m
- // FirstLink
- //
- // Created by ascii on 16/6/14.
- // Copyright © 2016年 FirstLink. All rights reserved.
- //
- #import "FKCircleProductViewModel.h"
- #import "FKCircleChoiceProductItem.h"
- int const FKCircleProductRequestNew = 1;
- int const FKCircleProductRequestNextPage = 2;
- @interface FKCircleProductViewModel ()
- @property (nonatomic, strong) NSMutableArray *buyRecordArray;
- @property (nonatomic, strong) NSMutableArray *basketArray;
- @property (nonatomic, strong) NSMutableArray *collectArray;
- @end
- @implementation FKCircleProductViewModel
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- /*
- #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.
- }
- */
- - (void)saveItems:(NSArray *)items productType:(FKCircleProductType)productType {
- if (items.count == 0) {
- return;
- }
- NSMutableArray *array = [self arrayOfProductType:productType];
- [array addObjectsFromArray:items];
- }
- - (void)removeAllObjects:(FKCircleProductType)productType {
- NSMutableArray *array = [self arrayOfProductType:productType];
- [array removeAllObjects];
- }
- - (id)itemAtIndex:(NSInteger)index productType:(FKCircleProductType)productType {
- NSMutableArray *array = [self arrayOfProductType:productType];
- if (index < array.count) {
- return [array objectAtIndex:index];
- }
- return nil;
- }
- - (NSInteger)countOfItems:(FKCircleProductType)productType {
- return [self arrayOfProductType:productType].count;
- }
- - (NSArray *)selectedItems {
- NSMutableArray *array = [NSMutableArray array];
-
- NSMutableArray *items = [NSMutableArray array];
- [items addObjectsFromArray:self.buyRecordArray];
- [items addObjectsFromArray:self.basketArray];
- [items addObjectsFromArray:self.collectArray];
- for (FKCircleChoiceProductItem *item in items) {
- if ([item isSelected]) {
- [array addObject:item];
- }
- }
- return array;
- }
- #pragma mark - Method
- - (NSMutableArray *)arrayOfProductType:(FKCircleProductType)productType {
- switch (productType) {
- case FKCircleProductTypeBuyRecord: {
- return self.buyRecordArray;
- break;
- }
- case FKCircleProductTypeBasket: {
- return self.basketArray;
- break;
- }
- case FKCircleProductTypeCollect: {
- return self.collectArray;
- break;
- }
- default:
- break;
- }
- return nil;
- }
- #pragma mark - Property
- - (NSMutableArray *)buyRecordArray {
- if (!_buyRecordArray) {
- _buyRecordArray = [NSMutableArray array];
- }
- return _buyRecordArray;
- }
- - (NSMutableArray *)basketArray {
- if (!_basketArray) {
- _basketArray = [NSMutableArray array];
- }
- return _basketArray;
- }
- - (NSMutableArray *)collectArray {
- if (!_collectArray) {
- _collectArray = [NSMutableArray array];
- }
- return _collectArray;
- }
- @end
|