Açıklama Yok

FKRefundDetailController.m 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. //
  2. // FKRefundDetailController.m
  3. // FirstLink
  4. //
  5. // Created by ascii on 16/3/15.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKRefundDetailController.h"
  9. #import "FKRefundDetailRequest.h"
  10. #import "FKRefundDetailReform.h"
  11. #import "FKRefundDetailItem.h"
  12. #import "FKRefundGoodItem.h"
  13. #import "FKRefundDetailViewModel.h"
  14. #import "FKOrderDetailProductCell.h"
  15. #import "PindanCommonCell.h"
  16. #import "PindanBaseCell.h"
  17. @interface FKRefundDetailController ()
  18. <UITableViewDelegate, UITableViewDataSource, FLNetworkDelegate>
  19. @property (nonatomic, strong) NSString *paymentID;
  20. @property (nonatomic, strong) FKRefundDetailViewModel *viewModel;
  21. @property (nonatomic, strong) UITableView *tableView;
  22. @end
  23. @implementation FKRefundDetailController
  24. - (instancetype)initWithPaymentID:(NSString *)paymentID {
  25. self = [super init];
  26. if (self) {
  27. _paymentID = paymentID;
  28. }
  29. return self;
  30. }
  31. - (void)viewDidLoad {
  32. [super viewDidLoad];
  33. self.view.backgroundColor = UIColorFromRGB(0xf4f4f4);
  34. [self requestRefundDetail];
  35. }
  36. - (void)viewWillAppear:(BOOL)animated {
  37. [super viewWillAppear:animated];
  38. self.navigationItem.title = @"退款详情";
  39. }
  40. #pragma mark - Request
  41. - (void)requestRefundDetail {
  42. [self.hudView show:YES];
  43. if (self.paymentID.length > 0) {
  44. [FKRefundDetailRequest requestRefundDetail:FKRefundRequestDetail paymentID:self.paymentID delegate:self];
  45. }
  46. }
  47. #pragma mark - Response
  48. - (void)networkDidReceiveError:(NSError*)error identify:(int)identify header:(MSGHeader*)header {
  49. [self.hudView hide:NO];
  50. [FLProgressHUDHelper showText:header.msg inView:self.view];
  51. }
  52. - (void)networkDidSuccessResponse:(NSDictionary*)response identify:(int)identify header:(MSGHeader*)header userInfo:(NSDictionary *)userInfo {
  53. [self.hudView hide:NO];
  54. if (header.code.intValue == RESPONSE_MSG_NORMAL) {
  55. if (identify == FKRefundRequestDetail) {
  56. self.viewModel.refundGoodsArray = [FKRefundDetailReform parserGoodsList:response];
  57. [self addAllSubviews];
  58. }
  59. } else {
  60. [FLProgressHUDHelper showText:header.msg inView:self.view];
  61. }
  62. }
  63. #pragma mark - UITableViewDelegate & UITableViewDataSource
  64. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  65. if ([self.viewModel respondsToSelector:@selector(numberOfSectionsInTableView)]) {
  66. return [self.viewModel numberOfSectionsInTableView];
  67. }
  68. return 0;
  69. }
  70. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  71. if ([self.viewModel respondsToSelector:@selector(numberOfRowsInSection:)]) {
  72. return [self.viewModel numberOfRowsInSection:section];
  73. }
  74. return 0;
  75. }
  76. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  77. return 10;
  78. }
  79. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  80. return 10;
  81. }
  82. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  83. UIView *view = [UIView new];
  84. view.backgroundColor = [UIColor whiteColor];
  85. return view;
  86. }
  87. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  88. kRefundDetailCellType cellType = [self.viewModel refundCellTypeAtIndexPath:indexPath];
  89. switch (cellType) {
  90. case kRefundDetailCellTypeStatus:
  91. return 45;
  92. case kRefundDetailCellTypeProduct:
  93. return (95 + 2);
  94. case kRefundDetailCellTypeChargeClear:
  95. return 44;
  96. case kRefundDetailCellTypeEntry:
  97. return 28;
  98. default:
  99. return 44;
  100. break;
  101. }
  102. }
  103. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  104. UITableViewCell *cell;
  105. kRefundDetailCellType cellType = [self.viewModel refundCellTypeAtIndexPath:indexPath];
  106. NSString *identify = [self orderCellIdentifyWith:cellType];
  107. FKRefundDetailItem *item = [self.viewModel refundDetailItemAtIndex:indexPath.section];
  108. switch (cellType) {
  109. case kRefundDetailCellTypeStatus: {
  110. PindanCommonCell *statusCell = [self.tableView dequeueReusableCellWithIdentifier:identify];
  111. statusCell.leftLabel.text = [item.createTime stringByReplacingOccurrencesOfString:@"T" withString:@" "];
  112. statusCell.rightLabel.text = [FKRefundDetailViewModel getRefundStatusText:item.status.intValue];
  113. statusCell.rightLabel.textColor = UIColorFromRGB(0xff624a);
  114. statusCell.bottomLine.hidden = YES;
  115. cell = statusCell;
  116. break;
  117. }
  118. case kRefundDetailCellTypeProduct: {
  119. FKOrderDetailProductCell *procuctCell = [self.tableView dequeueReusableCellWithIdentifier:identify];
  120. FKRefundGoodItem *goodItem = [item.goodsArray objectAtIndex:(indexPath.row - 1)];
  121. if (goodItem) {
  122. [procuctCell.productImgView sd_setImageWithURL:[NSURL URLWithString:goodItem.photoURL]];
  123. procuctCell.descripLabel.text = goodItem.title;
  124. procuctCell.priceLabel.text = [NSString stringWithFormat:@"¥%@", [FLStringHelper convertFenToYuan:goodItem.price]];
  125. procuctCell.numberLabel.text = [NSString stringWithFormat:@"X%@", goodItem.quantity];
  126. procuctCell.specLabel.text = goodItem.specName;
  127. }
  128. cell = procuctCell;
  129. break;
  130. }
  131. case kRefundDetailCellTypeChargeClear: {
  132. PindanBaseCell *chargeCell = [self.tableView dequeueReusableCellWithIdentifier:identify];
  133. chargeCell.bottomLine.hidden = NO;
  134. if ([chargeCell respondsToSelector:@selector(configOrderDetailPriceCell:text:)]) {
  135. [chargeCell configOrderDetailPriceCell:[self.viewModel chargeClearTitle] text:nil];
  136. [chargeCell remakeLeftLabelAligmentCenterY];
  137. }
  138. cell = chargeCell;
  139. break;
  140. }
  141. case kRefundDetailCellTypeEntry: {
  142. PindanCommonCell *entryCell = [self.tableView dequeueReusableCellWithIdentifier:identify];
  143. entryCell.bottomLine.hidden = YES;
  144. if ([entryCell respondsToSelector:@selector(configOrderDetailPriceCell:text:)]) {
  145. [entryCell configOrderDetailPriceCell:[self.viewModel priceDetailTitle:indexPath]
  146. text:[self.viewModel priceDetailText:indexPath]];
  147. }
  148. cell = entryCell;
  149. }
  150. default:
  151. break;
  152. }
  153. if (!cell) {
  154. cell = [[UITableViewCell alloc] init];
  155. cell.backgroundColor = [UIColor blueColor];
  156. }
  157. return cell;
  158. }
  159. #pragma mark - Method
  160. - (NSString *)orderCellIdentifyWith:(kRefundDetailCellType)cellType {
  161. switch (cellType) {
  162. case kRefundDetailCellTypeProduct:
  163. return NSStringFromClass([FKOrderDetailProductCell class]);
  164. case kRefundDetailCellTypeChargeClear:
  165. return NSStringFromClass([PindanBaseCell class]);
  166. case kRefundDetailCellTypeStatus:
  167. case kRefundDetailCellTypeEntry:
  168. return NSStringFromClass([PindanCommonCell class]);
  169. default:
  170. return nil;
  171. break;
  172. }
  173. return nil;
  174. }
  175. #pragma mark - Layout
  176. - (void)addAllSubviews {
  177. [self.view addSubview:self.tableView];
  178. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  179. make.left.right.top.bottom.equalTo(self.view);
  180. }];
  181. }
  182. #pragma mark - Property
  183. - (FKRefundDetailViewModel *)viewModel {
  184. if (!_viewModel) {
  185. _viewModel = [FKRefundDetailViewModel new];
  186. }
  187. return _viewModel;
  188. }
  189. - (UITableView *)tableView {
  190. if (!_tableView) {
  191. _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
  192. _tableView.dataSource = self;
  193. _tableView.delegate = self;
  194. _tableView.backgroundColor = UIColorFromRGB(0xf4f4f4);
  195. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  196. _tableView.showsVerticalScrollIndicator = NO;
  197. [_tableView registerClass:[PindanBaseCell class] forCellReuseIdentifier:NSStringFromClass([PindanBaseCell class])];
  198. [_tableView registerClass:[PindanCommonCell class] forCellReuseIdentifier:NSStringFromClass([PindanCommonCell class])];
  199. [_tableView registerClass:[FKOrderDetailProductCell class] forCellReuseIdentifier:NSStringFromClass([FKOrderDetailProductCell class])];
  200. if (@available(iOS 11.0, *)) {
  201. _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  202. }
  203. }
  204. return _tableView;
  205. }
  206. @end