Keine Beschreibung

FKGroupDetailViewModel.m 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //
  2. // FKPintuanDetailViewModel.m
  3. // FirstLink
  4. //
  5. // Created by ascii on 15/10/8.
  6. // Copyright © 2015年 FirstLink. All rights reserved.
  7. //
  8. #import "FKGroupDetailViewModel.h"
  9. @implementation FKGroupDetailViewModel
  10. #pragma mark - Purchase Cache
  11. - (FKPurchaseCache *)saveDataIntoCache:(FKPurchaseCache *)cache orderType:(kOrderType)orderType {
  12. cache.postID = self.item.postId;
  13. cache.userID = self.item.userId;
  14. cache.descString = self.item.title;
  15. cache.limiteAmount = self.item.limiteNum;
  16. cache.postageState = self.item.postageFreeState;
  17. cache.unitWeight = self.item.priceDetailItem.singleWeight;
  18. cache.internationalPostage = self.item.priceDetailItem.international_postage;
  19. cache.orderType = orderType;
  20. cache.userLevel = self.item.userLevel;
  21. cache.isPindanNeedIDCard = self.item.isNeedIDCard;
  22. // 解析规格
  23. NSMutableArray *selectedSpecArray = [NSMutableArray array];
  24. if (self.item.specsArray && self.item.specsArray.count > 0) {
  25. for (PindanSpecItem *item in self.item.specsArray) {
  26. if (item.selectedAmount > 0) [selectedSpecArray addObject:item];
  27. }
  28. } else {
  29. // 没有子类规格
  30. PindanSpecItem *noSpeItem = [[PindanSpecItem alloc]init];
  31. noSpeItem.postID = self.item.postId;
  32. noSpeItem.userID = self.item.userId;
  33. if (kOrderTypeGroup == orderType) {
  34. noSpeItem.price = self.item.priceDetailItem.group_price;
  35. } else {
  36. noSpeItem.price = self.item.priceDetailItem.estimate_price;
  37. if (self.item.userLevel == kUserLevelVIP
  38. && self.item.priceDetailItem.vip_price.length > 0) {
  39. noSpeItem.vipPrice = self.item.priceDetailItem.vip_price;
  40. }
  41. }
  42. noSpeItem.imgUrl = self.item.firstPic;
  43. noSpeItem.selectedAmount = 1;
  44. [selectedSpecArray addObject:noSpeItem];
  45. }
  46. cache.specArray = selectedSpecArray;
  47. return cache;
  48. }
  49. - (NSInteger)numberOfSections {
  50. if (self.item) {
  51. return 3;
  52. }
  53. return 0;
  54. }
  55. - (NSInteger)numberOfRowsInSection:(NSInteger)section {
  56. if (section == 0) { return 2; }
  57. if (section == 1) { return 5; }
  58. if (section == 2) { return (self.item.productShowArray.count + 2); }
  59. return 0;
  60. }
  61. - (kDetailCellType)cellTypeForIndexPath:(NSIndexPath *)indexPath {
  62. if (indexPath.section == 0) {
  63. if (indexPath.row == 0)
  64. return kDetailCellTypeMainImg;
  65. return kDetailCellTypeGroupProgress;
  66. } else if (indexPath.section == 1) {
  67. if (indexPath.row == 0) return kDetailCellTypePriceDetailHeader;
  68. if (indexPath.row == 1) return kDetailCellTypeNationalPrice;
  69. if (indexPath.row == 2) return kDetailCellTypeNationalPostage;
  70. if (indexPath.row == 3) return kDetailCellTypeCountryInPrice;
  71. if (indexPath.row == 4) return kDetailCellTypeGroupTalk;
  72. } else if (indexPath.section == 2) {
  73. if (indexPath.row == 0)
  74. return kDetailCellTypeProductHeader;
  75. if (indexPath.row == self.item.productShowArray.count + 1)
  76. return kDetailCellTypeFeature; // 最后一行
  77. return kDetailCellTypeProductShow;
  78. }
  79. return kDetailCellTypeUnknown;
  80. }
  81. - (ProductShowItem *)productItemAtIndex:(NSInteger)index {
  82. if (self.item.productShowArray.count > index) {
  83. return self.item.productShowArray[index];
  84. }
  85. return nil;
  86. }
  87. - (BOOL)isGroupStatusEnd {
  88. if (self.item.productState != kProductStateNormal) {
  89. return YES;
  90. }
  91. return NO;
  92. }
  93. - (NSString *)directBuyPrice {
  94. if (self.item) {
  95. return [NSString stringWithFormat:@"%@/件", [self.item.priceDetailItem totalPrice]];
  96. }
  97. return @"-.--/件";
  98. }
  99. - (NSString *)groupBuyPrice {
  100. if (self.item) {
  101. return [NSString stringWithFormat:@"%@/件", [self.item.priceDetailItem groupPrice]];
  102. }
  103. return @"-.--/件";
  104. }
  105. - (NSString *)inviteMemberString {
  106. return [NSString stringWithFormat:@"开团并邀请好友参团,人数不足可退款,详见拼团玩法"];
  107. }
  108. @end