No Description

FKCircleProductViewModel.m 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //
  2. // FKCircleProductViewModel.m
  3. // FirstLink
  4. //
  5. // Created by ascii on 16/6/14.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKCircleProductViewModel.h"
  9. #import "FKCircleChoiceProductItem.h"
  10. int const FKCircleProductRequestNew = 1;
  11. int const FKCircleProductRequestNextPage = 2;
  12. @interface FKCircleProductViewModel ()
  13. @property (nonatomic, strong) NSMutableArray *buyRecordArray;
  14. @property (nonatomic, strong) NSMutableArray *basketArray;
  15. @property (nonatomic, strong) NSMutableArray *collectArray;
  16. @end
  17. @implementation FKCircleProductViewModel
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. // Do any additional setup after loading the view.
  21. }
  22. - (void)didReceiveMemoryWarning {
  23. [super didReceiveMemoryWarning];
  24. // Dispose of any resources that can be recreated.
  25. }
  26. /*
  27. #pragma mark - Navigation
  28. // In a storyboard-based application, you will often want to do a little preparation before navigation
  29. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  30. // Get the new view controller using [segue destinationViewController].
  31. // Pass the selected object to the new view controller.
  32. }
  33. */
  34. - (void)saveItems:(NSArray *)items productType:(FKCircleProductType)productType {
  35. if (items.count == 0) {
  36. return;
  37. }
  38. NSMutableArray *array = [self arrayOfProductType:productType];
  39. [array addObjectsFromArray:items];
  40. }
  41. - (void)removeAllObjects:(FKCircleProductType)productType {
  42. NSMutableArray *array = [self arrayOfProductType:productType];
  43. [array removeAllObjects];
  44. }
  45. - (id)itemAtIndex:(NSInteger)index productType:(FKCircleProductType)productType {
  46. NSMutableArray *array = [self arrayOfProductType:productType];
  47. if (index < array.count) {
  48. return [array objectAtIndex:index];
  49. }
  50. return nil;
  51. }
  52. - (NSInteger)countOfItems:(FKCircleProductType)productType {
  53. return [self arrayOfProductType:productType].count;
  54. }
  55. - (NSArray *)selectedItems {
  56. NSMutableArray *array = [NSMutableArray array];
  57. NSMutableArray *items = [NSMutableArray array];
  58. [items addObjectsFromArray:self.buyRecordArray];
  59. [items addObjectsFromArray:self.basketArray];
  60. [items addObjectsFromArray:self.collectArray];
  61. for (FKCircleChoiceProductItem *item in items) {
  62. if ([item isSelected]) {
  63. [array addObject:item];
  64. }
  65. }
  66. return array;
  67. }
  68. #pragma mark - Method
  69. - (NSMutableArray *)arrayOfProductType:(FKCircleProductType)productType {
  70. switch (productType) {
  71. case FKCircleProductTypeBuyRecord: {
  72. return self.buyRecordArray;
  73. break;
  74. }
  75. case FKCircleProductTypeBasket: {
  76. return self.basketArray;
  77. break;
  78. }
  79. case FKCircleProductTypeCollect: {
  80. return self.collectArray;
  81. break;
  82. }
  83. default:
  84. break;
  85. }
  86. return nil;
  87. }
  88. #pragma mark - Property
  89. - (NSMutableArray *)buyRecordArray {
  90. if (!_buyRecordArray) {
  91. _buyRecordArray = [NSMutableArray array];
  92. }
  93. return _buyRecordArray;
  94. }
  95. - (NSMutableArray *)basketArray {
  96. if (!_basketArray) {
  97. _basketArray = [NSMutableArray array];
  98. }
  99. return _basketArray;
  100. }
  101. - (NSMutableArray *)collectArray {
  102. if (!_collectArray) {
  103. _collectArray = [NSMutableArray array];
  104. }
  105. return _collectArray;
  106. }
  107. @end