123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306 |
- //
- // SPSBQueryListTableViewController.m
- // 我的社保
- //
- // Created by shanp on 2021/5/27.
- //
- #import "SPSBQueryListTableViewController.h"
- #import "SPSBUIGeneralHeader.h"
- #import "SPSBQueryListModel.h"
- #import "SPSBRefreshHeader.h"
- #import "UIViewController+SPSBNetworkManager.h"
- #import "UITableView+SPSBDefault.h"
- #import "SPSBPurchasersModel.h"
- #import "SPSBQueryListDetailsViewController.h"
- @interface SPSBQueryListTableViewController () {
- NSArray *_dataArray;
- NSMutableDictionary *_shebaoDic;
- NSMutableDictionary *_fundDic;
- bool _isManualRefresh;
- UIView *_headerView;
- }
- @end
- @implementation SPSBQueryListTableViewController
- - (instancetype)init {
- self = [super initWithStyle:UITableViewStyleGrouped backgroundColor:SPSBTableViewBackgroundColorWhite];
- if (!self) return nil;
- return self;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self initData];
- [self setupTableView];
- }
- - (void)initData {
- _shebaoDic = NSMutableDictionary.new;
- _fundDic = NSMutableDictionary.new;
- }
- #pragma mark - Action
- - (NSDictionary *)getOredrStatusData {
- return @{@"2" : @[@"已付款", spsb_FF801A_color()],
- @"3" : @[@"申报中", spsb_FF801A_color()],
- @"4" : @[_spsb_businessType == SPSBSocialInsurancePurchase ? @"已参保" : @"已缴存", spsb_333333_color()],
- @"5" : @[_spsb_businessType == SPSBSocialInsurancePurchase ? @"参保失败" : @"缴费失败", spsb_333333_color()],
- @"11" : @[@"已退款", spsb_333333_color()],
- @"15" : @[@"退款中", spsb_FF5E5E_color()]};
- }
- - (void)refreshAllData {
- [self.spsb_networkManager cancelAll];
- [self.tableView.mj_header endRefreshing];
- [self.view dismissToast];
- _shebaoDic = NSMutableDictionary.new;
- _fundDic = NSMutableDictionary.new;
- [self getData];
- }
- - (void)reloadData {
- [self.spsb_networkManager cancelAll];
- [self.tableView.mj_header endRefreshing];
- [self.view dismissToast];
- if (!(_spsb_businessType == SPSBSocialInsurancePurchase ? _shebaoDic[_spsb_choseYear] : _fundDic[_spsb_choseYear])) {
- [self getData];
- } else {
- [self.tableView removeDefaultFootView];
- _dataArray = _spsb_businessType == SPSBSocialInsurancePurchase ? _shebaoDic[_spsb_choseYear][0] : _fundDic[_spsb_choseYear][0];
- [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:true];
- [self.tableView reloadData];
- }
- }
- - (void)getData {
- _spsb_businessType == SPSBSocialInsurancePurchase ? [self querySocialInsuranceWithYear:_spsb_choseYear] : [self queryAccumulationFundWithYear:_spsb_choseYear];
- }
- #pragma mark - Network Action
- - (void)querySocialInsuranceWithYear:(NSString *)year {
- @weakify(self)
- [self networkUseMethod:SPSBNetworkMethodPOST loadingTips:_isManualRefresh ? nil : @"正在查询" isLogin:true url:spsb_appUrl(SPSBUrlQueryShebao) urlParameters:nil parameters:^NSDictionary * _Nonnull{
- return @{@"year" : year, @"sbuId" : self->_spsb_purchasers.spsb_id};
- } success:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
- @strongify(self)
- [self querySocialInsuranceNetworkGetData:data year:year];
- return @"";
- } failure:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
- [self queryNetworkGetDataDidFail:error];
- return @"查询失败";
- }];
- }
- - (void)querySocialInsuranceNetworkGetData:(id)data year:(NSString *)year {
- _isManualRefresh = false;
- NSArray *dataArray = [SPSBQueryListModel getModelListWithArray:data[@"data"][@"list"]];
- dataArray = [SPSBQueryListModel getShowDataWithList:dataArray];
- [_shebaoDic setObject:dataArray forKey:year];
- _dataArray = dataArray[0];
- [self.tableView reloadData];
- if (self.tableView.contentOffset.y > 0) {
- [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:true];
- }
- [self.tableView removeDefaultFootView];
- [self.tableView.mj_header endRefreshing];
- }
- - (void)queryAccumulationFundWithYear:(NSString *)year {
- @weakify(self)
- [self networkUseMethod:SPSBNetworkMethodPOST loadingTips:_isManualRefresh ? nil : @"正在查询" isLogin:true url:spsb_appUrl(SPSBUrlQueryFund) urlParameters:nil parameters:^NSDictionary * _Nonnull{
- return @{@"year" : year, @"sbuId" : self->_spsb_purchasers.spsb_id};
- } success:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
- @strongify(self)
- [self queryAccumulationFundNetworkGetData:data year:year];
- return @"";
- } failure:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
- [self queryNetworkGetDataDidFail:error];
- return @"查询失败";
- }];
- }
- - (void)queryAccumulationFundNetworkGetData:(id)data year:(NSString *)year {
- _isManualRefresh = false;
- NSArray *dataArray = [SPSBQueryListModel getModelListWithArray:data[@"data"][@"list"]];
- dataArray = [SPSBQueryListModel getShowDataWithList:dataArray];
- [_fundDic setObject:dataArray forKey:year];
- _dataArray = dataArray[0];
- [self.tableView reloadData];
- if (self.tableView.contentOffset.y > 0) {
- [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:true];
- }
- [self.tableView removeDefaultFootView];
- [self.tableView.mj_header endRefreshing];
- }
- - (void)queryNetworkGetDataDidFail:(NSError *)error {
- _isManualRefresh = false;
- _dataArray = @[];
- [self.tableView reloadData];
- @weakify(self)
- [self.tableView setDefaultFootViewWithError:error image:nil height:jxh_viewHeight(self.tableView) - 20 - 45 action:^{
- @strongify(self)
- self->_isManualRefresh = true;
- [self getData];
- }];
- [self.tableView.mj_header endRefreshing];
- }
- #pragma mark - Delegate & DataSource
- static NSString * const reuseIdentifier = @"SPSBQueryListTableViewCell";
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
- if (!cell) {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
-
- UILabel *monthLabel = [UILabel convenienceWithFont:spsb_font(14) text:@"" textColor:spsb_333333_color()];
- monthLabel.tag = 3000;
- [cell.contentView addSubview:monthLabel];
- [monthLabel makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(15);
- make.centerY.equalTo(0);
- }];
-
- UILabel *cityLabel = [UILabel convenienceWithFont:spsb_font(14) text:@"" textColor:spsb_333333_color()];
- cityLabel.tag = 3001;
- [cell.contentView addSubview:cityLabel];
- [cityLabel makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(95);
- make.centerY.equalTo(0);
- }];
-
- UILabel *statusLabel = [UILabel convenienceWithFont:spsb_font(14) text:@"" textColor:spsb_999999_color()];
- statusLabel.tag = 3002;
- [cell.contentView addSubview:statusLabel];
- [statusLabel makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(jxh_screenWidth() - 120);
- make.centerY.equalTo(0);
- }];
-
- UIImageView *arrow = [[UIImageView alloc] initWithImage:jxh_getImage(list_arrow)];
- arrow.tag = 3003;
- [cell.contentView addSubview:arrow];
- [arrow makeConstraints:^(JXHConstraintMaker *make) {
- make.trailing.equalTo(-15);
- make.centerY.equalTo(0);
- }];
-
- UIView *line = [cell.contentView createLineWithLocation:JXHLineLocationBottom headOffset:15 footOffset:0];
- line.tag = 3004;
- }
- UILabel *monthLabel = [cell.contentView viewWithTag:3000];
- UILabel *stateLabel = [cell.contentView viewWithTag:3002];
- UILabel *cityLabel = [cell.contentView viewWithTag:3001];
- UIImageView *arrow = [cell.contentView viewWithTag:3003];
- UIView *line = [cell.contentView viewWithTag:3004];
- line.hidden = indexPath.row == 11;
- monthLabel.text = [NSString stringWithFormat:@"%ld月", (long)indexPath.row + 1];
- if (_dataArray.count > indexPath.row) {
- if ([_dataArray[indexPath.row] isKindOfClass:[SPSBQueryListModel class]]) {
- arrow.hidden = false;
- SPSBQueryListModel *queryModel = _dataArray[indexPath.row];
- cityLabel.text = queryModel.spsb_city;
- NSDictionary *contentDic = [self getOredrStatusData];
- if ([contentDic.allKeys containsObject:queryModel.spsb_pay_status] && [queryModel.spsb_pay_status integerValue] != 0) {
- stateLabel.text = contentDic[queryModel.spsb_pay_status][0];
- stateLabel.textColor = contentDic[queryModel.spsb_pay_status][1];
- return cell;
- }
- }
- }
- arrow.hidden = true;
- cityLabel.text = @"--";
- stateLabel.text = @"未购买";
- stateLabel.textColor = spsb_999999_color();
- return cell;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return _dataArray.count;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- [tableView deselectRowAtIndexPath:indexPath animated:false];
- NSDictionary *data;
- if (_spsb_businessType == SPSBSocialInsurancePurchase) {
- data = _shebaoDic[_spsb_choseYear][1];
- } else {
- data = _fundDic[_spsb_choseYear][1];
- }
- if (data[@(indexPath.row)]) {
- SPSBQueryListDetailsViewController *vc = SPSBQueryListDetailsViewController.new;
- vc.spsb_data = data[@(indexPath.row)];
- vc.spsb_purchasers = _spsb_purchasers;
- vc.spsb_businessType = _spsb_businessType;
- [self.navigationController pushViewController:vc animated:true];
- }
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
- return 20;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
- return UIView.new;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- return 45;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
- if (!_headerView) {
- _headerView = [self createHeaderView];
- }
- return _headerView;
- }
- #pragma mark - UI
- - (void)setupTableView {
- self.tableView.rowHeight = 50.f;
- @weakify(self)
- self.tableView.mj_header = [SPSBRefreshHeader headerWithRefreshingBlock:^{
- @strongify(self)
- self->_isManualRefresh = true;
- self->_shebaoDic = NSMutableDictionary.new;
- self->_fundDic = NSMutableDictionary.new;
- [self getData];
- }];
- }
- - (UIView *)createHeaderView {
- UIView *headerView = [[UIView alloc] initWithFrame:(CGRect){0, 0, jxh_screenWidth(), 45}];
- headerView.backgroundColor = spsb_FAFAFA_color();
-
- UILabel *monthLabel = [UILabel convenienceWithFont:spsb_font(14) text:@"月份" textColor:spsb_808080_color()];
- [headerView addSubview:monthLabel];
- [monthLabel makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(15);
- make.centerY.equalTo(0);
- }];
-
- UILabel *cityLabel = [UILabel convenienceWithFont:spsb_font(14) text:@"城市" textColor:spsb_808080_color()];
- [headerView addSubview:cityLabel];
- [cityLabel makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(95);
- make.centerY.equalTo(0);
- }];
-
- UILabel *statusLabel = [UILabel convenienceWithFont:spsb_font(14) text:@"状态" textColor:spsb_808080_color()];
- [headerView addSubview:statusLabel];
- [statusLabel makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(jxh_screenWidth() - 120);
- make.centerY.equalTo(0);
- }];
-
- return headerView;
- }
- @end
|