SPSBQueryListViewController.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. //
  2. // SPSBQueryListViewController.m
  3. // 我的社保
  4. //
  5. // Created by shanp on 2021/5/27.
  6. //
  7. #import "SPSBQueryListViewController.h"
  8. #import "SPSBUIGeneralHeader.h"
  9. #import "SPSBQueryListTableViewController.h"
  10. #import "SPSBPurchasersModel.h"
  11. #import "SPSBBusinessManager.h"
  12. #import "SPSBGeneralManager.h"
  13. #import <JXHClassifyView.h>
  14. #import "SPSBSQLProfile.h"
  15. #import "UIView+SPSBLoadingTipsView.h"
  16. #import "SPSBPurchasersListViewController.h"
  17. #import "SPSBNavigationController.h"
  18. #import "SPSBNotificationDelegateManager.h"
  19. #import "SPSBPurchaseSBDetailsViewController.h"
  20. #import "SPSBPurchaseGJJDetailsViewController.h"
  21. #import "SPSBMyPurchaseOrder.h"
  22. #define spsb_queryListHeaderButtonTag 3000
  23. #define spsb_queryListDefaultViewImageTag 3000
  24. #define spsb_queryListDefaultViewLabelTag 4000
  25. #define spsb_queryListDefaultViewButtonTag 5000
  26. @interface SPSBQueryListViewController ()<SPSBNotificationDelegate> {
  27. NSString *_choseYear;
  28. UIImageView *_choseIcon;
  29. UIImageView *_headerView;
  30. SPSBPurchaseBusinessType _businessType;
  31. SPSBPurchasersModel *_chosePurchasers;
  32. JXHClassifyView *_classifyView;
  33. JXHCenterButton *_choosePurchasersButton;
  34. SPSBQueryListTableViewController *_tableVC;
  35. UIView *_noCustomerView;
  36. bool _isFirstLoad;
  37. NSInteger _firstYear;
  38. }
  39. @end
  40. @implementation SPSBQueryListViewController
  41. - (void)viewDidLoad {
  42. [super viewDidLoad];
  43. [self initData];
  44. [self setupUI];
  45. spsb_setNotificationKey(SPSBPurchaseNotificationKey);
  46. }
  47. - (void)viewWillAppear:(BOOL)animated {
  48. [super viewWillAppear:animated];
  49. if (_noCustomerView && spsb_purchasersArray().count != 0) {
  50. [_noCustomerView removeFromSuperview];
  51. _noCustomerView = nil;
  52. _chosePurchasers = spsb_purchasersArray().lastObject;
  53. _tableVC.spsb_purchasers = _chosePurchasers;
  54. [_choosePurchasersButton setTitle:_chosePurchasers.spsb_user_name state:JXHButtonControlStateNormal];
  55. [self createContentView];
  56. }
  57. }
  58. - (void)viewDidAppear:(BOOL)animated {
  59. [super viewDidAppear:animated];
  60. if (_isFirstLoad) {
  61. _isFirstLoad = false;
  62. [self tableViewReloadData];
  63. }
  64. }
  65. - (void)dealloc {
  66. spsb_removeNotificationKey(SPSBPurchaseNotificationKey);
  67. }
  68. - (void)initData {
  69. _firstYear = spsb_firstYear();
  70. _choseYear = spsb_getNewDate().spsb_year;
  71. _businessType = _spsb_isQueryAccumulationFund ? SPSBAccumulationFundPurchase : SPSBSocialInsurancePurchase;
  72. }
  73. #pragma mark - Action
  74. - (void)changePurchasers {
  75. if (spsb_purchasersArray().count == 0) {
  76. [self.view showToastWithTitle:@"暂无参保人"];
  77. } else {
  78. SPSBPurchasersListViewController *vc = SPSBPurchasersListViewController.new;
  79. vc.spsb_type = SPSBPurchasersListTypeQuery;
  80. @weakify(self)
  81. vc.spsb_finishChose = ^(SPSBPurchasersModel * _Nonnull purchasers) {
  82. @strongify(self)
  83. [self chosePurchasers:purchasers];
  84. };
  85. SPSBNavigationController *nav = [[SPSBNavigationController alloc] initWithRootViewController:vc];
  86. [self presentViewController:nav animated:true completion:^{
  87. }];
  88. }
  89. }
  90. - (void)changeQuery:(JXHCenterButton *)sender {
  91. [_choseIcon remakeConstraints:^(JXHConstraintMaker *make) {
  92. make.bottom.equalTo(0);
  93. make.centerX.equalTo(sender);
  94. }];
  95. if (sender.tag == spsb_queryListHeaderButtonTag) {
  96. _businessType = SPSBSocialInsurancePurchase;
  97. } else {
  98. _businessType = SPSBAccumulationFundPurchase;
  99. }
  100. _tableVC.spsb_businessType = _businessType;
  101. if (_noCustomerView) {
  102. NSArray *data = [self getNoCustomerData];
  103. ((UIImageView *)[_noCustomerView viewWithTag:spsb_queryListDefaultViewImageTag]).image = data[0];
  104. ((UILabel *)[_noCustomerView viewWithTag:spsb_queryListDefaultViewLabelTag]).text = data[1];
  105. [((UIButton *)[_noCustomerView viewWithTag:spsb_queryListDefaultViewButtonTag]) setTitle:data[2] state:JXHButtonControlStateNormal];
  106. }
  107. if (_chosePurchasers) {
  108. [self tableViewReloadData];
  109. }
  110. }
  111. - (void)tableViewReloadData {
  112. [_classifyView scrollClassifyForIndex:_choseYear.integerValue - _firstYear];
  113. [_tableVC reloadData];
  114. }
  115. - (void)chosePurchasers:(SPSBPurchasersModel *)purchasers {
  116. _chosePurchasers = purchasers;
  117. _choseYear = spsb_getNewDate().spsb_year;
  118. _tableVC.spsb_choseYear = _choseYear;
  119. _tableVC.spsb_purchasers = _chosePurchasers;
  120. [_tableVC refreshAllData];
  121. [_choosePurchasersButton setTitle:_chosePurchasers.spsb_user_name state:JXHButtonControlStateNormal];
  122. [self tableViewReloadData];
  123. [JXHFMDBManager updateWithPath:SPSBShanpSocialInsuranceLocationSQL condition:^id(FMDatabase *database) {
  124. return @([database executeUpdate:@"delete from cache_data where key = ?", SPSBQueryPurchasersSQLKey]);
  125. }];
  126. [JXHFMDBManager updateWithPath:SPSBShanpSocialInsuranceLocationSQL condition:^id(FMDatabase *database) {
  127. return @([database executeUpdate:@"insert into cache_data (key, data) values (?, ?)", SPSBQueryPurchasersSQLKey, jxh_archiver(self->_chosePurchasers.spsb_id, SPSBQueryPurchasersSQLKey)]);
  128. }];
  129. }
  130. - (void)buyAction {
  131. spsb_setMyPurchaseOrder(SPSBMyPurchaseOrder.new);
  132. spsb_myPurchaseOrder().spsb_isSupplementaryPay = false;
  133. switch (_businessType) {
  134. case SPSBSocialInsurancePurchase: {
  135. [self.navigationController pushViewController:SPSBPurchaseSBDetailsViewController.new animated:true];
  136. }
  137. break;
  138. case SPSBAccumulationFundPurchase: {
  139. [self.navigationController pushViewController:SPSBPurchaseGJJDetailsViewController.new animated:true];
  140. }
  141. break;
  142. default:
  143. break;
  144. }
  145. }
  146. #pragma mark - Network Action
  147. #pragma mark - SPSBNotificationDelegate
  148. - (void)spsb_refundSuccuss {
  149. if (spsb_purchasersArray().count == 0) return;
  150. [_tableVC refreshAllData];
  151. [self.navigationController popToViewController:self animated:true];
  152. }
  153. #pragma mark - UI
  154. - (void)setupUI {
  155. self.title = @"查询";
  156. [self createRightButton];
  157. [self createHeaderView];
  158. [self createContentView];
  159. }
  160. - (void)createContentView {
  161. if (spsb_purchasersArray().count == 0) {
  162. [self createNoPurchasersTipsView];
  163. return;
  164. }
  165. [self createClassifyView];
  166. [self createTableView];
  167. _isFirstLoad = true;
  168. }
  169. - (void)createClassifyView {
  170. NSMutableArray *array = NSMutableArray.new;
  171. for (NSInteger i = _firstYear; i <= _choseYear.integerValue + 2; i ++)
  172. {
  173. [array addObject:[NSString stringWithFormat:@"%ld", (long)i]];
  174. }
  175. JXHClassifyViewConfiguration *configuration = ({
  176. JXHClassifyViewConfiguration *configuration = JXHClassifyViewConfiguration.new;
  177. configuration.jxh_titleArray = array;
  178. configuration.jxh_height = 50;
  179. configuration.jxh_font = spsb_font(15);
  180. configuration.jxh_normalColor = spsb_999999_color();
  181. configuration.jxh_selectedColor = spsb_3296FB_color();
  182. configuration.jxh_margen = 0.f;
  183. configuration.jxh_interval = 0.f;
  184. configuration.jxh_selectedViewSize = (CGSize){40, 2};
  185. configuration.jxh_selectedViewColor = spsb_3296FB_color();
  186. configuration.jxh_equalWidth = jxh_screenWidth() / 5;
  187. configuration.jxh_isNeedSelectedView = true;
  188. configuration;
  189. });
  190. @weakify(self)
  191. _classifyView = [[JXHClassifyView alloc] initWithConfiguration:configuration chooseAction:^(JXHClassifyView * _Nonnull classifyView, NSInteger index) {
  192. @strongify(self)
  193. self->_choseYear = [NSString stringWithFormat:@"%ld", (long)self->_firstYear + index];
  194. self->_tableVC.spsb_choseYear = self->_choseYear;
  195. [self tableViewReloadData];
  196. }];
  197. [self.view addSubview:_classifyView];
  198. [_classifyView makeConstraints:^(JXHConstraintMaker *make) {
  199. make.leading.and.trailing.equalTo(0);
  200. make.top.equalTo(self->_headerView.bottom);
  201. make.height.equalTo(configuration.jxh_height);
  202. }];
  203. }
  204. - (void)createTableView {
  205. _tableVC = SPSBQueryListTableViewController.new;
  206. _tableVC.spsb_businessType = _businessType;
  207. _tableVC.spsb_choseYear = _choseYear;
  208. _tableVC.spsb_purchasers = _chosePurchasers;
  209. [self addChildViewController:_tableVC];
  210. [self.view addSubview:_tableVC.tableView];
  211. [_tableVC.tableView makeConstraints:^(JXHConstraintMaker *make) {
  212. make.top.equalTo(self->_classifyView.bottom);
  213. make.leading.and.trailing.and.bottom.equalTo(0);
  214. }];
  215. }
  216. - (void)createNoPurchasersTipsView {
  217. _noCustomerView = UIView.new;
  218. NSArray *data = [self getNoCustomerData];
  219. UIImageView *imageView = [[UIImageView alloc] initWithImage:data[0]];
  220. imageView.tag = spsb_queryListDefaultViewImageTag;
  221. [_noCustomerView addSubview:imageView];
  222. UILabel *label = [UILabel convenienceWithFont:spsb_font(14) text:data[1] textColor:spsb_9197A3_color() textAlignment:NSTextAlignmentCenter];
  223. label.tag = spsb_queryListDefaultViewLabelTag;
  224. [_noCustomerView addSubview:label];
  225. UIButton *button = [UIButton convenienceWithFont:spsb_font(15) target:self action:@selector(buyAction)];
  226. [button setTitle:data[2] titleColor:spsb_3296FB_color() state:JXHButtonControlStateNormal];
  227. button.tag = spsb_queryListDefaultViewButtonTag;
  228. [_noCustomerView addSubview:button];
  229. [imageView makeConstraints:^(JXHConstraintMaker *make) {
  230. make.top.leading.and.trailing.equalTo(0);
  231. }];
  232. [label makeConstraints:^(JXHConstraintMaker *make) {
  233. make.centerX.equalTo(imageView);
  234. make.top.equalTo(imageView.bottom).offset(3);
  235. }];
  236. [button makeConstraints:^(JXHConstraintMaker *make) {
  237. make.top.equalTo(label.bottom).offset(50);
  238. make.bottom.equalTo(0);
  239. make.centerX.equalTo(imageView);
  240. }];
  241. [self.view addSubview:_noCustomerView];
  242. [_noCustomerView makeConstraints:^(JXHConstraintMaker *make) {
  243. make.centerX.equalTo(self.view);
  244. make.centerY.equalTo(self.view).offset(55);
  245. }];
  246. }
  247. - (NSArray *)getNoCustomerData {
  248. if (_businessType == SPSBSocialInsurancePurchase) {
  249. return @[jxh_getImage(search_shebao_qs), @"暂无社保缴纳记录", @"立即参保"];
  250. }
  251. return @[jxh_getImage(search_gjj_qs), @"暂无公积金缴存记录", @"立即缴存"];
  252. }
  253. - (void)createHeaderView {
  254. _headerView = [[UIImageView alloc] initWithImage:jxh_getImage(search_bg)];
  255. _headerView.userInteractionEnabled = true;
  256. _headerView.backgroundColor = spsb_3296FB_color();
  257. [self.view addSubview:_headerView];
  258. [_headerView makeConstraints:^(JXHConstraintMaker *make) {
  259. make.top.equalTo(self.view.safetop);
  260. make.leading.and.trailing.equalTo(0);
  261. make.height.equalTo(jxh_screenWidth() * 0.29);
  262. }];
  263. NSArray *images = @[jxh_getImage(search_shebao), jxh_getImage(search_gjj)];
  264. NSArray *titles = @[@"社保查询", @"公积金查询"];
  265. JXHCenterButton *tempButton = nil;
  266. NSInteger chose = _spsb_isQueryAccumulationFund ? 1 : 0;
  267. for (NSInteger i = 0; i < images.count; i ++) {
  268. JXHCenterButton *button = [JXHCenterButton convenienceWithAxis:JXHCenterButtonAxisVertical interval:8 font:spsb_semiboldFont(14) target:self action:@selector(changeQuery:)];
  269. [button setTitle:titles[i] titleColor:spsb_FFFFFF_color(1.f) image:images[i] backgroundImage:nil state:JXHButtonControlStateNormal | JXHButtonControlStateHighlighted];
  270. button.tag = spsb_queryListHeaderButtonTag + i;
  271. [_headerView addSubview:button];
  272. [button makeConstraints:^(JXHConstraintMaker *make) {
  273. if (tempButton) {
  274. make.leading.equalTo(tempButton.trailing);
  275. } else {
  276. make.leading.equalTo(0);
  277. }
  278. make.top.and.bottom.equalTo(0);
  279. make.width.equalTo(jxh_screenWidth() / 2);
  280. }];
  281. tempButton = button;
  282. if (i == chose) {
  283. _choseIcon = [[UIImageView alloc] initWithImage:jxh_getImage(inquire_arrow)];
  284. [_headerView addSubview:_choseIcon];
  285. [_choseIcon makeConstraints:^(JXHConstraintMaker *make) {
  286. make.bottom.equalTo(0);
  287. make.centerX.equalTo(button);
  288. }];
  289. }
  290. }
  291. }
  292. - (void)createRightButton {
  293. _choosePurchasersButton = [JXHCenterButton convenienceWithAxis:JXHCenterButtonAxisHorizontal interval:6 font:spsb_font(15) target:self action:@selector(changePurchasers)];
  294. [_choosePurchasersButton.jxh_titleLabel makeConstraints:^(JXHConstraintMaker *make) {
  295. make.width.lessThanOrEqualTo(100);
  296. }];
  297. [_choosePurchasersButton setImage:jxh_getImage(arrow_down) state:JXHButtonControlStateNormal | JXHButtonControlStateHighlighted];
  298. [_choosePurchasersButton setTitleColor:spsb_3296FB_color() state:JXHButtonControlStateNormal | JXHButtonControlStateHighlighted];
  299. [_choosePurchasersButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
  300. _choosePurchasersButton.frame = CGRectMake(0, 0, 100, 44);
  301. if (_spsb_purchasers) {
  302. _chosePurchasers = _spsb_purchasers;
  303. [_choosePurchasersButton setTitle:_chosePurchasers.spsb_user_name state:JXHButtonControlStateNormal];
  304. } else {
  305. if (spsb_purchasersArray().count == 0) {
  306. [_choosePurchasersButton setTitle:@"请选择" state:JXHButtonControlStateNormal];
  307. } else {
  308. NSString *cacheId = [JXHFMDBManager searchWithPath:SPSBShanpSocialInsuranceLocationSQL key:SPSBQueryPurchasersSQLKey condition:^id(FMDatabase *database) {
  309. return [database executeQuery:@"select * from cache_data where key = ?", SPSBQueryPurchasersSQLKey];
  310. }];
  311. _chosePurchasers = nil;
  312. if (cacheId) {
  313. for (SPSBPurchasersModel *purchasers in spsb_purchasersArray()) {
  314. if ([purchasers.spsb_id isEqualToString:cacheId]) {
  315. _chosePurchasers = purchasers;
  316. break;
  317. }
  318. }
  319. }
  320. if (!_chosePurchasers) {
  321. _chosePurchasers = spsb_purchasersArray().lastObject;
  322. }
  323. [_choosePurchasersButton setTitle:_chosePurchasers.spsb_user_name state:JXHButtonControlStateNormal];
  324. }
  325. }
  326. UIBarButtonItem *selectItem = [[UIBarButtonItem alloc] initWithCustomView:_choosePurchasersButton];
  327. self.navigationItem.rightBarButtonItem = selectItem;
  328. }
  329. @end
  330. #undef spsb_queryListHeaderButtonTag
  331. #undef spsb_queryListDefaultViewImageTag
  332. #undef spsb_queryListDefaultViewLabelTag
  333. #undef spsb_queryListDefaultViewButtonTag