SPSBQueryListTableViewController.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. //
  2. // SPSBQueryListTableViewController.m
  3. // 我的社保
  4. //
  5. // Created by shanp on 2021/5/27.
  6. //
  7. #import "SPSBQueryListTableViewController.h"
  8. #import "SPSBUIGeneralHeader.h"
  9. #import "SPSBQueryListModel.h"
  10. #import "SPSBRefreshHeader.h"
  11. #import "UIViewController+SPSBNetworkManager.h"
  12. #import "UITableView+SPSBDefault.h"
  13. #import "SPSBPurchasersModel.h"
  14. #import "SPSBQueryListDetailsViewController.h"
  15. @interface SPSBQueryListTableViewController () {
  16. NSArray *_dataArray;
  17. NSMutableDictionary *_shebaoDic;
  18. NSMutableDictionary *_fundDic;
  19. bool _isManualRefresh;
  20. UIView *_headerView;
  21. }
  22. @end
  23. @implementation SPSBQueryListTableViewController
  24. - (instancetype)init {
  25. self = [super initWithStyle:UITableViewStyleGrouped backgroundColor:SPSBTableViewBackgroundColorWhite];
  26. if (!self) return nil;
  27. return self;
  28. }
  29. - (void)viewDidLoad {
  30. [super viewDidLoad];
  31. [self initData];
  32. [self setupTableView];
  33. }
  34. - (void)initData {
  35. _shebaoDic = NSMutableDictionary.new;
  36. _fundDic = NSMutableDictionary.new;
  37. }
  38. #pragma mark - Action
  39. - (NSDictionary *)getOredrStatusData {
  40. return @{@"2" : @[@"已付款", spsb_FF801A_color()],
  41. @"3" : @[@"申报中", spsb_FF801A_color()],
  42. @"4" : @[_spsb_businessType == SPSBSocialInsurancePurchase ? @"已参保" : @"已缴存", spsb_333333_color()],
  43. @"5" : @[_spsb_businessType == SPSBSocialInsurancePurchase ? @"参保失败" : @"缴费失败", spsb_333333_color()],
  44. @"11" : @[@"已退款", spsb_333333_color()],
  45. @"15" : @[@"退款中", spsb_FF5E5E_color()]};
  46. }
  47. - (void)refreshAllData {
  48. [self.spsb_networkManager cancelAll];
  49. [self.tableView.mj_header endRefreshing];
  50. [self.view dismissToast];
  51. _shebaoDic = NSMutableDictionary.new;
  52. _fundDic = NSMutableDictionary.new;
  53. [self getData];
  54. }
  55. - (void)reloadData {
  56. [self.spsb_networkManager cancelAll];
  57. [self.tableView.mj_header endRefreshing];
  58. [self.view dismissToast];
  59. if (!(_spsb_businessType == SPSBSocialInsurancePurchase ? _shebaoDic[_spsb_choseYear] : _fundDic[_spsb_choseYear])) {
  60. [self getData];
  61. } else {
  62. [self.tableView removeDefaultFootView];
  63. _dataArray = _spsb_businessType == SPSBSocialInsurancePurchase ? _shebaoDic[_spsb_choseYear][0] : _fundDic[_spsb_choseYear][0];
  64. [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:true];
  65. [self.tableView reloadData];
  66. }
  67. }
  68. - (void)getData {
  69. _spsb_businessType == SPSBSocialInsurancePurchase ? [self querySocialInsuranceWithYear:_spsb_choseYear] : [self queryAccumulationFundWithYear:_spsb_choseYear];
  70. }
  71. #pragma mark - Network Action
  72. - (void)querySocialInsuranceWithYear:(NSString *)year {
  73. @weakify(self)
  74. [self networkUseMethod:SPSBNetworkMethodPOST loadingTips:_isManualRefresh ? nil : @"正在查询" isLogin:true url:spsb_appUrl(SPSBUrlQueryShebao) urlParameters:nil parameters:^NSDictionary * _Nonnull{
  75. return @{@"year" : year, @"sbuId" : self->_spsb_purchasers.spsb_id};
  76. } success:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
  77. @strongify(self)
  78. [self querySocialInsuranceNetworkGetData:data year:year];
  79. return @"";
  80. } failure:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
  81. [self queryNetworkGetDataDidFail:error];
  82. return @"查询失败";
  83. }];
  84. }
  85. - (void)querySocialInsuranceNetworkGetData:(id)data year:(NSString *)year {
  86. _isManualRefresh = false;
  87. NSArray *dataArray = [SPSBQueryListModel getModelListWithArray:data[@"data"][@"list"]];
  88. dataArray = [SPSBQueryListModel getShowDataWithList:dataArray];
  89. [_shebaoDic setObject:dataArray forKey:year];
  90. _dataArray = dataArray[0];
  91. [self.tableView reloadData];
  92. if (self.tableView.contentOffset.y > 0) {
  93. [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:true];
  94. }
  95. [self.tableView removeDefaultFootView];
  96. [self.tableView.mj_header endRefreshing];
  97. }
  98. - (void)queryAccumulationFundWithYear:(NSString *)year {
  99. @weakify(self)
  100. [self networkUseMethod:SPSBNetworkMethodPOST loadingTips:_isManualRefresh ? nil : @"正在查询" isLogin:true url:spsb_appUrl(SPSBUrlQueryFund) urlParameters:nil parameters:^NSDictionary * _Nonnull{
  101. return @{@"year" : year, @"sbuId" : self->_spsb_purchasers.spsb_id};
  102. } success:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
  103. @strongify(self)
  104. [self queryAccumulationFundNetworkGetData:data year:year];
  105. return @"";
  106. } failure:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
  107. [self queryNetworkGetDataDidFail:error];
  108. return @"查询失败";
  109. }];
  110. }
  111. - (void)queryAccumulationFundNetworkGetData:(id)data year:(NSString *)year {
  112. _isManualRefresh = false;
  113. NSArray *dataArray = [SPSBQueryListModel getModelListWithArray:data[@"data"][@"list"]];
  114. dataArray = [SPSBQueryListModel getShowDataWithList:dataArray];
  115. [_fundDic setObject:dataArray forKey:year];
  116. _dataArray = dataArray[0];
  117. [self.tableView reloadData];
  118. if (self.tableView.contentOffset.y > 0) {
  119. [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:true];
  120. }
  121. [self.tableView removeDefaultFootView];
  122. [self.tableView.mj_header endRefreshing];
  123. }
  124. - (void)queryNetworkGetDataDidFail:(NSError *)error {
  125. _isManualRefresh = false;
  126. _dataArray = @[];
  127. [self.tableView reloadData];
  128. @weakify(self)
  129. [self.tableView setDefaultFootViewWithError:error image:nil height:jxh_viewHeight(self.tableView) - 20 - 45 action:^{
  130. @strongify(self)
  131. self->_isManualRefresh = true;
  132. [self getData];
  133. }];
  134. [self.tableView.mj_header endRefreshing];
  135. }
  136. #pragma mark - Delegate & DataSource
  137. static NSString * const reuseIdentifier = @"SPSBQueryListTableViewCell";
  138. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  139. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
  140. if (!cell) {
  141. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
  142. UILabel *monthLabel = [UILabel convenienceWithFont:spsb_font(14) text:@"" textColor:spsb_333333_color()];
  143. monthLabel.tag = 3000;
  144. [cell.contentView addSubview:monthLabel];
  145. [monthLabel makeConstraints:^(JXHConstraintMaker *make) {
  146. make.leading.equalTo(15);
  147. make.centerY.equalTo(0);
  148. }];
  149. UILabel *cityLabel = [UILabel convenienceWithFont:spsb_font(14) text:@"" textColor:spsb_333333_color()];
  150. cityLabel.tag = 3001;
  151. [cell.contentView addSubview:cityLabel];
  152. [cityLabel makeConstraints:^(JXHConstraintMaker *make) {
  153. make.leading.equalTo(95);
  154. make.centerY.equalTo(0);
  155. }];
  156. UILabel *statusLabel = [UILabel convenienceWithFont:spsb_font(14) text:@"" textColor:spsb_999999_color()];
  157. statusLabel.tag = 3002;
  158. [cell.contentView addSubview:statusLabel];
  159. [statusLabel makeConstraints:^(JXHConstraintMaker *make) {
  160. make.leading.equalTo(jxh_screenWidth() - 120);
  161. make.centerY.equalTo(0);
  162. }];
  163. UIImageView *arrow = [[UIImageView alloc] initWithImage:jxh_getImage(list_arrow)];
  164. arrow.tag = 3003;
  165. [cell.contentView addSubview:arrow];
  166. [arrow makeConstraints:^(JXHConstraintMaker *make) {
  167. make.trailing.equalTo(-15);
  168. make.centerY.equalTo(0);
  169. }];
  170. UIView *line = [cell.contentView createLineWithLocation:JXHLineLocationBottom headOffset:15 footOffset:0];
  171. line.tag = 3004;
  172. }
  173. UILabel *monthLabel = [cell.contentView viewWithTag:3000];
  174. UILabel *stateLabel = [cell.contentView viewWithTag:3002];
  175. UILabel *cityLabel = [cell.contentView viewWithTag:3001];
  176. UIImageView *arrow = [cell.contentView viewWithTag:3003];
  177. UIView *line = [cell.contentView viewWithTag:3004];
  178. line.hidden = indexPath.row == 11;
  179. monthLabel.text = [NSString stringWithFormat:@"%ld月", (long)indexPath.row + 1];
  180. if (_dataArray.count > indexPath.row) {
  181. if ([_dataArray[indexPath.row] isKindOfClass:[SPSBQueryListModel class]]) {
  182. arrow.hidden = false;
  183. SPSBQueryListModel *queryModel = _dataArray[indexPath.row];
  184. cityLabel.text = queryModel.spsb_city;
  185. NSDictionary *contentDic = [self getOredrStatusData];
  186. if ([contentDic.allKeys containsObject:queryModel.spsb_pay_status] && [queryModel.spsb_pay_status integerValue] != 0) {
  187. stateLabel.text = contentDic[queryModel.spsb_pay_status][0];
  188. stateLabel.textColor = contentDic[queryModel.spsb_pay_status][1];
  189. return cell;
  190. }
  191. }
  192. }
  193. arrow.hidden = true;
  194. cityLabel.text = @"--";
  195. stateLabel.text = @"未购买";
  196. stateLabel.textColor = spsb_999999_color();
  197. return cell;
  198. }
  199. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  200. return _dataArray.count;
  201. }
  202. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  203. [tableView deselectRowAtIndexPath:indexPath animated:false];
  204. NSDictionary *data;
  205. if (_spsb_businessType == SPSBSocialInsurancePurchase) {
  206. data = _shebaoDic[_spsb_choseYear][1];
  207. } else {
  208. data = _fundDic[_spsb_choseYear][1];
  209. }
  210. if (data[@(indexPath.row)]) {
  211. SPSBQueryListDetailsViewController *vc = SPSBQueryListDetailsViewController.new;
  212. vc.spsb_data = data[@(indexPath.row)];
  213. vc.spsb_purchasers = _spsb_purchasers;
  214. vc.spsb_businessType = _spsb_businessType;
  215. [self.navigationController pushViewController:vc animated:true];
  216. }
  217. }
  218. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  219. return 20;
  220. }
  221. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  222. return UIView.new;
  223. }
  224. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  225. return 45;
  226. }
  227. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  228. if (!_headerView) {
  229. _headerView = [self createHeaderView];
  230. }
  231. return _headerView;
  232. }
  233. #pragma mark - UI
  234. - (void)setupTableView {
  235. self.tableView.rowHeight = 50.f;
  236. @weakify(self)
  237. self.tableView.mj_header = [SPSBRefreshHeader headerWithRefreshingBlock:^{
  238. @strongify(self)
  239. self->_isManualRefresh = true;
  240. self->_shebaoDic = NSMutableDictionary.new;
  241. self->_fundDic = NSMutableDictionary.new;
  242. [self getData];
  243. }];
  244. }
  245. - (UIView *)createHeaderView {
  246. UIView *headerView = [[UIView alloc] initWithFrame:(CGRect){0, 0, jxh_screenWidth(), 45}];
  247. headerView.backgroundColor = spsb_FAFAFA_color();
  248. UILabel *monthLabel = [UILabel convenienceWithFont:spsb_font(14) text:@"月份" textColor:spsb_808080_color()];
  249. [headerView addSubview:monthLabel];
  250. [monthLabel makeConstraints:^(JXHConstraintMaker *make) {
  251. make.leading.equalTo(15);
  252. make.centerY.equalTo(0);
  253. }];
  254. UILabel *cityLabel = [UILabel convenienceWithFont:spsb_font(14) text:@"城市" textColor:spsb_808080_color()];
  255. [headerView addSubview:cityLabel];
  256. [cityLabel makeConstraints:^(JXHConstraintMaker *make) {
  257. make.leading.equalTo(95);
  258. make.centerY.equalTo(0);
  259. }];
  260. UILabel *statusLabel = [UILabel convenienceWithFont:spsb_font(14) text:@"状态" textColor:spsb_808080_color()];
  261. [headerView addSubview:statusLabel];
  262. [statusLabel makeConstraints:^(JXHConstraintMaker *make) {
  263. make.leading.equalTo(jxh_screenWidth() - 120);
  264. make.centerY.equalTo(0);
  265. }];
  266. return headerView;
  267. }
  268. @end