SPSBWholeOrderListViewController.m 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. //
  2. // SPSBWholeOrderListViewController.m
  3. // 我的社保
  4. //
  5. // Created by shanp on 2021/6/18.
  6. //
  7. #import "SPSBWholeOrderListViewController.h"
  8. #import "SPSBUIGeneralHeader.h"
  9. #import "SPSBOrderListTableViewController.h"
  10. #import "UIViewController+SPSBNetworkManager.h"
  11. #import <JXHFixHeaderViewController.h>
  12. #import <JXHFixHeaderViewHeaderController.h>
  13. #import <JXHClassifyView.h>
  14. #import "SPSBRouteManager.h"
  15. #import "SPSBSalaryViewController.h"
  16. #import "SPSBPurchaseOrderListModel.h"
  17. #import "SPSBTransferOrderListModel.h"
  18. #import "UIViewController+SPSBDefault.h"
  19. @interface SPSBWholeOrderListViewController () {
  20. NSMutableArray *_purchaseData;
  21. NSMutableArray *_transferData;
  22. JXHFixHeaderViewController *_contentVC;
  23. NSArray<SPSBOrderListTableViewController *> *_tableViews;
  24. }
  25. @end
  26. @implementation SPSBWholeOrderListViewController
  27. - (void)viewDidLoad {
  28. [super viewDidLoad];
  29. [self setupUI];
  30. [self getData];
  31. }
  32. #pragma mark - Action
  33. - (void)rightButtonAction {
  34. SPSBRouter *router = [[SPSBRouter alloc] initWithClassName:NSStringFromClass([SPSBSalaryViewController class]) property:nil tabBarType:SPSBTabBarTypeMine];
  35. [SPSBRouteManager navigationBackAndRouteTo:router];
  36. }
  37. - (void)removeOrder:(NSString *)order tableView:(SPSBOrderListTableViewController *)tableVC {
  38. NSArray *array = tableVC.spsb_data;
  39. for (NSInteger i = 0; i < array.count; i ++) {
  40. SPSBOrderListModel *m = array[i];
  41. if ([m.spsba_identifer isEqualToString:order]) {
  42. [tableVC cancelOrderSuccessWithIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
  43. return;
  44. }
  45. }
  46. }
  47. #pragma mark - Network Action
  48. - (void)getData {
  49. @weakify(self)
  50. [self networkUseMethod:SPSBNetworkMethodPOST loadingTips:@"正在加载" isLogin:true url:spsb_appUrl(SPSBUrlGetAllOrderList) urlParameters:nil parameters:nil success:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
  51. @strongify(self)
  52. [self getPurchaseListSuccess:data];
  53. return nil;
  54. } failure:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
  55. @strongify(self)
  56. [self getDataDidFail:error];
  57. return @"加载失败";
  58. }];
  59. [self networkUseMethod:SPSBNetworkMethodPOST loadingTips:nil isLogin:true url:spsb_appUrl(SPSBUrlGetTransferOrderList) urlParameters:nil parameters:^NSDictionary * _Nonnull{
  60. return @{@"all" : @"1"};
  61. } success:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
  62. @strongify(self)
  63. [self getTransferListSuccess:data];
  64. return nil;
  65. } failure:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
  66. @strongify(self)
  67. [self getDataDidFail:error];
  68. return @"加载失败";
  69. }];
  70. }
  71. - (void)getPurchaseListSuccess:(id)data {
  72. _purchaseData = [[SPSBPurchaseOrderListModel getModelListWithArray:data[@"data"]] mutableCopy];
  73. if (_transferData) {
  74. [self finishGetData];
  75. }
  76. }
  77. - (void)getTransferListSuccess:(id)data {
  78. _transferData = [[SPSBTransferOrderListModel getModelListWithArray:data[@"data"]] mutableCopy];
  79. if (_purchaseData) {
  80. [self finishGetData];
  81. }
  82. }
  83. - (void)finishGetData {
  84. [self removeDefaultView];
  85. _contentVC.view.hidden = false;
  86. NSArray *data = [self changeData];
  87. _purchaseData = nil;
  88. _transferData = nil;
  89. for (NSInteger i = 0; i < 3; i ++) {
  90. _tableViews[i].spsb_data = data[i];
  91. }
  92. [self.view dismissToast];
  93. }
  94. - (NSArray *)changeData {
  95. NSArray *longArray;
  96. NSArray *shortArray;
  97. if (_purchaseData.count > _transferData.count) {
  98. longArray = _purchaseData;
  99. shortArray = _transferData;
  100. } else {
  101. longArray = _transferData;
  102. shortArray = _purchaseData;
  103. }
  104. NSMutableArray *array = [NSMutableArray arrayWithArray:longArray];
  105. NSInteger index = 0;
  106. SPSBOrderListModel *shortModel;
  107. for (NSInteger i = 0; i < array.count; i ++) {
  108. if (!shortModel && shortArray.count > index) {
  109. shortModel = shortArray[index];
  110. }
  111. if (!shortModel) {
  112. break;
  113. }
  114. SPSBOrderListModel *longModel = array[i];
  115. if (shortModel.spsba_time > longModel.spsba_time) {
  116. [array insertObject:shortModel atIndex:i];
  117. i --;
  118. index ++;
  119. shortModel = nil;
  120. }
  121. }
  122. if (shortArray.count > index) {
  123. [array addObjectsFromArray:[shortArray subarrayWithRange:NSMakeRange(index, shortArray.count - index)]];
  124. }
  125. NSMutableArray *waitForPayArray = [@[] mutableCopy];
  126. NSMutableArray *finishArray = [@[] mutableCopy];
  127. for (SPSBOrderListModel *mode in array) {
  128. if (mode.spsba_status.integerValue == 1) {
  129. [waitForPayArray addObject:mode];
  130. } else {
  131. [finishArray addObject:mode];
  132. }
  133. }
  134. return @[array, waitForPayArray, finishArray];
  135. }
  136. - (void)getDataDidFail:(NSError *)error {
  137. _purchaseData = nil;
  138. _transferData = nil;
  139. _contentVC.view.hidden = true;
  140. @weakify(self)
  141. [self setDefaultViewWithError:error image:nil action:^{
  142. @strongify(self)
  143. [self getData];
  144. }];
  145. }
  146. #pragma mark - UI
  147. - (void)setupUI {
  148. self.title = @"全部订单";
  149. [self createRightButton];
  150. [self createContentView];
  151. [self addClassifyView];
  152. [self createLists];
  153. [_contentVC.jxh_bgScrollView.panGestureRecognizer requireGestureRecognizerToFail:self.navigationController.interactivePopGestureRecognizer];
  154. }
  155. - (void)createRightButton {
  156. UIButton *rightButton = [UIButton convenienceWithFont:spsb_font(15) target:self action:@selector(rightButtonAction)];
  157. [rightButton setTitle:@"社保流水" titleColor:spsb_3296FB_color() state:JXHButtonControlStateNormal];
  158. [rightButton sizeToFit];
  159. UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
  160. self.navigationItem.rightBarButtonItem = item;
  161. }
  162. - (void)createLists {
  163. NSMutableArray *arr = NSMutableArray.new;
  164. for (NSInteger i = 0; i < 3; i ++) {
  165. SPSBOrderListTableViewController *list = SPSBOrderListTableViewController.new;
  166. [arr addObject:list];
  167. }
  168. _tableViews = arr;
  169. @weakify(self)
  170. _tableViews[0].spsb_canceledOrder = ^(NSString * _Nonnull orderNum) {
  171. @strongify(self)
  172. [self removeOrder:orderNum tableView:self->_tableViews[1]];
  173. };
  174. _tableViews[1].spsb_canceledOrder = ^(NSString * _Nonnull orderNum) {
  175. @strongify(self)
  176. [self removeOrder:orderNum tableView:self->_tableViews[0]];
  177. };
  178. [_contentVC setListViews:_tableViews];
  179. }
  180. - (void)addClassifyView {
  181. JXHClassifyViewConfiguration *configuration = ({
  182. JXHClassifyViewConfiguration *configuration = JXHClassifyViewConfiguration.new;
  183. configuration.jxh_titleArray = @[@"全部", @"待付款", @"已完成"];
  184. configuration.jxh_height = 50;
  185. configuration.jxh_font = spsb_font(16);
  186. configuration.jxh_normalColor = spsb_666666_color();
  187. configuration.jxh_selectedColor = spsb_3296FB_color();
  188. configuration.jxh_margen = 0.f;
  189. configuration.jxh_interval = 0.f;
  190. configuration.jxh_selectedViewSize = (CGSize){60, 2.5};
  191. configuration.jxh_selectedViewColor = spsb_3296FB_color();
  192. configuration.jxh_equalWidth = jxh_screenWidth() / 3;
  193. configuration.jxh_isNeedSelectedView = true;
  194. configuration;
  195. });
  196. [_contentVC setExteriorClassifyViewWithConfiguration:configuration];
  197. [self.view addSubview:_contentVC.jxh_classifyView];
  198. [_contentVC.jxh_classifyView makeConstraints:^(JXHConstraintMaker *make) {
  199. make.top.equalTo(self.view.safetop);
  200. make.leading.and.trailing.equalTo(0);
  201. make.height.equalTo(configuration.jxh_height);
  202. }];
  203. }
  204. - (void)createContentView {
  205. _contentVC = JXHFixHeaderViewController.new;
  206. [self addChildViewController:_contentVC];
  207. [self.view addSubview:_contentVC.view];
  208. [_contentVC.view makeConstraints:^(JXHConstraintMaker *make) {
  209. make.top.equalTo(self.view.safetop).offset(50);
  210. make.leading.and.trailing.and.bottom.equalTo(0);;
  211. }];
  212. JXHFixHeaderViewHeaderController *header = JXHFixHeaderViewHeaderController.new;
  213. [_contentVC setHeader:header];
  214. }
  215. @end