123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- //
- // FKPintuanDetailViewModel.m
- // FirstLink
- //
- // Created by ascii on 15/10/8.
- // Copyright © 2015年 FirstLink. All rights reserved.
- //
- #import "FKGroupDetailViewModel.h"
- @implementation FKGroupDetailViewModel
- #pragma mark - Purchase Cache
- - (FKPurchaseCache *)saveDataIntoCache:(FKPurchaseCache *)cache orderType:(kOrderType)orderType {
- cache.postID = self.item.postId;
- cache.userID = self.item.userId;
- cache.descString = self.item.title;
- cache.limiteAmount = self.item.limiteNum;
- cache.postageState = self.item.postageFreeState;
- cache.unitWeight = self.item.priceDetailItem.singleWeight;
- cache.internationalPostage = self.item.priceDetailItem.international_postage;
-
- cache.orderType = orderType;
- cache.userLevel = self.item.userLevel;
- cache.isPindanNeedIDCard = self.item.isNeedIDCard;
-
- // 解析规格
- NSMutableArray *selectedSpecArray = [NSMutableArray array];
- if (self.item.specsArray && self.item.specsArray.count > 0) {
- for (PindanSpecItem *item in self.item.specsArray) {
- if (item.selectedAmount > 0) [selectedSpecArray addObject:item];
- }
- } else {
- // 没有子类规格
- PindanSpecItem *noSpeItem = [[PindanSpecItem alloc]init];
- noSpeItem.postID = self.item.postId;
- noSpeItem.userID = self.item.userId;
-
- if (kOrderTypeGroup == orderType) {
- noSpeItem.price = self.item.priceDetailItem.group_price;
- } else {
- noSpeItem.price = self.item.priceDetailItem.estimate_price;
- if (self.item.userLevel == kUserLevelVIP
- && self.item.priceDetailItem.vip_price.length > 0) {
- noSpeItem.vipPrice = self.item.priceDetailItem.vip_price;
- }
- }
- noSpeItem.imgUrl = self.item.firstPic;
- noSpeItem.selectedAmount = 1;
-
- [selectedSpecArray addObject:noSpeItem];
- }
- cache.specArray = selectedSpecArray;
-
- return cache;
- }
- - (NSInteger)numberOfSections {
- if (self.item) {
- return 3;
- }
- return 0;
- }
- - (NSInteger)numberOfRowsInSection:(NSInteger)section {
- if (section == 0) { return 2; }
- if (section == 1) { return 5; }
- if (section == 2) { return (self.item.productShowArray.count + 2); }
- return 0;
- }
- - (kDetailCellType)cellTypeForIndexPath:(NSIndexPath *)indexPath {
- if (indexPath.section == 0) {
- if (indexPath.row == 0)
- return kDetailCellTypeMainImg;
- return kDetailCellTypeGroupProgress;
- } else if (indexPath.section == 1) {
- if (indexPath.row == 0) return kDetailCellTypePriceDetailHeader;
- if (indexPath.row == 1) return kDetailCellTypeNationalPrice;
- if (indexPath.row == 2) return kDetailCellTypeNationalPostage;
- if (indexPath.row == 3) return kDetailCellTypeCountryInPrice;
- if (indexPath.row == 4) return kDetailCellTypeGroupTalk;
- } else if (indexPath.section == 2) {
- if (indexPath.row == 0)
- return kDetailCellTypeProductHeader;
- if (indexPath.row == self.item.productShowArray.count + 1)
- return kDetailCellTypeFeature; // 最后一行
- return kDetailCellTypeProductShow;
- }
- return kDetailCellTypeUnknown;
- }
- - (ProductShowItem *)productItemAtIndex:(NSInteger)index {
- if (self.item.productShowArray.count > index) {
- return self.item.productShowArray[index];
- }
- return nil;
- }
- - (BOOL)isGroupStatusEnd {
- if (self.item.productState != kProductStateNormal) {
- return YES;
- }
- return NO;
- }
- - (NSString *)directBuyPrice {
- if (self.item) {
- return [NSString stringWithFormat:@"%@/件", [self.item.priceDetailItem totalPrice]];
- }
- return @"-.--/件";
- }
- - (NSString *)groupBuyPrice {
- if (self.item) {
- return [NSString stringWithFormat:@"%@/件", [self.item.priceDetailItem groupPrice]];
- }
- return @"-.--/件";
- }
- - (NSString *)inviteMemberString {
- return [NSString stringWithFormat:@"开团并邀请好友参团,人数不足可退款,详见拼团玩法"];
- }
- @end
|