123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- //
- // FKRefundDetailController.m
- // FirstLink
- //
- // Created by ascii on 16/3/15.
- // Copyright © 2016年 FirstLink. All rights reserved.
- //
- #import "FKRefundDetailController.h"
- #import "FKRefundDetailRequest.h"
- #import "FKRefundDetailReform.h"
- #import "FKRefundDetailItem.h"
- #import "FKRefundGoodItem.h"
- #import "FKRefundDetailViewModel.h"
- #import "FKOrderDetailProductCell.h"
- #import "PindanCommonCell.h"
- #import "PindanBaseCell.h"
- @interface FKRefundDetailController ()
- <UITableViewDelegate, UITableViewDataSource, FLNetworkDelegate>
- @property (nonatomic, strong) NSString *paymentID;
- @property (nonatomic, strong) FKRefundDetailViewModel *viewModel;
- @property (nonatomic, strong) UITableView *tableView;
- @end
- @implementation FKRefundDetailController
- - (instancetype)initWithPaymentID:(NSString *)paymentID {
- self = [super init];
- if (self) {
- _paymentID = paymentID;
- }
- return self;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.view.backgroundColor = UIColorFromRGB(0xf4f4f4);
-
- [self requestRefundDetail];
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
-
- self.navigationItem.title = @"退款详情";
- }
- #pragma mark - Request
- - (void)requestRefundDetail {
- [self.hudView show:YES];
- if (self.paymentID.length > 0) {
- [FKRefundDetailRequest requestRefundDetail:FKRefundRequestDetail paymentID:self.paymentID delegate:self];
- }
- }
- #pragma mark - Response
- - (void)networkDidReceiveError:(NSError*)error identify:(int)identify header:(MSGHeader*)header {
- [self.hudView hide:NO];
-
- [FLProgressHUDHelper showText:header.msg inView:self.view];
- }
- - (void)networkDidSuccessResponse:(NSDictionary*)response identify:(int)identify header:(MSGHeader*)header userInfo:(NSDictionary *)userInfo {
- [self.hudView hide:NO];
-
- if (header.code.intValue == RESPONSE_MSG_NORMAL) {
- if (identify == FKRefundRequestDetail) {
- self.viewModel.refundGoodsArray = [FKRefundDetailReform parserGoodsList:response];
-
- [self addAllSubviews];
- }
- } else {
- [FLProgressHUDHelper showText:header.msg inView:self.view];
- }
- }
- #pragma mark - UITableViewDelegate & UITableViewDataSource
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- if ([self.viewModel respondsToSelector:@selector(numberOfSectionsInTableView)]) {
- return [self.viewModel numberOfSectionsInTableView];
- }
- return 0;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- if ([self.viewModel respondsToSelector:@selector(numberOfRowsInSection:)]) {
- return [self.viewModel numberOfRowsInSection:section];
- }
- return 0;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- return 10;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
- return 10;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
- UIView *view = [UIView new];
- view.backgroundColor = [UIColor whiteColor];
- return view;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- kRefundDetailCellType cellType = [self.viewModel refundCellTypeAtIndexPath:indexPath];
-
- switch (cellType) {
- case kRefundDetailCellTypeStatus:
- return 45;
- case kRefundDetailCellTypeProduct:
- return (95 + 2);
- case kRefundDetailCellTypeChargeClear:
- return 44;
- case kRefundDetailCellTypeEntry:
- return 28;
- default:
- return 44;
- break;
- }
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- UITableViewCell *cell;
- kRefundDetailCellType cellType = [self.viewModel refundCellTypeAtIndexPath:indexPath];
- NSString *identify = [self orderCellIdentifyWith:cellType];
-
- FKRefundDetailItem *item = [self.viewModel refundDetailItemAtIndex:indexPath.section];
- switch (cellType) {
- case kRefundDetailCellTypeStatus: {
- PindanCommonCell *statusCell = [self.tableView dequeueReusableCellWithIdentifier:identify];
-
- statusCell.leftLabel.text = [item.createTime stringByReplacingOccurrencesOfString:@"T" withString:@" "];
- statusCell.rightLabel.text = [FKRefundDetailViewModel getRefundStatusText:item.status.intValue];
- statusCell.rightLabel.textColor = UIColorFromRGB(0xff624a);
- statusCell.bottomLine.hidden = YES;
-
- cell = statusCell;
- break;
- }
- case kRefundDetailCellTypeProduct: {
- FKOrderDetailProductCell *procuctCell = [self.tableView dequeueReusableCellWithIdentifier:identify];
- FKRefundGoodItem *goodItem = [item.goodsArray objectAtIndex:(indexPath.row - 1)];
- if (goodItem) {
- [procuctCell.productImgView sd_setImageWithURL:[NSURL URLWithString:goodItem.photoURL]];
- procuctCell.descripLabel.text = goodItem.title;
- procuctCell.priceLabel.text = [NSString stringWithFormat:@"¥%@", [FLStringHelper convertFenToYuan:goodItem.price]];
- procuctCell.numberLabel.text = [NSString stringWithFormat:@"X%@", goodItem.quantity];
- procuctCell.specLabel.text = goodItem.specName;
- }
-
- cell = procuctCell;
- break;
- }
- case kRefundDetailCellTypeChargeClear: {
- PindanBaseCell *chargeCell = [self.tableView dequeueReusableCellWithIdentifier:identify];
- chargeCell.bottomLine.hidden = NO;
-
- if ([chargeCell respondsToSelector:@selector(configOrderDetailPriceCell:text:)]) {
- [chargeCell configOrderDetailPriceCell:[self.viewModel chargeClearTitle] text:nil];
- [chargeCell remakeLeftLabelAligmentCenterY];
- }
-
- cell = chargeCell;
- break;
- }
- case kRefundDetailCellTypeEntry: {
- PindanCommonCell *entryCell = [self.tableView dequeueReusableCellWithIdentifier:identify];
- entryCell.bottomLine.hidden = YES;
-
- if ([entryCell respondsToSelector:@selector(configOrderDetailPriceCell:text:)]) {
- [entryCell configOrderDetailPriceCell:[self.viewModel priceDetailTitle:indexPath]
- text:[self.viewModel priceDetailText:indexPath]];
- }
-
- cell = entryCell;
- }
- default:
- break;
- }
-
- if (!cell) {
- cell = [[UITableViewCell alloc] init];
- cell.backgroundColor = [UIColor blueColor];
- }
-
- return cell;
- }
- #pragma mark - Method
- - (NSString *)orderCellIdentifyWith:(kRefundDetailCellType)cellType {
- switch (cellType) {
- case kRefundDetailCellTypeProduct:
- return NSStringFromClass([FKOrderDetailProductCell class]);
- case kRefundDetailCellTypeChargeClear:
- return NSStringFromClass([PindanBaseCell class]);
- case kRefundDetailCellTypeStatus:
- case kRefundDetailCellTypeEntry:
- return NSStringFromClass([PindanCommonCell class]);
- default:
- return nil;
- break;
- }
- return nil;
- }
- #pragma mark - Layout
- - (void)addAllSubviews {
- [self.view addSubview:self.tableView];
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.bottom.equalTo(self.view);
- }];
- }
- #pragma mark - Property
- - (FKRefundDetailViewModel *)viewModel {
- if (!_viewModel) {
- _viewModel = [FKRefundDetailViewModel new];
- }
- return _viewModel;
- }
- - (UITableView *)tableView {
- if (!_tableView) {
- _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
- _tableView.dataSource = self;
- _tableView.delegate = self;
- _tableView.backgroundColor = UIColorFromRGB(0xf4f4f4);
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
-
- _tableView.showsVerticalScrollIndicator = NO;
-
- [_tableView registerClass:[PindanBaseCell class] forCellReuseIdentifier:NSStringFromClass([PindanBaseCell class])];
- [_tableView registerClass:[PindanCommonCell class] forCellReuseIdentifier:NSStringFromClass([PindanCommonCell class])];
- [_tableView registerClass:[FKOrderDetailProductCell class] forCellReuseIdentifier:NSStringFromClass([FKOrderDetailProductCell class])];
-
- if (@available(iOS 11.0, *)) {
- _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- }
- }
- return _tableView;
- }
- @end
|