説明なし

KXCreditCardViewController.m 9.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. //
  2. // KXCreditCardViewController.m
  3. // CAISHEN
  4. //
  5. // Created by xiaoxi on 2017/12/1.
  6. // Copyright © 2017年 kuxuan. All rights reserved.
  7. //
  8. #import "KXCreditCardViewController.h"
  9. #import "KXCreditCardTableViewCell.h"
  10. #import "KXCreditCardModel.h"
  11. #import "KXLittleLogginView.h"
  12. #import "KXBaseLinkViewController.h"
  13. #import "KXCreditCardModel.h"
  14. @interface KXCreditCardViewController () <UITableViewDelegate,UITableViewDataSource,KXLittleLogginViewDelegate>
  15. @property (nonatomic, strong) UITableView *tableView;
  16. @property (nonatomic, strong) NSMutableArray *dataSource;
  17. @property (nonatomic, assign) NSInteger index;
  18. @property (nonatomic, assign) NSInteger page;
  19. @end
  20. @implementation KXCreditCardViewController
  21. static NSString *const cellID = @"KXCreditCardTableViewCell";
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. // Do any additional setup after loading the view.
  25. self.name = @"信用卡";
  26. [self setupContentView];
  27. [MobClick event:@"CreditTab"];
  28. }
  29. - (void)setupContentView {
  30. self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-NavHeight-TabbarHeight) style:UITableViewStylePlain];
  31. self.tableView.backgroundColor = [UIColor whiteColor];
  32. self.tableView.delegate = self;
  33. self.tableView.dataSource = self;
  34. self.tableView.tableFooterView = [[UIView alloc] init];
  35. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  36. [self.tableView registerClass:[KXCreditCardTableViewCell class] forCellReuseIdentifier:cellID];
  37. self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  38. [self headerFresh];
  39. }];
  40. self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  41. [self footerFresh];
  42. }];
  43. [self.tableView emptyViewConfigerBlock:^(FOREmptyAssistantConfiger *configer) {
  44. configer.emptyTitle = @"没有数据";
  45. configer.emptyTitleFont = FONT_SYS(14*SCREEN_MUTI);
  46. configer.emptyTitleColor = [UIColor detailTitleColor];
  47. }];
  48. [self.view addSubview:self.tableView];
  49. [self.tableView.mj_header beginRefreshing];
  50. // self.page = 1;
  51. // [self requestDataWithPage:self.page];
  52. }
  53. - (void)updateCreditStateWithModel:(KXCreditCardModel *)model{
  54. }
  55. - (void)headerFresh {
  56. self.page = 1;
  57. [self requestDataWithPage:self.page];
  58. }
  59. - (void)footerFresh {
  60. self.page ++;
  61. [self requestDataWithPage:self.page];
  62. }
  63. - (void)requestDataWithPage:(NSInteger)page {
  64. NSString *urlString = [NSString stringWithFormat:@"%@/CreditCard/list",URL];
  65. [KXHTTP post:urlString params:@{@"pageId":@(page)} success:^(id json) {
  66. NSArray *array = [NSArray yy_modelArrayWithClass:[KXCreditCardModel class] json:json[@"list"]];
  67. if (self.page == 1) {
  68. [self.dataSource removeAllObjects];
  69. }
  70. if (array.count) {
  71. [self.dataSource addObjectsFromArray:array];
  72. }
  73. [self.tableView.mj_header endRefreshing];
  74. [self.tableView.mj_footer endRefreshing];
  75. [self.tableView reloadData];
  76. } failure:^(NSError *error) {
  77. }];
  78. }
  79. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  80. return 1;
  81. }
  82. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  83. return self.dataSource.count;
  84. }
  85. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  86. KXCreditCardTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
  87. KXCreditCardModel *model = self.dataSource[indexPath.row];
  88. [cell.iconView sd_setImageWithURL:[NSURL URLWithString:model.card_icon] placeholderImage:[UIImage imageNamed:@"placeholder_rectangle"]];
  89. NSMutableAttributedString *nameAttStr = [[NSMutableAttributedString alloc] initWithString:model.name];
  90. if (model.keywords.count > 1) {
  91. NSTextAttachment *att = [[NSTextAttachment alloc] init];
  92. att.image = [UIImage imageNamed:@"ic_blue"];
  93. att.bounds = CGRectMake(8, 0, 16*SCREEN_MUTI, 16*SCREEN_MUTI);
  94. NSAttributedString *attStr = [NSAttributedString attributedStringWithAttachment:att];
  95. [nameAttStr appendAttributedString:attStr];
  96. NSTextAttachment *att1 = [[NSTextAttachment alloc] init];
  97. att1.image = [UIImage imageNamed:@"ic_red"];
  98. att1.bounds = CGRectMake(16, 0, 16*SCREEN_MUTI, 16*SCREEN_MUTI);
  99. NSAttributedString *attStr1 = [NSAttributedString attributedStringWithAttachment:att1];
  100. [nameAttStr appendAttributedString:attStr1];
  101. } else if (model.keywords.count == 1) {
  102. if ([model.keywords[0] isEqualToString:@"礼"]) {
  103. NSTextAttachment *att1 = [[NSTextAttachment alloc] init];
  104. att1.image = [UIImage imageNamed:@"ic_red"];
  105. att1.bounds = CGRectMake(8, 0, 16*SCREEN_MUTI, 16*SCREEN_MUTI);
  106. NSAttributedString *attStr1 = [NSAttributedString attributedStringWithAttachment:att1];
  107. [nameAttStr appendAttributedString:attStr1];
  108. } else if ([model.keywords[0] isEqualToString:@"荐"]) {
  109. NSTextAttachment *att = [[NSTextAttachment alloc] init];
  110. att.image = [UIImage imageNamed:@"ic_blue"];
  111. att.bounds = CGRectMake(8, 0, 16*SCREEN_MUTI, 16*SCREEN_MUTI);
  112. NSAttributedString *attStr = [NSAttributedString attributedStringWithAttachment:att];
  113. [nameAttStr appendAttributedString:attStr];
  114. }
  115. }
  116. cell.nameView.attributedText = nameAttStr;
  117. cell.adView.text = model.desc;
  118. NSMutableAttributedString *personsAttStr = [[NSMutableAttributedString alloc] initWithString:@"申请人数:" attributes:@{NSForegroundColorAttributeName:[UIColor KXColorWithHex:0x666666]}];
  119. NSAttributedString *personsAtt = [[NSAttributedString alloc] initWithString:model.apply_num attributes:@{NSForegroundColorAttributeName:[UIColor KXColorWithHex:0xe42a2a]}];
  120. [personsAttStr appendAttributedString:personsAtt];
  121. cell.personsView.attributedText = personsAttStr;
  122. return cell;
  123. }
  124. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  125. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  126. [cell setSeparatorInset:UIEdgeInsetsMake(0, LEADING_SPACE, 0, LEADING_SPACE)];
  127. }
  128. }
  129. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  130. return 83*SCREEN_MUTI;
  131. }
  132. //- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  133. //
  134. // UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40*SCREEN_MUTI)];
  135. // header.backgroundColor = [UIColor KXColorWithRed:239 green:239 blue:244];
  136. //
  137. // UIImageView *hotImageView = [[UIImageView alloc] initWithFrame:CGRectMake(14, (40-18)/2*SCREEN_MUTI, 18*SCREEN_MUTI, 18*SCREEN_MUTI)];
  138. // hotImageView.image = [UIImage imageNamed:@"main_hot"];
  139. // [header addSubview:hotImageView];
  140. //
  141. // UILabel *hotLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(hotImageView.frame)+10, 0, 150, 40*SCREEN_MUTI)];
  142. // hotLabel.text = @"热门信用卡";
  143. // hotLabel.textColor = [UIColor KXColorWithHex:0x595959];
  144. // hotLabel.font = FONT_SYS(14*SCREEN_MUTI);
  145. // [header addSubview:hotLabel];
  146. //
  147. // return header;
  148. //}
  149. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  150. //
  151. // return 40*SCREEN_MUTI;
  152. //}
  153. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  154. self.index = indexPath.item;
  155. KXCreditCardModel *model = self.dataSource[indexPath.row];
  156. NSString *urlString=[NSString stringWithFormat:@"%@/CreditCard/add",URL];
  157. [KXHTTP post:urlString params:@{@"product_id":model.ID} success:^(id json) {
  158. NSString *username = [[NSUserDefaults standardUserDefaults]valueForKey:USER_NAME];
  159. if (!username) {
  160. KXLittleLogginView *littleView = [[KXLittleLogginView alloc]initWithFrame:self.view.bounds];
  161. littleView.delegate = self;
  162. [self.view addSubview:littleView];
  163. }else{
  164. [MobClick event:@"creditListClick"];
  165. KXBaseLinkViewController *webVC = [[KXBaseLinkViewController alloc] init];
  166. webVC.nameStr = @"申请信用卡";
  167. webVC.linkString = model.url;
  168. [self.navigationController pushViewController:webVC animated:YES];
  169. }
  170. } failure:^(NSError *error) {
  171. }];
  172. }
  173. #pragma mark =======================KXLittleLogginViewDelegate================
  174. - (void)littleLogginViewSuccess
  175. {
  176. KXCreditCardModel *model = self.dataSource[self.index];
  177. NSString *urlString=[NSString stringWithFormat:@"%@/CreditCard/add",URL];
  178. [KXHTTP post:urlString params:@{@"product_id":model.ID} success:^(id json) {
  179. KXBaseLinkViewController *webVC = [[KXBaseLinkViewController alloc] init];
  180. webVC.nameStr = @"申请信用卡";
  181. webVC.linkString = model.url;
  182. [self.navigationController pushViewController:webVC animated:YES];
  183. } failure:^(NSError *error) {
  184. }];
  185. }
  186. - (void)didReceiveMemoryWarning {
  187. [super didReceiveMemoryWarning];
  188. // Dispose of any resources that can be recreated.
  189. }
  190. #pragma mark lazy loading
  191. - (NSMutableArray *)dataSource {
  192. if (!_dataSource) {
  193. _dataSource = [NSMutableArray array];
  194. }
  195. return _dataSource;
  196. }
  197. /*
  198. #pragma mark - Navigation
  199. // In a storyboard-based application, you will often want to do a little preparation before navigation
  200. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  201. // Get the new view controller using [segue destinationViewController].
  202. // Pass the selected object to the new view controller.
  203. }
  204. */
  205. @end