123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- //
- // SPSBWholeOrderListViewController.m
- // 我的社保
- //
- // Created by shanp on 2021/6/18.
- //
- #import "SPSBWholeOrderListViewController.h"
- #import "SPSBUIGeneralHeader.h"
- #import "SPSBOrderListTableViewController.h"
- #import "UIViewController+SPSBNetworkManager.h"
- #import <JXHFixHeaderViewController.h>
- #import <JXHFixHeaderViewHeaderController.h>
- #import <JXHClassifyView.h>
- #import "SPSBRouteManager.h"
- #import "SPSBSalaryViewController.h"
- #import "SPSBPurchaseOrderListModel.h"
- #import "SPSBTransferOrderListModel.h"
- #import "UIViewController+SPSBDefault.h"
- @interface SPSBWholeOrderListViewController () {
- NSMutableArray *_purchaseData;
- NSMutableArray *_transferData;
- JXHFixHeaderViewController *_contentVC;
- NSArray<SPSBOrderListTableViewController *> *_tableViews;
- }
- @end
- @implementation SPSBWholeOrderListViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self setupUI];
- [self getData];
- }
- #pragma mark - Action
- - (void)rightButtonAction {
- SPSBRouter *router = [[SPSBRouter alloc] initWithClassName:NSStringFromClass([SPSBSalaryViewController class]) property:nil tabBarType:SPSBTabBarTypeMine];
- [SPSBRouteManager navigationBackAndRouteTo:router];
- }
- - (void)removeOrder:(NSString *)order tableView:(SPSBOrderListTableViewController *)tableVC {
- NSArray *array = tableVC.spsb_data;
- for (NSInteger i = 0; i < array.count; i ++) {
- SPSBOrderListModel *m = array[i];
- if ([m.spsba_identifer isEqualToString:order]) {
- [tableVC cancelOrderSuccessWithIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
- return;
- }
- }
- }
- #pragma mark - Network Action
- - (void)getData {
- @weakify(self)
- [self networkUseMethod:SPSBNetworkMethodPOST loadingTips:@"正在加载" isLogin:true url:spsb_appUrl(SPSBUrlGetAllOrderList) urlParameters:nil parameters:nil success:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
- @strongify(self)
- [self getPurchaseListSuccess:data];
- return nil;
- } failure:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
- @strongify(self)
- [self getDataDidFail:error];
- return @"加载失败";
- }];
-
- [self networkUseMethod:SPSBNetworkMethodPOST loadingTips:nil isLogin:true url:spsb_appUrl(SPSBUrlGetTransferOrderList) urlParameters:nil parameters:^NSDictionary * _Nonnull{
- return @{@"all" : @"1"};
- } success:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
- @strongify(self)
- [self getTransferListSuccess:data];
- return nil;
- } failure:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
- @strongify(self)
- [self getDataDidFail:error];
- return @"加载失败";
- }];
- }
- - (void)getPurchaseListSuccess:(id)data {
- _purchaseData = [[SPSBPurchaseOrderListModel getModelListWithArray:data[@"data"]] mutableCopy];
- if (_transferData) {
- [self finishGetData];
- }
- }
- - (void)getTransferListSuccess:(id)data {
- _transferData = [[SPSBTransferOrderListModel getModelListWithArray:data[@"data"]] mutableCopy];
- if (_purchaseData) {
- [self finishGetData];
- }
- }
- - (void)finishGetData {
- [self removeDefaultView];
- _contentVC.view.hidden = false;
- NSArray *data = [self changeData];
- _purchaseData = nil;
- _transferData = nil;
- for (NSInteger i = 0; i < 3; i ++) {
- _tableViews[i].spsb_data = data[i];
- }
- [self.view dismissToast];
- }
- - (NSArray *)changeData {
- NSArray *longArray;
- NSArray *shortArray;
- if (_purchaseData.count > _transferData.count) {
- longArray = _purchaseData;
- shortArray = _transferData;
- } else {
- longArray = _transferData;
- shortArray = _purchaseData;
- }
- NSMutableArray *array = [NSMutableArray arrayWithArray:longArray];
- NSInteger index = 0;
- SPSBOrderListModel *shortModel;
- for (NSInteger i = 0; i < array.count; i ++) {
- if (!shortModel && shortArray.count > index) {
- shortModel = shortArray[index];
- }
- if (!shortModel) {
- break;
- }
- SPSBOrderListModel *longModel = array[i];
- if (shortModel.spsba_time > longModel.spsba_time) {
- [array insertObject:shortModel atIndex:i];
- i --;
- index ++;
- shortModel = nil;
- }
- }
- if (shortArray.count > index) {
- [array addObjectsFromArray:[shortArray subarrayWithRange:NSMakeRange(index, shortArray.count - index)]];
- }
- NSMutableArray *waitForPayArray = [@[] mutableCopy];
- NSMutableArray *finishArray = [@[] mutableCopy];
- for (SPSBOrderListModel *mode in array) {
- if (mode.spsba_status.integerValue == 1) {
- [waitForPayArray addObject:mode];
- } else {
- [finishArray addObject:mode];
- }
- }
- return @[array, waitForPayArray, finishArray];
- }
- - (void)getDataDidFail:(NSError *)error {
- _purchaseData = nil;
- _transferData = nil;
- _contentVC.view.hidden = true;
- @weakify(self)
- [self setDefaultViewWithError:error image:nil action:^{
- @strongify(self)
- [self getData];
- }];
-
- }
- #pragma mark - UI
- - (void)setupUI {
- self.title = @"全部订单";
- [self createRightButton];
- [self createContentView];
- [self addClassifyView];
- [self createLists];
- [_contentVC.jxh_bgScrollView.panGestureRecognizer requireGestureRecognizerToFail:self.navigationController.interactivePopGestureRecognizer];
- }
- - (void)createRightButton {
- UIButton *rightButton = [UIButton convenienceWithFont:spsb_font(15) target:self action:@selector(rightButtonAction)];
- [rightButton setTitle:@"社保流水" titleColor:spsb_3296FB_color() state:JXHButtonControlStateNormal];
- [rightButton sizeToFit];
- UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
- self.navigationItem.rightBarButtonItem = item;
- }
- - (void)createLists {
- NSMutableArray *arr = NSMutableArray.new;
- for (NSInteger i = 0; i < 3; i ++) {
- SPSBOrderListTableViewController *list = SPSBOrderListTableViewController.new;
- [arr addObject:list];
- }
- _tableViews = arr;
- @weakify(self)
- _tableViews[0].spsb_canceledOrder = ^(NSString * _Nonnull orderNum) {
- @strongify(self)
- [self removeOrder:orderNum tableView:self->_tableViews[1]];
- };
- _tableViews[1].spsb_canceledOrder = ^(NSString * _Nonnull orderNum) {
- @strongify(self)
- [self removeOrder:orderNum tableView:self->_tableViews[0]];
- };
- [_contentVC setListViews:_tableViews];
- }
- - (void)addClassifyView {
- JXHClassifyViewConfiguration *configuration = ({
- JXHClassifyViewConfiguration *configuration = JXHClassifyViewConfiguration.new;
- configuration.jxh_titleArray = @[@"全部", @"待付款", @"已完成"];
- configuration.jxh_height = 50;
- configuration.jxh_font = spsb_font(16);
- configuration.jxh_normalColor = spsb_666666_color();
- configuration.jxh_selectedColor = spsb_3296FB_color();
- configuration.jxh_margen = 0.f;
- configuration.jxh_interval = 0.f;
- configuration.jxh_selectedViewSize = (CGSize){60, 2.5};
- configuration.jxh_selectedViewColor = spsb_3296FB_color();
- configuration.jxh_equalWidth = jxh_screenWidth() / 3;
- configuration.jxh_isNeedSelectedView = true;
- configuration;
- });
-
- [_contentVC setExteriorClassifyViewWithConfiguration:configuration];
- [self.view addSubview:_contentVC.jxh_classifyView];
- [_contentVC.jxh_classifyView makeConstraints:^(JXHConstraintMaker *make) {
- make.top.equalTo(self.view.safetop);
- make.leading.and.trailing.equalTo(0);
- make.height.equalTo(configuration.jxh_height);
- }];
- }
- - (void)createContentView {
- _contentVC = JXHFixHeaderViewController.new;
- [self addChildViewController:_contentVC];
- [self.view addSubview:_contentVC.view];
- [_contentVC.view makeConstraints:^(JXHConstraintMaker *make) {
- make.top.equalTo(self.view.safetop).offset(50);
- make.leading.and.trailing.and.bottom.equalTo(0);;
- }];
- JXHFixHeaderViewHeaderController *header = JXHFixHeaderViewHeaderController.new;
- [_contentVC setHeader:header];
- }
- @end
|