SPSBWaitToDoViewController.m 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. //
  2. // SPSBWaitToDoViewController.m
  3. // 我的社保
  4. //
  5. // Created by shanp on 2021/6/22.
  6. //
  7. #import "SPSBWaitToDoViewController.h"
  8. #import "SPSBUIGeneralHeader.h"
  9. #import "UIViewController+SPSBNetworkManager.h"
  10. #import "SPSBRefreshHeader.h"
  11. #import "UIViewController+SPSBLoadDataStatus.h"
  12. #import "SPSBWaitToDoModel.h"
  13. #import "UITableView+SPSBDefault.h"
  14. #import "SPSBWaitToDoDetailsViewController.h"
  15. @interface SPSBWaitToDoTableViewCell : UITableViewCell {
  16. UILabel *_titleLabel;
  17. UILabel *_timeLabel;
  18. UILabel *_cityLabel;
  19. UILabel *_statusLabel;
  20. UIView *_tipsView;
  21. }
  22. @end
  23. @implementation SPSBWaitToDoTableViewCell
  24. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  25. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  26. if (!self) return nil;
  27. self.contentView.backgroundColor = spsb_F5F5F5_color();
  28. UIView *bgView = UIView.new;
  29. bgView.backgroundColor = spsb_FFFFFF_color(1.f);
  30. [self.contentView addSubview:bgView];
  31. [bgView makeConstraints:^(JXHConstraintMaker *make) {
  32. make.top.and.leading.and.trailing.equalTo(0);
  33. make.height.equalTo(90);
  34. }];
  35. _titleLabel = [UILabel convenienceWithFont:spsb_font(17) text:nil textColor:spsb_333333_color()];
  36. [bgView addSubview:_titleLabel];
  37. [_titleLabel makeConstraints:^(JXHConstraintMaker *make) {
  38. make.leading.equalTo(15);
  39. make.top.equalTo(20);
  40. }];
  41. _timeLabel = [UILabel convenienceWithFont:spsb_font(14) text:nil textColor:spsb_999999_color()];
  42. [bgView addSubview:_timeLabel];
  43. [_timeLabel makeConstraints:^(JXHConstraintMaker *make) {
  44. make.leading.equalTo(15);
  45. make.bottom.equalTo(-20);
  46. }];
  47. _cityLabel = [UILabel convenienceWithFont:spsb_font(17) text:nil textColor:spsb_333333_color() textAlignment:NSTextAlignmentRight];
  48. [bgView addSubview:_cityLabel];
  49. [_cityLabel makeConstraints:^(JXHConstraintMaker *make) {
  50. make.trailing.equalTo(-33);
  51. make.centerY.equalTo(self->_titleLabel.centerY);
  52. make.leading.greaterThanOrEqualTo(self->_titleLabel.trailing).offset(10);
  53. }];
  54. [_cityLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
  55. _statusLabel = [UILabel convenienceWithFont:spsb_font(14) text:nil textColor:spsb_FF801A_color() textAlignment:NSTextAlignmentRight];
  56. [bgView addSubview:_statusLabel];
  57. [_statusLabel makeConstraints:^(JXHConstraintMaker *make) {
  58. make.trailing.equalTo(-33);
  59. make.centerY.equalTo(self->_timeLabel.centerY);
  60. }];
  61. _tipsView = UIView.new;
  62. _tipsView.backgroundColor = spsb_FF5E5E_color();
  63. [_tipsView setLayerCornerRadius:4 clipToBounds:false];
  64. [bgView addSubview:_tipsView];
  65. [_tipsView makeConstraints:^(JXHConstraintMaker *make) {
  66. make.trailing.equalTo(self->_cityLabel.leading).offset(-6);
  67. make.centerY.equalTo(self->_titleLabel.centerY);
  68. make.size.equalTo(CGSizeMake(8, 8));
  69. }];
  70. UIImageView *arrow = [[UIImageView alloc] initWithImage:jxh_getImage(list_arrow)];
  71. [bgView addSubview:arrow];
  72. [arrow makeConstraints:^(JXHConstraintMaker *make) {
  73. make.trailing.equalTo(-15);
  74. make.centerY.equalTo(self->_titleLabel.centerY);
  75. }];
  76. return self;
  77. }
  78. - (void)reloadData:(SPSBWaitToDoModel *)data {
  79. _titleLabel.text = data.spsb_source_name;
  80. _timeLabel.text = data.spsb_create_time;
  81. _cityLabel.text = data.spsb_city_name;
  82. switch ([data.spsb_flow_status integerValue]) {
  83. case 1: {
  84. _statusLabel.text = @"处理中";
  85. _statusLabel.textColor = spsb_FF801A_color();
  86. }
  87. break;
  88. case 2: {
  89. _statusLabel.text = @"已完成";
  90. _statusLabel.textColor = spsb_999999_color();
  91. }
  92. break;
  93. default: {
  94. _statusLabel.text = @"已关闭";
  95. _statusLabel.textColor = spsb_999999_color();
  96. }
  97. break;
  98. }
  99. _tipsView.hidden = [data.spsb_todo_flag integerValue] == 1 ? false : true;
  100. }
  101. @end
  102. @interface SPSBWaitToDoViewController () {
  103. NSArray<SPSBWaitToDoModel *> *_dataArray;
  104. bool _firstLoad;
  105. }
  106. @end
  107. @implementation SPSBWaitToDoViewController
  108. - (instancetype)init {
  109. self = [super initWithStyle:UITableViewStylePlain backgroundColor:SPSBTableViewBackgroundColorGray];
  110. if (!self) return nil;
  111. return self;
  112. }
  113. - (void)viewDidLoad {
  114. [super viewDidLoad];
  115. [self setupUI];
  116. _firstLoad = true;
  117. }
  118. - (void)viewWillAppear:(BOOL)animated {
  119. [super viewWillAppear:animated];
  120. if (_firstLoad) {
  121. _firstLoad = false;
  122. [self getDataWithTips:true];
  123. } else {
  124. [self getDataWithTips:false];
  125. }
  126. }
  127. #pragma mark - Action
  128. #pragma mark - Network Action
  129. - (void)getDataWithTips:(bool)tips {
  130. @weakify(self)
  131. [self networkUseMethod:SPSBNetworkMethodPOST loadingTips:tips ? @"正在加载": nil isLogin:true url:spsb_appUrl(SPSBUrlGetMaterialflowList) urlParameters:nil parameters:nil success:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
  132. @strongify(self)
  133. [self getDataSuccess:data];
  134. return @"";
  135. } failure:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
  136. @strongify(self)
  137. [self getdataFailure:error];
  138. return @"加载失败";
  139. }];
  140. }
  141. - (void)getDataSuccess:(id)data {
  142. _dataArray = [SPSBWaitToDoModel getModelListWithArray:data[@"data"]];
  143. [self.tableView reloadData];
  144. if (_dataArray.count == 0) {
  145. self.tableView.backgroundColor = spsb_FFFFFF_color(1.f);
  146. [self.tableView setDefaultFootViewWithError:nil image:jxh_getImage(todo_qs) height:jxh_viewHeight(self.tableView) action:^{
  147. }];
  148. } else {
  149. self.tableView.backgroundColor = spsb_F5F5F5_color();
  150. [self.tableView removeDefaultFootView];
  151. }
  152. [self.tableView.mj_header endRefreshing];
  153. }
  154. - (void)getdataFailure:(NSError *)error {
  155. _dataArray = @[];
  156. [self.tableView reloadData];
  157. @weakify(self)
  158. self.tableView.backgroundColor = spsb_FFFFFF_color(1.f);
  159. [self.tableView setDefaultFootViewWithError:error image:jxh_getImage(todo_qs) height:jxh_viewHeight(self.tableView) action:^{
  160. @strongify(self)
  161. self.tableView.backgroundColor = spsb_F5F5F5_color();
  162. [self getDataWithTips:true];
  163. }];
  164. [self.tableView.mj_header endRefreshing];
  165. }
  166. #pragma mark - Delegate & DataSource
  167. static NSString * const reuseIdentifier = @"SPSBWaitToDoTableViewCell";
  168. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  169. SPSBWaitToDoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
  170. if (!cell) {
  171. cell = [[SPSBWaitToDoTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
  172. }
  173. [cell reloadData:_dataArray[indexPath.row]];
  174. return cell;
  175. }
  176. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  177. return _dataArray.count;
  178. }
  179. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  180. [tableView deselectRowAtIndexPath:indexPath animated:false];
  181. SPSBWaitToDoDetailsViewController *vc = SPSBWaitToDoDetailsViewController.new;
  182. vc.spsb_data = _dataArray[indexPath.row];
  183. [self.navigationController pushViewController:vc animated:true];
  184. }
  185. #pragma mark - UI
  186. - (void)setupUI {
  187. self.title = @"待办事项";
  188. [self setupTableView];
  189. @weakify(self)
  190. self.tableView.mj_header = [SPSBRefreshHeader headerWithRefreshingBlock:^{
  191. @strongify(self)
  192. [self getDataWithTips:false];
  193. }];
  194. }
  195. - (void)setupTableView {
  196. self.tableView.rowHeight = 100.f;
  197. }
  198. @end