123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- //
- // FKMyBookViewModel.m
- // FirstLink
- //
- // Created by jack on 16/4/29.
- // Copyright © 2016年 FirstLink. All rights reserved.
- //
- #import "FKBookNormalViewModel.h"
- #import "FKBookProItem.h"
- #import "FKBookBrandItem.h"
- @implementation FKBookNormalViewModel
- @synthesize itemArray = _itemArray;
- + (NSDictionary *)mts_mapping {
- return @{
- @"list" : mts_key(itemArray),
- @"brand_list" : mts_key(brandArray),
- @"pager.total" : mts_key(productTotal),
- @"server_time" : mts_key(serveTime),
- };
- }
- + (BOOL)mts_shouldSetUndefinedKeys {
- return NO;
- }
- + (NSDictionary *)mts_arrayClassMapping{
- return @{mts_key(itemArray) : FKBookProItem.class,
- mts_key(brandArray) : FKBookBrandItem.class};
- }
- - (NSInteger)numberOfRowsInSection:(NSInteger)section{
- return self.itemArray.count;
- }
- - (CGFloat)heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- return 118.0f;
- }
- - (CGFloat)heightForHeaderInSection:(NSInteger)section{
- return CGFLOAT_MIN;
- }
- - (NSString *)cellIdentify{
- return FK_BOOK_PRO_CELL_IDENTIFY;
- }
- - (NSString *)brandIdAtIndex:(NSUInteger)index{
- if (index <= self.brandArray.count){
- FKBookBrandItem *item = self.brandArray[index];
- return item.itemID;
- }
- return nil;
- }
- - (NSString *)brandNameAtIndex:(NSUInteger)index{
- if (index <= self.brandArray.count){
- FKBookBrandItem *item = self.brandArray[index];
- return item.name;
- }
- return nil;
- }
- - (BookContentType)contentType{
- return BookContentTypeNormal;
- }
- - (BOOL)enableBottomRefresh{
- if (self.itemArray.count >= self.productTotal) {
- return NO;
- }
- return YES;
- }
- - (void)appendMoreItem:(NSArray *)moreArray{
- if (!self.itemArray || !self.itemArray.count) self.itemArray = moreArray;
-
- NSMutableArray *arrayM = [NSMutableArray arrayWithArray:self.itemArray];
- [arrayM addObjectsFromArray:moreArray];
- self.itemArray = arrayM;
- }
- - (BOOL)saveServeTime{
- if ([FLStringHelper isValidString:self.serveTime]) {
- [[NSUserDefaults standardUserDefaults] setObject:self.serveTime forKey:FK_BOOK_BRAND_SERVER_TIME_KEY];
- return [[NSUserDefaults standardUserDefaults] synchronize];
- }
-
- return NO;
- }
- - (id)proModelAtIndex:(NSUInteger)index{
- if (index < self.itemArray.count) {
- return self.itemArray[index];
- }
- return nil;
- }
- - (NSArray *)getBrandStrArray{
- if (self.brandArray.count) {
- NSMutableArray *arrayM = [NSMutableArray arrayWithCapacity:self.brandArray.count];
- for (FKBookBrandItem *item in self.brandArray) {
- if ([FLStringHelper isValidString:item.name]){
- [arrayM addObject:item.name];
- }
- }
- return arrayM;
- }
- return nil;
- }
- @end
|