123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447 |
- //
- // LogisticsViewController.m
- // FirstLink
- //
- // Created by ascii on 15/5/29.
- // Copyright (c) 2015年 FirstLink. All rights reserved.
- //
- #import "LogisticsViewController.h"
- #import "LogisticsViewModel.h"
- #import <HMSegmentedControl/HMSegmentedControl.h>
- #import "WebViewController.h"
- #import "FKOrderDetailProductCell.h"
- #import "LogisticsProgressCell.h"
- #import "LogisticsSuccessCell.h"
- #import "LogisticsQuestionCell.h"
- #import "LogisticsAnswerCell.h"
- #import "LogisticsTimeOutCell.h"
- #import "FKPackageIncompleteView.h"
- #import "FKTargetConfigUtil.h"
- @interface LogisticsViewController ()
- <UITableViewDelegate, UITableViewDataSource, FKCardSegmentViewDelegate>
- @property (nonatomic, strong) FKCardSegmentView *cardSegmentView;
- @property (nonatomic, strong) FKPackageIncompleteView *packageIncompleteView;
- @property (nonatomic, strong) HMSegmentedControl *segmentedControl;
- @property (nonatomic, strong) LogisticsViewModel *viewModel;
- @property (nonatomic, strong) UITableView *tableView;
- @property (nonatomic, assign) BOOL isShowQuestion;
- @end
- static NSString * const FKOrderDetailProductCellIdentifier = @"FKOrderDetailProductCellIdentifier";
- static NSString * const LogisticsProgressCellIdentifier = @"LogisticsProgressCellIdentifier";
- static NSString * const LogisticsSuccessCellIdentifier = @"LogisticsSuccessCellIdentifier";
- static NSString * const LogisticsQuestionCellIdentifier = @"LogisticsQuestionCellIdentifier";
- static NSString * const LogisticsAnswerCellIdentifier = @"LogisticsAnswerCellIdentifier";
- static NSString * const LogisticsTimeOutCellIdentifier = @"LogisticsTimeOutCellIdentifier";
- @implementation LogisticsViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view from its nib.
-
- self.isShowQuestion = YES;
- self.navigationItem.title = @"物流信息";
- self.view.backgroundColor = UIColorFromRGB(0xf9f9f9);
-
- if (self.openURLPara) {
- self.waybillID = self.openURLPara[@"waybill_id"];
- self.logisticsID = self.openURLPara[@"id"];
- }
-
- [self.hudView show:YES];
- [self loadNewRequest];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- #pragma mark - Request
- - (void)loadNewRequest {
- if (!self.waybillID || self.waybillID.length == 0){
- [self finishLoadingData];
- [self showStatusTipInView:self.tableView
- image:[UIImage imageNamed:@"StatusNoMessageIcon"]
- title:NoMessageTip];
- return;
- }
- WeakSelf(weakSelf);
- [self.viewModel requestLogistics:self.waybillID
- logisticsID:self.logisticsID
- success:^(MSGHeader *header, NSDictionary *response)
- {
- [weakSelf.hudView hide:NO];
- [weakSelf finishLoadingData];
- if ([header.code intValue] == RESPONSE_MSG_NORMAL) {
- weakSelf.viewModel.logisticsStatus = [LogisticsViewModel parseLogisticsStatus:response];
-
- NSArray<FKPackageLogisticsItem *> *inPackageArray = [LogisticsViewModel parsePackages:response[@"data"][@"warehousing_package_list"]];
- NSArray<FKPackageLogisticsItem *> *outPackageArray = [LogisticsViewModel parsePackages:response[@"data"][@"send_package_list"]];
-
- weakSelf.viewModel.inPackageArray = inPackageArray;
- weakSelf.viewModel.outPackageArray = outPackageArray;
-
- [weakSelf.view addSubview:weakSelf.packageIncompleteView];
- [weakSelf.view addSubview:weakSelf.cardSegmentView];
- [weakSelf.view addSubview:weakSelf.segmentedControl];
- [weakSelf.view addSubview:weakSelf.tableView];
- [weakSelf.view addSubview:weakSelf.statusView];
-
- [weakSelf setupViews];
- } else {
- [FLProgressHUDHelper showText:header.msg inView:weakSelf.view];
- }
- } failure:^(MSGHeader *header, NSError *error) {
- [weakSelf.hudView hide:NO];
- [weakSelf finishLoadingData];
- [FLProgressHUDHelper showText:error.localizedDescription inView:weakSelf.view];
- }];
- }
- #pragma mark - Layout
- - (CGFloat)topEdgeOffset {
- return 0;
- }
- - (void)setupViews {
- self.packageIncompleteView.hidden = YES;
- if ([self.viewModel isPackageCompleted]) {
- [self.cardSegmentView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.equalTo(self.view);
- make.top.equalTo(self.view).offset(6);
- make.height.mas_equalTo(48);
- }];
- } else {
- self.packageIncompleteView.hidden = NO;
- [self.packageIncompleteView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.equalTo(self.view);
- make.top.equalTo(self.view).offset(0);
- make.height.mas_equalTo(40);
- }];
-
- [self.cardSegmentView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.equalTo(self.view);
- make.top.equalTo(self.packageIncompleteView.mas_bottom).offset(6);
- make.height.mas_equalTo(48);
- }];
- }
-
- NSArray<FKPackageLogisticsItem *> *packageArray = [self.viewModel selectPackageArray];
-
- self.segmentedControl.hidden = YES;
- self.tableView.hidden = YES;
- self.statusView.hidden = YES;
- if (packageArray.count > 1) {
- self.segmentedControl.hidden = NO;
- [self.segmentedControl mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.equalTo(self.view);
- make.top.equalTo(self.cardSegmentView.mas_bottom).offset([self topEdgeOffset]);
- make.height.mas_equalTo(44);
- }];
-
- self.segmentedControl.sectionTitles = [self.viewModel sectionTitleArray];
- self.segmentedControl.selectedSegmentIndex = [self.viewModel selectedIndex];
- [self.segmentedControl setNeedsDisplay];
-
- self.tableView.hidden = NO;
- [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.segmentedControl.mas_bottom);
- make.left.right.bottom.equalTo(self.view);
- }];
- } else if (packageArray.count == 1) {
- self.tableView.hidden = NO;
- [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.equalTo(self.view);
- make.top.equalTo(self.cardSegmentView.mas_bottom).offset([self topEdgeOffset]);
- }];
- } else {
- self.statusView.hidden = NO;
-
- self.statusView.statusImageView.image = [UIImage imageNamed:@"StatusNoMessageIcon"];
- self.statusView.statusLabel.text = NoMessageTip;
- self.statusView.backgroundColor = UIColorFromRGB(0xf4f4f4);
-
- [self.statusView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.equalTo(self.view);
- make.top.equalTo(self.cardSegmentView.mas_bottom).offset([self topEdgeOffset]);
- }];
- }
-
- [self.tableView reloadData];
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- #pragma mark - UITableViewDataSource, UITableViewDelegate
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return [self.viewModel numberOfSectionsWithSegmentIndex:self.segmentedControl.selectedSegmentIndex];
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return [self.viewModel numberOfRowsInSection:section withSegmentIndex:self.segmentedControl.selectedSegmentIndex];
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- NSInteger segmentIndex = self.segmentedControl.selectedSegmentIndex;
- kLogisticsCellType cellType = [self.viewModel cellTypeAtIndexPath:indexPath withSegmentIndex:segmentIndex];
- switch (cellType) {
- case kLogisticsCellTypeProduct: {
- return (95 + 2); break;
- }
- case kLogisticsCellTypeProgress:
- case kLogisticsCellTypeSuccess: {
- LogisticsItem *item = [self.viewModel logisticsItemAtIndexPath:indexPath withSegmentIndex:segmentIndex];
- return [LogisticsProgressCell cellHeightWith:item.desc];
- break;
- }
- case kLogisticsCellTypeQuestionAnswer: {
- return [LogisticsAnswerCell height:[LogisticsViewController LOGISTICS_ANSWER_TEXT]]; break;
- }
- case kLogisticsCellTypeTimeOut:
- break;
- default:
- break;
- }
- return 44.0;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- if (section == 0) {
- return CGFLOAT_MIN;
- }
- return 20;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
- return CGFLOAT_MIN;
- }
- - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- UITableViewCell *cell;
- NSInteger segmentIndex = self.segmentedControl.selectedSegmentIndex;
- kLogisticsCellType cellType = [self.viewModel cellTypeAtIndexPath:indexPath withSegmentIndex:segmentIndex];
- switch (cellType) {
- case kLogisticsCellTypeProduct: {
- FKOrderDetailProductCell *productCell = [tableView dequeueReusableCellWithIdentifier:FKOrderDetailProductCellIdentifier];
- FKOrderGoodItem *goodItem = [self.viewModel orderGoodItemAtIndexPath:indexPath withSegmentIndex:segmentIndex];
- if (goodItem) {
- [productCell.productImgView sd_setImageWithURL:[NSURL URLWithString:goodItem.photoURL] placeholderImage:nil];
- productCell.descripLabel.text = goodItem.title;
- productCell.priceLabel.text = [NSString stringWithFormat:@"¥%@", [FLStringHelper convertFenToYuan:goodItem.price]];
- productCell.numberLabel.text = [NSString stringWithFormat:@"X%@", goodItem.quantity];
- productCell.specLabel.text = goodItem.specName;
- }
-
- cell = productCell;
- break;
- }
- case kLogisticsCellTypeProgress:
- case kLogisticsCellTypeSuccess: {
- LogisticsItem *item = [self.viewModel logisticsItemAtIndexPath:indexPath withSegmentIndex:segmentIndex];
- if (indexPath.row == 0) {
- LogisticsSuccessCell *detailCell = [tableView dequeueReusableCellWithIdentifier:LogisticsSuccessCellIdentifier];
-
- detailCell.logisticsTextLabel.text = item.desc;
- NSString *createTime = [item.createTime stringByReplacingOccurrencesOfString:@"T"
- withString:@" "];
- detailCell.logisticsTimeLabel.text = createTime;
- detailCell.horizontalLine.hidden = YES;
-
- cell = detailCell;
- } else {
- LogisticsProgressCell *detailCell = [tableView dequeueReusableCellWithIdentifier:LogisticsProgressCellIdentifier];
-
- detailCell.logisticsTextLabel.text = item.desc;
- detailCell.logisticsTimeLabel.text = [item.createTime stringByReplacingOccurrencesOfString:@"T"
- withString:@" "];
- detailCell.horizontalLine.hidden = NO;
-
- cell = detailCell;
- }
- break;
- }
- case kLogisticsCellTypeQuestionAnswer: {
- if (self.isShowQuestion) {
- LogisticsQuestionCell *questionCell = [tableView dequeueReusableCellWithIdentifier:LogisticsQuestionCellIdentifier];
- [questionCell.iconButton addTarget:self action:@selector(clickAnswerOpenAction:) forControlEvents:UIControlEventTouchUpInside];
-
- cell = questionCell;
- } else {
- LogisticsAnswerCell *answerCell = [tableView dequeueReusableCellWithIdentifier:LogisticsAnswerCellIdentifier];
- [answerCell.closeButton addTarget:self action:@selector(clickAnswerCloseAction:) forControlEvents:UIControlEventTouchUpInside];
- answerCell.contentLabel.text = [LogisticsViewController LOGISTICS_ANSWER_TEXT];
-
- cell = answerCell;
- }
- break;
- }
- case kLogisticsCellTypeTimeOut: {
- LogisticsTimeOutCell *timeOutCell = [tableView dequeueReusableCellWithIdentifier:LogisticsTimeOutCellIdentifier];
- [timeOutCell.timeOutBtn addTarget:self action:@selector(clickTimeOutButton:) forControlEvents:UIControlEventTouchUpInside];
-
- cell = timeOutCell;
- break;
- }
- default:
- break;
- }
-
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- return cell;
- }
- #pragma mark - FKCardSegmentViewDelegate
- - (void)cardSegmentView:(FKCardSegmentView *)view didSelectWithVipIndex:(kCardSegmentIndex)index {
- if (index == kCardSegmentIndexLeft) {
- [self setButton:self.cardSegmentView.leftButton image:[UIImage imageNamed:@"vip_segment_left_select"]];
- [self setButton:self.cardSegmentView.rightButton image:[UIImage imageNamed:@"vip_segment_unselect_gray"]];
- } else if (index == kCardSegmentIndexRight) {
- [self setButton:self.cardSegmentView.leftButton image:[UIImage imageNamed:@"vip_segment_unselect_gray"]];
- [self setButton:self.cardSegmentView.rightButton image:[UIImage imageNamed:@"vip_segment_right_select"]];
- }
- self.viewModel.cardSegmentIndex = index;
- if (self.segmentedControl.hidden == NO) {
- [self.segmentedControl setSelectedSegmentIndex:0];
- }
-
- [self setupViews];
- }
- - (void)setButton:(UIButton *)button image:(UIImage *)image {
- [button setBackgroundImage:image forState:UIControlStateNormal];
- [button setBackgroundImage:image forState:UIControlStateHighlighted];
- }
- #pragma mark - Action
- - (IBAction)clickAnswerOpenAction:(id)sender {
- self.isShowQuestion = NO;
- [self.tableView reloadData];
- }
- - (IBAction)clickAnswerCloseAction:(id)sender {
- self.isShowQuestion = YES;
- [self.tableView reloadData];
- }
- - (IBAction)clickTimeOutButton:(id)sender {
- NSString *urlString = [NSString stringWithFormat:@"%@/support/timeout-pay.html", [[FKServerUtil sharedInstance] webServer]];
- WebViewController *newViewController = [[WebViewController alloc] init];
- newViewController.url = urlString;
- newViewController.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:newViewController animated:YES];
- }
- #pragma mark - Property
- + (NSString *)LOGISTICS_ANSWER_TEXT {
- return [NSString stringWithFormat:@"我们会在最短时间内帮您在海外官网下单;\n下单成功后,官网约在3天内发货;\n%@直接提供海外直达中国的物流服务,全程可监控;\n清关后EMS直接收包投递;\n如出现清关缓慢等异常情况,我们将立即与您联系", [FKTargetConfigUtil appName]];
- }
- - (FKPackageIncompleteView *)packageIncompleteView {
- if (!_packageIncompleteView) {
- _packageIncompleteView = [FKPackageIncompleteView new];
- _packageIncompleteView.backgroundColor = UIColorFromRGB(0xe8d0a2);
- _packageIncompleteView.frame = CGRectMake(0, 0, UISCREENWIDTH, 40);
- }
- return _packageIncompleteView;
- }
- - (FKCardSegmentView *)cardSegmentView {
- if (!_cardSegmentView) {
- _cardSegmentView = [[FKCardSegmentView alloc] initWithFrame:CGRectMake(0, 6, UISCREENWIDTH, 48)];
- _cardSegmentView.backgroundColor = UIColorFromRGB(0xf9f9f9);
- _cardSegmentView.superVipImgView.hidden = YES;
- _cardSegmentView.discountImgView.hidden = YES;
-
- _cardSegmentView.leftButtonLabel.text = @"国际物流";
- _cardSegmentView.leftButtonLabel.font = [UIFont boldSystemFontOfSize:14];
- _cardSegmentView.rightButtonLabel.text = @"国内物流";
- _cardSegmentView.rightButtonLabel.font = [UIFont boldSystemFontOfSize:14];
- _cardSegmentView.delegate = self;
-
- [self setButton:_cardSegmentView.leftButton image:[UIImage imageNamed:@"vip_segment_left_select"]];
- [self setButton:_cardSegmentView.rightButton image:[UIImage imageNamed:@"vip_segment_unselect_gray"]];
- }
- return _cardSegmentView;
- }
- - (HMSegmentedControl *)segmentedControl {
- if (!_segmentedControl) {
- _segmentedControl = [HMSegmentedControl new];
- _segmentedControl.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationDown;
- _segmentedControl.selectionIndicatorHeight = 2;
- _segmentedControl.segmentEdgeInset = UIEdgeInsetsMake(0, 15, -8, 15);
- _segmentedControl.selectionIndicatorEdgeInsets = UIEdgeInsetsMake(0, 15, -8, 15);
- _segmentedControl.selectionIndicatorColor = UIColorFromRGB(0xff6362);
- _segmentedControl.selectionStyle = HMSegmentedControlSelectionStyleTextWidthStripe;
- _segmentedControl.selectedTitleTextAttributes = @{NSForegroundColorAttributeName : [UIColor blackColor],
- NSFontAttributeName : [UIFont systemFontOfSize:15]};
- _segmentedControl.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor grayColor],
- NSFontAttributeName : [UIFont systemFontOfSize:15]};
-
- _segmentedControl.type = HMSegmentedControlTypeText;
- _segmentedControl.segmentWidthStyle = HMSegmentedControlSegmentWidthStyleDynamic;
-
- WeakSelf(weakSelf);
- _segmentedControl.indexChangeBlock = ^(NSInteger index) {
- [weakSelf.tableView reloadData];
- };
- }
- return _segmentedControl;
- }
- - (LogisticsViewModel *)viewModel {
- if (!_viewModel) {
- _viewModel = [[LogisticsViewModel alloc] init];
- }
- return _viewModel;
- }
- - (UITableView *)tableView {
- if (!_tableView) {
- _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _tableView.backgroundColor = UIColorFromRGB(0xffffff);
- _tableView.dataSource = self;
- _tableView.delegate = self;
-
- [_tableView registerClass:[FKOrderDetailProductCell class] forCellReuseIdentifier:FKOrderDetailProductCellIdentifier];
- [_tableView registerClass:[LogisticsProgressCell class] forCellReuseIdentifier:LogisticsProgressCellIdentifier];
- [_tableView registerClass:[LogisticsSuccessCell class] forCellReuseIdentifier:LogisticsSuccessCellIdentifier];
- [_tableView registerClass:[LogisticsQuestionCell class] forCellReuseIdentifier:LogisticsQuestionCellIdentifier];
- [_tableView registerClass:[LogisticsAnswerCell class] forCellReuseIdentifier:LogisticsAnswerCellIdentifier];
- [_tableView registerClass:[LogisticsTimeOutCell class] forCellReuseIdentifier:LogisticsTimeOutCellIdentifier];
-
- if (@available(iOS 11.0, *)) {
- _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- }
- }
- return _tableView;
- }
- @end
|